Repository navigation
Fix torch.compile(fullgraph=True) of selective_log_softmax_and_entropy on torch 2.6 - #7719
Merged
Merged
Conversation
β¦fullgraph on torch 2.6
|
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. |
3 tasks done
qgallouedec
self-requested a review
October 15, 2026 05:07
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.
This PR makes
trl.kernels.selective_log_softmax_and_entropycompile withtorch.compile(fullgraph=True)on torch 2.6.Fix #7715.
Motivation
On torch 2.6, Dynamo can't trace
Tensor.stride()inside the backward of atorch.autograd.Functionin fullgraph mode. The backward of_LogProbEntropyFunctionread the strides ofindex,row_maskand the gradient tensor, so compiling withfullgraph=TrueraisedUnsupported: Illegal getattr invocation stride in strict mode. This was found while working on #7642 (torch 2.6.0 floor).Solution
The backward no longer calls
.stride(). It reuses the strides computed in the forward pass, and since the gradient tensor is allocated contiguous, its strides come from its shape.Changes
indexandrow_maskstrides onctxin the forward pass and reuse them in the backward pass.grad_logitsfrom its shape.Note
Low Risk
Stride plumbing only; kernel math and pointer logic are unchanged, with contiguous
grad_logitsstrides matching the prior_layoutresult.Overview
Fixes
torch.compile(fullgraph=True)failures forselective_log_softmax_and_entropyon PyTorch 2.6, where Dynamo rejects.stride()inside the backward of_LogProbEntropyFunction.Forward now stores
indexand mask batch/row strides onctx(index_strides,mask_strides) alongside the existing layout metadata. Backward reads those saved values instead of recomputing strides via_layout()(which calledtensor.stride()). For the contiguousgrad_logitsbuffer, strides are derived from shape as(rows_per_batch * n_cols, n_cols)rather than introspecting the tensor. Mask pointer selection is unchanged in behavior (indexwhen mask is absent, elserow_mask).Reviewed by Cursor Bugbot for commit 9c8a235. Bugbot is set up for automated code reviews on this repo. Configure here.