Skip to content

Conversation

@michaelbenayoun
Copy link
Member

What does this PR do?

XLA-friendly gradient checkpointing function that accept keyword arguments.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

from torch_xla.utils.checkpoint import checkpoint

fn_with_kwargs = partial(fn, **kwargs)
return checkpoint(fn_with_kwargs, *args)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the other way around:

Suggested change
return checkpoint(fn_with_kwargs, *args)
return checkpoint(*args, fn_with_kwargs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the first argument must be the function we checkpoint, check here.

Copy link
Collaborator

@tengomucho tengomucho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this function? Can you provide a test that shows its usage and tests that it works?

@michaelbenayoun
Copy link
Member Author

michaelbenayoun commented Dec 15, 2025

why do you need this function? Can you provide a test that shows its usage and tests that it works?

It is just a wrapper around the original checkpoint function. The goal is to make it possible to pass keyword arguments to the function we are wrapping with checkpoint.

I can add a test, but you mentioned many times that the CI was too long. For such a small change I was not considering it, please confirm you want a test.

if self.gradient_checkpointing and self.training:
hidden_states = checkpoint(
decoder_layer.__call__,
hidden_states = checkpoint_with_kwargs(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you change this here, only for granite, but not for the other models. I think you should change it everywhere, or nowhere, or explain why you only changed it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont undertsand? We change it "everywhere".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants