Skip to content

Fix virtual pipeline support - #1249

Open
cjwystz wants to merge 6 commits into
flagos-ai:mainfrom
cjwystz:main
Open

Fix virtual pipeline support#1249
cjwystz wants to merge 6 commits into
flagos-ai:mainfrom
cjwystz:main

Conversation

@cjwystz

@cjwystz cjwystz commented Jul 23, 2026

Copy link
Copy Markdown

PR Category

Train

PR Types

New Features

PR Description

Modifications

  • Add vp_stage parameter to get_qwen35_language_model_spec() and implement full parameter transmission
  • Introduce vp_stage parameter into get_qwen35_mtp_block_spec() to complete parallel adaptation for MTP module
  • Pass vp_stage to experimental attention variant structure function to ensure correct layer offset calculation
  • Parse and inject vp_stage into model instances within model_provider
  • Add judgment logic for intermediate VPP chunks in batch acquisition to avoid excessive data iterator reading
  • Extract virtual pipeline stage identifier in forward_step and pass it down to data interface
  • Remove VPP restrictions for vision encoder and implement dynamic layer number calculation under VPP mode
  • Supplement vp_stage argument for train_valid_test_dataloaders_provider to unify global calling interfaces

Background

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_stage parameter, 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

  1. Adaptation in layer_specs.py
    Add optional parameter vp_stage=None to 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.

  2. 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.

  3. Training Pipeline Upgrade in train_qwen35.py
    Extract vp_stage from 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

  • Verified stable training on 16-GPU cluster with no runtime exceptions
  • Verified correct layer allocation with 10 layers configured per virtual pipeline stage
  • Confirmed MTP blocks are only constructed on the last virtual chunk of final pipeline stage
  • Fixed excessive data reading issue and ensured consistent batch data alignment across all chunks
  • Verified accurate layer calculation and normal operation of vision encoder under VPP mode
  • Training throughput meets expected performance indicators

Impact Scope

  • Compatibility: vp_stage is set to None by default. All original logic remains unchanged when VPP is disabled.
  • Affected Modules: Qwen35 language backbone, MTP multi-token prediction module, multimodal vision encoder

Contributors

tengqm and others added 6 commits July 18, 2026 19:16
…#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.
@CLAassistant

CLAassistant commented Jul 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

6 participants