Skip to content

Tests: tensor parallel parity for gated-query attention (Qwen3.5); skip missing model types before the ranks start - #17870

Merged
danielhanchen merged 3 commits into
mainfrom
tp-gated-query-heads
Nov 15, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
tp-gated-query-heads

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Test coverage for tensor parallel on gated-query attention (Qwen3.5 / Qwen3-Next), plus a test-harness fix. The product fix itself landed on main in #17785, which counts gated-query heads from the config. This PR now only adds tests.

What the tests pin

  • Qwen3.5 parity under TP: the cross-architecture gloo parity test (tests/test_parallel_general_gloo.py) gains a tiny qwen3_5_text case, with one Gated DeltaNet layer and one gated attention layer. q_proj emits [query | gate] per head. Before the fix, the plan recorded twice the heads, and UNSLOTH_TP_SIZE=2 crashed in SDPA on the first forward. That crash reproduced on Kaggle 2xT4 and gloo CPU. With main's head count, the loss matches one process and grads are within 1e-6.
  • Skip before the ranks start: a case whose model type the installed transformers lacks now skips before any rank starts. On transformers 4.57.6 the skip used to run inside the spawned ranks, which killed both ranks and errored every case in the module.

Results

transformers 5.22.1: -k qwen3_5 passes on current main.

…o_proj

Qwen3.5 / Qwen3-Next / Qwen3.5-MoE attention has q_proj emit [query | gate] per head (2 * head_dim rows each)
while o_proj reads one head_dim per head. _attention_sizes divided the q_proj rows by head_dim, so the plan
recorded twice the heads and set each rank's num_attention_heads to 4 where it held 2, and the first
forward under UNSLOTH_TP_SIZE=2 crashed in SDPA ('size of tensor a (2) must match ... (4) at dimension 1'),
on Kaggle 2xT4 and on gloo CPU alike. Contiguous row shards already hold whole [query | gate] blocks, so
only the count changes. The gloo cross-architecture parity test gains a tiny qwen3_5_text (one Gated
DeltaNet layer, one gated attention layer): crash before, loss equal and grads within 1e-6 of one process
after.
… lacks before the ranks run

build() calls pytest.skip for a missing model type; inside a spawned gloo rank that Skipped (a BaseException)
escaped _case_tp's per-architecture except and killed both ranks, so on transformers < 5.2 the new
qwen3_5_text case turned every tensor parallel test of the module into 'rank exit codes [1, 1]'. The case
now records the skip in the parent's result and the test skips.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 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-15T19:25:14.990320Z 6e88667 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 6e886678ba

ℹ️ 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 changed the title Tensor parallel: count gated-query heads (Qwen3.5 / Qwen3-Next) from o_proj Tests: tensor parallel parity for gated-query attention (Qwen3.5); skip missing model types before the ranks start Nov 15, 2026
@danielhanchen
danielhanchen merged commit 60cb819 into main Nov 15, 2026
@danielhanchen
danielhanchen deleted the tp-gated-query-heads branch November 15, 2026 22:34
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 16, 2026
Final comment pass for recently merged PRs.

Trims comments added by unslothai#17660, unslothai#17806, unslothai#17807, unslothai#17808, unslothai#17812, unslothai#17830,
unslothai#17854, unslothai#17857 and unslothai#17870 that are still on main.
Multi-line explanations are collapsed to one line, and comments that
restate the code are removed.
Comments that explain a version quirk or a correctness trap are kept,
along with license headers and pragmas.
Changed comment lines: unslothai#17660 5 -> 2, unslothai#17806 4 -> 2, unslothai#17808 1 -> 0,
unslothai#17830 3 -> 1, unslothai#17857 1 -> 0. unslothai#17807, unslothai#17812, unslothai#17854 and unslothai#17870 are
unchanged.
Overall: 6 files, 14 lines removed, 5 added. Only comments change: the
AST check (comment_tools.py check) and the pre-push gate both pass.
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