Skip to content

fix: XLNet: relative_positional_encoding computes on CPU every forward#44782

Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom
JiwaniZakir:fix/issue-44737
Mar 19, 2026
Merged

fix: XLNet: relative_positional_encoding computes on CPU every forward#44782
Rocketknight1 merged 1 commit intohuggingface:mainfrom
JiwaniZakir:fix/issue-44737

Conversation

@JiwaniZakir
Copy link
Copy Markdown
Contributor

Fixes #44737

XLNetModel.relative_positional_encoding was creating all torch.arange tensors on CPU by default, then calling .to(output_h.device) at the call site to move them. Adds a device parameter to relative_positional_encoding in src/transformers/models/xlnet/modeling_xlnet.py and passes it through to all four torch.arange calls (freq_seq, fwd_pos_seq, bwd_pos_seq). The call site in XLNetModel.forward is updated to pass device=output_h.device directly, eliminating the redundant .to() transfer. Verified by running the XLNet model forward pass on GPU and confirming no CPU-GPU tensor transfers occur in relative_positional_encoding.

@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: xlnet

@Rocketknight1
Copy link
Copy Markdown
Member

run-slow: xlnet

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

LGTM, will merge after slow tests

@github-actions
Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/xlnet"]
quantizations: []

@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 3d09aa1b workflow commit (merge commit)
PR d7659c10 branch commit (from PR)
main 09fea1e6 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@Rocketknight1 Rocketknight1 added this pull request to the merge queue Mar 18, 2026
@JiwaniZakir
Copy link
Copy Markdown
Contributor Author

Thanks @Rocketknight1 for triggering the slow tests — happy to wait for those to complete.

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Mar 18, 2026
@Rocketknight1 Rocketknight1 added this pull request to the merge queue Mar 19, 2026
Merged via the queue into huggingface:main with commit 70e454c Mar 19, 2026
24 checks passed
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.

XLNet: relative_positional_encoding computes on CPU every forward pass (missing device= in torch.arange)

3 participants