Fix virtual pipeline support - #1249
Open
cjwystz wants to merge 6 commits into
Open
Conversation
…#1240) Add standard Apache 2.0 copyright header (Copyright 2026 FlagOS Contributors) to all source files. - **703 files** stamped with Apache 2.0 headers - **80 files** with upstream copyright (HuggingFace, Physical Intelligence, NVIDIA) — left untouched - **104 files** with other licenses (51 MPL, 41 proprietary, 10 MIT, 2 BSD) — third-party/upstream code - **31 files** skipped by rule — binary, JSON, etc. This PR was written in part with the assistance of generative AI.
…. 2026/7/21 (flagos-ai#1244) <!-- Copyright 2026 FlagOS Contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> ### PR Category <!-- One of [ Train | Inference | Compress | Serve | RL | Core | Hardware | CICD | Tools | Others ] --> [CICD] ### PR Types <!-- One of [ User Experience | New Features | Bug Fixes | Improvements | Performance | Breaking Change| Deprecations | Test Case | Docs | Others ] --> Test Case ### PR Description <!-- Describe what you’ve done --> update golden value of functional_test hetero_train and train.
### PR Category <!-- One of [ Train | Inference | Compress | Serve | RL | Core | Hardware | CICD | Tools | Others ] --> Train ### PR Types <!-- One of [ User Experience | New Features | Bug Fixes | Improvements | Performance | Breaking Change| Deprecations | Test Case | Docs | Others ] --> Others ### PR Description <!-- Describe what you’ve done --> Update qwen3vl for the current `Megatron-LM-FL` and add functional tests.
Added vp_stage parameter to language model and MTP block spec functions for virtual pipeline support.
Refactor Qwen3.5 model training script to support virtual pipeline parallelism (VPP) by adding vp_stage parameter to relevant functions and updating model specifications accordingly.
cjwystz
requested review from
aoyulong,
heavyrain-lzy and
zhaoyinglia
as code owners
July 23, 2026 14:55
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.
PR Category
Train
PR Types
New Features
PR Description
Modifications
vp_stageparameter toget_qwen35_language_model_spec()and implement full parameter transmissionvp_stageparameter intoget_qwen35_mtp_block_spec()to complete parallel adaptation for MTP modulevp_stageto experimental attention variant structure function to ensure correct layer offset calculationvp_stageinto model instances withinmodel_providerforward_stepand pass it down to data interfacevp_stageargument fortrain_valid_test_dataloaders_providerto unify global calling interfacesBackground
Virtual Pipeline Parallelism (VPP) is an efficient mainstream parallel optimization in Megatron-LM. It splits each physical pipeline stage into multiple virtual stages and adopts interleaved scheduling to reduce pipeline bubbles, thus significantly improving overall training throughput in distributed large model scenarios.
The original Qwen35 training framework lacked support for the
vp_stageparameter, leading to multiple adaptation defects. The language model failed to compute accurate layer offsets under VPP and triggered assertion errors. The MTP module could not determine the correct deployment rank without virtual stage identification. Intermediate virtual chunks kept consuming data iterators and caused data disorder. Besides, the vision encoder was incompatible with VPP scheduling, making full VPP acceleration unavailable for the whole multimodal model.Implementation Details
Adaptation in layer_specs.py
Add optional parameter
vp_stage=Noneto language model and MTP specification functions. Transmit the parameter down to transformer block definition functions to calculate precise layer offsets when VPP is enabled. Meanwhile, judge whether to initialize MTP branches according to current virtual pipeline stage.Vision Encoder Optimization in transformer_config.py
Delete original assertions that disabled VPP for vision modules. Add logic to obtain virtual pipeline parallel world size and dynamically adjust total layer numbers of vision encoder, enabling unified VPP support for both text and vision branches.
Training Pipeline Upgrade in train_qwen35.py
Extract
vp_stagefrom keyword arguments and pass it into models during initialization. Add identification rules for intermediate VPP chunks, which skip loading new data while retaining position id and attention mask calculation required by RoPE. Deliver virtual stage information in forward process and skip redundant vision data assembly. Update dataloader provider function signature to be fully compatible with VPP scheduler calling standards.Tests
Impact Scope
vp_stageis set to None by default. All original logic remains unchanged when VPP is disabled.Contributors