Skip to content

Fix CUDA Graph breaking host to device copy from scalar tensor allocation - #47547

Merged
hmellor merged 4 commits into
mainfrom
gemma-4-cuda-graphs
Jul 29, 2026
Merged

Fix CUDA Graph breaking host to device copy from scalar tensor allocation#47547
hmellor merged 4 commits into
mainfrom
gemma-4-cuda-graphs

Conversation

@hmellor

@hmellor hmellor commented Jul 25, 2026

Copy link
Copy Markdown
Member

CI

Fixed a CUDA-graph-capture crash in several models by replacing torch.tensor(self.config.<x>_token_id, device=inputs_embeds.device) (a host→device copy that graph capture forbids) with torch.full((), self.config.<x>_token_id, dtype=torch.long, device=inputs_embeds.device), which fills the scalar directly on-device.

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@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.

@vasqu vasqu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Careful approval because it totally makes sense BUT 2 things

  1. Can we add a small test that catches this
  2. I think pretty much any of our placeholder mask code uses simple torch.tensor, so we could apply this across all models

cc @zucchini-nlp @IlyasMoutawwakil just in case

@hmellor

hmellor commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

@vasqu I could add an mlinter rule?

@vasqu

vasqu commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Sure why not tbh

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@vasqu

vasqu commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Can we update the title of the PR please 😬

@hmellor hmellor changed the title Make Gemma 4 CUDA Graph compilable Fix CUDA Graph breaking host to device copy from scalar tensor allocation Jul 28, 2026
@hmellor

hmellor commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Updated the title and description

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 30153404874:1
Result: failure | Jobs: 8 | Tests: 1,559 | Failures: 0 | Duration: 0s

@hmellor
hmellor enabled auto-merge July 29, 2026 08:19
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: aria, audioflamingo3, aya_vision, blip_2, bloom, chmv2, cohere2_vision, conditional_detr, cosmos3_edge, cosmos3_omni, d_fine, deepseek_ocr2, deepseek_vl, deepseek_vl_hybrid, deimv2, detr

@hmellor
hmellor added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit 0f93ffa Jul 29, 2026
112 checks passed
@hmellor
hmellor deleted the gemma-4-cuda-graphs branch July 29, 2026 11:25
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
…tion (huggingface#47547)

* Make Gemma 4 CUDA Graph compilable

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

* fix everywhere

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

* Run modular conversion for instructblipvideo

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

3 participants