feat(multimodal): migrate Qwen3.5-VL to HybridModel - #6315
Draft
BestJuly wants to merge 1 commit into
Draft
Conversation
The GPTModel code path is being deprecated, so move the examples/multimodal_dev
Qwen3.5-VL language decoder from GPTModel to HybridModel.
- MultimodalModel / Qwen35VLModel now take a hybrid stack spec plus a unified
--hybrid-layer-pattern instead of a transformer layer spec and an MTP block
spec. Each historical Qwen block becomes two hybrid layers: a GatedDeltaNet
('G') or full-attention ('*') layer followed by a dense ('-') or MoE ('E')
MLP layer, reproducing the --linear-attention-freq 4 cadence of the GPT path.
MTP depths replicate the last block, as get_gpt_mtp_block_spec derived the
MTP spec from the final decoder layer.
- Add mrope support to HybridModel, mirroring GPTModel: build a
MultimodalRotaryEmbedding when position_embedding_type is 'mrope', and
compute the sectioned (optionally raw, fused-kernel) freqs in forward.
Widen the HybridModelConfig position_embedding_type literal accordingly.
- Because HybridModel counts one layer per pattern symbol, the Qwen variant
configs are converted from block counts to hybrid layer counts.
- Import fla.ops.cp.build_cp_context separately from the rest of FLA so that a
build without the CP extension still enables GatedDeltaNet, and raise a
descriptive error only when chunkwise CP is actually requested.
- run_qwen35_vl.sh derives the pattern from NUM_LAYERS, NUM_EXPERTS and the new
MTP_NUM_LAYERS knob, and only passes the MTP arguments when MTP is enabled.
The decoder checkpoint layout changes with this migration; see the README for
details on why existing GPTModel-format Qwen3.5-VL checkpoints are not directly
loadable.
Signed-off-by: Li Tao <lit@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
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
Migrate the
examples/multimodal_devQwen3.5-VL language decoder fromGPTModeltoHybridModel, ahead of the deprecation of the GPTModel code path.Why
The Qwen3.5-VL decoder is a hybrid GatedDeltaNet / full-attention stack. On the
GPT path that structure was expressed implicitly through
--experimental-attention-variant gated_delta_netplus--linear-attention-freq 4, with the attention/MLP ordering baked intoTransformerLayer.HybridModelexpresses it explicitly through--hybrid-layer-pattern, which is where this model family belongs long term.Changes
Model wiring (
examples/multimodal_dev)MultimodalModel/Qwen35VLModelnow takehybrid_stack_specandhybrid_layer_patterninstead of atransformer_layer_specand anmtp_block_spec.get_qwen35_vl_language_specis removed.G)or full-attention (
*) layer followed by a dense (-) or MoE (E) MLPlayer. Three GDN blocks then one attention block reproduces the
--linear-attention-freq 4cadence exactly.get_gpt_mtp_block_spec, whichderived the MTP spec from the final decoder layer.
because
HybridModelcounts one layer per pattern symbol.mRoPE support in
HybridModel(megatron/core/models/hybrid/hybrid_model.py)MultimodalRotaryEmbeddingwhenposition_embedding_type == 'mrope'and compute sectioned (optionally raw, fused-kernel) freqs in
forward,mirroring
GPTModelline for line, including theapply_rope_fusion/rotary_interleaved/fused_single_qkv_rope/inference conditions and the flash-decode
NotImplementedError.HybridModelConfig.position_embedding_typeliteral accordingly.GatedDeltaNet (
megatron/core/ssm/gated_delta_net.py)fla.ops.cp.build_cp_contextseparately from the rest of FLA so an FLAbuild without the CP extension still enables GatedDeltaNet, and raise a
descriptive error only when chunkwise CP is actually requested.
Launcher (
scripts/run_qwen35_vl.sh)NUM_LAYERS,NUM_EXPERTSand the newMTP_NUM_LAYERSknob; pass the MTP arguments only when MTP is enabled.NUM_LAYERSneed not be a multiple of 4: trailing blocks stay GatedDeltaNet,which is what
--linear-attention-freq 4produced, so shallow proxy runs keepworking.
Tests
examples/multimodal_dev/tests/test_hybrid_migration.py— factory wiring plusstructural equivalence between the hybrid pattern and the former GPT layout.
The key check cross-validates
validate_segment_layers(hybrid) againstget_linear_attention_pattern(GPT) so a semantic drift on either side fails.tests/unit_tests/models/test_hybrid_model.py—HybridModelconstructor withposition_embedding_type='mrope'.examples/multimodal_dev/tests/test_cp_thd_correctness.py— ported to thehybrid stack spec.
Checkpoint compatibility
The decoder checkpoint layout changes: one GPT decoder layer is split across two
hybrid layer indices, the final-norm key changes, and hybrid MTP uses a nested
HybridStack. An existing GPTModel-format Qwen3.5-VL checkpoint is therefore notdirectly loadable.
tools/checkpoint/gpt_hybrid_conversion.pydoes not coverthis case either — it explicitly rejects GDN (
G) and MTP checkpoints. This isdocumented in
examples/multimodal_dev/README.md.Scope of risk
The
megatron/corechanges are additive: the mRoPE branches only run whenposition_embedding_type == 'mrope', which no existingHybridModelconfiguration uses, and the FLA import change only alters behavior on builds
that lack
fla.ops.cp. Everything else is confined toexamples/multimodal_dev.