Skip to content

Sync Dynamic-CP feature from dev to main - #5279

Closed
ilml wants to merge 1 commit into
NVIDIA:mainfrom
ilml:sync-dynamic-cp-dev-to-main
Closed

Sync Dynamic-CP feature from dev to main#5279
ilml wants to merge 1 commit into
NVIDIA:mainfrom
ilml:sync-dynamic-cp-dev-to-main

Conversation

@ilml

@ilml ilml commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Ports the Dynamic CP (dynamic context parallelism) feature from the dev branch to main, superseding the Hybrid Context Parallel implementation (#2282) with the evolved design from dev PRs #2000 (Dynamic CP part 2), #3405 (THD+rope fix and Dynamic-CP naming), #4226 (minor improvements), and follow-up fixes.

What's included

Core feature files — byte-identical copies from dev:

  • megatron/core/datasets/data_schedule.pyBasePackingScheduler, DpBalancedScheduler, DefaultDynamicCPScheduler, wrap_data_iterator, get_batch_on_this_rank_for_sequence_packing (keeps HybridCPDataLoaderWrapper for compatibility)
  • megatron/core/datasets/data_schedule_utils.py — new module (scheduling/rerouting/packing helpers)
  • megatron/core/parallel_state.py — dynamic DPxCP group helpers (get_dynamic_data_context_parallel_groups)
  • megatron/core/packed_seq_params.py, megatron/core/datasets/readme.md

Surgical ports (only dynamic-CP hunks; unrelated dev-only features excluded):

  • megatron/training/arguments.py--dynamic-context-parallel, --min-dynamic-context-parallel-size, --sequence-packing-scheduler + validation
  • megatron/core/model_parallel_config.py — new config fields; hybrid_context_parallel kept as a deprecated alias
  • megatron/core/extensions/transformer_engine.py — adds get_thd_partitioned_indices and dynamic-CP group selection in TEDotProductAttention
  • packed-seq/cu_seqlens plumbing in attention.py, multi_latent_attention.py, absorbed_mla.py, multi_token_prediction.py, gpt_model.py, gated_delta_net.py, mamba_mixer.py, mamba_context_parallel.py, schedules.py, gpt_dataset.py, sft_dataset.py, data_samplers.py, core/utils.py, transformer_config.py, initialize.py
  • megatron/training/training.py / pretrain_gpt.py — replace HybridCPDataLoaderWrapper wiring with dev's wrap_data_iterator pattern

Rename fallout (main-only callers updated):

  • pretrain_hybrid.py, megatron/elastification/pretrain_hybrid_flex.pyargs.dynamic_context_parallel + renamed group helper import
  • tools/prepare_cache.py — drops the removed hybrid_context_parallel dataset-config kwarg (mirrors dev)
  • Existing unit tests minimally synced from dev so they keep passing after the rename (test_parallel_state.py, test_get_batch.py, test_hybrid_moe_model.py golden config). No new tests added.

Breaking change

The CLI flag --hybrid-context-parallel is renamed to --dynamic-context-parallel (matching dev). The ModelParallelConfig.hybrid_context_parallel field remains as a deprecated alias that maps to dynamic_context_parallel with a DeprecationWarning.

Verification

  • Every changed file passes python3 -m py_compile.
  • Core feature files verified byte-identical to origin/dev.
  • black/isort clean on all changed megatron/core/ and tests/ files (CI formatting scope).
  • Cross-file audit: no remaining references to removed symbols (get_hybrid_data_context_parallel_groups, args.hybrid_context_parallel) outside the intentional deprecated-alias sites.

🤖 Generated with Claude Code

Port the Dynamic CP (dynamic context parallelism) feature from the dev
branch, superseding the Hybrid Context Parallel implementation (NVIDIA#2282)
with the evolved design from dev PRs NVIDIA#2000, NVIDIA#3405, NVIDIA#4226 and follow-up
fixes.

- Copy the packing schedulers (BasePackingScheduler, DpBalancedScheduler,
  DefaultDynamicCPScheduler), wrap_data_iterator and
  get_batch_on_this_rank_for_sequence_packing into
  megatron/core/datasets/data_schedule.py, and add
  megatron/core/datasets/data_schedule_utils.py (both byte-identical to
  dev), keeping HybridCPDataLoaderWrapper for compatibility.
- Rename --hybrid-context-parallel to --dynamic-context-parallel; keep
  hybrid_context_parallel as a deprecated alias on ModelParallelConfig.
- Add min_dynamic_context_parallel_size and sequence_packing_scheduler
  knobs with validation.
- Add get_thd_partitioned_indices to transformer_engine.py and thread
  packed-seq/cu_seqlens plumbing through attention, MLA, MTP, mamba/GDN
  and the GPT model, matching dev.
- Replace the HybridCPDataLoaderWrapper wiring in training.py and
  pretrain_gpt.py with dev's wrap_data_iterator pattern, and update
  parallel_state dynamic DPxCP group helpers (byte-identical to dev).
- Update main-only callers (pretrain_hybrid.py, tools/prepare_cache.py,
  megatron/elastification/pretrain_hybrid_flex.py) and existing unit
  tests for the rename.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ilml ilml closed this Jun 11, 2026
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.

1 participant