fix: XLNet: relative_positional_encoding computes on CPU every forward#44782
Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom Mar 19, 2026
Merged
fix: XLNet: relative_positional_encoding computes on CPU every forward#44782Rocketknight1 merged 1 commit intohuggingface:mainfrom
Rocketknight1 merged 1 commit intohuggingface:mainfrom
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: xlnet |
Member
|
run-slow: xlnet |
Rocketknight1
approved these changes
Mar 18, 2026
Member
Rocketknight1
left a comment
There was a problem hiding this comment.
LGTM, will merge after slow tests
Contributor
|
This comment contains models: ["models/xlnet"] |
|
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. |
Contributor
Author
|
Thanks @Rocketknight1 for triggering the slow tests — happy to wait for those to complete. |
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.
Fixes #44737
XLNetModel.relative_positional_encodingwas creating alltorch.arangetensors on CPU by default, then calling.to(output_h.device)at the call site to move them. Adds adeviceparameter torelative_positional_encodinginsrc/transformers/models/xlnet/modeling_xlnet.pyand passes it through to all fourtorch.arangecalls (freq_seq,fwd_pos_seq,bwd_pos_seq). The call site inXLNetModel.forwardis updated to passdevice=output_h.devicedirectly, eliminating the redundant.to()transfer. Verified by running the XLNet model forward pass on GPU and confirming no CPU-GPU tensor transfers occur inrelative_positional_encoding.