Merged
refactor(dsv3.2): remove the varlen-CP capability, keep the model #1150
hanboyouAdd on Oct 31
refactor(dsv3.2): remove the varlen-CP capability, keep the model #1150
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for hanboyou's contribution.)Oct 31 Added label: cann-cla/yes
CANN-robot
Oct 31 Comments:
Oct 31 Comments:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/torchtitan-npu | ✅ xuyujun, lrwei0709 (2/2) | ✅ xuyujun (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
mystri, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Oct 31 Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
Oct 31 Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
Oct 31 Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
Oct 31 Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
90 messages are collapsed here。 See more
Nov 2 Added label: lgtmapproved
Nov 2 Merged pull request
CANN-robot
Nov 2 Comments:
Nov 2 Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


23 days ago Associated issue: [RFC] TorchTitan v0.4.0 分阶段升级规划与进度跟踪
CANN-robot
23 days ago Comments:
23 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
与
!1146(cleanup/remove-deepseek-v32,整体删除 DeepSeek-V3.2)并列的窄范围方案:保留 V3.2 模型本身,只删除它的 CP 能力。两者都从dev_0.4.0出发;本 PR 的对比基线是cf686747。删除的 CP 面:
patches/torchtitan/distributed/varlen_cp.py:仅 V3.2 使用的 varlen-CP backport(上游 #3430),含CPVarlenMetadata/from_global;patches/torchtitan/distributed/context_parallel.py:_varlen_from_masks与patched_cp_shard的 legacy single-mask varlen 分支(它导入了被删的CPVarlenMetadata;V3.2 的 map 路径不经过这里);保留仓库自己的 doc-chunk load balancer 和apply()的 eager block-mask 改写;models/deepseek_v3_2/model.py:CPVarlenMetadata导入、AttentionMetadata的 CP 联合类型、ReferenceVarlenMetadata的 CP 拒绝、forward 里的 CP 类型检查;override/deepseek_v3_2/sparse_attn/ascendc.py:CPVarlenMetadata的 K/V gather 分支与AscVarlenMetadata.prepare_cp_metadata;test_cp_metadata.py,移除test_attn_gym_core.py/test_metadata_seam.py的 CP 用例、conftest.py的varlen_cpfixture 与失效的迁移跳过项;dsv3_2_dsa_cp2及其 README 条目(该用例原就只在 deferred suite 里,CP 配置已被 pinned decoder 拒绝);patches/torchtitan/README.md去掉 #3430,mtp.md说明 V3.2 自身不支持 CP。保留并仍受覆盖的路径:V3.2 参考核 / AscendC 核的 folded 之前的非 CP forward、MTP、metadata seam、doc-chunk CP(V4/V4.1)、共享 CP patch 的激活。
CP 的拒绝不再依赖本仓的第二道 metadata 守卫:
SparseInnerAttention.Config与AscSparseInnerAttention.Config都派生自VarlenAttention.Config,pinned decoder 在context_parallel_degree > 1时于配置阶段抛NotImplementedError: Context Parallel is not supported with ... VarlenAttention。这与本 PR 之前 reference core 的 rank-local 拒绝相比,拒绝时机更早、覆盖两个 backend。不改动:V3.2 的模型配置、sharding、checkpoint adapter、loss goldens、
run_tests.py里的 dsv3.2 deferred 注册(pre-fold 迁移仍是后续工作,见migration/dsv3.2-fold-batch-dim)。评审跟进(e1fe72f4)
torchtitan_npu/override/qwen3_5/parallelize.py中已死的k_global_gather_indices分支及其 mesh/batch 参数;Qwen3.5 的 CPU-only metadata 测试不再整模块 skip,只保留未迁移 CP 用例的 skip。AttentionMetadata别名与build_reference_varlen_metadata包装,直接使用 pinnedcreate_varlen_metadata_for_document。AscVarlenMetadata的actual_seq_qlen/actual_seq_klen合并为actual_seq_lengths(pinned factory 对cu_seq_q/cu_seq_k赋同一个 packed offsets 张量),并修正 “rank's copy” 旧措辞。test_decoder_update_from_config_refuses_context_parallel,独立覆盖配置阶段拒绝 CP;上面两个 skip 的归类已更正。torchvisionpin 从不可获取的0.30.0.dev20260918改为 CPU wheel0.29.0+cpu(--index-url https://download.pytorch.org/whl/cpu),并在装完后 import 自检。本地torch 2.14.0.dev20260719+cpu+torchvision 0.29.0+cpu的torchvision.ioimport 已验证通过;stable CUDA wheel0.29.0会因torchvision::nms未注册而失败。check-pr-docs/references/repo-impact-map.md的 CI torchvision 描述同步为 CPU wheel。Upstream-PR: none约定,只保留 doc-chunk 的窄说明;MTP feature guide 的迁移历史已移出当前事实描述。类型
Checklist:
如何测试
环境:pinned TorchTitan
dc3985ad4912f67f71d5a125f2fdf40144ec8354(TORCHTITAN_DIR),TORCH_DEVICE_BACKEND_AUTOLOAD=0;依赖目录提供 attn-gym 0.0.16 与 spmd_types 0.2.5。V3.2 / MTP 定向 CPU UT:
结果:26 passed, 2 skipped。两个 skip 分别是:
tests/unit_tests/models/test_deepseek_v32_mtp_model.py:89的独立pytest.mark.skip(V3.2 attention 仍走 pre-fold[B, L, D]),以及test_mtp_cp_chunk_loss.py::test_dsv32_mtp_keeps_community_cp_restriction(_DEFERRED_DSV32_FOLD_TESTS,pre-fold 迁移后恢复)。配置阶段拒绝 CP 已由test_metadata_seam.py::test_decoder_update_from_config_refuses_context_parallel独立覆盖,不再依赖 deferred 用例。共享 CP / metadata CPU UT(doc-chunk balancer、restore、V4/V4.1 CP、attention metadata、decoder seam、qwen3.5 拒绝用例):
结果:99 passed, 2 skipped,即 V4/V4.1 的 CP 计算路径未被本次删除影响。
集成用例注册表:
build_deepseek_v3_2_test_list()只返回dsv3_2_dsa_1rank、dsv3_2_dsa_ep2_fsdp2,CP2 用例已移除。全量 CPU 单测:
结果:1172 passed, 102 skipped, 1 failed。唯一失败是
tests/unit_tests/models/deepseek_v4_1/test_v41_rope.py::test_a5_launcher_selects_the_full_fused_stack,因本机未安装cann_ops_nn(launcher 选择全融合栈时导入失败),与本 PR 无关;本轮其余全量通过。此前记录在 base 对比轮次的 19 个 Grain/数据对齐失败在本轮未复现(环境依赖已就绪)。静态检查(pinned Pyrefly 0.45.1 通过 scratch shim 指向 pinned 版本):
export PYTHONPATH=<pyrefly-shim>:<pinned torchtitan>:<.deps>:<21-deps> python scripts/check_architecture_boundaries.py # passed python -m pre_commit run --all-files --show-diff-on-failure结果:全部通过(ruff check/format、codespell、OAT 13 个 staged 文件增量扫描、architecture ratchet、Pyrefly 0 errors / 217 suppressed)。
精度和性能验证结果
本次是非计算性删除:被删的
patched_cp_shardvarlen 分支与prepare_cp_metadata只在 CP>1 的 V3.2 路径上运行,而该路径在配置阶段就被 pinned decoder 拒绝。保留的 doc-chunk CP(V4/V4.1)由第 2 组 CPU 用例覆盖,逐值断言通过。NPU 2 卡 loss-grad norm:未执行(pre-fold case 不可运行)。 2026-11-02 复跑时设备已可用(
npu-smi1 NPU / 2 chips,torch.npu.device_count() == 2),但本 PR 的 2 卡dsv3_2_dsa_ep2_fsdp2仍是 pre-fold:pinned 0.4.0 已移除--training.local-batch-size/--training.global-batch-size/--training.seq-len,且DeepSeekV32Model.Config.update_from_config仍读training.seq_len,因此该 case 继续按既有 deferral 不执行。本 PR 删掉的 CP metadata 只在 CP>1 的 V3.2 路径上运行,而该路径在配置阶段就被 pinned decoder 拒绝;不伪造 loss/grad_norm 数字,待 V3.2 folded-token 迁移后补跑。其他信息
context_parallel.py):该文件是共享 patch,不是 V3.2 的运行时路径;V3.2 的模型/override 中没有cp_shard引用。它的 doc-chunk balancer 服务 V4/V4.1(两者的 metadata 类都声明cp_layout = DOC_CHUNK_LAYOUT,V4 另有 MTP 批次的直接cp_shard调用),V3.2 即使开启 CP 也会在配置阶段被 pinned decoder 拒绝。V3.2 的 CP metadata 实际走Decoder._cp_shard→prepare_cp_metadata_map→AscVarlenMetadata.prepare_cp_metadata(内部CPVarlenMetadata.from_global)。patched_cp_shard的 varlen 分支是旧 single-mask(attention_masks)路径的遗留,最后的潜在调用方是已被显式拒绝 CP 的 qwen3.5;它必须随varlen_cp.py一起删除(否则导入失败),不影响 V4/V4.1 的 doc-chunk 路径。[B, L, ...],相关 unit/integration 入口继续按dev_0.4.0的既有 deferral 跳过;把 V3.2 迁到 folded token 是migration/dsv3.2-fold-batch-dim的工作,不在本 PR 范围。.agents/notes/proposed/upstream/2026-10-14-staged-upgrade-plan.md仍会提到当时的 backport(该文档是提案记录,未改写);当前代码、测试、现行文档和 implemented note 已无CPVarlenMetadata/varlen_cp引用。