feat(model): accept pre-sharded packed Qwen3-VL inputs - #4917
Merged
Conversation
Contributor
Author
|
/ok to test 449ced7 |
Contributor
Author
|
/ok to test edbd870 |
Contributor
Author
|
/ok to test edbd870 |
Contributor
Author
|
/ok to test e7cdad0 |
Detect THD inputs that already use MCore zigzag context-parallel layout, skip a second partition, and select matching vision and deepstack rows with a count-only CP collective. Adapted from the original algorithm by Zhichen Zeng (@Zhichenzzz): radixark@eeb84d7 Current-main integration based on Yusheng Su (@yushengsu-thu): radixark@390f983 Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
yaoyu-33
force-pushed
the
yuya/feat-qwen-vl-pre-sharded-cp-input
branch
from
July 23, 2026 23:23
e7cdad0 to
49a3fe5
Compare
Contributor
Author
|
/ok to test 49a3fe5 |
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.
What does this PR do ?
Accept Qwen3-VL packed THD inputs that a caller has already partitioned into Megatron's load-balanced zigzag context-parallel layout.
The current packed-CP path assumes
input_idsstill contains the full packed stream and always computes a local partition index. Some training frameworks pass rank-local tokens together with global packed-sequence metadata. Partitioning those tokens a second time either selects the wrong rows or fails before vision embeddings can be scattered.This PR recognizes that contract when the physical global token count equals
cp_size * local_token_count, validates that each packed segment can be divided into2 * cp_sizechunks, and skips the second partition. Because local token chunks no longer contain enough information to reconstruct multimodal positions, callers on this path must provide explicit rank-local 3D MRoPEposition_ids.Vision embeddings are still produced in full-sequence order. A count-only CP all-gather reconstructs the vision-token offset of each zigzag chunk and selects the rows owned by the local rank. The same indices are applied to deepstack features; ranks with no local visual tokens receive an empty selection.
Relationship to #4784
#4784 has landed, and this branch is now cleanly rebased onto current
main.This PR deliberately does not duplicate #4784's positional
autograd.Function.applyfix, reduce-scatter backward correction, placeholder dtype handling, or zero-image-rank hang fix. The combined CP path still needs to be revalidated on two GPUs before final approval.Attribution
The algorithm and current-main adaptation come from the radixark fork. This PR preserves those contributions directly:
The original downstream validation reported Qwen3-VL-2B CP2 with TP2/TP4, THD packing, healthy logprob differences of 0.0127-0.0131, and no NCCL timeout. Those GPU results belong to the original contributors and were not re-run in this adaptation.
Changelog
GitHub Actions CI
Local checks:
uv run --no-project --with pre-commit pre-commit run --all-files— passedgit diff --checkand Python compilation — passedThe focused tests used a temporary local import stub for CUDA/Transformer Engine modules unavailable on macOS; no stub is present in this branch. A normal full environment cannot be resolved locally because
nvidia-resiliency-extis Linux-only.Before marking ready, run in the standard Linux/GPU environment:
uv run python -m pytest tests/unit_tests/models/qwen_vl/modelling_qwen3_vl/test_model.py -k 'packed_input_pre_sharded or cp_local_vision_embed_indices or pre_sharded_packed_cp or applies_one_partition_index' -vvBefore your PR is "Ready for review"
Pre checks:
Additional Information