From 10b6f9056cfefe7dff0c1b3293903335931235ea Mon Sep 17 00:00:00 2001 From: weijia chen Date: Mon, 27 Jul 2026 15:36:42 -0700 Subject: [PATCH 1/2] fix(dsv4-cp): relax sequence_packing_scheduler assert for offline-packed THD DSv4 hybrid + CP > 1 previously required sequence_packing_scheduler, but offline-packed SFT supplies pre-packed THD data externally without the scheduler. Allow cp_partition_mode=contiguous as an alternative signal that THD inputs are externally provided, so Bridge offline-packed SFT does not need to set sequence_packing_scheduler to bypass the validation. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- megatron/core/transformer/transformer_config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/megatron/core/transformer/transformer_config.py b/megatron/core/transformer/transformer_config.py index f98680ce137..3a96bf84745 100644 --- a/megatron/core/transformer/transformer_config.py +++ b/megatron/core/transformer/transformer_config.py @@ -1536,7 +1536,11 @@ def __post_init__(self): ): assert ( self.sequence_packing_scheduler is not None - ), "DSv4 Hybrid with CP requires a sequence_packing_scheduler for THD inputs." + or self.cp_partition_mode == "contiguous" + ), ( + "DSv4 Hybrid with CP requires either a sequence_packing_scheduler for online THD packing, " + "or cp_partition_mode='contiguous' for externally pre-packed (offline) THD data." + ) if self.context_parallel_size > 1: if ( From efc4009147cc032ebf15899c936c659f49e69251 Mon Sep 17 00:00:00 2001 From: weijia chen Date: Thu, 30 Jul 2026 14:15:07 -0700 Subject: [PATCH 2/2] fix(dsv4-cp): remove sequence_packing_scheduler assert for DSv4 hybrid + CP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assert required sequence_packing_scheduler to be set for DSv4 hybrid with CP > 1, assuming THD inputs always come from MCore online packing. This blocked offline-packed SFT (externally pre-packed THD data) without a semantically correct workaround. Remove the assert entirely — the forward path already enforces THD format via ValueError("DSv4 Hybrid with CP requires qkv_format=thd") if THD data is not actually provided. Legitimate misconfigurations are caught at runtime. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- megatron/core/transformer/transformer_config.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/megatron/core/transformer/transformer_config.py b/megatron/core/transformer/transformer_config.py index 3a96bf84745..dca69debe32 100644 --- a/megatron/core/transformer/transformer_config.py +++ b/megatron/core/transformer/transformer_config.py @@ -1531,17 +1531,6 @@ def __post_init__(self): if self.cp_partition_mode not in ("zigzag", "contiguous"): raise ValueError(f"Unsupported cp_partition_mode: {self.cp_partition_mode}") - if self.experimental_attention_variant == "dsv4_hybrid" and ( - self.context_parallel_size > 1 or self.dynamic_context_parallel - ): - assert ( - self.sequence_packing_scheduler is not None - or self.cp_partition_mode == "contiguous" - ), ( - "DSv4 Hybrid with CP requires either a sequence_packing_scheduler for online THD packing, " - "or cp_partition_mode='contiguous' for externally pre-packed (offline) THD data." - ) - if self.context_parallel_size > 1: if ( self.experimental_attention_variant == "dsv4_hybrid"