Skip to content

[bugfix] support MTP-only pipeline stages - #155

Open
taking-lying-flat wants to merge 2 commits into
modelscope:mainfrom
taking-lying-flat:agent/fix-mtp-only-stage-spec
Open

[bugfix] support MTP-only pipeline stages#155
taking-lying-flat wants to merge 2 commits into
modelscope:mainfrom
taking-lying-flat:agent/fix-mtp-only-stage-spec

Conversation

@taking-lying-flat

@taking-lying-flat taking-lying-flat commented Jul 31, 2026

Copy link
Copy Markdown

Summary

  • build the complete model-specific decoder layer specs in the Qwen3.5/Qwen3Next GDN loader when constructing MTP
  • reuse the final global decoder layer spec for MTP, independent of the current PP/VP stage layout
  • keep the existing local decoder spec path and all other model loaders unchanged

Root cause

The Qwen3.5 397B pipeline layout can place MTP on a stage with no local decoder layers. Passing that empty local decoder block to Megatron's MTP builder causes it to index an empty layer_specs list.

Using Megatron's generic decoder helper directly would lose Qwen3.5's heterogeneous GDN/attention layer structure. The loader now generates its complete experimental-attention specs, applies the same Qwen-specific replacements used for local layers, and passes the final global decoder layer spec to the existing MTP builder.

Validation

  • flake8 and yapf on the changed file
  • pre-commit text hooks on the changed file
  • Python syntax compilation

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Comment thread src/mcore_bridge/model/register.py Outdated
for layer_type in stage
]

self.config.pipeline_model_parallel_layout = fallback_layout

@HowardZorn HowardZorn Aug 4, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看了看Megatron-LM的情况,这里他们用的是一个不切vp_stage的layout(但是mcore-bridge这里没有这样的函数get_gpt_decoder_layer_specs()),这里您的选择是去找第一个decoder layers,我觉得也可以。不过后续可能需要对齐一下

    if args.mtp_num_layers is not None:
        assert not (config.transformer_impl == "inference_optimized")
        if (
            hasattr(transformer_layer_spec, 'layer_specs')
            and len(transformer_layer_spec.layer_specs) == 0
        ):
            # Get the decoder layer spec explicitly if no decoder layer in the last stage,
            # Only happens with block spec (TransformerBlockSubmodules) when using MoE.
            transformer_layer_spec_for_mtp = _get_transformer_layer_spec(use_te, config)
        else:
            # Define the decoder block spec
            if args.experimental_attention_variant is not None:
                decoder_layer_specs = (
                    get_transformer_layer_with_experimental_attention_variant_spec(config=config)
                )
            else:
                decoder_layer_specs = get_gpt_decoder_layer_specs(
                    config,
                    use_transformer_engine=use_te,
                    normalization=args.normalization,
                    qk_l2_norm=args.qk_l2_norm,
                    vp_stage=vp_stage,
                )
            transformer_layer_spec_for_mtp = decoder_layer_specs[-1]
        # Use spec of the last layer in decoder block as spec of the transformer layer in MTP
        mtp_block_spec = get_gpt_mtp_block_spec(
            config, transformer_layer_spec_for_mtp, use_transformer_engine=use_te, vp_stage=vp_stage
        )

@HowardZorn

Copy link
Copy Markdown

@taking-lying-flat 我逐渐理解这个工程其实会变成每个experiment attention模型的loader都需要加料的情况,这样工程量可能有点大

@taking-lying-flat

Copy link
Copy Markdown
Author

@HowardZorn。 确实 不敢大重构 按照 Megatron-LM. 出现bug 就修复吧

@HowardZorn

Copy link
Copy Markdown

@HowardZorn。 确实 不敢大重构 按照 Megatron-LM. 出现 bug 就修复吧

@taking-lying-flat 感觉我们需要 @Jintao-Huang 来看看怎么样处理了。

@taking-lying-flat
taking-lying-flat marked this pull request as ready for review August 9, 2026 22:50
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.

2 participants