[docker] backport output-gate slicing when query groups < TP#2221
Open
LLMShark wants to merge 1 commit into
Open
[docker] backport output-gate slicing when query groups < TP#2221LLMShark wants to merge 1 commit into
LLMShark wants to merge 1 commit into
Conversation
LLMShark
marked this pull request as ready for review
July 20, 2026 08:05
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.
Summary
num_query_groups < tensor_model_parallel_size.Problem
slime currently pins Megatron to
1dcf0dafa884ad52ffb243625717a3471643e087. In that revision, the GQA projection is gathered when the number of query groups is smaller than the TP world size, andqueryis narrowed back to the heads owned by the local TP rank. The matchinggatetensor is reshaped but not narrowed.The reported Qwen3.5-397B-A17B failure used TP=8 with
num_attention_heads=32,num_query_groups=2,attention_output_gate=true, and head dimension 256:Before the fix, the reported gate shape was
[6144, 1, 16, 256]; the TP-local query/output owns 4 heads, so the matching gate must be narrowed to[6144, 1, 4, 256]before_apply_output_gate. The unsliced gate causes the invalidviewfailure.PR #1662 previously reduced a Qwen3.5 configuration from TP=4 to TP=2 because the model has two query groups. This backport fixes the underlying gated-attention partition mismatch instead of requiring TP to stay at or below the query-group count.
Fix
The added hunk is the production change from NVIDIA/Megatron-LM@16a8cdb: use the same TP-local slice for
gatethat Megatron already applies toquery.The existing Qwen3.5-0.8B test has 8 attention heads, 2 query groups, and output gating enabled. Moving it from TP=1 to TP=4 exercises the failing
num_query_groups < TPpath without increasing its existing four-GPU allocation.Validation
docker/patch/latest/megatron.patchwithgit apply --3wayto a clean checkout of the pinned Megatron commit; every hunk applied cleanly and no conflict markers were produced.git diff --checktests/test_qwen3.5_0.8B_gsm8k_short.pyThe full GPU training test was not run locally. Because this changes the image's Megatron patch,
run-ci-imageshould be used to validate the TP=4 Qwen3.5 E2E path on a rebuilt test image.