Open
Conversation
Remove the ctx parameter assumption from ensure_contiguous wrapper so it works with both legacy forward(ctx, ...) and new forward(...) signatures needed for setup_context pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
setup_contexttotorch.autograd.Functionsubclasses that use the legacyforward(ctx, ...)pattern, enabling compatibility withtorch.functransforms (torch.func.grad,torch.func.grad_and_value, etc.).Currently, any code that uses
torch.func.grad_and_value()with Liger-Kernel enabled crashes:This affects using
torch.func.grad_and_value()internally for chunked gradient computation.Details
For each
autograd.Function:ctxfromforward()signaturesetup_context(ctx, inputs, output)to handle context setupbackwardsignature to match new forward output countFunctions with
@amp_custom_fwd/@amp_custom_bwddecorators were skipped — these need separate handling due to the decorator assumingargs[0]isctx.Testing Done
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence