### Checklist / 检查清单 - [x] I have searched existing issues, and this is a new feature request. / 我已经搜索过现有的 issues,确认这是一个新的 Feature Request。 ### Feature Request Description / Feature Request 描述 ### 背景 megatron 已经在 2026.7.4 通过 https://github.com/NVIDIA/Megatron-LM/pull/5087 添加了对 DSv4 系列的 CP 支持. ### 问题描述 使用主线上最新 commit 的 ms-swift + mcore-bridge + Megatron-LM + Transformer Engine 2.16.1 对 DeepSeek V4 Flash 进行 `megatron sft` 时, 尝试开启 CP 并行, 在补充 DSv4 CP 所需的 `sequence_packing_scheduler` 和 `cp_partition_mode=contiguous` 后,模型已经能够进入 Megatron 的 DSv4 THD CP 路径,但随后在 `csa.py::_forward_thd_cp()` 中报错: ```text File ".../mcore_bridge/model/gpts/deepseek_v4.py", line 279, in forward core_attn_out = self.core_attention( File ".../megatron/core/transformer/experimental_attention_variant/csa.py", line 1803, in forward output = self._forward_thd_cp( File ".../megatron/core/transformer/experimental_attention_variant/csa.py", line 2278, in _forward_thd_cp raise RuntimeError( RuntimeError: DSv4 THD CP path requires boundary_hidden and boundary_kv from the hidden-only boundary exchange and boundary KV projection path. ``` 看起来 `padding_free=true` 后,DSv4 attention 已经进入 THD CP 分支;但是 mcore-bridge 的 `mcore_bridge/model/gpts/deepseek_v4.py` 中还没有同步实现 Megatron 里 DeepSeek-V4 Hybrid Attention 的 boundary exchange 逻辑 (没有向 `core_attention` 传入 `boundary_hidden` 和 `boundary_kv`) ### `megatron sft` 的参数 ```bash --padding_free true \ --context_parallel_size 2 \ --tensor_model_parallel_size 1 \ --sequence_parallel false \ --megatron_extra_kwargs '{"sequence_packing_scheduler":"dp_balanced","cp_partition_mode":"contiguous","max_seqlen_per_dp_cp_rank":2048}' \ --group_by_length false ``` ### 初步分析 Megatron-LM dev 中 DeepSeek-V4 Hybrid Attention 的 CP 实现似乎已经新增了 THD CP boundary 逻辑 1. 在 THD CP 路径下调用 boundary hidden exchange 2. 将 `boundary_hidden` 传入 `get_query_key_value_tensors()` 3. 对 boundary hidden 做 KV projection,得到 `boundary_kv` 4. 在调用 `core_attention()` 时传入:`boundary_hidden` 和 `boundary_kv` ### 期望行为 期望 mcore-bridge 能够为 DeepSeek-V4 补充与 Megatron-LM dev 对齐的 CP boundary 支持, 由此支持 DeepSeek V4 的 CP 并行. ### 复现 使用 ms-swift `megatron sft` 微调 DeepSeek-V4-Flash; 1. 设置: ```bash --padding_free true --context_parallel_size 2 --tensor_model_parallel_size 1 --sequence_parallel false ``` 2. 通过 `megatron_extra_kwargs` 补充: ```json { "sequence_packing_scheduler": "dp_balanced", "cp_partition_mode": "contiguous", "max_seqlen_per_dp_cp_rank": 2048 } ``` 3. 训练进入 forward 后,在 DSv4 THD CP attention 分支报错: ```text RuntimeError: DSv4 THD CP path requires boundary_hidden and boundary_kv from the hidden-only boundary exchange and boundary KV projection path. ``` ### Pull Request / Pull Request 信息 请问目前是否有支持 DeepSeek V4 系列 CP 并行的计划, 参考 Megatron 的实现补齐所需的两个参数?