Skip to content

ROCm: pack hybrid models by default when flash varlen passes its self-check - #18611

Merged
danielhanchen merged 1 commit into
mainfrom
rocm-hybrid-packing-default
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
rocm-hybrid-packing-default

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #18313 and #17738.

Why ROCm was opt-in

#13383 made hybrid packing (Qwen3.5, Qwen3.5-MoE, Qwen3-Next, and the PLE layers from #14011) default-on for CUDA only. At the time UNSLOTH_EXPERIMENTAL_HYBRID_PACKING=1 failed closed on gfx1151 because the boundary-aware causal conv was not allowed on HIP (unsloth-zoo #2503 fixed that), and once it worked, the full attention layers still ran SDPA over a dense (T, T) mask on ROCm, so packing was a wash (#17738). #18313 moved ROCm packed rows onto torch's flash varlen behind a one-time self-check, which removes that cost.

Change

With the variable unset, _auto_hybrid_device_ok now also accepts a ROCm GPU when the #18313 self-check (hf_packed_attention._torch_varlen) passes on that device. The check runs once per device (about 0.3 s on gfx1151) and is cached. Everything else is unchanged:

  • The same mixer kinds as CUDA (gated delta and PLE), and the existing exactness probe still runs before any packing.
  • A ROCm build whose flash varlen fails the self-check keeps the padded path, with the reason logged.
  • =0 still turns packing off and =1 still opts in Mamba2 / split QKV mixers and other devices.
  • CUDA is unchanged.

The opt-in note from #17751 now says the path is "not on by default on this device" instead of naming CUDA only.

gfx1151, Linux, torch 2.11.0+rocm7.13, transformers 5.5.4

Fake Qwen3.5-4B shaped model (real 4B layer sizes, 4 layers, random weights), LoRA r=16, packing = True, max_length 2048, batch 4, variable unset vs =0. Two runs per arm.

arm packed median useful tok/s median s/step first losses
main, unset no (padded) 1691 2.96 12.9115, 12.9003, 12.9244
main, =0 no 1687 2.95 12.9115, 12.9003, 12.9244
this PR, unset yes 2417 3.38 12.9344, 12.8879, 12.9011
this PR, =0 no 1699 2.97 12.9115, 12.9003, 12.9244

Default ROCm runs now pack and train at about 1.42x the padded throughput. The packed losses are the same values #18313 measured for the opt-in path, and =0 is unchanged.

Tests

tests/utils/test_hybrid_packing_default.py adds a case with a ROCm GPU weight where the self-check passes (default-on) and fails (padded, reported as an opt-in device). Reverting the change fails the passing case.

@danielhanchen danielhanchen self-assigned this Nov 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T10:34:29.374556Z d6dd684 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: d6dd684d68

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 37da474 into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the rocm-hybrid-packing-default branch November 20, 2026 12:00
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.

1 participant