Closed
refactor: migrate to TorchTitan 0.4.0 launch-config (Python recipes + opt-in overrides) #1173
hanboyouAdd on Nov 3Closed at 10 days ago
refactor: migrate to TorchTitan 0.4.0 launch-config (Python recipes + opt-in overrides) #1173
Closed
Total: 251 files changed+8569-5383
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 1. **不修改上游 checkout。** torchtitan-npu 不直接编辑 torchtitan 源码。适配按职责放入以下位置: | 22 | 1. **不修改上游 checkout。** torchtitan-npu 不直接编辑 torchtitan 源码。适配按职责放入以下位置: |
| 23 | - **Package patch**(`torchtitan_npu/patches/`):补齐 PyTorch PrivateUse1 backend,或替换当前运行时中缺失的 Python/CANN 符号。`patches/torchtitan/` 只允许有上游依据的临时 patch;`patches/torch_npu/` 用于当前有效的 NPU runtime compatibility patch | 23 | - **Package patch**(`torchtitan_npu/patches/`):补齐 PyTorch PrivateUse1 backend,或替换当前运行时中缺失的 Python/CANN 符号。`patches/torchtitan/` 只允许有上游依据的临时 patch;`patches/torch_npu/` 用于当前有效的 NPU runtime compatibility patch |
| 24 | - - **配置级 override**(`torchtitan_npu/override/`):使用 `@override` 声明组件替换,通过 `override.imports` 显式启用 | 24 | + - **配置级 override**(`torchtitan_npu_recipes/overrides/`):使用 `@override` 声明组件替换,通过 `override.imports` 显式启用 |
| 25 | - **模型模块**(`torchtitan_npu/models/`):提供 DeepSeek-V3.2 和 DeepSeek-V4 的模型配置、并行化与 checkpoint 适配 | 25 | - **模型模块**(`torchtitan_npu/models/`):提供 DeepSeek-V3.2 和 DeepSeek-V4 的模型配置、并行化与 checkpoint 适配 |
| 26 | - **NPU 算子**(`torchtitan_npu/ops/`):封装 CANN 或设备专属算子能力 | 26 | - **NPU 算子**(`torchtitan_npu/ops/`):封装 CANN 或设备专属算子能力 |
| 27 | 27 | ||
| @@ -53,10 +53,11 @@ | |||
| 53 | | `torchtitan_npu/patches/torchtitan/` | 包导入时生效的上游临时补丁 | | 53 | | `torchtitan_npu/patches/torchtitan/` | 包导入时生效的上游临时补丁 | |
| 54 | | `torchtitan_npu/patches/torch_npu/` | 当前有效的 NPU runtime compatibility patch;保留其自动加载和生效时机 | | 54 | | `torchtitan_npu/patches/torch_npu/` | 当前有效的 NPU runtime compatibility patch;保留其自动加载和生效时机 | |
| 55 | | `torchtitan_npu/extensions/` | 永久扩展、组件集成和可选外部 adaptor | | 55 | | `torchtitan_npu/extensions/` | 永久扩展、组件集成和可选外部 adaptor | |
| 56 | -| `torchtitan_npu/override/` | 通过 `override.imports` 显式启用的配置级组件替换 | | 56 | +| `torchtitan_npu_recipes/overrides/` | 通过 `override.imports` 显式启用的配置级组件替换 | |
| 57 | | `torchtitan_npu/models/` | DeepSeek-V3.2、DeepSeek-V4 模型配置、实现、并行化和 checkpoint 适配 | | 57 | | `torchtitan_npu/models/` | DeepSeek-V3.2、DeepSeek-V4 模型配置、实现、并行化和 checkpoint 适配 | |
| 58 | | `torchtitan_npu/ops/` | CANN 与 NPU 专属算子封装 | | 58 | | `torchtitan_npu/ops/` | CANN 与 NPU 专属算子封装 | |
| 59 | | `torchtitan_npu/tools/` | 随 package 分发的 checkpoint 转换与导出工具 | | 59 | | `torchtitan_npu/tools/` | 随 package 分发的 checkpoint 转换与导出工具 | |
| 60 | +| `torchtitan_npu_recipes/` | 面向用户的完整训练 recipe;每个模型一个模块,函数返回完整 `Trainer.Config`。可依赖标准库、上游与本仓公开接口,不承载可复用实现,也不被 `torchtitan_npu` 导入 | | ||
| 60 | | `tests/unit_tests/` | CPU 单测和静态契约测试 | | 61 | | `tests/unit_tests/` | CPU 单测和静态契约测试 | |
| 61 | | `scripts/` | 训练、合规检查及其他仓库级脚本 | | 62 | | `scripts/` | 训练、合规检查及其他仓库级脚本 | |
| 62 | 63 | ||
| @@ -18,8 +18,9 @@ Tracking: PR #688 | |||
| 18 | - `patches/` 与 `models/` 是上游待合入层。新增代码不得建立对 `extensions/`、`override/` 或 `ops/` 的反向依赖;现有跨层边按迁移债务逐项收敛。 | 18 | - `patches/` 与 `models/` 是上游待合入层。新增代码不得建立对 `extensions/`、`override/` 或 `ops/` 的反向依赖;现有跨层边按迁移债务逐项收敛。 |
| 19 | - `extensions/` 是本仓永久扩展层,可以依赖 `patches/` 提供的符号,不得新增对 `models/`、`override/` 或 `ops/` 的依赖。 | 19 | - `extensions/` 是本仓永久扩展层,可以依赖 `patches/` 提供的符号,不得新增对 `models/`、`override/` 或 `ops/` 的依赖。 |
| 20 | - patch 先替换 `torchtitan`,extension 随后可以通过 `torchtitan_npu.patches.*` 复用 patch 提供的定义,也可以从正常的 `torchtitan.*`、`torch.*` 或 `torch_npu.*` 导入路径使用替换结果。依赖方向保持单向:patch 不得新增对 extension 的依赖。 | 20 | - patch 先替换 `torchtitan`,extension 随后可以通过 `torchtitan_npu.patches.*` 复用 patch 提供的定义,也可以从正常的 `torchtitan.*`、`torch.*` 或 `torch_npu.*` 导入路径使用替换结果。依赖方向保持单向:patch 不得新增对 extension 的依赖。 |
| 21 | -- `override/` 经 `override.imports` 显式替换 NPU/CANN 组件;`ops/` 只承载 kernel 与 `torch.library` 注册。 | 21 | +- `override.imports` 显式替换的工厂位于 recipe 包 `torchtitan_npu_recipes/overrides/`;插件包不得直接或惰性导入 recipe 包。可复用实现类留在插件侧的 `models/`、`extensions/`、`ops/`,工厂只负责派生替换 config。`ops/` 只承载 kernel 与 `torch.library` 注册。 |
| 22 | - 自动注入的目标顺序是 `patches → extensions`;selected override 随后在组件构建前生效。`models` 与 `ops` 按需导入。 | 22 | - 自动注入的目标顺序是 `patches → extensions`;selected override 随后在组件构建前生效。`models` 与 `ops` 按需导入。 |
| 23 | +- 组件替换的所有权边界:工厂在 `torchtitan_npu_recipes/overrides/`(含 `deepseek_v4/cv_parallel.py` 中 recipe 选择的 CV dispatcher 入口),实现类在插件侧对应 owner。CV 运行时机器、pass pipeline 与调度仍属 `extensions/experiment/cv_parallel/`。 | ||
| 23 | - patches 是可早期激活的上游替身层;影响 dataclass schema 或默认工厂的 patch 早于依赖该符号的模块。`patches/torchtitan/__init__.py` 的显式导入列表定义当前激活顺序;该顺序由检查保护,不以「trainer 最后导入」这类与当前实现不符的绝对规则表达。extensions 在 patches 完成激活后加载,可以复用 patch 定义,并通过配置外包装、运行期 seam、单目标 hook 或公开注册 API 生效。 | 24 | - patches 是可早期激活的上游替身层;影响 dataclass schema 或默认工厂的 patch 早于依赖该符号的模块。`patches/torchtitan/__init__.py` 的显式导入列表定义当前激活顺序;该顺序由检查保护,不以「trainer 最后导入」这类与当前实现不符的绝对规则表达。extensions 在 patches 完成激活后加载,可以复用 patch 定义,并通过配置外包装、运行期 seam、单目标 hook 或公开注册 API 生效。 |
| 24 | - `config/` 作为公开配置 schema 与转换基础层保留,但其包导入不得隐式安装 patch。 | 25 | - `config/` 作为公开配置 schema 与转换基础层保留,但其包导入不得隐式安装 patch。 |
| 25 | - `torchtitan_npu/compile/`、`torchtitan_npu/distributed/`、`torchtitan_npu/interfaces/` 和 `torchtitan_npu/patches/workaround/` 已迁移或删除;可安装的 checkpoint 转换工具放在 `torchtitan_npu/tools/`,与根目录仓库维护脚本区分。 | 26 | - `torchtitan_npu/compile/`、`torchtitan_npu/distributed/`、`torchtitan_npu/interfaces/` 和 `torchtitan_npu/patches/workaround/` 已迁移或删除;可安装的 checkpoint 转换工具放在 `torchtitan_npu/tools/`,与根目录仓库维护脚本区分。 |
| @@ -57,7 +58,9 @@ ownership debt manifest、目录布局检查和 extension ownership 检查脚本 | |||
| 57 | | DeepSeek-V4/V4.1 模型配置、并行化与 checkpoint 适配 | `extensions/` 与 `override/` | 提炼公开模型/配置接口后逐项替换,不改变训练、checkpoint 或数值语义 | | 58 | | DeepSeek-V4/V4.1 模型配置、并行化与 checkpoint 适配 | `extensions/` 与 `override/` | 提炼公开模型/配置接口后逐项替换,不改变训练、checkpoint 或数值语义 | |
| 58 | | Qwen3.5 模型模块 | 模型专属 `override/` | 通过明确注册或调用边界消除反向依赖 | | 59 | | Qwen3.5 模型模块 | 模型专属 `override/` | 通过明确注册或调用边界消除反向依赖 | |
| 59 | | `extensions/torchtitan/trainer.py`、checkpoint extension | `extensions/components/` | 在 loader 和组件注册表稳定后改为按需接线 | | 60 | | `extensions/torchtitan/trainer.py`、checkpoint extension | `extensions/components/` | 在 loader 和组件注册表稳定后改为按需接线 | |
| 60 | -| TorchAO adaptor、CV Parallel 与 TorchFT extension | `models/`、`override/`、`ops/` 或 patch 私有符号 | 用公开 adaptor/extension 接口分阶段替换 | | 61 | +| TorchAO adaptor、CV Parallel 与 TorchFT extension | `models/`、`ops/` 或 patch 私有符号 | 用公开 adaptor/extension 接口分阶段替换 | |
| 62 | +| `extensions/experiment/cv_parallel/batch_chunk_metadata.py` | `models/deepseek_v4/ascendc_metadata.py`(AscendC metadata tier、`build_aicpu_metadata`) | 保留:metadata tier 是模型拥有的契约,CV 运行时按模型复算 `AscV4Metadata`;不接受在 extension 里复制该层级 | | ||
| 63 | +| `extensions/experiment/cv_parallel/batch_chunk_token_dispatcher.py` | `models/common/token_dispatcher.py`(`AscAllToAllTokenDispatcher`) | 保留:dispatcher 是可复用模型组件,CV 在其上加符号尺寸包装;不接受复制类 | | ||
| 61 | | `patches/torchtitan/models/qwen3_5/vision_encoder.py` | `extensions/torchtitan/eager_flex.py` | 将 eager 兼容逻辑移到单向可激活层,消除 patch 反向依赖 | | 64 | | `patches/torchtitan/models/qwen3_5/vision_encoder.py` | `extensions/torchtitan/eager_flex.py` | 将 eager 兼容逻辑移到单向可激活层,消除 patch 反向依赖 | |
| 62 | 65 | ||
| 63 | `patches/torchtitan/` 的新增文件使用 `Upstream-PR:` 头部。现有文件含历史 `Pending upstream PR`/`Upstream PR` 标记和基线中已登记的缺失项;当前门禁只禁止新增元数据债务,统一整理另行完成。 | 66 | `patches/torchtitan/` 的新增文件使用 `Upstream-PR:` 头部。现有文件含历史 `Pending upstream PR`/`Upstream PR` 标记和基线中已登记的缺失项;当前门禁只禁止新增元数据债务,统一整理另行完成。 |
| @@ -0,0 +1,129 @@ | |||
| 1 | +# Agent Note: Python recipes and thin example launchers | ||
| 2 | + | ||
| 3 | +Status: implemented | ||
| 4 | +Created: 2026-11-02 | ||
| 5 | +Last updated: 2026-11-02 | ||
| 6 | + | ||
| 7 | +## Context | ||
| 8 | + | ||
| 9 | +迁移到上游 `dc3985ad4912f67f71d5a125f2fdf40144ec8354` 后,torchtitan 的配置入口是 | ||
| 10 | +`--module <module> --config <function>`:函数返回完整 `Trainer.Config`,`--section.option` 仅作为 | ||
| 11 | +冻结的兼容 CLI。上游 `torchtitan/config/README.md` 推荐把运行组合放在顶层 `torchtitan_recipes`, | ||
| 12 | +并明确数据图和模型配置属于 recipe,而不是 CLI 字符串。 | ||
| 13 | + | ||
| 14 | +本仓此前把运行配置留在 `examples/**/*.sh` 的 `--section.option` 拼接里,并通过环境变量提供数据: | ||
| 15 | + | ||
| 16 | +- V4.1 caption CPT 从 `DATASET`、`DATASET_PATH`、`PACKING_BUFFER_SIZE` 读取数据图和 packing; | ||
| 17 | +- V4.1 SFT 从 `DSV41_SFT_DATASET`、`DATASET_PATH`、`DSV41_SFT_*` 读取数据集和 encoder 策略; | ||
| 18 | +- V4 SFT 从 `DSV4_SFT_DATASET` 读取语料,V4/V4.1 文本 recipe 硬编码 `tests/assets/c4_test/data.json`; | ||
| 19 | +- Qwen3.5 debug launcher 无条件把 `DATASET_PATH` 指向 `../torchtitan/tests/assets/cc12m_test`, | ||
| 20 | + 即使 `DATASET=cc12m` 也会被本地路径覆盖; | ||
| 21 | +- V4.1 1M launcher 仍传已经不受支持的 `--dataloader.dataset*` / `--dataloader.per_doc_alignment`; | ||
| 22 | +- `USE_GOLDEN`、`USE_TILELANG`、`ENABLE_NPU_MOE_DISPATCHER`、`OPTIMIZER_OVERRIDES`、`CLI_OVERRIDES` | ||
| 23 | + 在 shell 中改写训练配置,无法从 Python 组合或审查。 | ||
| 24 | + | ||
| 25 | +这些接口让数据源、packing、checkpoint 策略和 override 列表只能通过隐式环境约定表达,无法满足 | ||
| 26 | +「配置即 Python 程序」的上游方向,也无法在 CPU 上对实际生效配置做逐字段核对。 | ||
| 27 | + | ||
| 28 | +## Proposal | ||
| 29 | + | ||
| 30 | +新增第二个顶层包 `torchtitan_npu_recipes/`: | ||
| 31 | + | ||
| 32 | +```text | ||
| 33 | +torchtitan_npu_recipes/ | ||
| 34 | +├── __init__.py # 包说明与自定义 recipe 示例,不导入子模块 | ||
| 35 | +├── deepseek_v4.py # V4 launcher 的具名 recipe | ||
| 36 | +├── deepseek_v4_1.py # V4.1 launcher 的具名 recipe | ||
| 37 | +└── qwen3_5.py # Qwen3.5 debug 与 27B 4K SFT recipe | ||
| 38 | +``` | ||
| 39 | + | ||
| 40 | +职责划分: | ||
| 41 | + | ||
| 42 | +- `torchtitan_npu` 继续持有可复用模型、processor、collator、数据图和配置 builder。本轮只把 | ||
| 43 | + `_make_trainer_config` / `_vision_dataloader_config` / SFT builder / Qwen multimodal builder | ||
| 44 | + 的隐式环境读取改为显式参数(`dataset`、`dataset_path`、`num_packing_bins`、`per_doc_alignment`、 | ||
| 45 | + `text_dataset_path`、encoder 策略、`engram_enabled`)。 | ||
| 46 | +- `torchtitan_npu_recipes` 只选择一次运行的组合:模型 flavor、数据图、并行度、优化器、调度器、 | ||
| 47 | + 编译/AC、checkpoint 策略、量化、profiler/comm 和 `override.imports`。 | ||
| 48 | +- 依赖方向是 `torchtitan_npu_recipes → torchtitan_npu`;插件包不导入 recipes。 | ||
| 49 | +- recipe 零参数可调用,每次调用重新构造配置;不返回模块级共享 registry,也不修改共享 `MM_DATASETS`。 | ||
| 50 | +- 世界大小不写入配置。launcher 的 `NGPU × NNODES` 必须等于 `DP replicate × DP shard × CP × TP × PP`;EP 使用这些 rank 的子组,不再次乘入总卡数。 | ||
| 51 | +- `examples/**/*.sh` 只保留进程数、节点地址、CANN/HCCL 环境、资源路径(tokenizer、checkpoint | ||
| 52 | + 目录、dump 目录)、日志前缀和 `MODULE`/`CONFIG` 选择,并把 `"$@"` 原样放在最后。 | ||
| 53 | +- 既有模式保留为显式 recipe 变体:`*_golden`(`USE_GOLDEN=1`)、`*_tilelang` | ||
| 54 | + (V4.1 `USE_TILELANG=1`)、`*_moe_dispatcher`(Qwen `ENABLE_NPU_MOE_DISPATCHER=1`)。 | ||
| 55 | + | ||
| 56 | +### 数据接口 | ||
| 57 | + | ||
| 58 | +| 原接口 | 新接口 | | ||
| 59 | +| --- | --- | | ||
| 60 | +| `DATASET` / `DATASET_PATH`(V4.1 caption) | `deepseek_v4_1_vision_cpt(dataset=..., dataset_path=...)`;caption recipe 入口(含 golden/tilelang 变体)同样接受这些参数,launcher recipe 使用默认值 | | ||
| 61 | +| `PACKING_BUFFER_SIZE` | `num_packing_bins`;含义是同时打开的输出 bin 数,不是缓存输入文档数 | | ||
| 62 | +| `DSV41_SFT_DATASET` / `DSV41_SFT_*` | `deepseek_v4_1_vision_sft(dataset_path=..., image_root=..., thinking_mode=..., drop_thinking=..., add_default_bos_token=..., reasoning_effort=...)` | | ||
| 63 | +| `DSV4_SFT_DATASET` | `deepseek_v4_flash_sft(dataset_path=...)` | | ||
| 64 | +| 硬编码 C4 fixture | `text_dataset_path` 参数;默认值仍是 `tests/assets/c4_test/data.json` | | ||
| 65 | +| Qwen `DATASET_PATH` 覆盖 | `qwen35_debugmodel(dataset=..., dataset_path=...)`;`dataset="cc12m"` 不再被本地路径覆盖 | | ||
| 66 | +| V4.1 1M `--dataloader.per_doc_alignment 256` | `deepseek_v4_1_flash_cpt_1m_a5(per_doc_alignment=256)` | | ||
| 67 | +| `DSV4_PER_DOC_ALIGNMENT` / `DSV41_PER_DOC_ALIGNMENT` | builder 的 `per_doc_alignment` / `context_parallel_degree` 参数 | | ||
| 68 | + | ||
| 69 | +`per_doc_alignment` 在 V4 与 V4.1 都由 `compression_alignment(compress_ratios) × cp_degree` 推导; | ||
| 70 | +显式参数会先经过 `_make_trainer_config`,再传入 caption 或 text builder,避免「只改文本分支、 | ||
| 71 | +caption 分支仍取默认值」。 | ||
| 72 | + | ||
| 73 | +## 行为保持 | ||
| 74 | + | ||
| 75 | +- 54 个可解析的旧 launcher 配置(default/golden/tilelang/moe-dispatcher)与 recipe 解析结果逐字段 | ||
| 76 | + 比对:50 个完全一致,包括 `override.imports` 顺序、optimizer 参数组(含 Muon NS steps=10)、 | ||
| 77 | + `compile`/checkpoint/profiler/comm、量化嵌套字段和 dataloader 图。 | ||
| 78 | +- 剩余 4 个 Qwen case 只差 `dataloader.dataset.source.path`:旧 launcher 注入 | ||
| 79 | + `../torchtitan/tests/assets/cc12m_test`,新 recipe 使用上游注册的仓内 | ||
| 80 | + `tests/assets/cc12m_test`;两个 tar 的 sha256 相同(`fc7c3587...`),但 `dataset="cc12m"` | ||
| 81 | + 不再被本地路径覆盖。这是本迁移要修复的行为。 | ||
| 82 | +- 其余方向性变化: | ||
| 83 | + - Qwen debug recipe 使用上游注册的 `cc12m-test` 源(`tests/assets/cc12m_test`),不再把 launcher | ||
| 84 | + 的 `../torchtitan/tests/assets/cc12m_test` 绝对路径注入配置。仓内 tar 内容相同,但 `DATASET=cc12m` | ||
| 85 | + 不再被本地路径覆盖。 | ||
| 86 | + - V4.1 1M 的旧 launcher 通过已移除的 CLI 字段请求 256 对齐,解析时会失败。新 recipe 直接 | ||
| 87 | + 写入 processor(`2 × CP128`),并在构造时关闭 Engram,保留原脚本声明的配置意图。 | ||
| 88 | + - V4.1 caption recipe 入口(含 golden/tilelang 变体)接受 `dataset`、`dataset_path` 和 | ||
| 89 | + `num_packing_bins`;V4/V4.1 文本入口接受 `text_dataset_path`。默认仍使用已注册数据源。 | ||
| 90 | +- V4/V4.1 旧 launcher 中由 shell 计算的 `DP_REPLICATE`、`DSV4_PER_DOC_ALIGNMENT`、STEPS 等 | ||
| 91 | + 现由 recipe 固定;launcher 的默认 world size 与 recipe 对齐(V4 1M 和 V4.1 1M 明确为 128 rank)。 | ||
| 92 | + | ||
| 93 | +## Verification | ||
| 94 | + | ||
| 95 | +- launcher 拦截:`runs/recipe-migration/capture-launchers.py` 在所有 `examples/**/*.sh` 上替换 | ||
| 96 | + `bash`/`torchrun`,不启动训练,记录 55 个 handoff(含 golden/tilelang/dispatcher 模式)。 | ||
| 97 | +- 配置解析:`capture-configs.py` 在单一解释器中解析 55 个 handoff;结果与冻结基线的 | ||
| 98 | + `before-configs/*.json` 逐字段比较(`compare_configs.py`,只归一化 checkout 根路径)。 | ||
| 99 | +- CPU 单测:`tests/unit_tests/recipes/test_recipe_package.py` 验证每个 launcher 选择的 recipe 可解析、 | ||
| 100 | + recipe 每次调用独立、显式 `dataset_path`/`text_dataset_path` 到达数据图、recipe 不读取已移除的 | ||
| 101 | + 数据环境变量;Qwen 与 V4.1 SFT 的旧环境测试改为显式参数测试。 | ||
| 102 | +- 打包:`pip wheel . --no-deps` 生成的 wheel 包含 `torchtitan_npu_recipes/` 全部模块(`__init__.py`、 | ||
| 103 | + `deepseek_v4.py`、`deepseek_v4_1.py`、`qwen3_5.py`);`pyproject.toml` 的 | ||
| 104 | + `packages.find.include` 已显式列出该包。 | ||
| 105 | +- Lint:改动文件的 `ruff check`/`ruff format --check`、架构边界检查和完整 `pre-commit` 结果记录在 | ||
| 106 | + `runs/recipe-migration/implementation-result.md`;Pyrefly 既有基线诊断单独报告,不整批抑制。 | ||
| 107 | +- 未执行:真实 NPU 训练、`torch.compile`、CP/大 EP 运行。本变更只移动配置形状,不声称 NPU 数值 | ||
| 108 | + 或性能已重验;`tests/integration_tests` 已改为测试自有 fixture recipe,但未在 NPU 上运行。 | ||
| 109 | + | ||
| 110 | +### 实际验证记录(2026-11-02) | ||
| 111 | + | ||
| 112 | +- 33 个 example launcher、55 个模式组合全部完成配置解析;以修改前 `f79d027a` 为冻结基线, | ||
| 113 | + 54 个原先可启动的配置逐字段一致。仅归一化 checkout 根路径及已验证内容相同的 CC12M fixture 路径。 | ||
| 114 | + V4.1 1M 的旧默认拓扑与旧 CLI 均有失败证据,故只报告新 recipe 可解析,不声称存在旧训练对照。 | ||
| 115 | +- 相关 CPU 测试为 101 passed、3 skipped;跳过项均为既有的 Qwen CP folded-token 迁移限制。 | ||
| 116 | + 新增 direct-Python CPU-offload 检查,确保未经过 CLI 解析时 optimizer 也收到 offload 策略。 | ||
| 117 | +- 45 个已跟踪 shell 脚本通过 `bash -n`;构建的 wheel 中 4 个 recipe 模块与当前源码逐字节相同。 | ||
| 118 | +- 完整 pre-commit 的 Pyrefly 仍失败;冻结基线和当前版本均为相同的 56 个诊断,没有新增诊断。 | ||
| 119 | + 不将该状态写为完整 lint 通过;OAT 对本次 65 个 staged 文件扫描通过。 | ||
| 120 | +- 完整配置快照、字段比较和命令日志位于工作区 `runs/recipe-migration/`,未随 package 分发。 | ||
| 121 | + | ||
| 122 | +## Remaining | ||
| 123 | + | ||
| 124 | +- `tests/integration_tests/recipe_configs.py` 会从 CI job 的 fixture 环境变量构造测试 recipe;这是测试 | ||
| 125 | + 接线,不是生产 recipe 接口。若后续 CI 改为直接传 `MODULE`/`CONFIG`,应把该模块并入 job 定义。 | ||
| 126 | +- 旧的模型 registry 零参数函数保留,供直接调用者和集成测试使用;新组合不再加入 registry, | ||
| 127 | + 而是写到 `torchtitan_npu_recipes` 或用户模块。 | ||
| 128 | +- `USE_GOLDEN` 等选择器仍然是 shell 到 recipe 的显式映射;若未来移除 CLI 兼容层,可把选择器 | ||
| 129 | + 收敛为单一 recipe 参数。 | ||
| @@ -958,7 +958,7 @@ Backport 头(`rope.py:1-10`):fork 分支 `sdmyzlp/torchtitan` `br_dpsk_v4_ | |||
| 958 | 958 | ||
| 959 | #### 重写要点与工作量 | 959 | #### 重写要点与工作量 |
| 960 | 1. 删除 `_complex_apply_rotary_emb`/`_cossin_apply_rotary_emb`/`_rope_forward` 的 monkey-patch(上游已具备可选 key + inverse + `CosSinRoPE` inverse 报错)。 | 960 | 1. 删除 `_complex_apply_rotary_emb`/`_cossin_apply_rotary_emb`/`_rope_forward` 的 monkey-patch(上游已具备可选 key + inverse + `CosSinRoPE` inverse 报错)。 |
| 961 | -2. 我方模型配置(`models/deepseek_v4/__init__.py:111,149,258,508`、`models/deepseek_v4_1/__init__.py:353-354` 的 `dataclasses.replace(rope, split=...)`)改为在 attention 层 `torch.split` 后调 rope(对齐 `deepseek_v4/attention.py:326-336,377-379`);`torchtitan_npu/override/common/rope.py:30-31,126,205,254,309-313` 的 Ascend 专用 rope(`AscPartialComplexRoPE` 等)随之改造。 | 961 | +2. 我方模型配置(`models/deepseek_v4/__init__.py:111,149,258,508`、`models/deepseek_v4_1/__init__.py:353-354` 的 `dataclasses.replace(rope, split=...)`)改为在 attention 层 `torch.split` 后调 rope(对齐 `deepseek_v4/attention.py:326-336,377-379`);`torchtitan_npu_recipes/overrides/common/rope.py:30-31,126,205,254,309-313` 的 Ascend 专用 rope(`AscPartialComplexRoPE` 等)随之改造。 |
| 962 | 3. 若短期要保留 `split` 走 RoPE 内部:仅保留 `Split*RoPEConfig` + `_rope_init/_split/_unsplit/_rope_forward`,删除两个 `apply_rotary_emb` 替换(上游已含 inverse/None-key 分支),并核对 `CosSinRoPE.forward` 覆写路径。 | 962 | 3. 若短期要保留 `split` 走 RoPE 内部:仅保留 `Split*RoPEConfig` + `_rope_init/_split/_unsplit/_rope_forward`,删除两个 `apply_rotary_emb` 替换(上游已含 inverse/None-key 分支),并核对 `CosSinRoPE.forward` 覆写路径。 |
| 963 | 4. **工作量 S–M**(上游对齐路线:S–M,牵动 2 个模型配置 + 1 个 override;保留 split 路线:S)。 | 963 | 4. **工作量 S–M**(上游对齐路线:S–M,牵动 2 个模型配置 + 1 个 override;保留 split 路线:S)。 |
| 964 | 964 | ||
| @@ -973,7 +973,7 @@ Backport 头(`rope.py:1-10`):fork 分支 `sdmyzlp/torchtitan` `br_dpsk_v4_ | |||
| 973 | `# Pending upstream PR: https://github.com/pytorch/torchtitan/pull/4095`(`token_dispatcher.py:1`)。 | 973 | `# Pending upstream PR: https://github.com/pytorch/torchtitan/pull/4095`(`token_dispatcher.py:1`)。 |
| 974 | 974 | ||
| 975 | #### 注入方式 | 975 | #### 注入方式 |
| 976 | -**precise-injection**:`apply()`(`:379-403`,import 时执行)替换 `torchtitan.models.common.token_dispatcher.{LocalTokenDispatcher, AllToAllTokenDispatcher, DeepEPTokenDispatcher}` 与 `config_utils` 里对应 3 个绑定;消费方是 `torchtitan_npu/override/common/token_dispatcher.py`(NPU 融合算子派发器,`:184,315,381` 读 `absorb_router_scores`/`routed_scores_R`)。 | 976 | +**precise-injection**:`apply()`(`:379-403`,import 时执行)替换 `torchtitan.models.common.token_dispatcher.{LocalTokenDispatcher, AllToAllTokenDispatcher, DeepEPTokenDispatcher}` 与 `config_utils` 里对应 3 个绑定;消费方是 `torchtitan_npu_recipes/overrides/common/token_dispatcher.py`(NPU 融合算子派发器,`:184,315,381` 读 `absorb_router_scores`/`routed_scores_R`)。 |
| 977 | 977 | ||
| 978 | #### 上游 main 现状 | 978 | #### 上游 main 现状 |
| 979 | - **能力仍不存在**:`grep -rn "absorb_router_scores\|routed_scores" torchtitan/` **零命中**;PR #4095 **未合并**(`git log --all --grep="(#4095)"` 无命中)。main 的 `LocalDispatchMetadata`(`:22-27`)只有 `token_indices_experts_sorted_N` / `topk_scores_experts_sorted_N`;分数仍在 combine 后置乘:`LocalTokenDispatcher.combine`(`:136-158`)→ `_score_and_scatter_add`(`:160-179`,`routed_output_ND * topk_scores_N`),`AllToAllTokenDispatcher.combine`(`:595-668`)同。 | 979 | - **能力仍不存在**:`grep -rn "absorb_router_scores\|routed_scores" torchtitan/` **零命中**;PR #4095 **未合并**(`git log --all --grep="(#4095)"` 无命中)。main 的 `LocalDispatchMetadata`(`:22-27`)只有 `token_indices_experts_sorted_N` / `topk_scores_experts_sorted_N`;分数仍在 combine 后置乘:`LocalTokenDispatcher.combine`(`:136-158`)→ `_score_and_scatter_add`(`:160-179`,`routed_output_ND * topk_scores_N`),`AllToAllTokenDispatcher.combine`(`:595-668`)同。 |
| @@ -992,7 +992,7 @@ Backport 头(`rope.py:1-10`):fork 分支 `sdmyzlp/torchtitan` `br_dpsk_v4_ | |||
| 992 | #### 重写要点与工作量 | 992 | #### 重写要点与工作量 |
| 993 | 1. 保留 `absorb_router_scores` 语义,但按新契约重写:`LocalDispatchMetadata.routed_scores_R` 扩展仍可行(frozen dataclass 继承注 `kw_only=True` 即可);`AllToAll._permute` 改为新 3 元组并在 `dispatch` 内自行对 `routed_scores_rank_major_R[permuted_indices]` 做同样索引;`combine` 去掉 legacy 参数。 | 993 | 1. 保留 `absorb_router_scores` 语义,但按新契约重写:`LocalDispatchMetadata.routed_scores_R` 扩展仍可行(frozen dataclass 继承注 `kw_only=True` 即可);`AllToAll._permute` 改为新 3 元组并在 `dispatch` 内自行对 `routed_scores_rank_major_R[permuted_indices]` 做同样索引;`combine` 去掉 legacy 参数。 |
| 994 | 2. 重新锚定 `_sync_token_count_exchange` 覆写(返回 tensor,保持 `non_blocking=False` 同步拷贝;这个 compile 竞争修复值得顺带提到上游)。 | 994 | 2. 重新锚定 `_sync_token_count_exchange` 覆写(返回 tensor,保持 `non_blocking=False` 同步拷贝;这个 compile 竞争修复值得顺带提到上游)。 |
| 995 | -3. `config_utils` 绑定只剩 `AllToAllTokenDispatcher`;我方 override(`torchtitan_npu/override/common/token_dispatcher.py`,含 `npu_moe_re_routing`/`npu_moe_token_unpermute` 融合路径)需要同步改造(`:184,315,381`)。 | 995 | +3. `config_utils` 绑定只剩 `AllToAllTokenDispatcher`;我方 override(`torchtitan_npu_recipes/overrides/common/token_dispatcher.py`,含 `npu_moe_re_routing`/`npu_moe_token_unpermute` 融合路径)需要同步改造(`:184,315,381`)。 |
| 996 | 4. 与模块 3 的 `_RouterScoreAbsorbingRoutedExperts` 联动:新的 `RoutedExperts.forward` 里要把 `metadata.routed_scores_R` 接到 activation 之前/`w2` 之前。 | 996 | 4. 与模块 3 的 `_RouterScoreAbsorbingRoutedExperts` 联动:新的 `RoutedExperts.forward` 里要把 `metadata.routed_scores_R` 接到 activation 之前/`w2` 之前。 |
| 997 | 5. **工作量 M–L**(patch 主体 M;连带 NPU fused override 与 MoE 侧接线为 L)。 | 997 | 5. **工作量 M–L**(patch 主体 M;连带 NPU fused override 与 MoE 侧接线为 L)。 |
| 998 | 998 | ||
| @@ -1832,7 +1832,7 @@ distributed/full_dtensor.py, distributed/varlen_cp.py}` | |||
| 1832 | 1832 | ||
| 1833 | **重写要点(M,主要是外围迁移与回归)** | 1833 | **重写要点(M,主要是外围迁移与回归)** |
| 1834 | 1. 删除本 patch 及 `patches/torchtitan/__init__.py:9 from .distributed import … full_dtensor`;`distributed/full_dtensor.py` 在新 pin 下 import 即失败。 | 1834 | 1. 删除本 patch 及 `patches/torchtitan/__init__.py:9 from .distributed import … full_dtensor`;`distributed/full_dtensor.py` 在新 pin 下 import 即失败。 |
| 1835 | -2. 全仓清理 `spmd_backend` / `get_spmd_backend` / `from torchtitan.distributed.full_dtensor import …`:至少 `torchtitan_npu/override/qwen3_5/parallelize.py:15/87/102/120/242/256`、`override/deepseek_v4/moe.py:21`、`override/common/swiglu_group/ascendc.py:71`、`override/common/token_dispatcher.py:51/207/217`、`tests/unit_tests/override/common/test_moe_score_absorption.py`、`tests/unit_tests/models/qwen3_5/test_qwen3_5_npu_adapter.py`、`tests/unit_tests/models/deepseek_v4_1/test_model_split.py:183`、`docs/feature_guides/ep_process_group.md:26`。 | 1835 | +2. 全仓清理 `spmd_backend` / `get_spmd_backend` / `from torchtitan.distributed.full_dtensor import …`:至少 `torchtitan_npu_recipes/overrides/qwen3_5/parallelize.py:15/87/102/120/242/256`、`override/deepseek_v4/moe.py:21`、`override/common/swiglu_group/ascendc.py:71`、`override/common/token_dispatcher.py:51/207/217`、`tests/unit_tests/override/common/test_moe_score_absorption.py`、`tests/unit_tests/models/qwen3_5/test_qwen3_5_npu_adapter.py`、`tests/unit_tests/models/deepseek_v4_1/test_model_split.py:183`、`docs/feature_guides/ep_process_group.md:26`。 |
| 1836 | 3. 若确实需要保留 full_dtensor 后端(NPU 上某些算子只在 DTensor 下通),必须**自带一份后端实现**(下游模块 + 自己的模型 parallelize 校验),不再 monkey-patch 上游;同时把相应校验(CP + SDPA 不支持)搬到自己的 `preprocess_inputs`/parallelize 校验里。 | 1836 | 3. 若确实需要保留 full_dtensor 后端(NPU 上某些算子只在 DTensor 下通),必须**自带一份后端实现**(下游模块 + 自己的模型 parallelize 校验),不再 monkey-patch 上游;同时把相应校验(CP + SDPA 不支持)搬到自己的 `preprocess_inputs`/parallelize 校验里。 |
| 1837 | 4. 迁移后需要重新验证 CP + spmd_types 在 NPU 上的数值与 shape 约束(上游 `shard_tensors` 会 raise "sequence length … must be divisible by CP size" 等新错误)。 | 1837 | 4. 迁移后需要重新验证 CP + spmd_types 在 NPU 上的数值与 shape 约束(上游 `shard_tensors` 会 raise "sequence length … must be divisible by CP size" 等新错误)。 |
| 1838 | 1838 | ||
| @@ -1853,7 +1853,7 @@ distributed/full_dtensor.py, distributed/varlen_cp.py}` | |||
| 1853 | **重写要点(M–L)** | 1853 | **重写要点(M–L)** |
| 1854 | 1. 数据类保留,但对外契约改成 `CPInnerAttention.prepare_cp_metadata(metadata, *, permutation)` 的返回类型(rank-local metadata),permutation 由上游 load balancer 提供;`from_global` 里"自己造 load balancer/自己算 indices"的部分改为接收上游 `permutation`(`[1, seq_len]` 或 `[batch, seq_len]`)。 | 1854 | 1. 数据类保留,但对外契约改成 `CPInnerAttention.prepare_cp_metadata(metadata, *, permutation)` 的返回类型(rank-local metadata),permutation 由上游 load balancer 提供;`from_global` 里"自己造 load balancer/自己算 indices"的部分改为接收上游 `permutation`(`[1, seq_len]` 或 `[batch, seq_len]`)。 |
| 1855 | 2. 类型名跟随上游:`VarlenMetadata` → `VarlenAttentionMetadata`;不要再 import `AttentionMasksType`。 | 1855 | 2. 类型名跟随上游:`VarlenMetadata` → `VarlenAttentionMetadata`;不要再 import `AttentionMasksType`。 |
| 1856 | -3. 消费方同步适配:`torchtitan_npu/override/deepseek_v3_2/sparse_attn/ascendc.py:28/258`(`isinstance(varlen_meta, CPVarlenMetadata)` 的分支要挂到新 metadata 类型上)、`torchtitan_npu/models/deepseek_v4/…`(compressor 依赖 `k_global_gather_indices` 语义)、`tests/unit_tests/models/deepseek_v3_2/test_cp_metadata.py`、`tests/unit_tests/models/deepseek_v4/{test_cp_dispatch.py,cp_dispatch_worker.py,test_cp_compressor.py}`、`tests/unit_tests/conftest.py:205`。 | 1856 | +3. 消费方同步适配:`torchtitan_npu_recipes/overrides/deepseek_v3_2/sparse_attn/ascendc.py:28/258`(`isinstance(varlen_meta, CPVarlenMetadata)` 的分支要挂到新 metadata 类型上)、`torchtitan_npu/models/deepseek_v4/…`(compressor 依赖 `k_global_gather_indices` 语义)、`tests/unit_tests/models/deepseek_v3_2/test_cp_metadata.py`、`tests/unit_tests/models/deepseek_v4/{test_cp_dispatch.py,cp_dispatch_worker.py,test_cp_compressor.py}`、`tests/unit_tests/conftest.py:205`。 |
| 1857 | 4. 依赖 torch 私有 `torch.distributed.tensor.experimental._context_parallel._load_balancer._LoadBalancer` 的部分要么随上游改用公开/自研 permutation(推荐,与 #4617 对齐),要么在 NPU torch 版本上继续 pin 并加版本护栏。 | 1857 | 4. 依赖 torch 私有 `torch.distributed.tensor.experimental._context_parallel._load_balancer._LoadBalancer` 的部分要么随上游改用公开/自研 permutation(推荐,与 #4617 对齐),要么在 NPU torch 版本上继续 pin 并加版本护栏。 |
| 1858 | 5. 若最终改走 Ulysses 路线(CP 切 head、metadata 全局),本模块可整体删除,但需评估 AscendC sparse-attention 内核是否支持 head 维切分——这是决策分叉点,建议单独出设计评审。 | 1858 | 5. 若最终改走 Ulysses 路线(CP 切 head、metadata 全局),本模块可整体删除,但需评估 AscendC sparse-attention 内核是否支持 head 维切分——这是决策分叉点,建议单独出设计评审。 |
| 1859 | 1859 | ||
| @@ -23,7 +23,7 @@ | |||
| 23 | | 某项特性的行为、启用方式与限制 | `docs/feature_guides/` 中对应指南,用 `rg -l <特性关键字> docs/feature_guides` 定位 | 启用方式、配置键、支持范围、shape/dtype/并行约束或验证结论变化 | | 23 | | 某项特性的行为、启用方式与限制 | `docs/feature_guides/` 中对应指南,用 `rg -l <特性关键字> docs/feature_guides` 定位 | 启用方式、配置键、支持范围、shape/dtype/并行约束或验证结论变化 | |
| 24 | | 开发者流程:配置扩展、checkpoint、指标与调试、lint、UT 架构、数值对齐 | `docs/developer_guides/` 中对应指南 | 开发者可见的 schema、流程、入口或判定标准变化 | | 24 | | 开发者流程:配置扩展、checkpoint、指标与调试、lint、UT 架构、数值对齐 | `docs/developer_guides/` 中对应指南 | 开发者可见的 schema、流程、入口或判定标准变化 | |
| 25 | | 目录职责、自动导入顺序与依赖方向 | `docs/architecture.md`,以及目标目录的 `AGENTS.md` | 包布局、导入顺序或分层边界变化 | | 25 | | 目录职责、自动导入顺序与依赖方向 | `docs/architecture.md`,以及目标目录的 `AGENTS.md` | 包布局、导入顺序或分层边界变化 | |
| 26 | -| `torchtitan_npu/override/**` 的注册与启用契约 | `torchtitan_npu/override/README.md`、README 项目结构 | 对 override 作者或用户可见的注册/启用方式变化 | | 26 | +| `torchtitan_npu_recipes/overrides/**` 的注册与启用契约 | `torchtitan_npu_recipes/overrides/README.md`、README 项目结构 | 对 override 作者或用户可见的注册/启用方式变化 | |
| 27 | | 临时上游 patch 的适用条件和生命周期 | `torchtitan_npu/patches/torchtitan/README.md` | patch 目标、上游状态或移除条件变化 | | 27 | | 临时上游 patch 的适用条件和生命周期 | `torchtitan_npu/patches/torchtitan/README.md` | patch 目标、上游状态或移除条件变化 | |
| 28 | | 测试分层、marker、runner、CI 命令或产物 | `tests/AGENTS.md`、`tests/integration_tests/README.md`、`docs/developer_guides/unit-test-architecture.md`、`.ci/*.sh`、`.gitcode/workflows/llt_action.yml`(UT)、`.gitcode/workflows/codecheck_action.yml`(代码检查) | 开发者或用户的执行方式变化;普通新增 test node 不写文档 | | 28 | | 测试分层、marker、runner、CI 命令或产物 | `tests/AGENTS.md`、`tests/integration_tests/README.md`、`docs/developer_guides/unit-test-architecture.md`、`.ci/*.sh`、`.gitcode/workflows/llt_action.yml`(UT)、`.gitcode/workflows/codecheck_action.yml`(代码检查) | 开发者或用户的执行方式变化;普通新增 test node 不写文档 | |
| 29 | | PR 类型、checklist 和验证要求 | `.gitcode/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.md` | PR 工作流本身变化 | | 29 | | PR 类型、checklist 和验证要求 | `.gitcode/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.md` | PR 工作流本身变化 | |
| @@ -97,7 +97,7 @@ | |||
| 97 | - `docs/user-guides/installation.md` 中适用的软件配套行; | 97 | - `docs/user-guides/installation.md` 中适用的软件配套行; |
| 98 | - `.ci/setup_torchtitan.sh`(checkout 到 `/tmp/torchtitan`,供 codecheck workflow 使用) | 98 | - `.ci/setup_torchtitan.sh`(checkout 到 `/tmp/torchtitan`,供 codecheck workflow 使用) |
| 99 | 与 `.ci/common.sh`、`.ci/unit_test.sh`(checkout 到 `third_party/torchtitan`); | 99 | 与 `.ci/common.sh`、`.ci/unit_test.sh`(checkout 到 `third_party/torchtitan`); |
| 100 | -- `torchtitan_npu/patches/torchtitan/README.md` 和 `torchtitan_npu/override/README.md` | 100 | +- `torchtitan_npu/patches/torchtitan/README.md` 和 `torchtitan_npu_recipes/overrides/README.md` |
| 101 | 中确实绑定该上游 API 的说明; | 101 | 中确实绑定该上游 API 的说明; |
| 102 | - `docs/community/governance.md` 的「版本基线」要求,及其指向 installation 版本配套表的 | 102 | - `docs/community/governance.md` 的「版本基线」要求,及其指向 installation 版本配套表的 |
| 103 | 锚点;根 `AGENTS.md` 与 `.agents/AGENTS.md` 中「从版本推导 tag」的机制描述。 | 103 | 锚点;根 `AGENTS.md` 与 `.agents/AGENTS.md` 中「从版本推导 tag」的机制描述。 |
| @@ -9,23 +9,74 @@ | |||
| 9 | ] | 9 | ] |
| 10 | }, | 10 | }, |
| 11 | "import": [ | 11 | "import": [ |
| 12 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/converter.py", "target_module": "torchtitan_npu.models.deepseek_v4_1.indexer"}, | 12 | + { |
| 13 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/converter.py", "target_module": "torchtitan_npu.override.common.swiglu_group.ascendc"}, | 13 | + "source": "torchtitan_npu/extensions/adaptor/torchao/converter.py", |
| 14 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", "target_module": "torchtitan_npu.models.deepseek_v4_1.attention"}, | 14 | + "target_module": "torchtitan_npu.models.deepseek_v4_1.indexer" |
| 15 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", "target_module": "torchtitan_npu.models.deepseek_v4_1.compressor"}, | 15 | + }, |
| 16 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", "target_module": "torchtitan_npu.models.deepseek_v4_1.indexer"}, | 16 | + { |
| 17 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", "target_module": "torchtitan_npu.override.common.swiglu_group.ascendc"}, | 17 | + "source": "torchtitan_npu/extensions/adaptor/torchao/converter.py", |
| 18 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/components/deepseek_v4_1.py", "target_module": "torchtitan_npu.models.deepseek_v4_1.attention"}, | 18 | + "target_module": "torchtitan_npu.models.common.swiglu_group" |
| 19 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4.py", "target_module": "torchtitan_npu.models.deepseek_v4.compressor"}, | 19 | + }, |
| 20 | - {"source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4.py", "target_module": "torchtitan_npu.override.common.swiglu_group.ascendc"}, | 20 | + { |
| 21 | - {"source": "torchtitan_npu/extensions/compile/sdc_checksum.py", "target_module": "torchtitan_npu.ops.misc.sdc_checksum"}, | 21 | + "source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", |
| 22 | - {"source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_metadata.py", "target_module": "torchtitan_npu.models.deepseek_v4.metadata"}, | 22 | + "target_module": "torchtitan_npu.models.deepseek_v4_1.attention" |
| 23 | - {"source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_metadata.py", "target_module": "torchtitan_npu.override.deepseek_v4.sparse_attn.ascendc"}, | 23 | + }, |
| 24 | - {"source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_token_dispatcher.py", "target_module": "torchtitan_npu.ops.ascendc.moe_token_permute"}, | 24 | + { |
| 25 | - {"source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_token_dispatcher.py", "target_module": "torchtitan_npu.override.common.token_dispatcher"}, | 25 | + "source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", |
| 26 | - {"source": "torchtitan_npu/extensions/torchtitan/experiments/torchft/trainer.py", "target_module": "torchtitan_npu.models.deepseek_v4.model"}, | 26 | + "target_module": "torchtitan_npu.models.deepseek_v4_1.compressor" |
| 27 | - {"source": "torchtitan_npu/extensions/torchtitan/trainer.py", "target_module": "torchtitan_npu.override.common.optimizer"}, | 27 | + }, |
| 28 | - {"source": "torchtitan_npu/patches/torchtitan/models/qwen3_5/vision_encoder.py", "target_module": "torchtitan_npu.extensions.torchtitan.eager_flex"} | 28 | + { |
| 29 | + "source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", | ||
| 30 | + "target_module": "torchtitan_npu.models.deepseek_v4_1.indexer" | ||
| 31 | + }, | ||
| 32 | + { | ||
| 33 | + "source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4_1.py", | ||
| 34 | + "target_module": "torchtitan_npu.models.common.swiglu_group" | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + "source": "torchtitan_npu/extensions/adaptor/torchao/components/deepseek_v4_1.py", | ||
| 38 | + "target_module": "torchtitan_npu.models.deepseek_v4_1.attention" | ||
| 39 | + }, | ||
| 40 | + { | ||
| 41 | + "source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4.py", | ||
| 42 | + "target_module": "torchtitan_npu.models.deepseek_v4.compressor" | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + "source": "torchtitan_npu/extensions/adaptor/torchao/configs/deepseek_v4.py", | ||
| 46 | + "target_module": "torchtitan_npu.models.common.swiglu_group" | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + "source": "torchtitan_npu/extensions/compile/sdc_checksum.py", | ||
| 50 | + "target_module": "torchtitan_npu.ops.misc.sdc_checksum" | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + "source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_metadata.py", | ||
| 54 | + "target_module": "torchtitan_npu.models.deepseek_v4.metadata" | ||
| 55 | + }, | ||
| 56 | + { | ||
| 57 | + "source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_metadata.py", | ||
| 58 | + "target_module": "torchtitan_npu.models.deepseek_v4.ascendc_metadata" | ||
| 59 | + }, | ||
| 60 | + { | ||
| 61 | + "source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_token_dispatcher.py", | ||
| 62 | + "target_module": "torchtitan_npu.ops.ascendc.moe_token_permute" | ||
| 63 | + }, | ||
| 64 | + { | ||
| 65 | + "source": "torchtitan_npu/extensions/experiment/cv_parallel/batch_chunk_token_dispatcher.py", | ||
| 66 | + "target_module": "torchtitan_npu.models.common.token_dispatcher" | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + "source": "torchtitan_npu/extensions/torchtitan/experiments/torchft/trainer.py", | ||
| 70 | + "target_module": "torchtitan_npu.models.deepseek_v4.model" | ||
| 71 | + }, | ||
| 72 | + { | ||
| 73 | + "source": "torchtitan_npu/extensions/torchtitan/trainer.py", | ||
| 74 | + "target_module": "torchtitan_npu_recipes.overrides.common.optimizer" | ||
| 75 | + }, | ||
| 76 | + { | ||
| 77 | + "source": "torchtitan_npu/patches/torchtitan/models/qwen3_5/vision_encoder.py", | ||
| 78 | + "target_module": "torchtitan_npu.extensions.torchtitan.eager_flex" | ||
| 79 | + } | ||
| 29 | ], | 80 | ], |
| 30 | "activation_order": { | 81 | "activation_order": { |
| 31 | "torchtitan_npu/extensions/__init__.py": [ | 82 | "torchtitan_npu/extensions/__init__.py": [ |
| @@ -9,10 +9,11 @@ | |||
| 9 | | `torchtitan_npu/config/` | 配置 schema、转换器和注册 API | | 9 | | `torchtitan_npu/config/` | 配置 schema、转换器和注册 API | |
| 10 | | `torchtitan_npu/patches/` | 上游或 runtime compatibility patch | | 10 | | `torchtitan_npu/patches/` | 上游或 runtime compatibility patch | |
| 11 | | `torchtitan_npu/extensions/` | 永久扩展、可选 adaptor 和组件集成 | | 11 | | `torchtitan_npu/extensions/` | 永久扩展、可选 adaptor 和组件集成 | |
| 12 | -| `torchtitan_npu/override/` | 由 `override.imports` 显式启用的组件替换 | | 12 | +| `torchtitan_npu_recipes/overrides/` | 由 `override.imports` 显式启用的组件替换 | |
| 13 | | `torchtitan_npu/models/` | 模型配置、实现、并行化和 checkpoint 适配 | | 13 | | `torchtitan_npu/models/` | 模型配置、实现、并行化和 checkpoint 适配 | |
| 14 | | `torchtitan_npu/ops/` | NPU 专属算子与后端注册 | | 14 | | `torchtitan_npu/ops/` | NPU 专属算子与后端注册 | |
| 15 | | `torchtitan_npu/tools/` | 随 package 分发的转换和导出工具 | | 15 | | `torchtitan_npu/tools/` | 随 package 分发的转换和导出工具 | |
| 16 | +| `torchtitan_npu_recipes/` | 面向用户的完整训练 recipe;函数返回完整 `Trainer.Config`,按 `--module`/`--config` 选择,不承载可复用实现 | | ||
| 16 | | `scripts/` | 仓库维护、训练和合规脚本 | | 17 | | `scripts/` | 仓库维护、训练和合规脚本 | |
| 17 | | `tests/` | CPU UT、NPU smoke/ST 与 tooling 自测 | | 18 | | `tests/` | CPU UT、NPU smoke/ST 与 tooling 自测 | |
| 18 | 19 | ||
| @@ -218,7 +218,7 @@ pip install -e . | |||
| 218 | <td>✅</td> | 218 | <td>✅</td> |
| 219 | </tr> | 219 | </tr> |
| 220 | <tr> | 220 | <tr> |
| 221 | - <td><a href="torchtitan_npu/override/README.md">TileLang 融合算子</a></td> | 221 | + <td><a href="torchtitan_npu_recipes/overrides/README.md">TileLang 融合算子</a></td> |
| 222 | <td>❌</td> | 222 | <td>❌</td> |
| 223 | <td>✅</td> | 223 | <td>✅</td> |
| 224 | </tr> | 224 | </tr> |
| @@ -264,7 +264,8 @@ torchtitan-npu/ | |||
| 264 | │ ├── tools/ # 随 package 分发的 checkpoint 转换与导出工具 | 264 | │ ├── tools/ # 随 package 分发的 checkpoint 转换与导出工具 |
| 265 | │ ├── __init__.py # 导入 package patch 与 extension | 265 | │ ├── __init__.py # 导入 package patch 与 extension |
| 266 | │ └── train.py # 训练入口 | 266 | │ └── train.py # 训练入口 |
| 267 | -├── examples/ # 各模型训练示例脚本与说明 | 267 | +├── torchtitan_npu_recipes/ # 面向用户的完整训练 recipe(按模型分模块) |
| 268 | +├── examples/ # 各模型训练示例脚本与说明(薄 launcher,选择 recipe) | ||
| 268 | ├── experiments/ # 实验性适配包(torchao-npu 量化) | 269 | ├── experiments/ # 实验性适配包(torchao-npu 量化) |
| 269 | ├── scripts/ # 训练与仓库辅助脚本 | 270 | ├── scripts/ # 训练与仓库辅助脚本 |
| 270 | ├── tests/ # 单元测试和测试数据 | 271 | ├── tests/ # 单元测试和测试数据 |
| @@ -284,13 +285,13 @@ System: Ascend 950,图模式 | |||
| 284 | 285 | ||
| 285 | | 模型 | NPU 数 | 量化 | GBS | 序列长度 | FSDP | TP | PP | CP | EP | 单卡吞吐 (tokens/s) | step time | BF16 MFU | | 286 | | 模型 | NPU 数 | 量化 | GBS | 序列长度 | FSDP | TP | PP | CP | EP | 单卡吞吐 (tokens/s) | step time | BF16 MFU | |
| 286 | | :--- | ---: | :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | 287 | | :--- | ---: | :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | |
| 287 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 64 | MXFP8 | 512 | 4k | 64 | 1 | 1 | 1 | 64 | 2126 | 15.42 s | / | | 288 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 64 | MXFP8 | 512 | 4k | 64 | 1 | 1 | 1 | 64 | 2126 | 15.42 s | / | |
| 288 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 64 | MXFP8 | 64 | 64k | 8 | 1 | 1 | 8 | 64 | 1501.6 | 43.64 s | / | | 289 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 64 | MXFP8 | 64 | 64k | 8 | 1 | 1 | 8 | 64 | 1501.6 | 43.64 s | / | |
| 289 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 128 | MXFP8 | 8 | 1M | 1 | 1 | 1 | 128 | 128 | 1325 | 49.46 s | / | | 290 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 128 | MXFP8 | 8 | 1M | 1 | 1 | 1 | 128 | 128 | 1325 | 49.46 s | / | |
| 290 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 64 | BF16 | 512 | 4k | 64 | 1 | 1 | 1 | 64 | 1603 | 20.44 s | 28.81% | | 291 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 64 | BF16 | 512 | 4k | 64 | 1 | 1 | 1 | 64 | 1603 | 20.44 s | 28.81% | |
| 291 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 64 | BF16 | 64 | 64k | 8 | 1 | 1 | 8 | 64 | 1421 | 46.12 s | 32.87% | | 292 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 64 | BF16 | 64 | 64k | 8 | 1 | 1 | 8 | 64 | 1421 | 46.12 s | 32.87% | |
| 292 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 64 | QAT | 512 | 4k | 64 | 1 | 1 | 1 | 64 | 1576 | 20.79 s | / | | 293 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 64 | QAT | 512 | 4k | 64 | 1 | 1 | 1 | 64 | 1576 | 20.79 s | / | |
| 293 | -| [DeepSeek-V4-Flash](torchtitan_npu/models/deepseek_v4/config_registry.py) | 64 | QAT | 64 | 64k | 8 | 1 | 1 | 8 | 64 | 1532 | 42.78 s | / | | 294 | +| [DeepSeek-V4-Flash](torchtitan_npu_recipes/models/deepseek_v4.py) | 64 | QAT | 64 | 64k | 8 | 1 | 1 | 8 | 64 | 1532 | 42.78 s | / | |
| 294 | 295 | ||
| 295 | 296 | ||
| 296 | # 免责声明 | 297 | # 免责声明 |
| @@ -5,29 +5,30 @@ | |||
| 5 | ## Repository layout | 5 | ## Repository layout |
| 6 | 6 | ||
| 7 | ```text | 7 | ```text |
| 8 | -torchtitan_npu/ Ascend NPU 插件主体 | 8 | +torchtitan_npu/ Ascend NPU 插件主体 |
| 9 | -experiments/ 独立实验包;当前包含 torchao-npu distribution | 9 | +torchtitan_npu_recipes/ 面向用户的完整训练 recipe 与 opt-in override 实现 |
| 10 | -docs/ 架构、开发者、功能和用户文档 | 10 | +experiments/ 独立实验包;当前包含 torchao-npu distribution |
| 11 | -examples/ 可运行 recipe、模型配置与示例 launcher | 11 | +docs/ 架构、开发者、功能和用户文档 |
| 12 | +examples/ 模型与硬件的薄 launcher,选择 recipe | ||
| 12 | scripts/ 训练、转换、合规检查与辅助脚本 | 13 | scripts/ 训练、转换、合规检查与辅助脚本 |
| 13 | tests/ CPU UT、NPU ST 与 tooling 自测 | 14 | tests/ CPU UT、NPU ST 与 tooling 自测 |
| 14 | .agents/ Agent Notes 与可复用 skills | 15 | .agents/ Agent Notes 与可复用 skills |
| 15 | ``` | 16 | ``` |
| 16 | 17 | ||
| 17 | -根目录只保留工程配置、包/训练入口及上述目录。`third_party/` 的普通内容默认忽略;已跟踪的 `third_party/agent-skills/KPBot` 是 submodule。不新增其他生产代码落点。 | 18 | +根目录只保留工程配置、两个 Python 包、训练入口及上述目录。`third_party/` 的普通内容默认忽略;已跟踪的 `third_party/agent-skills/KPBot` 是 submodule。不新增其他生产代码落点。 |
| 18 | 19 | ||
| 19 | ## 插件主体 | 20 | ## 插件主体 |
| 20 | 21 | ||
| 21 | -`torchtitan_npu/` 的正式生产子包为 `config/`、`patches/`、`extensions/`、`override/`、`models/`、`ops/` 与 `tools/`。可选外部包适配位于 `extensions/adaptor/`。 | 22 | +`torchtitan_npu/` 的正式生产子包为 `config/`、`patches/`、`extensions/`、`models/`、`ops/` 与 `tools/`。可选外部包适配位于 `extensions/adaptor/`。`override.imports` 显式启用的组件替换属于 recipe 层,位于 `torchtitan_npu_recipes/overrides/`。 |
| 22 | 23 | ||
| 23 | | 子包 | 职责 | 直接依赖边界 | | 24 | | 子包 | 职责 | 直接依赖边界 | |
| 24 | | --- | --- | --- | | 25 | | --- | --- | --- | |
| 25 | | `config/` | NPU config schema、纯转换器和显式注册 API | 当前包导入会安装 ConfigManager loader wrapper;目标是移至 extension 激活入口且不反向导入具体 extension | | 26 | | `config/` | NPU config schema、纯转换器和显式注册 API | 当前包导入会安装 ConfigManager loader wrapper;目标是移至 extension 激活入口且不反向导入具体 extension | |
| 26 | | `patches/` | 上游 `torchtitan` 或 `torch_npu` 的待合入补丁 | 不得新增对 `extensions/` 的依赖;现有反向边记录为迁移债务 | | 27 | | `patches/` | 上游 `torchtitan` 或 `torch_npu` 的待合入补丁 | 不得新增对 `extensions/` 的依赖;现有反向边记录为迁移债务 | |
| 27 | | `models/` | 尚未上游化的模型定义、配置、并行化与 checkpoint 适配 | 现有跨层依赖为迁移债务,不以本文宣称已清零 | | 28 | | `models/` | 尚未上游化的模型定义、配置、并行化与 checkpoint 适配 | 现有跨层依赖为迁移债务,不以本文宣称已清零 | |
| 28 | -| `extensions/` | 本仓永久额外扩展、组件集成与图编译注册 | 可以依赖 `patches/` 提供的定义;不得新增对 `models/`、`override/` 或 `ops/` 的依赖 | | 29 | +| `extensions/` | 本仓永久额外扩展、组件集成与图编译注册 | 可以依赖 `patches/` 提供的定义;不得新增对 `models/`、`ops/` 或 `torchtitan_npu_recipes` 的依赖 | |
| 29 | | `extensions/adaptor/` | 可选外部 distribution 的适配器 | 使用公开配置、模型、算子或 extension API;对 patch 私有符号的现有使用为迁移债务 | | 30 | | `extensions/adaptor/` | 可选外部 distribution 的适配器 | 使用公开配置、模型、算子或 extension API;对 patch 私有符号的现有使用为迁移债务 | |
| 30 | -| `override/` | `override.imports` 显式启用的 NPU/CANN 组件替换 | 可使用 `ops/`;现有对 `extensions/` 的依赖为迁移债务 | | 31 | +| `torchtitan_npu_recipes/overrides/` | `override.imports` 显式启用的 NPU/CANN 组件替换工厂 | 位于 recipe 包;可依赖插件公开的模型、`ops`、`extensions` 组件;不得被 `torchtitan_npu` 导入 | |
| 31 | | `ops/` | 设备后端 kernel、最小启动封装与 `torch.library` 注册 | 仅保留实现算子所需的后端代码 | | 32 | | `ops/` | 设备后端 kernel、最小启动封装与 `torch.library` 注册 | 仅保留实现算子所需的后端代码 | |
| 32 | | `tools/` | 随 package 分发的 checkpoint 转换与导出工具 | 依赖公开模型与 integration API,不承载训练期自动注入 | | 33 | | `tools/` | 随 package 分发的 checkpoint 转换与导出工具 | 依赖公开模型与 integration API,不承载训练期自动注入 | |
| 33 | 34 | ||
| @@ -61,6 +62,46 @@ patches → extensions → selected override | |||
| 61 | 62 | ||
| 62 | patch 替换后必须刷新或说明上游 `from ... import ...` 已捕获的绑定;无法穷尽捕获点时,改用公开注册机制或 extension。extensions 默认上游模块和 dataclass 都已存在,因此不依赖早期导入,也不替换被上游 dataclass 捕获的 `.Config`。它只使用配置外包装、运行期方法 seam、单目标 hook 注册组件或公开注册 API(例如 `torch.library`、graph-pass registry)。不属于 patches 且无法通过这些机制实现的能力,不以 monkey-patch 落地,而应提出稳定扩展点或扩展本仓配置外包装。 | 63 | patch 替换后必须刷新或说明上游 `from ... import ...` 已捕获的绑定;无法穷尽捕获点时,改用公开注册机制或 extension。extensions 默认上游模块和 dataclass 都已存在,因此不依赖早期导入,也不替换被上游 dataclass 捕获的 `.Config`。它只使用配置外包装、运行期方法 seam、单目标 hook 注册组件或公开注册 API(例如 `torch.library`、graph-pass registry)。不属于 patches 且无法通过这些机制实现的能力,不以 monkey-patch 落地,而应提出稳定扩展点或扩展本仓配置外包装。 |
| 63 | 64 | ||
| 65 | +## 可运行 recipe | ||
| 66 | + | ||
| 67 | +`torchtitan_npu_recipes/` 是第二个顶层 Python 包,承载「一次运行」的组合和这些运行显式选择的 | ||
| 68 | +组件替换。目录按职责划分: | ||
| 69 | + | ||
| 70 | +```text | ||
| 71 | +torchtitan_npu_recipes/ | ||
| 72 | +├── models/ 每个模型一个模块:完整训练 recipe(deepseek_v4、deepseek_v4_1、qwen3_5) | ||
| 73 | +├── graph_trainer/ GraphTrainer/CV 配置组合 | ||
| 74 | +├── overrides/ override.imports 显式选择的组件替换工厂(common 与模型专属) | ||
| 75 | +└── tests/ CI-only 的 models/ 与 graph_trainer/ fixture | ||
| 76 | +``` | ||
| 77 | + | ||
| 78 | +`models/{deepseek_v4,deepseek_v4_1,qwen3_5}.py` 拥有 base/full 训练配置:模型 spec、数据图、 | ||
| 79 | +优化器 schema、scheduler、训练预算、并行度、checkpoint、activation checkpoint 与 | ||
| 80 | +`override.imports`。每个公开函数没有必填参数并返回完整 `Trainer.Config`,以 | ||
| 81 | +`--module torchtitan_npu_recipes.models.<model> --config <recipe>` 选择。 | ||
| 82 | +`torchtitan_npu` 与 recipe 的职责不同:插件包提供可复用的模型、processor、collator、 | ||
| 83 | +optimizer profile 与 builder;recipe 只选择组合、数据源、并行度、优化器、编译、checkpoint | ||
| 84 | +策略和 `override.imports`。 | ||
| 85 | + | ||
| 86 | +约束如下: | ||
| 87 | + | ||
| 88 | +- recipe 不得有必填参数(launcher 与 `--config` 以零参数选择);本地数据、拓扑或 golden/tilelang | ||
| 89 | + 选择通过可选参数或新函数表达,环境变量不参与。 | ||
| 90 | +- recipe 不读取 `DATASET`、`DATASET_PATH`、`PACKING_BUFFER_SIZE`、`DSV4_SFT_DATASET` 等数据环境变量; | ||
| 91 | + 数据源在构造配置时显式传入。 | ||
| 92 | +- 并行度写入配置,世界大小不写入。launcher 的 `NGPU`/`NODE_IPS` 必须等于并行度乘积。 | ||
| 93 | +- 每次调用构造新的配置对象,不返回或修改模块级共享 registry。 | ||
| 94 | +- 依赖方向为 `torchtitan_npu_recipes → torchtitan_npu`;插件包不得直接或惰性导入 recipes。 | ||
| 95 | +- 基础 recipe 显式构造完整 `Trainer*.Config`;变体用上游 `torchtitan.config.derive` 以类型化 | ||
| 96 | + block 作为 keyword delta 派生,只声明真实差异,不在 recipe 中重做 `__post_init__` 的生命周期 | ||
| 97 | + (例如 Muon 参数组物化与 CPU-offload carrier)。 | ||
| 98 | +- 数据源、optimizer 与 cluster 默认值不留在 `torchtitan_npu/models/*/config_registry.py`;该 | ||
| 99 | + 文件只保留模型 flavor registry(以及模型 graph memory policy 注册)。 | ||
| 100 | +- 共享实现不下沉到 recipe 包:可复用的 dispatcher、SwigluGroup、metadata tier、优化器容器与 | ||
| 101 | + 并行化实现属于 `torchtitan_npu`;`overrides/` 只放工厂和真正 recipe-only 的适配。 | ||
| 102 | +- `examples/` 的 shell 只保留进程数、节点地址、rendezvous、CANN/HCCL 环境、资源路径、日志和 | ||
| 103 | + `MODULE`/`CONFIG` 选择,并把用户 `"$@"` 原样放在最后。 | ||
| 104 | + | ||
| 64 | ## 目标子层 | 105 | ## 目标子层 |
| 65 | 106 | ||
| 66 | ### patches | 107 | ### patches |
| @@ -77,7 +118,7 @@ patch 替换后必须刷新或说明上游 `from ... import ...` 已捕获的绑 | |||
| 77 | 118 | ||
| 78 | ### override、models 与 ops | 119 | ### override、models 与 ops |
| 79 | 120 | ||
| 80 | -override 使用 `@override` 注册并由完整 `module.function` 选择;它保持输入输出、DTensor、sharding、checkpoint 与 `torch.compile` 语义。依赖 extension 的 override 显式声明此前提;extension 禁用时 warn-once 是禁用开关落地后的目标行为。 | 121 | +opt-in override 工厂位于 `torchtitan_npu_recipes/overrides/`,使用 `@override` 注册并由完整 `module.function` 选择;它保持输入输出、DTensor、sharding、checkpoint 与 `torch.compile` 语义。实现类按职责留在插件包:模型元数据 tier(`models/deepseek_v4/ascendc_metadata.py`、`models/deepseek_v4_1/ascendc_metadata.py`)、token dispatcher(`models/common/token_dispatcher.py`)、SwiGLUGroup(`models/common/swiglu_group.py`)与 a3 workaround(`models/common/a3_workaround.py`)在 `models/`;CPU-offload 优化器容器在 `extensions/cpu_offload/containers.py`;kernel 在 `ops/`。文本/多模态 loader builder 在 `models/common/dataloader.py` 与 `models/<model>/dataloader.py`,Muon profile 在 `models/<model>/muon.py` 或 `models/deepseek_v4_1/optimizer.py`,LoRA 参数谓词在 `models/common/lora.py`。`overrides/` 中的工厂从这些模块派生替换 config,不复制实现;唯一的 recipe 选择型入口是 CV dispatcher 工厂 `overrides/deepseek_v4/cv_parallel.py`,其实现与调度仍归 `extensions/experiment/cv_parallel/`。依赖 extension 的 override 显式声明此前提;extension 禁用时 warn-once 是禁用开关落地后的目标行为。 |
| 81 | 122 | ||
| 82 | 目标上 models 保持对 NPU 实现细节的零直接依赖,需要 kernel 时经上游或 override 注入。当前 DeepSeek-V4/V4.1 与 Qwen3.5 仍有 extension 或 override 的直接导入,属于已登记的迁移债务;新增模型代码不得复制这种模式。ops 按后端或语言组织,后端目录声明 token,算子命名为 `torchtitan_npu::{backend}_{kernel}`。ops 不放上游替换或组件封装,反向通过 `register_autograd` 注册,且 `ops/__init__.py` 不批量导入子模块。 | 123 | 目标上 models 保持对 NPU 实现细节的零直接依赖,需要 kernel 时经上游或 override 注入。当前 DeepSeek-V4/V4.1 与 Qwen3.5 仍有 extension 或 override 的直接导入,属于已登记的迁移债务;新增模型代码不得复制这种模式。ops 按后端或语言组织,后端目录声明 token,算子命名为 `torchtitan_npu::{backend}_{kernel}`。ops 不放上游替换或组件封装,反向通过 `register_autograd` 注册,且 `ops/__init__.py` 不批量导入子模块。 |
| 83 | 124 | ||
| @@ -17,7 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | | 模块 | 配置入口 | checkpoint 默认值 | | 18 | | 模块 | 配置入口 | checkpoint 默认值 | |
| 19 | | --- | --- | --- | | 19 | | --- | --- | --- | |
| 20 | -| `torchtitan_npu.models.deepseek_v4.config_registry` | `deepseek_v4_debugmodel`、`deepseek_v4_flash`、`deepseek_v4_pro` | `enable=False`,`interval=100` | | 20 | +| `torchtitan_npu_recipes.models.deepseek_v4` | `deepseek_v4_debugmodel`、`deepseek_v4_flash`、`deepseek_v4_pro` | `enable=False`,`interval=100` | |
| 21 | | `torchtitan_npu.models.deepseek_v3_2.config_registry` | `deepseek_v3_2_debugmodel` | `enable=False`,`interval=10`,`last_save_model_only=False` | | 21 | | `torchtitan_npu.models.deepseek_v3_2.config_registry` | `deepseek_v3_2_debugmodel` | `enable=False`,`interval=10`,`last_save_model_only=False` | |
| 22 | 22 | ||
| 23 | `enable=False` 时既不会保存 checkpoint,也不会执行 checkpoint 加载。训练命令需要显式 | 23 | `enable=False` 时既不会保存 checkpoint,也不会执行 checkpoint 加载。训练命令需要显式 |
| @@ -262,4 +262,4 @@ bash scripts/run_train.sh \ | |||
| 262 | - [快速上手](../user-guides/quickstart.md) | 262 | - [快速上手](../user-guides/quickstart.md) |
| 263 | - [安装指南](../user-guides/installation.md) | 263 | - [安装指南](../user-guides/installation.md) |
| 264 | - [训练启动脚本](../../scripts/run_train.sh) | 264 | - [训练启动脚本](../../scripts/run_train.sh) |
| 265 | -- [DeepSeek-V4 checkpoint 配置](../../torchtitan_npu/models/deepseek_v4/config_registry.py) | 265 | +- [DeepSeek-V4 checkpoint 配置](../../torchtitan_npu_recipes/models/deepseek_v4.py) |
| @@ -112,8 +112,8 @@ Routed expert 在 `w2` 投影前乘 router score,并回到 BF16;将乘法延 | |||
| 112 | | 改动目录或文件 | 必做验证 | | 112 | | 改动目录或文件 | 必做验证 | |
| 113 | |---|---| | 113 | |---|---| |
| 114 | | `torchtitan_npu/**` | `3.1`、`3.2`、`3.3`、`3.4` | | 114 | | `torchtitan_npu/**` | `3.1`、`3.2`、`3.3`、`3.4` | |
| 115 | -| `torchtitan_npu/override/common` | `3.1`、`3.2`、`3.4` | | 115 | +| `torchtitan_npu_recipes/overrides/common` | `3.1`、`3.2`、`3.4` | |
| 116 | -| `torchtitan_npu/override/<model>/<非 common>` | `3.2`、`3.3`、`3.4` | | 116 | +| `torchtitan_npu_recipes/overrides/<model>/<非 common>` | `3.2`、`3.3`、`3.4` | |
| 117 | | `scripts/checkpoint_conversion/**` | `3.1`、`3.4` | | 117 | | `scripts/checkpoint_conversion/**` | `3.1`、`3.4` | |
| 118 | | `scripts/numerical_alignment/**` | `3.1`、`3.2`、`3.3` | | 118 | | `scripts/numerical_alignment/**` | `3.1`、`3.2`、`3.3` | |
| 119 | | `scripts/run_train.sh` | `3.4` | | 119 | | `scripts/run_train.sh` | `3.4` | |
| @@ -9,7 +9,7 @@ torchtitan-npu 通过 `torchtitan_npu/patches/torchtitan/models/common/aux_loss. | |||
| 9 | | 参考路径(`SparseIndexerLoss`) | `sparse_indexer_loss/mean` | 前向,`_accumulate_and_inject` | | 9 | | 参考路径(`SparseIndexerLoss`) | `sparse_indexer_loss/mean` | 前向,`_accumulate_and_inject` | |
| 10 | | 融合路径(`AscSparseIndexerLoss`,由 `sparse_attn.asc` override 替换) | `asc_sparse_indexer_loss/mean` | 反向,`ctx.acc_buffer.add_(...)` | | 10 | | 融合路径(`AscSparseIndexerLoss`,由 `sparse_attn.asc` override 替换) | `asc_sparse_indexer_loss/mean` | 反向,`ctx.acc_buffer.add_(...)` | |
| 11 | 11 | ||
| 12 | -源码位置:参考路径为 `torchtitan_npu/models/deepseek_v3_2/model.py`,融合路径为 `torchtitan_npu/override/deepseek_v3_2/sparse_attn/ascendc.py`。 | 12 | +源码位置:参考路径为 `torchtitan_npu/models/deepseek_v3_2/model.py`,融合路径为 `torchtitan_npu_recipes/overrides/deepseek_v3_2/sparse_attn/ascendc.py`。 |
| 13 | 13 | ||
| 14 | 融合算子在反向才产出求和后的 KL 值,两条路径的累加时机因此不同,激活检查点(AC)策略对日志值的影响也不同: | 14 | 融合算子在反向才产出求和后的 KL 值,两条路径的累加时机因此不同,激活检查点(AC)策略对日志值的影响也不同: |
| 15 | 15 | ||
| @@ -106,16 +106,25 @@ entry 的 `prepare_cp_metadata` 用 rank-local chunk 重建这三个 frame 以 | |||
| 106 | 106 | ||
| 107 | ## 2. 启用方式 | 107 | ## 2. 启用方式 |
| 108 | 108 | ||
| 109 | +```python | ||
| 110 | +# my_company_configs/cp.py | ||
| 111 | +from torchtitan_npu_recipes.models.deepseek_v4_1 import deepseek_v4_1_stripped | ||
| 112 | + | ||
| 113 | + | ||
| 114 | +def v41_stripped_cp2(): | ||
| 115 | + # lcm(compress_ratios) * cp = 2 * 2 = 4 | ||
| 116 | + return deepseek_v4_1_stripped(per_doc_alignment=4) | ||
| 117 | +``` | ||
| 118 | + | ||
| 109 | ```bash | 119 | ```bash |
| 110 | # DeepSeek-V4.1,两个 rank;先设置 HF_ASSETS_PATH 指向 tokenizer。 | 120 | # DeepSeek-V4.1,两个 rank;先设置 HF_ASSETS_PATH 指向 tokenizer。 |
| 111 | -MODULE=torchtitan_npu.models.deepseek_v4_1 CONFIG=deepseek_v4_1_stripped NGPU=2 \ | 121 | +MODULE=my_company_configs.cp CONFIG=v41_stripped_cp2 NGPU=2 \ |
| 112 | bash scripts/run_train.sh \ | 122 | bash scripts/run_train.sh \ |
| 113 | --hf-assets-path "$HF_ASSETS_PATH" \ | 123 | --hf-assets-path "$HF_ASSETS_PATH" \ |
| 114 | --training.max-context-length 512 \ | 124 | --training.max-context-length 512 \ |
| 115 | --training.num-tokens-per-microbatch-per-dp-rank 512 \ | 125 | --training.num-tokens-per-microbatch-per-dp-rank 512 \ |
| 116 | --training.num-tokens-per-train-step 512 \ | 126 | --training.num-tokens-per-train-step 512 \ |
| 117 | --training.steps 2 --training.disable-cuda-graphs --compile.no-enable \ | 127 | --training.steps 2 --training.disable-cuda-graphs --compile.no-enable \ |
| 118 | - --dataloader.per-doc-alignment 4 \ | ||
| 119 | --parallelism.spmd-backend spmd_types \ | 128 | --parallelism.spmd-backend spmd_types \ |
| 120 | --parallelism.context-parallel-degree 2 \ | 129 | --parallelism.context-parallel-degree 2 \ |
| 121 | --parallelism.context-parallel-load-balancer doc_chunk \ | 130 | --parallelism.context-parallel-load-balancer doc_chunk \ |
| @@ -125,18 +134,19 @@ MODULE=torchtitan_npu.models.deepseek_v4_1 CONFIG=deepseek_v4_1_stripped NGPU=2 | |||
| 125 | --parallelism.tensor-parallel-degree 1 \ | 134 | --parallelism.tensor-parallel-degree 1 \ |
| 126 | --parallelism.pipeline-parallel-degree 1 \ | 135 | --parallelism.pipeline-parallel-degree 1 \ |
| 127 | --optimizer.name AdamW --checkpoint.no-enable \ | 136 | --optimizer.name AdamW --checkpoint.no-enable \ |
| 128 | - --override.imports torchtitan_npu.override.common.rope.workaround \ | 137 | + --override.imports torchtitan_npu_recipes.overrides.common.rope.workaround \ |
| 129 | - torchtitan_npu.override.common.optimizer.virtual \ | 138 | + torchtitan_npu_recipes.overrides.common.optimizer.virtual \ |
| 130 | - torchtitan_npu.override.deepseek_v4_1.lightning_indexer.asc \ | 139 | + torchtitan_npu_recipes.overrides.deepseek_v4_1.lightning_indexer.asc \ |
| 131 | - torchtitan_npu.override.deepseek_v4_1.sparse_attn.asc | 140 | + torchtitan_npu_recipes.overrides.deepseek_v4_1.sparse_attn.asc |
| 132 | ``` | 141 | ``` |
| 133 | 142 | ||
| 134 | DeepSeek-V4 的 Grain 配置将文档对齐值放在 dataset 的 `AlignedTextProcessor.Config.per_doc_alignment`; | 143 | DeepSeek-V4 的 Grain 配置将文档对齐值放在 dataset 的 `AlignedTextProcessor.Config.per_doc_alignment`; |
| 135 | 启用 CP 时,需在 recipe 中将该值设为 `128 × CP` 的倍数。 | 144 | 启用 CP 时,需在 recipe 中将该值设为 `128 × CP` 的倍数。 |
| 136 | 145 | ||
| 137 | -V4.1 的 CP 配方是 `examples/deepseek_v4_1/deepseek_v4_1_flash_cpt_1m_a5.sh`:脚本默认 | 146 | +V4.1 的 1M CP 配方是 `torchtitan_npu_recipes.models.deepseek_v4_1.deepseek_v4_1_flash_cpt_1m_a5`, |
| 138 | -`CP=128`、`EP=128`、`--dataloader.per_doc_alignment 256`,启动时按 `EP` 校验拓扑(`WORLD_SIZE` | 147 | +launcher `examples/deepseek_v4_1/deepseek_v4_1_flash_cpt_1m_a5.sh` 选择它:recipe 固定 |
| 139 | -与 `384` 都要能被 `EP` 整除);`CP` / `EP` 可用同名环境变量覆盖。 | 148 | +`CP=128`、`EP=128`、`per_doc_alignment=256`(`2 × 128`),需要 128 个 rank;其他 CP/EP 组合 |
| 149 | +写自定义 recipe,不通过环境变量切换。 | ||
| 140 | 150 | ||
| 141 | - `--parallelism.context-parallel-degree > 1` 启用 CP;必须配合 | 151 | - `--parallelism.context-parallel-degree > 1` 启用 CP;必须配合 |
| 142 | `--parallelism.spmd-backend spmd_types`(声明式 `S(0) -> R` all-gather 的前提)。切分与 metadata | 152 | `--parallelism.spmd-backend spmd_types`(声明式 `S(0) -> R` all-gather 的前提)。切分与 metadata |
| @@ -154,7 +164,7 @@ V4.1 的 CP 配方是 `examples/deepseek_v4_1/deepseek_v4_1_flash_cpt_1m_a5.sh` | |||
| 154 | 拒绝。数据加载器配置的文档对齐值必须是对应 lcm × cp 的倍数:模型配置更新时由 | 164 | 拒绝。数据加载器配置的文档对齐值必须是对应 lcm × cp 的倍数:模型配置更新时由 |
| 155 | `require_dataloader_alignment` 检查,每个 geometry 的 entry 再由 | 165 | `require_dataloader_alignment` 检查,每个 geometry 的 entry 再由 |
| 156 | `require_document_alignment(cu_seqlens, cp_size=cp, ratio=r)` 检查(V4 在 `doc_chunk_entry`,V4.1 | 166 | `require_document_alignment(cu_seqlens, cp_size=cp, ratio=r)` 检查(V4 在 `doc_chunk_entry`,V4.1 |
| 157 | - 在 `shard_asc_v41_metadata`),V4.1 使用 `--dataloader.per-doc-alignment`;V4 Grain 使用 dataset processor 的配置。 | 167 | + 在 `shard_asc_v41_metadata`),V4.1 与 V4 都通过 recipe 的 `per_doc_alignment` 参数写入 dataset processor 的配置。 |
| 158 | - 需要完整 NPU 环境(`torch_npu`、CANN、HCCL、匹配的 `cann_ops_transformer`)。只有 AscendC 融合 | 168 | - 需要完整 NPU 环境(`torch_npu`、CANN、HCCL、匹配的 `cann_ops_transformer`)。只有 AscendC 融合 |
| 159 | 路径支持 CP;模型目录的参考 metadata hook 显式拒绝 CP,V4.1 的 `update_from_config` 还会要求 | 169 | 路径支持 CP;模型目录的参考 metadata hook 显式拒绝 CP,V4.1 的 `update_from_config` 还会要求 |
| 160 | 同时请求 `override.deepseek_v4_1.sparse_attn.asc` 与 | 170 | 同时请求 `override.deepseek_v4_1.sparse_attn.asc` 与 |
| @@ -336,7 +346,7 @@ V4.1 的参考 metadata(`DeepSeekV41Metadata`)只带整行边界与 `positio | |||
| 336 | 346 | ||
| 337 | ### 5.2 rank-local frame 重建 | 347 | ### 5.2 rank-local frame 重建 |
| 338 | 348 | ||
| 339 | -`AscV41Metadata.prepare_cp_metadata`(`torchtitan_npu/override/deepseek_v4_1/sparse_attn/ascendc.py`) | 349 | +`AscV41Metadata.prepare_cp_metadata`(`torchtitan_npu_recipes/overrides/deepseek_v4_1/sparse_attn/ascendc.py`) |
| 340 | 从 `cp_shard_context()` 取 pre-shard `positions` 与 mesh,调用 `shard_asc_v41_metadata`: | 350 | 从 `cp_shard_context()` 取 pre-shard `positions` 与 mesh,调用 `shard_asc_v41_metadata`: |
| 341 | 351 | ||
| 342 | ```text | 352 | ```text |
| @@ -420,18 +430,18 @@ Engram 不在这一列。它的 token history 要的是每行**在本文档内** | |||
| 420 | | `torchtitan_npu/models/common/carry_exchange.py` | `CarryExchange` / `CarryStream`:ratio-4 carry 的 ring(只换 tokens;位置由 `slab_positions` 算出)、增强 `cu_seqlens` 与 `trim`;cp=1 为 no-op | | 430 | | `torchtitan_npu/models/common/carry_exchange.py` | `CarryExchange` / `CarryStream`:ratio-4 carry 的 ring(只换 tokens;位置由 `slab_positions` 算出)、增强 `cu_seqlens` 与 `trim`;cp=1 为 no-op | |
| 421 | | `torchtitan_npu/models/deepseek_v4/compressor.py` | 压缩器(CP/非 CP 同一实例):`forward` 用 `attention_metadata.key_stream` 恢复窗口、ratio-4 时内部 carry 并裁掉自己那块;`Indexer` 复用它,`idx_q` 在 chunk 行、`idx_k` 是行内的池化块 | | 431 | | `torchtitan_npu/models/deepseek_v4/compressor.py` | 压缩器(CP/非 CP 同一实例):`forward` 用 `attention_metadata.key_stream` 恢复窗口、ratio-4 时内部 carry 并裁掉自己那块;`Indexer` 复用它,`idx_q` 在 chunk 行、`idx_k` 是行内的池化块 | |
| 422 | | `torchtitan_npu/models/deepseek_v4/sharding.py` | `swa_k` / `cmp_k` / `idx_k` 的 `cp: S(0) -> R` 声明 | | 432 | | `torchtitan_npu/models/deepseek_v4/sharding.py` | `swa_k` / `cmp_k` / `idx_k` 的 `cp: S(0) -> R` 声明 | |
| 423 | -| `torchtitan_npu/override/deepseek_v4/metadata.py` | `AicpuMetadata` / `AscV4Metadata`(`aicpu_metadata` + `a3_workaround`)/ `prepare_cp_metadata`(`doc_chunk_entry` + `build_aicpu_metadata`) | | 433 | +| `torchtitan_npu_recipes/overrides/deepseek_v4/metadata.py` | `AicpuMetadata` / `AscV4Metadata`(`aicpu_metadata` + `a3_workaround`)/ `prepare_cp_metadata`(`doc_chunk_entry` + `build_aicpu_metadata`) | |
| 424 | -| `torchtitan_npu/override/deepseek_v4/sparse_attn/ascendc.py` | `build_aicpu_metadata`(按 entry 的 frame 重建记录,arch22 上建 key 压缩)、SMLA/SMLAG 的 frame 参数 | | 434 | +| `torchtitan_npu_recipes/overrides/deepseek_v4/sparse_attn/ascendc.py` | `build_aicpu_metadata`(按 entry 的 frame 重建记录,arch22 上建 key 压缩)、SMLA/SMLAG 的 frame 参数 | |
| 425 | -| `torchtitan_npu/override/deepseek_v4/lightning_indexer/ascendc.py` | LI 前向 / SLIKG 反向(选择器自己的 frame、arch22 的压缩池、teacher 边,分母为 `swa_k.cu_seqlens[-1]`) | | 435 | +| `torchtitan_npu_recipes/overrides/deepseek_v4/lightning_indexer/ascendc.py` | LI 前向 / SLIKG 反向(选择器自己的 frame、arch22 的压缩池、teacher 边,分母为 `swa_k.cu_seqlens[-1]`) | |
| 426 | -| `torchtitan_npu/override/deepseek_v4/lightning_indexer/pypto.py` | PyPTO 版 selector:独立实现同一契约(输入准备、排序、teacher 边),只替换 LI/SLIKG kernel 对 | | 436 | +| `torchtitan_npu_recipes/overrides/deepseek_v4/lightning_indexer/pypto.py` | PyPTO 版 selector:独立实现同一契约(输入准备、排序、teacher 边),只替换 LI/SLIKG kernel 对 | |
| 427 | -| `torchtitan_npu/override/deepseek_v4/compressor/ascendc.py` | CANN 融合压缩器(无 carry、无 CP 分支;`_state_inputs` 按 stream 形状内部构造零 tiling 表) | | 437 | +| `torchtitan_npu_recipes/overrides/deepseek_v4/compressor/ascendc.py` | CANN 融合压缩器(无 carry、无 CP 分支;`_state_inputs` 按 stream 形状内部构造零 tiling 表) | |
| 428 | | `torchtitan_npu/models/deepseek_v4_1/attention.py` | V4.1 查询保持 doc-chunk 布局,key 消费方按需恢复 slab | | 438 | | `torchtitan_npu/models/deepseek_v4_1/attention.py` | V4.1 查询保持 doc-chunk 布局,key 消费方按需恢复 slab | |
| 429 | | `torchtitan_npu/models/deepseek_v4_1/compressor.py` | V4.1 本地池化压缩器(CP-agnostic,无 carry) | | 439 | | `torchtitan_npu/models/deepseek_v4_1/compressor.py` | V4.1 本地池化压缩器(CP-agnostic,无 carry) | |
| 430 | | `torchtitan_npu/models/deepseek_v4_1/sharding.py` | V4.1 sparse core / selector 的 `S(0) -> R` 声明 | | 440 | | `torchtitan_npu/models/deepseek_v4_1/sharding.py` | V4.1 sparse core / selector 的 `S(0) -> R` 声明 | |
| 431 | | `torchtitan_npu/models/deepseek_v4_1/model.py` | `DeepSeekV41Metadata` 与 `build_v41_frames`(整行边界与三帧);`prepare_cp_metadata` 拒绝 CP;`preprocess_inputs` 按行构造 Engram 的 token history;teacher 成对启用检查 | | 441 | | `torchtitan_npu/models/deepseek_v4_1/model.py` | `DeepSeekV41Metadata` 与 `build_v41_frames`(整行边界与三帧);`prepare_cp_metadata` 拒绝 CP;`preprocess_inputs` 按行构造 Engram 的 token history;teacher 成对启用检查 | |
| 432 | -| `torchtitan_npu/override/deepseek_v4_1/sparse_attn/ascendc.py` | `AscV41Metadata` / `shard_asc_v41_metadata` / `build_fused_metadata` | | 442 | +| `torchtitan_npu_recipes/overrides/deepseek_v4_1/sparse_attn/ascendc.py` | `AscV41Metadata` / `shard_asc_v41_metadata` / `build_fused_metadata` | |
| 433 | -| `torchtitan_npu/override/deepseek_v4_1/lightning_indexer/ascendc.py` | V4.1 BF16 selector(整行 index keys × 本 rank chunk) | | 443 | +| `torchtitan_npu_recipes/overrides/deepseek_v4_1/lightning_indexer/ascendc.py` | V4.1 BF16 selector(整行 index keys × 本 rank chunk) | |
| 434 | -| `torchtitan_npu/override/deepseek_v4_1/metadata.py` | V4.1 的 `AicpuGeometry` / `AicpuMetadata`:按 kernel 分组的 AI_CPU 记录结构 | | 444 | +| `torchtitan_npu_recipes/overrides/deepseek_v4_1/metadata.py` | V4.1 的 `AicpuGeometry` / `AicpuMetadata`:按 kernel 分组的 AI_CPU 记录结构 | |
| 435 | 445 | ||
| 436 | ## 7. 验证 | 446 | ## 7. 验证 |
| 437 | 447 | ||
| @@ -26,7 +26,7 @@ CPU Offload 是一套"CPU 常驻 + NPU 计算"的显存优化方案: | |||
| 26 | --training.enable-cpu-offload | 26 | --training.enable-cpu-offload |
| 27 | ``` | 27 | ``` |
| 28 | 28 | ||
| 29 | -优化器状态的驻留面由是否列出 `torchtitan_npu.override.common.optimizer.swap_optimizer` | 29 | +优化器状态的驻留面由是否列出 `torchtitan_npu_recipes.overrides.common.optimizer.swap_optimizer` |
| 30 | 的 override 决定(数据面始终 offload): | 30 | 的 override 决定(数据面始终 offload): |
| 31 | 31 | ||
| 32 | | 配置 | 参数/梯度 | 优化器状态 | | 32 | | 配置 | 参数/梯度 | 优化器状态 | |
| @@ -75,7 +75,7 @@ CPU Offload 是一套"CPU 常驻 + NPU 计算"的显存优化方案: | |||
| 75 | | `extensions/distributed/grad_accum.py` | 梯度累加 + 单 rank 参数预取(FSDP 集成) | | 75 | | `extensions/distributed/grad_accum.py` | 梯度累加 + 单 rank 参数预取(FSDP 集成) | |
| 76 | | `extensions/distributed/grad_clip.py` | clip 补丁:NPU 侧范数计算(cached / bounded 双模式) | | 76 | | `extensions/distributed/grad_clip.py` | clip 补丁:NPU 侧范数计算(cached / bounded 双模式) | |
| 77 | | `patches/torch_npu/cpu_dtensor_init.py` | `Module._init_param` 包装:CPU DTensor 参数 NPU 初始化 | | 77 | | `patches/torch_npu/cpu_dtensor_init.py` | `Module._init_param` 包装:CPU DTensor 参数 NPU 初始化 | |
| 78 | -| `override/common/optimizer.py` | `CpuOffload*OptimizersContainer`:唯一 owner,显式安装/关闭;NPU-state 默认与 CPU-state(含 HostSparse)变体按 `swap_optimizer` 选择 | | 78 | +| `torchtitan_npu/extensions/cpu_offload/containers.py` | `CpuOffload*OptimizersContainer`:唯一 owner,显式安装/关闭;NPU-state 默认与 CPU-state(含 HostSparse)变体按 `swap_optimizer` 选择。`torchtitan_npu_recipes/overrides/common/optimizer.py` 中的 `cpu_offload`/`swap_optimizer` 工厂从这里派生替换 config | |
| 79 | 79 | ||
| 80 | ## 支持组合 | 80 | ## 支持组合 |
| 81 | 81 | ||
| @@ -16,7 +16,12 @@ bash examples/deepseek_v4_1/deepseek_v4_1_flash_lora_4k_a3.sh \ | |||
| 16 | --training.steps 150 --checkpoint.interval 50 | 16 | --training.steps 150 --checkpoint.interval 50 |
| 17 | ``` | 17 | ``` |
| 18 | 18 | ||
| 19 | -使用 `--optimizer.name AdamW` 选择 AdamW。默认 rank 为 16、alpha 为 32,专家 rank 为 16。通过 `CONFIG=deepseek_v4_1_flash_text_lora` 使用同一脚本训练正式纯文本模型:脚本将默认数据集切换为 `c4_test`,也可用 `DATASET`、`DATASET_PATH` 选择文本数据。多模态默认数据集为 `cc12m-test`。用户环境变量与末尾 CLI 参数可覆盖脚本默认值。 | 19 | +使用 `--optimizer.name AdamW` 选择 AdamW。默认 rank 为 16、alpha 为 32,专家 rank 为 16。 |
| 20 | +纯文本 LoRA 通过 `MODULE=torchtitan_npu_recipes.models.deepseek_v4_1 | ||
| 21 | +CONFIG=deepseek_v4_1_flash_text_lora_4k_a3` 选择文本 recipe;默认数据源为仓内 C4 fixture, | ||
| 22 | +本地语料通过该 recipe 的 `text_dataset_path` 参数传入。多模态 recipe 默认数据源为 | ||
| 23 | +`cc12m-test`。机器资源仍由 `NODE_IPS`、`HF_ASSETS_PATH`、`CKPT_*_LOAD_PATH` 提供,末尾 | ||
| 24 | +CLI 参数可覆盖 recipe 默认值。 | ||
| 20 | 25 | ||
| 21 | `deepseek_v4_1_debugmodel_lora` 为纯文本调试配置。设备数量应满足模型内存需求,仅缩小并行度不会缩小模型。 | 26 | `deepseek_v4_1_debugmodel_lora` 为纯文本调试配置。设备数量应满足模型内存需求,仅缩小并行度不会缩小模型。 |
| 22 | 27 | ||
| @@ -18,7 +18,7 @@ GraphTrainer 是 torchtitan 上游 `experiments/graph_trainer/` 中的编译式 | |||
| 18 | 18 | ||
| 19 | ### 配置入口 | 19 | ### 配置入口 |
| 20 | 20 | ||
| 21 | -`torchtitan_npu/models/deepseek_v4/config_registry.py` 新增 5 个配置工厂,均复用对应 eager 配置,经 `to_graph_trainer_config` 包装为 `GraphTrainer.Config`: | 21 | +`torchtitan_npu_recipes/graph_trainer/deepseek_v4.py` 提供 base 图配置,均复用对应 eager recipe,经 `torchtitan_npu/models/deepseek_v4/graph_trainer.py` 的 `to_graph_trainer_config` 包装为 `GraphTrainer.Config`: |
| 22 | 22 | ||
| 23 | | 配置名 | 对应 eager 配置 | | 23 | | 配置名 | 对应 eager 配置 | |
| 24 | | --- | --- | | 24 | | --- | --- | |
| @@ -65,14 +65,14 @@ torchrun --nproc_per_node=8 -m torchtitan.train \ | |||
| 65 | --parallelism.data-parallel-shard-degree 8 \ | 65 | --parallelism.data-parallel-shard-degree 8 \ |
| 66 | --parallelism.spmd-backend default \ | 66 | --parallelism.spmd-backend default \ |
| 67 | --override.imports \ | 67 | --override.imports \ |
| 68 | - torchtitan_npu.override.common.rms_norm.asc \ | 68 | + torchtitan_npu_recipes.overrides.common.rms_norm.asc \ |
| 69 | - torchtitan_npu.override.common.rope.asc_complex \ | 69 | + torchtitan_npu_recipes.overrides.common.rope.asc_complex \ |
| 70 | - 'torchtitan_npu.override.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' \ | 70 | + 'torchtitan_npu_recipes.overrides.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' \ |
| 71 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc \ | 71 | + torchtitan_npu_recipes.overrides.deepseek_v4.lightning_indexer.asc \ |
| 72 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre \ | 72 | + torchtitan_npu_recipes.overrides.deepseek_v4.mhc.asc_hc_pre \ |
| 73 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post \ | 73 | + torchtitan_npu_recipes.overrides.deepseek_v4.mhc.asc_hc_post \ |
| 74 | - torchtitan_npu.override.common.token_dispatcher.asc \ | 74 | + torchtitan_npu_recipes.overrides.common.token_dispatcher.asc \ |
| 75 | - torchtitan_npu.override.common.optimizer.virtual | 75 | + torchtitan_npu_recipes.overrides.common.optimizer.virtual |
| 76 | ``` | 76 | ``` |
| 77 | 77 | ||
| 78 | 编译配置(`aot_fx_trace`、禁用 `cudagraph_pass`)由配置工厂内置,无需 CLI 传入;`--compile.disable_passes cudagraph_pass` 仅对 eager 配置的默认编译路径必需。 | 78 | 编译配置(`aot_fx_trace`、禁用 `cudagraph_pass`)由配置工厂内置,无需 CLI 传入;`--compile.disable_passes cudagraph_pass` 仅对 eager 配置的默认编译路径必需。 |
| @@ -33,7 +33,7 @@ disable_passes = ["cudagraph_pass"] | |||
| 33 | 配置位置: | 33 | 配置位置: |
| 34 | 34 | ||
| 35 | ```text | 35 | ```text |
| 36 | -torchtitan_npu/models/deepseek_v4/config_registry.py | 36 | +torchtitan_npu_recipes/graph_trainer/deepseek_v4.py |
| 37 | ``` | 37 | ``` |
| 38 | 38 | ||
| 39 | 五个 GraphTrainer recipe 均使用 `num_mtp_layers=0` 和 `memory_policy="full"`。 | 39 | 五个 GraphTrainer recipe 均使用 `num_mtp_layers=0` 和 `memory_policy="full"`。 |
| @@ -165,7 +165,7 @@ CPU offload 与 SAR 之前把变异写入显式化为数据流,原生 SAR 随 | |||
| 165 | 165 | ||
| 166 | | 功能 | 文件 | | 166 | | 功能 | 文件 | |
| 167 | | --- | --- | | 167 | | --- | --- | |
| 168 | -| DSV4 GraphTrainer 配置 | `torchtitan_npu/models/deepseek_v4/config_registry.py` | | 168 | +| DSV4 GraphTrainer 配置 | `torchtitan_npu_recipes/graph_trainer/deepseek_v4.py` | |
| 169 | | 通用 full policy | `torchtitan/experiments/graph_trainer/memory_policy.py` | | 169 | | 通用 full policy | `torchtitan/experiments/graph_trainer/memory_policy.py` | |
| 170 | | NPU policy 框架 | `torchtitan_npu/patches/torchtitan/experiments/graph_trainer/memory_policy.py` | | 170 | | NPU policy 框架 | `torchtitan_npu/patches/torchtitan/experiments/graph_trainer/memory_policy.py` | |
| 171 | | `dsv4-mhc` / `dsv4-mhc-moe-save` 策略 | `torchtitan_npu/models/deepseek_v4/memory_policy.py` | | 171 | | `dsv4-mhc` / `dsv4-mhc-moe-save` 策略 | `torchtitan_npu/models/deepseek_v4/memory_policy.py` | |
| @@ -94,7 +94,7 @@ cu_seqlens = [0, 3, 5] # 一行里打包了 2 条序列 | |||
| 94 | 94 | ||
| 95 | 文档在进入行拼接前按 `lcm(compress_ratios)`(V4 为 `128`)对齐:dataloader 在 EOS 之后补 pad token | 95 | 文档在进入行拼接前按 `lcm(compress_ratios)`(V4 为 `128`)对齐:dataloader 在 EOS 之后补 pad token |
| 96 | (label 为 `-100`,位置继续累加),因此每篇文档都是所有压缩比的整数倍,尾部余数恒为 0,压缩块不会跨文档。 | 96 | (label 为 `-100`,位置继续累加),因此每篇文档都是所有压缩比的整数倍,尾部余数恒为 0,压缩块不会跨文档。 |
| 97 | -对齐由 processor 的 `per_doc_alignment` 驱动:非 CP 时 registry 从 `compress_ratios` 推出 `lcm`(V4 为 `128`);CP 时该值提升为 `lcm × cp_size`(V4 为 `128 × cp`,由 recipe/example 通过 `DSV4_PER_DOC_ALIGNMENT` 指定),与压缩器、内核看到的块网格同源。布局构建器把这条契约当作前提:`build_v4_metadata` 对非空且按 | 97 | +对齐由 processor 的 `per_doc_alignment` 驱动:非 CP 时 registry 从 `compress_ratios` 推出 `lcm`(V4 为 `128`);CP 时该值提升为 `lcm × cp_size`(V4 为 `128 × cp`,由 Python recipe 的 `per_doc_alignment` 参数指定),与压缩器、内核看到的块网格同源。布局构建器把这条契约当作前提:`build_v4_metadata` 对非空且按 |
| 98 | `lcm(compress_ratios)` 对齐的流,直接把这一行按 ratio 除出压缩网格(`cmp_k.cu_seqlens`),没有逐文档扫描、 | 98 | `lcm(compress_ratios)` 对齐的流,直接把这一行按 ratio 除出压缩网格(`cmp_k.cu_seqlens`),没有逐文档扫描、 |
| 99 | 也没有「尾部不足一块」的分支;破约的流(含空文档或长度不是对齐倍数)在构建处直接报错。压缩器本身同样是扁平的 | 99 | 也没有「尾部不足一块」的分支;破约的流(含空文档或长度不是对齐倍数)在构建处直接报错。压缩器本身同样是扁平的 |
| 100 | `unflatten(1, (-1, ratio))` 折叠,只有在 ratio-4 重叠时才用 `cu_seqlens` 的段起点做掩码。CP 时文档按 `128 × cp` 对齐(每个 entry 再检查 `cp × max(ratio, 1)`):查询按文档内部分 cp 片,切分后每段仍要是压缩块的整数倍。`doc_chunk_entry` 对未按该值对齐的流直接报错。CP=128 面向长文本(1M 序列),把短文档拼成长文本再切分不是目标场景,填充开销在该场景下可接受。 | 100 | `unflatten(1, (-1, ratio))` 折叠,只有在 ratio-4 重叠时才用 `cu_seqlens` 的段起点做掩码。CP 时文档按 `128 × cp` 对齐(每个 entry 再检查 `cp × max(ratio, 1)`):查询按文档内部分 cp 片,切分后每段仍要是压缩块的整数倍。`doc_chunk_entry` 对未按该值对齐的流直接报错。CP=128 面向长文本(1M 序列),把短文档拼成长文本再切分不是目标场景,填充开销在该场景下可接受。 |
| @@ -107,11 +107,20 @@ SFT 使用 `DeepSeekV4ChatProcessor`,两个 processor 共用 `align_text_seque | |||
| 107 | 先做 next-token shift,再补无监督 pad。过长或无监督 token 的对话被过滤。 | 107 | 先做 next-token shift,再补无监督 pad。过长或无监督 token 的对话被过滤。 |
| 108 | CPT 使用 `ConcatThenSplitPackingConfig`,SFT 使用 `FirstFitPackingConfig`。 | 108 | CPT 使用 `ConcatThenSplitPackingConfig`,SFT 使用 `FirstFitPackingConfig`。 |
| 109 | 109 | ||
| 110 | -SFT 入口选择 `deepseek_v4_flash_sft` recipe;JSON/JSONL 路径通过 `DSV4_SFT_DATASET` 传入。 | 110 | +SFT 入口选择 `deepseek_v4_flash_sft` recipe;JSON/JSONL 路径是 recipe 的 `dataset_path` 参数。 |
| 111 | -现有 launcher 将 `DATASET_PATH` 转为该变量: | 111 | +launcher 不再把 `DATASET_PATH` 转为配置,使用本地语料时写自定义 recipe: |
| 112 | + | ||
| 113 | +```python | ||
| 114 | +# my_company_configs/dsv4.py | ||
| 115 | +from torchtitan_npu_recipes.models import deepseek_v4 | ||
| 116 | + | ||
| 117 | + | ||
| 118 | +def dsv4_sft_local(): | ||
| 119 | + return deepseek_v4.deepseek_v4_flash_sft_4k_a3(dataset_path="/path/to/train.jsonl") | ||
| 120 | +``` | ||
| 112 | 121 | ||
| 113 | ```bash | 122 | ```bash |
| 114 | -DATASET_PATH=/path/to/train.jsonl \ | 123 | +MODULE=my_company_configs.dsv4 CONFIG=dsv4_sft_local \ |
| 115 | bash examples/deepseek_v4/deepseek_v4_flash_sft_4k_a3.sh | 124 | bash examples/deepseek_v4/deepseek_v4_flash_sft_4k_a3.sh |
| 116 | ``` | 125 | ``` |
| 117 | 126 | ||
| @@ -153,7 +162,7 @@ CP 的 `cmp_k.residual = reach % ratio`;文档按 `cp × ratio` 对齐后 `rea | |||
| 153 | 162 | ||
| 154 | ## AscendC 融合路径 | 163 | ## AscendC 融合路径 |
| 155 | 164 | ||
| 156 | -[`sparse_attn/ascendc.py`](../../torchtitan_npu/override/deepseek_v4/sparse_attn/ascendc.py) 中的 `AscCompressedSparseInnerAttention` 执行以下步骤: | 165 | +[`sparse_attn/ascendc.py`](../../torchtitan_npu_recipes/overrides/deepseek_v4/sparse_attn/ascendc.py) 中的 `AscCompressedSparseInnerAttention` 执行以下步骤: |
| 157 | 166 | ||
| 158 | 1. 校验模型输入是 `AscV4Metadata`,读这一层的 `q` / `swa_k` / `cmp_k` frame。 | 167 | 1. 校验模型输入是 `AscV4Metadata`,读这一层的 `q` / `swa_k` / `cmp_k` frame。 |
| 159 | 2. query 转 TND;swa_k / cmp_k 是整行(CP 下由 wrapper 的 `S(1) -> R` 声明式 all-gather 得到),直接转 TND。 | 168 | 2. query 转 TND;swa_k / cmp_k 是整行(CP 下由 wrapper 的 `S(1) -> R` 声明式 all-gather 得到),直接转 TND。 |
| @@ -189,7 +198,7 @@ python -m tests.integration_tests.run_tests /tmp/dsv4-grain-sft-results \ | |||
| 189 | | --- | --- | | 198 | | --- | --- | |
| 190 | | `positions` | 必须提供 `[B, S]`,且每条序列从 0 连续递增 | | 199 | | `positions` | 必须提供 `[B, S]`,且每条序列从 0 连续递增 | |
| 191 | | Padding | varlen 流必须覆盖本 rank 的全部 `B * S` 个 token,metadata 不表达 padding token | | 200 | | Padding | varlen 流必须覆盖本 rank 的全部 `B * S` 个 token,metadata 不表达 padding token | |
| 192 | -| Context Parallel | 支持(AscendC 融合路径,CLI 指定 `NGPU=2 bash examples/deepseek_v4/debug/deepseek_v4_mini_1p_cpt_2k_a3.sh --parallelism.context-parallel-degree 2 --parallelism.spmd-backend spmd_types --parallelism.context-parallel-load-balancer doc_chunk --dataloader.per_doc_alignment 256`);**静态 doc-chunk 布局**:`cp_shard` 在切之前按 `doc_chunk_permutation` 重排整行(零通信),所以输入(token / positions / labels / MTP 深度)一次就是「每篇文档的第 r 个 chunk」,本层 KV 侧再用 `cp.restore` 恢复到 slab,KV/压缩 KV 整行;布局与还原在 `models/common/restore.py`(`doc_chunk_permutation` / `chunk_plan` / `to_slab`),两栈共用;ratio-4 carry 仍在 `models/common/carry_exchange.py` 的 `CarryExchange`(压缩器本身 CP-agnostic) | | 201 | +| Context Parallel | 支持(AscendC 融合路径;CP=2 需要文档对齐 256,通过自定义 recipe `deepseek_v4_mini_1p_cpt_2k_a3(per_doc_alignment=256)` 构造,再以 CLI 指定 `--parallelism.context-parallel-degree 2 --parallelism.spmd-backend spmd_types --parallelism.context-parallel-load-balancer doc_chunk`);**静态 doc-chunk 布局**:`cp_shard` 在切之前按 `doc_chunk_permutation` 重排整行(零通信),所以输入(token / positions / labels / MTP 深度)一次就是「每篇文档的第 r 个 chunk」,本层 KV 侧再用 `cp.restore` 恢复到 slab,KV/压缩 KV 整行;布局与还原在 `models/common/restore.py`(`doc_chunk_permutation` / `chunk_plan` / `to_slab`),两栈共用;ratio-4 carry 仍在 `models/common/carry_exchange.py` 的 `CarryExchange`(压缩器本身 CP-agnostic) | |
| 193 | | Tensor Parallel | DSA 路径固定 TP=1(indexer score 对 head 维求和),TP 方案待 CP 之后另行设计 | | 202 | | Tensor Parallel | DSA 路径固定 TP=1(indexer score 对 head 维求和),TP 方案待 CP 之后另行设计 | |
| 194 | | 空压缩流 | doc-packing 场景要求每条序列至少产生一个完整压缩块;融合路径在 metadata 边界对 `ratio > 1` 且无完整块直接报错(AscendC CSA/HCA 不接受空 `cmp_kv`) | | 203 | | 空压缩流 | doc-packing 场景要求每条序列至少产生一个完整压缩块;融合路径在 metadata 边界对 `ratio > 1` 且无完整块直接报错(AscendC CSA/HCA 不接受空 `cmp_kv`) | |
| 195 | | 运行环境 | 需要 `torch_npu`、CANN、HCCL、Ascend NPU,以及匹配的 `cann_ops_transformer` | | 204 | | 运行环境 | 需要 `torch_npu`、CANN、HCCL、Ascend NPU,以及匹配的 `cann_ops_transformer` | |
| @@ -1,14 +1,14 @@ | |||
| 1 | # 融合算子接入指南 | 1 | # 融合算子接入指南 |
| 2 | 2 | ||
| 3 | 本文面向在 `torchtitan-npu` 中接入 AscendC、Triton 或者 Tilelang 等融合算子的开发者。 | 3 | 本文面向在 `torchtitan-npu` 中接入 AscendC、Triton 或者 Tilelang 等融合算子的开发者。 |
| 4 | -融合算子应作为 NPU 适配层通过 [override 机制](../../torchtitan_npu/override/README.md) 接入,不修改上游 `torchtitan`;默认训练路径不受影响,只有在 `override.imports` 中显式列出入口后才会替换组件。 | 4 | +融合算子应作为 NPU 适配层通过 [override 机制](../../torchtitan_npu_recipes/overrides/README.md) 接入,不修改上游 `torchtitan`;默认训练路径不受影响,只有在 `override.imports` 中显式列出入口后才会替换组件。 |
| 5 | 5 | ||
| 6 | ## 选择接入入口 | 6 | ## 选择接入入口 |
| 7 | 7 | ||
| 8 | | 接入对象 | 接入方式 | 说明 | 算子示例 | | 8 | | 接入对象 | 接入方式 | 说明 | 算子示例 | |
| 9 | | --- | --- | --- | --- | | 9 | | --- | --- | --- | --- | |
| 10 | -| 融合算子对应完整可配置组件 | `override` + `ops` | 整体替换组件;已有设备算子可由 replacement 直接调用 | [`torch_npu.npu_rms_norm`](../../torchtitan_npu/override/common/rms_norm.py) | | 10 | +| 融合算子对应完整可配置组件 | `override` + `ops` | 整体替换组件;已有设备算子可由 replacement 直接调用 | [`torch_npu.npu_rms_norm`](../../torchtitan_npu_recipes/overrides/common/rms_norm.py) | |
| 11 | -| 融合算子是可配置组件的一部分 | `override` + `ops` | 只替换组件中的对应逻辑,其余逻辑沿用上游实现 | [`npu_moe_token_unpermute`](../../torchtitan_npu/ops/ascendc/moe_token_unpermute.py)(接入:[`torchtitan_npu.override.common.token_dispatcher.asc`](../../torchtitan_npu/override/common/token_dispatcher.py)) | | 11 | +| 融合算子是可配置组件的一部分 | `override` + `ops` | 只替换组件中的对应逻辑,其余逻辑沿用上游实现 | [`npu_moe_token_unpermute`](../../torchtitan_npu/ops/ascendc/moe_token_unpermute.py)(接入:[`torchtitan_npu_recipes.overrides.common.token_dispatcher.asc`](../../torchtitan_npu_recipes/overrides/common/token_dispatcher.py)) | |
| 12 | 12 | ||
| 13 | `torch.library.custom_op` 只是 `ops` 实现需要进入 `torch.compile` 图时的兼容封装, | 13 | `torch.library.custom_op` 只是 `ops` 实现需要进入 `torch.compile` 图时的兼容封装, |
| 14 | 不改变上述两种组件替换方式。 | 14 | 不改变上述两种组件替换方式。 |
| @@ -20,7 +20,7 @@ | |||
| 20 | 公开入口统一为: | 20 | 公开入口统一为: |
| 21 | 21 | ||
| 22 | ```text | 22 | ```text |
| 23 | -torchtitan_npu.override.<scope>.<target>.<variant> | 23 | +torchtitan_npu_recipes.overrides.<scope>.<target>.<variant> |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | - `scope`:`common` 或模型名(如 `deepseek_v3_2`、`deepseek_v4`)。只依赖 `torchtitan` | 26 | - `scope`:`common` 或模型名(如 `deepseek_v3_2`、`deepseek_v4`)。只依赖 `torchtitan` |
| @@ -48,7 +48,7 @@ torchtitan_npu.override.<scope>.<target>.<variant> | |||
| 48 | 简单 target 使用单文件;同一 target 包含多个较大的后端实现时使用 package: | 48 | 简单 target 使用单文件;同一 target 包含多个较大的后端实现时使用 package: |
| 49 | 49 | ||
| 50 | ```text | 50 | ```text |
| 51 | -torchtitan_npu/override/<scope>/<target>/ | 51 | +torchtitan_npu_recipes/overrides/<scope>/<target>/ |
| 52 | ├── __init__.py # @override 注册入口 | 52 | ├── __init__.py # @override 注册入口 |
| 53 | ├── ascendc.py # AscendC 实现 | 53 | ├── ascendc.py # AscendC 实现 |
| 54 | └── triton.py # 可选的 Triton 实现 | 54 | └── triton.py # 可选的 Triton 实现 |
| @@ -176,15 +176,15 @@ python -m torchtitan_npu.train \ | |||
| 176 | --module torchtitan_npu.models.deepseek_v4 \ | 176 | --module torchtitan_npu.models.deepseek_v4 \ |
| 177 | --config deepseek_v4_debugmodel \ | 177 | --config deepseek_v4_debugmodel \ |
| 178 | --override.imports \ | 178 | --override.imports \ |
| 179 | - torchtitan_npu.override.common.rms_norm.asc \ | 179 | + torchtitan_npu_recipes.overrides.common.rms_norm.asc \ |
| 180 | - 'torchtitan_npu.override.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' | 180 | + 'torchtitan_npu_recipes.overrides.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' |
| 181 | ``` | 181 | ``` |
| 182 | 182 | ||
| 183 | 多个无参数入口可用空格或逗号分隔。带参数的入口必须将 JSON 作为一个 shell 参数,例如: | 183 | 多个无参数入口可用空格或逗号分隔。带参数的入口必须将 JSON 作为一个 shell 参数,例如: |
| 184 | 184 | ||
| 185 | ```bash | 185 | ```bash |
| 186 | --override.imports \ | 186 | --override.imports \ |
| 187 | - 'torchtitan_npu.override.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' | 187 | + 'torchtitan_npu_recipes.overrides.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' |
| 188 | ``` | 188 | ``` |
| 189 | 189 | ||
| 190 | 同一模块包含多个 override 入口时,只会启用命令中点名的入口函数。`torchtitan` 在配置构造完成、组件 | 190 | 同一模块包含多个 override 入口时,只会启用命令中点名的入口函数。`torchtitan` 在配置构造完成、组件 |
| @@ -202,7 +202,7 @@ python -m torchtitan_npu.train \ | |||
| 202 | 没有单独的 metadata 入口;五个几何数是替换后 config 的必填字段,由该入口的参数写入 | 202 | 没有单独的 metadata 入口;五个几何数是替换后 config 的必填字段,由该入口的参数写入 |
| 203 | (默认值为 V4.1-Flash 形状)。本入口不声明量化:量化 selector 的 metadata 由量化后的 attention | 203 | (默认值为 V4.1-Flash 形状)。本入口不声明量化:量化 selector 的 metadata 由量化后的 attention |
| 204 | 自己建(另一条 backend,见上文),池的容量与块大小取自模型 config。它与 `lightning_indexer.asc` | 204 | 自己建(另一条 backend,见上文),池的容量与块大小取自模型 config。它与 `lightning_indexer.asc` |
| 205 | - 必须同开(教师边只有两侧都在时才存在),见 `torchtitan_npu/override/README.md#deepseek-v41`。 | 205 | + 必须同开(教师边只有两侧都在时才存在),见 `torchtitan_npu_recipes/overrides/README.md#deepseek-v41`。 |
| 206 | - DeepSeek-V4 的 `sparse_attn.asc` 只有一个 attention 入口,metadata(每个几何一份 entry)由该 | 206 | - DeepSeek-V4 的 `sparse_attn.asc` 只有一个 attention 入口,metadata(每个几何一份 entry)由该 |
| 207 | config 自己构建;训练 indexer 时还必须同时启用 selector:CANN 路径用 `lightning_indexer.asc`, | 207 | config 自己构建;训练 indexer 时还必须同时启用 selector:CANN 路径用 `lightning_indexer.asc`, |
| 208 | PyPTO 路径用 `lightning_indexer.pypto`。前者在 SMLAG 反向产出 teacher,后者消费它。 | 208 | PyPTO 路径用 `lightning_indexer.pypto`。前者在 SMLAG 反向产出 teacher,后者消费它。 |
| @@ -211,7 +211,7 @@ python -m torchtitan_npu.train \ | |||
| 211 | - 两个 override 声明同一节点,或一个声明另一个的祖先/后代节点时会冲突;可移除互斥入口, | 211 | - 两个 override 声明同一节点,或一个声明另一个的祖先/后代节点时会冲突;可移除互斥入口, |
| 212 | 或使用 `fqns` 缩小范围。 | 212 | 或使用 `fqns` 缩小范围。 |
| 213 | 213 | ||
| 214 | -导入任意 `torchtitan_npu.override.*` 子模块会先执行包初始化,因而可能同时加载 | 214 | +导入任意 `torchtitan_npu_recipes.overrides.*` 子模块会先执行包初始化,因而可能同时加载 |
| 215 | `torchtitan_npu` 的 package patch。运行环境应具备匹配的 PyTorch、`torch_npu`、CANN、HCCL; | 215 | `torchtitan_npu` 的 package patch。运行环境应具备匹配的 PyTorch、`torch_npu`、CANN、HCCL; |
| 216 | 使用 `cann_ops_transformer` 或 PyPTO 时,还需安装对应 runtime。package patch 只用于无法用 | 216 | 使用 `cann_ops_transformer` 或 PyPTO 时,还需安装对应 runtime。package patch 只用于无法用 |
| 217 | 配置级 override 表达的 backend 缺口或临时适配。 | 217 | 配置级 override 表达的 backend 缺口或临时适配。 |
| @@ -248,11 +248,11 @@ python -m torchtitan_npu.train \ | |||
| 248 | 248 | ||
| 249 | ## 参考实现 | 249 | ## 参考实现 |
| 250 | 250 | ||
| 251 | -- [`override/README.md`](../../torchtitan_npu/override/README.md):override 机制、入口和当前清单。 | 251 | +- [`override/README.md`](../../torchtitan_npu_recipes/overrides/README.md):override 机制、入口和当前清单。 |
| 252 | -- [`deepseek_v3_2/sparse_attn`](../../torchtitan_npu/override/deepseek_v3_2/sparse_attn):TND metadata 与 AscendC DSA。 | 252 | +- [`deepseek_v3_2/sparse_attn`](../../torchtitan_npu_recipes/overrides/deepseek_v3_2/sparse_attn):TND metadata 与 AscendC DSA。 |
| 253 | -- [`deepseek_v4/sparse_attn`](../../torchtitan_npu/override/deepseek_v4/sparse_attn):AscendC 与 PyPTO DSA。 | 253 | +- [`deepseek_v4/sparse_attn`](../../torchtitan_npu_recipes/overrides/deepseek_v4/sparse_attn):AscendC 与 PyPTO DSA。 |
| 254 | -- [`deepseek_v4/mhc`](../../torchtitan_npu/override/deepseek_v4/mhc):AscendC 与 Triton 多后端替换。 | 254 | +- [`deepseek_v4/mhc`](../../torchtitan_npu_recipes/overrides/deepseek_v4/mhc):AscendC 与 Triton 多后端替换。 |
| 255 | -- [`torchtitan_npu/override/common/token_dispatcher.py`](../../torchtitan_npu/override/common/token_dispatcher.py):`token_dispatcher.asc` 在 `AllToAllTokenDispatcher` 中替换局部 dispatch/combine 计算。 | 255 | +- [`torchtitan_npu_recipes/overrides/common/token_dispatcher.py`](../../torchtitan_npu_recipes/overrides/common/token_dispatcher.py):`token_dispatcher.asc` 在 `AllToAllTokenDispatcher` 中替换局部 dispatch/combine 计算。 |
| 256 | -- [`torchtitan_npu/override/common/rope.py`](../../torchtitan_npu/override/common/rope.py):`rope.asc_partial` 整体替换 partial-RoPE 站点,含可选 CANN 依赖的惰性加载。 | 256 | +- [`torchtitan_npu_recipes/overrides/common/rope.py`](../../torchtitan_npu_recipes/overrides/common/rope.py):`rope.asc_partial` 整体替换 partial-RoPE 站点,含可选 CANN 依赖的惰性加载。 |
| 257 | - [`torchtitan_npu/ops/ascendc/inplace_partial_rotary_mul.py`](../../torchtitan_npu/ops/ascendc/inplace_partial_rotary_mul.py):原生 mutator 算子的 functional autograd 包装(clone + 前向/反向原地旋转)。 | 257 | - [`torchtitan_npu/ops/ascendc/inplace_partial_rotary_mul.py`](../../torchtitan_npu/ops/ascendc/inplace_partial_rotary_mul.py):原生 mutator 算子的 functional autograd 包装(clone + 前向/反向原地旋转)。 |
| 258 | - [`ops/ascendc/moe_token_unpermute.py`](../../torchtitan_npu/ops/ascendc/moe_token_unpermute.py):custom op、Fake 和 Autograd 注册示例。 | 258 | - [`ops/ascendc/moe_token_unpermute.py`](../../torchtitan_npu/ops/ascendc/moe_token_unpermute.py):custom op、Fake 和 Autograd 注册示例。 |
| @@ -12,16 +12,23 @@ bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel.sh \ | |||
| 12 | --dump-folder outputs/dual_chunk_cv > dual_chunk_cv.log 2>&1 | 12 | --dump-folder outputs/dual_chunk_cv > dual_chunk_cv.log 2>&1 |
| 13 | ``` | 13 | ``` |
| 14 | 14 | ||
| 15 | -默认复用 `graph_trainer_deepseek_v4_flash_43layers_16experts` 配置,使用 8 卡、43 层、EP8/FSDP8、MBS=2;GBS=64、seq4096、100 步等通用默认值继承 A5 launcher。可通过 `CONFIG` 和 `NGPU` 选择配置与卡数,通过追加 `--training.steps`、`--training.global-batch-size`、`--training.seq-len` 和 `--dump-folder` 调整训练参数。tokenizer、数据和 checkpoint 路径沿用 A5 launcher 的 `HF_ASSETS_PATH`、`DATASET_PATH`、`CKPT_SAVE_LOAD_PATH` 设置;运行前应配置有效路径。卡数须满足模型的 EP/FSDP 拓扑要求。 | 15 | +默认 recipe 为 `torchtitan_npu_recipes.tests.graph_trainer.deepseek_v4.deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel`, |
| 16 | +使用 8 卡、43 层、EP8/FSDP8、每 rank microbatch 8192 tokens、seq4096 和 100 步。可通过 | ||
| 17 | +`CONFIG`/`NGPU` 选择 recipe 与卡数,通过追加 `--training.steps`、 | ||
| 18 | +`--training.num-tokens-per-microbatch-per-dp-rank`、`--training.max-context-length` 和 | ||
| 19 | +`--dump-folder` 调整训练参数。tokenizer 和 checkpoint 路径沿用 A5 launcher 的 | ||
| 20 | +`HF_ASSETS_PATH`、`CKPT_SAVE_LOAD_PATH` 设置;数据由 recipe 决定,本地数据写自定义 recipe。 | ||
| 21 | +卡数须满足 recipe 的 EP/FSDP 拓扑要求。 | ||
| 16 | 22 | ||
| 17 | 后四卡的小模型验证使用仓库已有的 `deepseek_v4_debugmodel` 的 GraphTrainer 入口: | 23 | 后四卡的小模型验证使用仓库已有的 `deepseek_v4_debugmodel` 的 GraphTrainer 入口: |
| 18 | 24 | ||
| 19 | ```bash | 25 | ```bash |
| 20 | ASCEND_RT_VISIBLE_DEVICES=4,5,6,7 \ | 26 | ASCEND_RT_VISIBLE_DEVICES=4,5,6,7 \ |
| 21 | -CONFIG=graph_trainer_deepseek_v4_debugmodel \ | 27 | +MODULE=torchtitan_npu_recipes.tests.graph_trainer.deepseek_v4 CONFIG=deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel \ |
| 22 | NGPU=4 \ | 28 | NGPU=4 \ |
| 23 | bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel.sh \ | 29 | bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel.sh \ |
| 24 | - --training.global-batch-size 8 --training.seq-len 512 --training.steps 10 \ | 30 | + --training.num-tokens-per-microbatch-per-dp-rank 512 --training.max-context-length 512 \ |
| 31 | + --training.steps 10 \ | ||
| 25 | --dump-folder outputs/dual_chunk_debug_cv > dual_chunk_debug_cv.log 2>&1 | 32 | --dump-folder outputs/dual_chunk_debug_cv > dual_chunk_debug_cv.log 2>&1 |
| 26 | ``` | 33 | ``` |
| 27 | 34 | ||
| @@ -37,11 +44,11 @@ config = graph_trainer_deepseek_v4_flash_43layers_16experts | |||
| 37 | 如果通过 CLI 整体替换 `--override.imports`,须保留以下实验依赖: | 44 | 如果通过 CLI 整体替换 `--override.imports`,须保留以下实验依赖: |
| 38 | 45 | ||
| 39 | ```text | 46 | ```text |
| 40 | -torchtitan_npu.override.deepseek_v4.lightning_indexer.asc | 47 | +torchtitan_npu_recipes.overrides.deepseek_v4.lightning_indexer.asc |
| 41 | -torchtitan_npu.extensions.experiment.cv_parallel.batch_chunk_token_dispatcher.asc_dispatcher | 48 | +torchtitan_npu_recipes.overrides.deepseek_v4.cv_parallel.asc_dispatcher |
| 42 | ``` | 49 | ``` |
| 43 | 50 | ||
| 44 | -实验 dispatcher 入口 `batch_chunk_token_dispatcher.asc_dispatcher` 在启用时注册 `cv_parallel` pipeline, | 51 | +实验 dispatcher 入口 `torchtitan_npu_recipes.overrides.deepseek_v4.cv_parallel.asc_dispatcher` 在启用时注册 `cv_parallel` pipeline, |
| 45 | 并在 trainer 的 per-step hook 里安装 metadata 重切。它替换 `common.token_dispatcher.asc`,同一配置节点不能 | 52 | 并在 trainer 的 per-step hook 里安装 metadata 重切。它替换 `common.token_dispatcher.asc`,同一配置节点不能 |
| 46 | 同时启用两种 override。RoPE 沿用公共实现; | 53 | 同时启用两种 override。RoPE 沿用公共实现; |
| 47 | dispatcher 的包装只适配符号 token 数,实际前后向仍调用原生 NPU kernel。普通配置不会选中实验实现。 | 54 | dispatcher 的包装只适配符号 token 数,实际前后向仍调用原生 NPU kernel。普通配置不会选中实验实现。 |
| @@ -242,7 +242,7 @@ bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3_graphtrainer.sh | |||
| 242 | 242 | ||
| 243 | 本仓 `ep_chunk_concretization` 补丁对 `strategy=graph` 新增运行时约束:所选 `batch` 或 `seq` 输入维长度必须不小于 2 且为偶数。Graph chunking 会将该维固定拆成两个等长 chunk;若长度为 1 或奇数,trace 输入准备阶段会直接抛出 `ValueError`,避免生成不等长 chunk 后再进入符号 shape 推导。`strategy=eager` 不经过该输入标记流程,不受此项补丁校验影响。 | 243 | 本仓 `ep_chunk_concretization` 补丁对 `strategy=graph` 新增运行时约束:所选 `batch` 或 `seq` 输入维长度必须不小于 2 且为偶数。Graph chunking 会将该维固定拆成两个等长 chunk;若长度为 1 或奇数,trace 输入准备阶段会直接抛出 `ValueError`,避免生成不等长 chunk 后再进入符号 shape 推导。`strategy=eager` 不经过该输入标记流程,不受此项补丁校验影响。 |
| 244 | 244 | ||
| 245 | -若需把 EP overlap 固化为某个配置的默认值,在 `config_registry.py` 的对应工厂中对 `config.compile.ep_overlap` 赋 `EpOverlapConfig(...)`。 | 245 | +若需把 EP overlap 固化为某个配置的默认值,在 `torchtitan_npu_recipes/graph_trainer/deepseek_v4.py`(或 `tests/graph_trainer/` 的 CI fixture)的对应 recipe 中把 `compile` block 写成 `GraphTrainerCompileConfig(..., ep_overlap=EpOverlapConfig(...))`。 |
| 246 | 246 | ||
| 247 | ## DSV4 整网实跑验证(2026-09-16) | 247 | ## DSV4 整网实跑验证(2026-09-16) |
| 248 | 248 | ||
| @@ -268,5 +268,5 @@ bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3_graphtrainer.sh | |||
| 268 | 268 | ||
| 269 | - DSV4 模型侧 GraphTrainer 适配:[`deepseek_v4_graph_trainer.md`](deepseek_v4_graph_trainer.md) | 269 | - DSV4 模型侧 GraphTrainer 适配:[`deepseek_v4_graph_trainer.md`](deepseek_v4_graph_trainer.md) |
| 270 | - 临时补丁目录约定:[`torchtitan_npu/patches/torchtitan/README.md`](../../torchtitan_npu/patches/torchtitan/README.md) | 270 | - 临时补丁目录约定:[`torchtitan_npu/patches/torchtitan/README.md`](../../torchtitan_npu/patches/torchtitan/README.md) |
| 271 | -- Override 注册表:[`torchtitan_npu/override/README.md`](../../torchtitan_npu/override/README.md) | 271 | +- Override 注册表:[`torchtitan_npu_recipes/overrides/README.md`](../../torchtitan_npu_recipes/overrides/README.md) |
| 272 | - 上游 GraphTrainer 与 EP overlap 说明:[`torchtitan/experiments/graph_trainer/README.md`](https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/graph_trainer/README.md) | 272 | - 上游 GraphTrainer 与 EP overlap 说明:[`torchtitan/experiments/graph_trainer/README.md`](https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/graph_trainer/README.md) |
| @@ -136,7 +136,7 @@ DeepSeek-V3.2 直接继承社区 MTP decoder,并复用社区的 block 构造 | |||
| 136 | | `deepseek_v4/__init__.py` | 根据模型规格构造非压缩、mHC-aware 的 MTP blocks | | 136 | | `deepseek_v4/__init__.py` | 根据模型规格构造非压缩、mHC-aware 的 MTP blocks | |
| 137 | | `deepseek_v4/model.py` | 保留主干多流 state,并组织主预测和 MTP 预测 | | 137 | | `deepseek_v4/model.py` | 保留主干多流 state,并组织主预测和 MTP 预测 | |
| 138 | | `deepseek_v4/mtp.py` | 实现 DeepSeek-V4 mHC MTP block、CP batch 和 chunk loss | | 138 | | `deepseek_v4/mtp.py` | 实现 DeepSeek-V4 mHC MTP block、CP batch 和 chunk loss | |
| 139 | -| `deepseek_v4/config_registry.py` | 默认 recipe 构造 MTP 模型并配置 MTP chunk loss | | 139 | +| `torchtitan_npu_recipes/models/deepseek_v4.py` | 默认 recipe 构造 MTP 模型并配置 MTP chunk loss | |
| 140 | | `deepseek_v4/parallelize.py` | 让 MTP blocks 复用现有 DSV4 并行流程 | | 140 | | `deepseek_v4/parallelize.py` | 让 MTP blocks 复用现有 DSV4 并行流程 | |
| 141 | | `deepseek_v4/sharding.py` | 增加 MTP fusion、mHC head 和有效掩码布局 | | 141 | | `deepseek_v4/sharding.py` | 增加 MTP fusion、mHC head 和有效掩码布局 | |
| 142 | | `deepseek_v4/state_dict_adapter.py` | 转换本地 `mtp_layers` 与 HF `mtp.<depth>` 参数 | | 142 | | `deepseek_v4/state_dict_adapter.py` | 转换本地 `mtp_layers` 与 HF `mtp.<depth>` 参数 | |
| @@ -169,7 +169,7 @@ DeepSeek-V4: | |||
| 169 | --config deepseek_v4_debugmodel | 169 | --config deepseek_v4_debugmodel |
| 170 | ``` | 170 | ``` |
| 171 | 171 | ||
| 172 | -该 recipe 会构造一个 MTP 深度,并使用 `MTPChunkedLossWrapper.Config`;其内部仍使用标准 `CrossEntropyLoss`。DeepSeek-V3.2 不在 NPU `config_registry.py` 中重复声明 MTP recipe,模型侧直接复用社区 MTP 能力。 | 172 | +该 recipe 会构造一个 MTP 深度,并使用 `MTPChunkedLossWrapper.Config`;其内部仍使用标准 `CrossEntropyLoss`。DeepSeek-V3.2 不在 NPU 侧声明独立 MTP recipe,模型侧直接复用社区 MTP 能力。 |
| 173 | 173 | ||
| 174 | 模型和 loss 必须同时切换。只构造 MTP layers 而继续使用普通 loss,或者只配置 `MTPLoss` 而没有构造 MTP layers,都会造成模型输出与 loss 输入不匹配。 | 174 | 模型和 loss 必须同时切换。只构造 MTP layers 而继续使用普通 loss,或者只配置 `MTPLoss` 而没有构造 MTP layers,都会造成模型输出与 loss 输入不匹配。 |
| 175 | 175 | ||
| @@ -7,7 +7,7 @@ | |||
| 7 | ## 当前方案 | 7 | ## 当前方案 |
| 8 | 8 | ||
| 9 | DSV4 使用混合优化器容器:匹配 Muon 规则的二维矩阵参数交给 `DistMuon`,其余参数交给 | 9 | DSV4 使用混合优化器容器:匹配 Muon 规则的二维矩阵参数交给 `DistMuon`,其余参数交给 |
| 10 | -AdamW。`torchtitan_npu/models/deepseek_v4/config_registry.py` 中的 | 10 | +AdamW。`torchtitan_npu/models/deepseek_v4/muon.py` 中的 |
| 11 | `_dsv4_optimizer_config()` 提供常规 DSV4 optimizer schema; | 11 | `_dsv4_optimizer_config()` 提供常规 DSV4 optimizer schema; |
| 12 | `_dsv4_muon_profile()` 提供参数匹配、FlexShard compute layout 和 bucket 元数据。 | 12 | `_dsv4_muon_profile()` 提供参数匹配、FlexShard compute layout 和 bucket 元数据。 |
| 13 | `--optimizer.name Muon` 才 materialize 出 DistMuon 与 AdamW fallback 两组。 | 13 | `--optimizer.name Muon` 才 materialize 出 DistMuon 与 AdamW fallback 两组。 |
| @@ -32,17 +32,15 @@ Muon 与 AdamW fallback 当前共用 `--optimizer.lr`,没有独立 `muon_lr` | |||
| 32 | 32 | ||
| 33 | ## 如何使用 Muon | 33 | ## 如何使用 Muon |
| 34 | 34 | ||
| 35 | -使用常规 `deepseek_v4_flash_43layers_16experts` recipe,并显式选择 Muon。以下是单机 | 35 | +使用 `deepseek_v4_flash_8p_cpt_4k_a3` recipe(43 层/16 专家 debug 模型),并显式选择 Muon。 |
| 36 | -8 卡的直接启动命令;swap override 也是显式列出,而非 recipe 隐式启用: | 36 | +以下是单机 8 卡的直接启动命令;swap override 也显式列出,便于核对最终集合: |
| 37 | 37 | ||
| 38 | ```bash | 38 | ```bash |
| 39 | -MODULE=torchtitan_npu.models.deepseek_v4 \ | 39 | +MODULE=torchtitan_npu_recipes.models.deepseek_v4 \ |
| 40 | -CONFIG=deepseek_v4_flash_43layers_16experts \ | 40 | +CONFIG=deepseek_v4_flash_8p_cpt_4k_a3 \ |
| 41 | NGPU=8 \ | 41 | NGPU=8 \ |
| 42 | bash scripts/run_train.sh \ | 42 | bash scripts/run_train.sh \ |
| 43 | --hf-assets-path /path/to/DeepSeekV4_tokenizer \ | 43 | --hf-assets-path /path/to/DeepSeekV4_tokenizer \ |
| 44 | - --dataloader.dataset c4_test \ | ||
| 45 | - --dataloader.dataset-path tests/assets/c4_test \ | ||
| 46 | --parallelism.spmd-backend spmd_types \ | 44 | --parallelism.spmd-backend spmd_types \ |
| 47 | --parallelism.data-parallel-shard-degree 8 \ | 45 | --parallelism.data-parallel-shard-degree 8 \ |
| 48 | --parallelism.data-parallel-replicate-degree 1 \ | 46 | --parallelism.data-parallel-replicate-degree 1 \ |
| @@ -50,9 +48,9 @@ bash scripts/run_train.sh \ | |||
| 50 | --parallelism.tensor-parallel-degree 1 \ | 48 | --parallelism.tensor-parallel-degree 1 \ |
| 51 | --parallelism.context-parallel-degree 1 \ | 49 | --parallelism.context-parallel-degree 1 \ |
| 52 | --parallelism.pipeline-parallel-degree 1 \ | 50 | --parallelism.pipeline-parallel-degree 1 \ |
| 53 | - --training.local-batch-size 1 \ | 51 | + --training.num-tokens-per-microbatch-per-dp-rank 4096 \ |
| 54 | - --training.global-batch-size -1 \ | 52 | + --training.num-tokens-per-train-step 262144 \ |
| 55 | - --training.seq-len 4096 \ | 53 | + --training.max-context-length 4096 \ |
| 56 | --training.steps 100 \ | 54 | --training.steps 100 \ |
| 57 | --optimizer.name Muon \ | 55 | --optimizer.name Muon \ |
| 58 | --optimizer.lr 2.2e-4 \ | 56 | --optimizer.lr 2.2e-4 \ |
| @@ -64,13 +62,13 @@ bash scripts/run_train.sh \ | |||
| 64 | --debug.no-moe-force-load-balance \ | 62 | --debug.no-moe-force-load-balance \ |
| 65 | --checkpoint.no-enable \ | 63 | --checkpoint.no-enable \ |
| 66 | --override.imports \ | 64 | --override.imports \ |
| 67 | - torchtitan_npu.override.common.rms_norm.asc \ | 65 | + torchtitan_npu_recipes.overrides.common.rms_norm.asc \ |
| 68 | - torchtitan_npu.override.common.rope.asc_complex \ | 66 | + torchtitan_npu_recipes.overrides.common.rope.asc_complex \ |
| 69 | - torchtitan_npu.override.deepseek_v4.sparse_attn.asc \ | 67 | + torchtitan_npu_recipes.overrides.deepseek_v4.sparse_attn.asc \ |
| 70 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc \ | 68 | + torchtitan_npu_recipes.overrides.deepseek_v4.lightning_indexer.asc \ |
| 71 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post \ | 69 | + torchtitan_npu_recipes.overrides.deepseek_v4.mhc.asc_hc_post \ |
| 72 | - torchtitan_npu.override.common.token_dispatcher.asc \ | 70 | + torchtitan_npu_recipes.overrides.common.token_dispatcher.asc \ |
| 73 | - torchtitan_npu.override.common.optimizer.swap_optimizer | 71 | + torchtitan_npu_recipes.overrides.common.optimizer.swap_optimizer |
| 74 | ``` | 72 | ``` |
| 75 | 73 | ||
| 76 | DeepSeek-V4 示例脚本默认使用 Muon,并固定同一组 Muon 与 swap 参数。 | 74 | DeepSeek-V4 示例脚本默认使用 Muon,并固定同一组 Muon 与 swap 参数。 |
| @@ -100,11 +98,11 @@ swap 是显式 opt-in override,不存在 `swap_optimizer=true` 配置字段。 | |||
| 100 | `--override.imports` 末尾增加: | 98 | `--override.imports` 末尾增加: |
| 101 | 99 | ||
| 102 | ```text | 100 | ```text |
| 103 | -torchtitan_npu.override.common.optimizer.swap_optimizer | 101 | +torchtitan_npu_recipes.overrides.common.optimizer.swap_optimizer |
| 104 | ``` | 102 | ``` |
| 105 | 103 | ||
| 106 | `swap_optimizer` 与 | 104 | `swap_optimizer` 与 |
| 107 | -`torchtitan_npu.override.common.optimizer.virtual`(Virtual Optimizer)都替换 | 105 | +`torchtitan_npu_recipes.overrides.common.optimizer.virtual`(Virtual Optimizer)都替换 |
| 108 | `OptimizersContainer.Config`,不能同时启用。使用 Muon state swap 时, | 106 | `OptimizersContainer.Config`,不能同时启用。使用 Muon state swap 时, |
| 109 | `override.imports` 中不得包含 Virtual Optimizer;需要 Virtual Optimizer 时则移除 | 107 | `override.imports` 中不得包含 Virtual Optimizer;需要 Virtual Optimizer 时则移除 |
| 110 | `swap_optimizer`。 | 108 | `swap_optimizer`。 |
| @@ -50,7 +50,7 @@ Hook 只处理已有 gradient 且 state 尚未初始化的参数,不会覆盖 | |||
| 50 | 50 | ||
| 51 | Virtual Optimizer 通过 TorchTitan 的配置级 override 启用,不增加 `virtual_optimizer_size`、`swap_optimizer_times` 等配置字段。 | 51 | Virtual Optimizer 通过 TorchTitan 的配置级 override 启用,不增加 `virtual_optimizer_size`、`swap_optimizer_times` 等配置字段。 |
| 52 | 52 | ||
| 53 | -Virtual Optimizer 与 `torchtitan_npu.override.common.optimizer.swap_optimizer` 都替换 | 53 | +Virtual Optimizer 与 `torchtitan_npu_recipes.overrides.common.optimizer.swap_optimizer` 都替换 |
| 54 | `OptimizersContainer.Config`,不能同时出现在 `override.imports` 中。 | 54 | `OptimizersContainer.Config`,不能同时出现在 `override.imports` 中。 |
| 55 | 55 | ||
| 56 | ### 命令行示例 | 56 | ### 命令行示例 |
| @@ -59,7 +59,7 @@ Virtual Optimizer 与 `torchtitan_npu.override.common.optimizer.swap_optimizer` | |||
| 59 | python -m torchtitan_npu.train \ | 59 | python -m torchtitan_npu.train \ |
| 60 | --module torchtitan_npu.models.deepseek_v4 \ | 60 | --module torchtitan_npu.models.deepseek_v4 \ |
| 61 | --config deepseek_v4_debugmodel \ | 61 | --config deepseek_v4_debugmodel \ |
| 62 | - --override.imports torchtitan_npu.override.common.optimizer.virtual \ | 62 | + --override.imports torchtitan_npu_recipes.overrides.common.optimizer.virtual \ |
| 63 | --checkpoint.enable \ | 63 | --checkpoint.enable \ |
| 64 | --checkpoint.async-mode disabled | 64 | --checkpoint.async-mode disabled |
| 65 | ``` | 65 | ``` |
| @@ -70,7 +70,7 @@ python -m torchtitan_npu.train \ | |||
| 70 | 70 | ||
| 71 | ```python | 71 | ```python |
| 72 | cfg.override.imports.append( | 72 | cfg.override.imports.append( |
| 73 | - "torchtitan_npu.override.common.optimizer.virtual" | 73 | + "torchtitan_npu_recipes.overrides.common.optimizer.virtual" |
| 74 | ) | 74 | ) |
| 75 | cfg.checkpoint.enable = True | 75 | cfg.checkpoint.enable = True |
| 76 | cfg.checkpoint.async_mode = "disabled" | 76 | cfg.checkpoint.async_mode = "disabled" |
| @@ -130,8 +130,8 @@ CPU 单元测试覆盖 swap allocation、zero-sized fallback、lazy state 初始 | |||
| 130 | 130 | ||
| 131 | ## 相关链接 | 131 | ## 相关链接 |
| 132 | 132 | ||
| 133 | -- [Virtual Optimizer override](../../torchtitan_npu/override/common/optimizer.py) | 133 | +- [Virtual Optimizer override](../../torchtitan_npu_recipes/overrides/common/optimizer.py) |
| 134 | - [Virtual Optimizer 单元测试](../../tests/unit_tests/override/common/test_optimizer.py) | 134 | - [Virtual Optimizer 单元测试](../../tests/unit_tests/override/common/test_optimizer.py) |
| 135 | -- [Override 机制与入口](../../torchtitan_npu/override/README.md) | 135 | +- [Override 机制与入口](../../torchtitan_npu_recipes/overrides/README.md) |
| 136 | - [软件安装](../user-guides/installation.md) | 136 | - [软件安装](../user-guides/installation.md) |
| 137 | - [快速上手](../user-guides/quickstart.md) | 137 | - [快速上手](../user-guides/quickstart.md) |
| @@ -17,8 +17,8 @@ tests/assets/deepseek_v3/ | |||
| 17 | 2. 准备数据集。 | 17 | 2. 准备数据集。 |
| 18 | 18 | ||
| 19 | 已在 `tests/assets/c4_test/` 中预置 `c4_test` 测试数据集,单卡命令直接使用该目录,无需额外下载。 | 19 | 已在 `tests/assets/c4_test/` 中预置 `c4_test` 测试数据集,单卡命令直接使用该目录,无需额外下载。 |
| 20 | - | 20 | +所用数据集属于训练配置,写在 recipe 中;`--dataloader.dataset` 等旧参数已不存在。使用其他数据集时, |
| 21 | -使用其他数据集时,需同时修改单卡命令中的 `--dataloader.dataset` 和 `--dataloader.dataset-path`。 | 21 | +写一个自定义 recipe(见下文“选择 recipe”),由 Python 构造 source、processor 和 packing 图。 |
| 22 | 22 | ||
| 23 | ## 配置 CANN 环境变量 | 23 | ## 配置 CANN 环境变量 |
| 24 | 24 | ||
| @@ -41,7 +41,9 @@ ASCEND_SET_ENV_PATH=/path/to/ascend-toolkit/set_env.sh \ | |||
| 41 | 41 | ||
| 42 | ## 启动训练任务 | 42 | ## 启动训练任务 |
| 43 | 43 | ||
| 44 | -DeepSeek V3 单卡训练任务可直接使用 `scripts/run_train.sh` 启动。`scripts/run_train.sh` 默认使用 1 张 NPU 和 `deepseek_v3_debugmodel` 配置,并把额外命令行参数原样透传给训练入口。 | 44 | +DeepSeek V3 单卡训练任务可直接使用 `scripts/run_train.sh` 启动。`scripts/run_train.sh` 默认使用 |
| 45 | +1 张 NPU、`torchtitan_npu.models.deepseek_v3` 模块和 `deepseek_v3_debugmodel` 配置,并把额外命令行 | ||
| 46 | +参数原样透传给训练入口。仓库示例的正式配置在 `torchtitan_npu_recipes/` 中,由 `MODULE`/`CONFIG` 选择。 | ||
| 45 | 47 | ||
| 46 | ### 单卡训练任务 | 48 | ### 单卡训练任务 |
| 47 | 49 | ||
| @@ -49,23 +51,44 @@ DeepSeek V3 单卡训练任务可直接使用 `scripts/run_train.sh` 启动。`s | |||
| 49 | 51 | ||
| 50 | ```bash | 52 | ```bash |
| 51 | NGPU=1 \ | 53 | NGPU=1 \ |
| 54 | +MODULE=torchtitan_npu.models.deepseek_v3 CONFIG=deepseek_v3_debugmodel \ | ||
| 52 | bash scripts/run_train.sh \ | 55 | bash scripts/run_train.sh \ |
| 53 | --hf-assets-path tests/assets/deepseek_v3 \ | 56 | --hf-assets-path tests/assets/deepseek_v3 \ |
| 54 | - --dataloader.dataset c4_test \ | ||
| 55 | - --dataloader.dataset-path tests/assets/c4_test \ | ||
| 56 | - --training.local-batch-size 1 \ | ||
| 57 | - --training.seq-len 2048 \ | ||
| 58 | --training.steps 5 | 57 | --training.steps 5 |
| 59 | ``` | 58 | ``` |
| 60 | 59 | ||
| 61 | > [!NOTE] | 60 | > [!NOTE] |
| 62 | > 通用 launcher 配置项说明: | 61 | > 通用 launcher 配置项说明: |
| 63 | > - `ASCEND_SET_ENV_PATH`:可选,自定义 CANN `set_env.sh` 路径;设置后优先加载该文件。 | 62 | > - `ASCEND_SET_ENV_PATH`:可选,自定义 CANN `set_env.sh` 路径;设置后优先加载该文件。 |
| 64 | -> - `MODULE`:模型 Python 模块,默认为 `torchtitan.models.deepseek_v3`。 | 63 | +> - `MODULE`:提供 recipe 函数的 Python 模块;示例脚本默认指向 `torchtitan_npu_recipes.<model>`。 |
| 65 | -> - `CONFIG`:`torchtitan/models/deepseek_v3/config_registry.py` 中注册的配置函数,默认为 `deepseek_v3_debugmodel`。 | 64 | +> - `CONFIG`:模块内的零参数配置函数(recipe)。 |
| 66 | -> - `NGPU`:当前节点参与训练的 NPU 数量,默认为 `1`。 | 65 | +> - `NGPU`:当前节点参与训练的 NPU 数量,默认为 `1`。世界大小必须等于 recipe 中并行度乘积。 |
| 67 | -> - Tokenizer 和数据集由上述命令中的 CLI 参数指定;`scripts/run_train.sh` 不读取 `HF_ASSETS_PATH`、`DATASET` 或 `DATASET_PATH` 环境变量。 | 66 | +> - Tokenizer 资源路径由 `--hf-assets-path`(或示例脚本的 `HF_ASSETS_PATH`)提供;数据集在 recipe 中配置,`scripts/run_train.sh` 不读取 `DATASET`、`DATASET_PATH` 等数据环境变量。 |
| 68 | -> - 脚本后的其他参数会原样传给 `torchtitan_npu.train`,可用于覆盖配置函数中的训练和并行参数。 | 67 | +> - 脚本后的其他参数会原样传给 `torchtitan_npu.train`,可用于覆盖 recipe 中的训练和并行参数。 |
| 68 | + | ||
| 69 | +### 选择 recipe 与自定义配置 | ||
| 70 | + | ||
| 71 | +`MODULE` 接受任意可导入模块,因此本地数据或 cluster 配置不需要改仓库脚本: | ||
| 72 | + | ||
| 73 | +```python | ||
| 74 | +# my_company_configs/dsv4.py | ||
| 75 | +from torchtitan_npu_recipes.models import deepseek_v4 | ||
| 76 | + | ||
| 77 | + | ||
| 78 | +def dsv4_flash_cpt_local(): | ||
| 79 | + return deepseek_v4.deepseek_v4_flash_cpt_4k_a3( | ||
| 80 | + text_dataset_path="/data/corpus/c4/train.jsonl", | ||
| 81 | + ) | ||
| 82 | +``` | ||
| 83 | + | ||
| 84 | +```bash | ||
| 85 | +MODULE=my_company_configs.dsv4 CONFIG=dsv4_flash_cpt_local \ | ||
| 86 | + NGPU=16 bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a3.sh | ||
| 87 | +``` | ||
| 88 | + | ||
| 89 | +示例脚本仍可用 `CONFIG` 覆盖默认 recipe,`USE_GOLDEN=1` 选择 reference 算子版本; | ||
| 90 | +DeepSeek-V4.1 A5 另可用 `USE_TILELANG=1` 选择 TileLang mHC 变体,Qwen3.5 用 | ||
| 91 | +`ENABLE_NPU_MOE_DISPATCHER=1` 选择 ASC MoE dispatcher 变体。 | ||
| 69 | 92 | ||
| 70 | 93 | ||
| 71 | ### 单机 8 卡 EP8 训练任务 | 94 | ### 单机 8 卡 EP8 训练任务 |
| @@ -2,7 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | `examples/` 放置面向用户的 recipe launcher、参数组合和小规模 debug 入口。 | 3 | `examples/` 放置面向用户的 recipe launcher、参数组合和小规模 debug 入口。 |
| 4 | 4 | ||
| 5 | -- launcher 只组合已实现的 module、config 和 `override.imports`,不承载可复用生产逻辑。 | 5 | +- launcher 只选择 `torchtitan_npu_recipes` 中的 `MODULE`/`CONFIG`,保留进程数、节点、CANN/HCCL |
| 6 | -- 保留用户传入的额外 CLI 参数;不在 wrapper 中隐式改变 checkpoint、数值或并行语义。 | 6 | + 环境、资源路径和日志设置;训练配置写在 recipe,不在 shell 拼接或从环境变量读取数据源。 |
| 7 | -- 每个示例的模型、硬件代际、进程数、可选依赖和默认 override 必须可从脚本和相关文档中确认。 | 7 | +- 保留用户传入的额外 CLI 参数并放在最后;不在 wrapper 中隐式改变 checkpoint、数值或并行语义。 |
| 8 | +- `USE_GOLDEN`、`USE_TILELANG`、`ENABLE_NPU_MOE_DISPATCHER` 等既有选择器只做显式 recipe 映射。 | ||
| 9 | +- 每个示例的模型、硬件代际、进程数、可选依赖和默认 recipe 必须可从脚本和相关文档中确认。 | ||
| 8 | - `debug/` 只表示小规模调试配置,不代表数值或性能已验收。 | 10 | - `debug/` 只表示小规模调试配置,不代表数值或性能已验收。 |
| @@ -4,163 +4,33 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Run this script on a single node. | 7 | + |
| 8 | -# Append CLI arguments to override the defaults below: | 8 | +# Single-node A3 8P DeepSeek-V4 Flash debug CPT (43 layers, 16 experts). |
| 9 | -# ./examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3.sh --training.steps 5 | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | -# USE_GOLDEN=1 selects the reference combination (the model's default attention). | 10 | +# |
| 11 | -# For deterministic execution, append | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | -# --debug.seed 42 --debug.deterministic to the command line. | 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. |
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 13 | 14 | ||
| 14 | set -euo pipefail | 15 | set -euo pipefail |
| 15 | 16 | ||
| 16 | -NGPU="${NGPU:-8}" | 17 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4}" |
| 17 | -WORLD_SIZE="${NGPU}" | 18 | +if [[ -z "${CONFIG:-}" ]]; then |
| 18 | - | 19 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 19 | -# Model | 20 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a3_golden" |
| 20 | -MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4}" | 21 | + else |
| 21 | -CONFIG="${CONFIG:-deepseek_v4_flash_43layers_16experts}" | 22 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a3" |
| 22 | - | 23 | + fi |
| 23 | -# Dataloader & Checkpoint | ||
| 24 | -# Dataset selection and source paths belong to the selected MODULE/CONFIG recipe. | ||
| 25 | -HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" # your tokenizer path | ||
| 26 | -CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" # your model save/load ckpt path | ||
| 27 | - | ||
| 28 | -# Parallelism | ||
| 29 | -TP=1 | ||
| 30 | -PP=1 | ||
| 31 | -EP=8 | ||
| 32 | -CP="${CP:-1}" | ||
| 33 | -DP_SHARD=8 | ||
| 34 | -DP_REPLICATE=$((WORLD_SIZE / (DP_SHARD * CP * TP * PP))) | ||
| 35 | -SPMD_BACKEND="spmd_types" | ||
| 36 | - | ||
| 37 | -# Training | ||
| 38 | -SEQ_LEN=4096 | ||
| 39 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=4096 | ||
| 40 | -NUM_TOKENS_PER_TRAIN_STEP=262144 | ||
| 41 | -STEPS=100 | ||
| 42 | - | ||
| 43 | -# Debug | ||
| 44 | -USE_GOLDEN="${USE_GOLDEN:-0}" | ||
| 45 | -DEBUG_ARGS=" | ||
| 46 | - --debug.no-moe-force-load-balance | ||
| 47 | - --debug.print-config | ||
| 48 | -" | ||
| 49 | - | ||
| 50 | -# HF assets | ||
| 51 | -HF_ASSETS_ARGS=" | ||
| 52 | - --hf-assets-path ${HF_ASSETS_PATH} | ||
| 53 | -" | ||
| 54 | - | ||
| 55 | -# Parallelism | ||
| 56 | -PARALLELISM_ARGS=" | ||
| 57 | - --parallelism.spmd-backend ${SPMD_BACKEND} | ||
| 58 | - --parallelism.data-parallel-shard-degree ${DP_SHARD} | ||
| 59 | - --parallelism.data-parallel-replicate-degree ${DP_REPLICATE} | ||
| 60 | - --parallelism.expert-parallel-degree ${EP} | ||
| 61 | - --parallelism.tensor-parallel-degree ${TP} | ||
| 62 | - --parallelism.context-parallel-degree ${CP} | ||
| 63 | - --parallelism.context-parallel-load-balancer doc_chunk | ||
| 64 | - --parallelism.pipeline-parallel-degree ${PP} | ||
| 65 | -" | ||
| 66 | - | ||
| 67 | -# Compile | ||
| 68 | -COMPILE_ARGS=" | ||
| 69 | - --compile.enable | ||
| 70 | - --compile.components model | ||
| 71 | - --compile.backend inductor | ||
| 72 | -" | ||
| 73 | - | ||
| 74 | -# Training | ||
| 75 | -TRAINING_ARGS=" | ||
| 76 | - --training.num-tokens-per-microbatch-per-dp-rank ${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK} | ||
| 77 | - --training.num-tokens-per-train-step ${NUM_TOKENS_PER_TRAIN_STEP} | ||
| 78 | - --training.max-context-length ${SEQ_LEN} | ||
| 79 | - --training.steps ${STEPS} | ||
| 80 | - --training.disable-cuda-graphs | ||
| 81 | -" | ||
| 82 | - | ||
| 83 | -# Checkpoint | ||
| 84 | -# `checkpoint.folder` is the save/load root (`CKPT_SAVE_LOAD_PATH`). If it | ||
| 85 | -# already contains a valid step-* checkpoint, upstream TorchTitan resumes from | ||
| 86 | -# it; use a new/empty folder when starting a fresh run. | ||
| 87 | -CHECKPOINT_ARGS=" | ||
| 88 | - --checkpoint.no-enable | ||
| 89 | - --checkpoint.load-only | ||
| 90 | - --checkpoint.folder ${CKPT_SAVE_LOAD_PATH} | ||
| 91 | -" | ||
| 92 | - | ||
| 93 | -# Profiler | ||
| 94 | -PROFILER_ARGS=" | ||
| 95 | - --profiler.no-enable-profiling | ||
| 96 | - --profiler.save-traces-folder profiling_path | ||
| 97 | - --profiler.extension.no-enable-online-parse | ||
| 98 | - --profiler.extension.profiler-start 6 | ||
| 99 | - --profiler.extension.profiler-end 7 | ||
| 100 | - --profiler.extension.profile-ranks 0 | ||
| 101 | -" | ||
| 102 | - | ||
| 103 | -# Communication | ||
| 104 | -COMM_ARGS=" | ||
| 105 | - --comm.init-timeout-seconds 7200 | ||
| 106 | - --comm.train-timeout-seconds 600 | ||
| 107 | -" | ||
| 108 | - | ||
| 109 | -# Optimizer | ||
| 110 | -OPTIMIZER_ARGS=" | ||
| 111 | - --optimizer.name Muon | ||
| 112 | - --optimizer.lr 1.0e-5 | ||
| 113 | - --optimizer.beta1 0.9 | ||
| 114 | - --optimizer.beta2 0.95 | ||
| 115 | - --optimizer.eps 1.0e-8 | ||
| 116 | - --optimizer.weight_decay 1.0e-1 | ||
| 117 | - --optimizer.muon_momentum 0.95 | ||
| 118 | - --optimizer.muon_enable_nesterov | ||
| 119 | - --optimizer.muon_ns_steps 10 | ||
| 120 | - --optimizer.muon_adjust_lr_fn match_rms_adamw | ||
| 121 | -" | ||
| 122 | -OPTIMIZER_OVERRIDES="${OPTIMIZER_OVERRIDES-torchtitan_npu.override.common.optimizer.swap_optimizer}" | ||
| 123 | - | ||
| 124 | -if [[ "${USE_GOLDEN}" == "1" ]]; then | ||
| 125 | - DEFAULT_CLI_OVERRIDES="" | ||
| 126 | - NPU_OPS_OVERRIDES=( | ||
| 127 | - torchtitan_npu.override.common.rope.workaround | ||
| 128 | - ) | ||
| 129 | -else | ||
| 130 | - DEFAULT_CLI_OVERRIDES="torchtitan_npu.override.common.rope.asc_complex" | ||
| 131 | - NPU_OPS_OVERRIDES=( | ||
| 132 | - # Attention / DSA | ||
| 133 | - torchtitan_npu.override.common.rms_norm.asc | ||
| 134 | - | ||
| 135 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc | ||
| 136 | - | ||
| 137 | - torchtitan_npu.override.deepseek_v4.sparse_attn.asc | ||
| 138 | - # MHC | ||
| 139 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre | ||
| 140 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post | ||
| 141 | - # MoE token dispatcher | ||
| 142 | - torchtitan_npu.override.common.token_dispatcher.asc | ||
| 143 | - ) | ||
| 144 | fi | 24 | fi |
| 25 | +NGPU="${NGPU:-8}" | ||
| 26 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 27 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 145 | 28 | ||
| 146 | -# Wrapper defaults extend override.imports after the base targets. | ||
| 147 | -CLI_OVERRIDES="${CLI_OVERRIDES:-${DEFAULT_CLI_OVERRIDES}}" | ||
| 148 | - | ||
| 149 | -DSV4_PER_DOC_ALIGNMENT="${DSV4_PER_DOC_ALIGNMENT:-$((128 * CP))}" \ | ||
| 150 | MODULE="${MODULE}" \ | 29 | MODULE="${MODULE}" \ |
| 151 | CONFIG="${CONFIG}" \ | 30 | CONFIG="${CONFIG}" \ |
| 152 | NGPU="${NGPU}" \ | 31 | NGPU="${NGPU}" \ |
| 153 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | 32 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 154 | bash scripts/run_train.sh \ | 33 | bash scripts/run_train.sh \ |
| 155 | - $COMPILE_ARGS \ | 34 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 156 | - $HF_ASSETS_ARGS \ | 35 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 157 | - $PARALLELISM_ARGS \ | ||
| 158 | - $TRAINING_ARGS \ | ||
| 159 | - $DEBUG_ARGS \ | ||
| 160 | - $OPTIMIZER_ARGS \ | ||
| 161 | - $PROFILER_ARGS \ | ||
| 162 | - $COMM_ARGS \ | ||
| 163 | - $CHECKPOINT_ARGS \ | ||
| 164 | - --override.imports "${NPU_OPS_OVERRIDES[@]}" $OPTIMIZER_OVERRIDES \ | ||
| 165 | - $CLI_OVERRIDES \ | ||
| 166 | "$@" | 36 | "$@" |
| @@ -4,26 +4,37 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Run A3 GraphTrainer with sequence-based MoE EP overlap and NPU auto scheduling. | 7 | + |
| 8 | +# Single-node A3 GraphTrainer debug CPT with sequence-based MoE EP overlap. | ||
| 9 | +# | ||
| 10 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 11 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 12 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 13 | + | ||
| 8 | set -euo pipefail | 14 | set -euo pipefail |
| 9 | 15 | ||
| 10 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 11 | 16 | ||
| 12 | -export CONFIG="${CONFIG:-graph_trainer_deepseek_v4_flash_43layers_16experts}" | ||
| 13 | export TORCHINDUCTOR_USE_TORCH_PROFILER_BENCHMARKER=1 | 17 | export TORCHINDUCTOR_USE_TORCH_PROFILER_BENCHMARKER=1 |
| 14 | export TORCHINDUCTOR_USE_EXPERIMENTAL_BENCHMARKER=0 | 18 | export TORCHINDUCTOR_USE_EXPERIMENTAL_BENCHMARKER=0 |
| 15 | export TORCH_NPU_USE_COMPATIBLE_IMPL=1 | 19 | export TORCH_NPU_USE_COMPATIBLE_IMPL=1 |
| 16 | 20 | ||
| 17 | -EP_OVERLAP_ARGS=( | 21 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.graph_trainer.deepseek_v4}" |
| 18 | - --compile.ep_overlap.enabled | 22 | +if [[ -z "${CONFIG:-}" ]]; then |
| 19 | - --compile.ep_overlap.chunk_dim seq | 23 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 20 | - --compile.ep_overlap.strategy graph | 24 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a3_graphtrainer_golden" |
| 21 | - --compile.ep_overlap.module_fqn "layers.*.moe" | 25 | + else |
| 22 | - --compile.pass_pipeline mutation-functionalization+npu_auto_overlap | 26 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a3_graphtrainer" |
| 23 | -) | 27 | + fi |
| 28 | +fi | ||
| 29 | +NGPU="${NGPU:-8}" | ||
| 30 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 31 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 24 | 32 | ||
| 25 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_8p_cpt_4k_a3.sh" \ | 33 | +MODULE="${MODULE}" \ |
| 26 | - --debug.moe-force-load-balance \ | 34 | +CONFIG="${CONFIG}" \ |
| 27 | - --parallelism.spmd-backend partial_dtensor \ | 35 | +NGPU="${NGPU}" \ |
| 28 | - "${EP_OVERLAP_ARGS[@]}" \ | 36 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 37 | +bash scripts/run_train.sh \ | ||
| 38 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 39 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 29 | "$@" | 40 | "$@" |
| @@ -4,61 +4,43 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# A5 wrapper around the common DeepSeek-V4 Flash CPT launcher. Keep the shared | 7 | + |
| 8 | -# model, training, and parallelism defaults in the A3 script; this entrypoint | 8 | +# Single-node A5 8P DeepSeek-V4 Flash debug CPT: FP8, selective recompute. |
| 9 | -# only supplies A5-specific runtime, quantization, and recompute settings. | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | -# Append CLI arguments to override the defaults below: | 10 | +# |
| 11 | -# ./examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5.sh --training.steps 5 | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 12 | 14 | ||
| 13 | set -euo pipefail | 15 | set -euo pipefail |
| 14 | 16 | ||
| 15 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 16 | 17 | ||
| 17 | -# Use the command line `npu-smi info -t topo` to query the CPU affinity of the | 18 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 18 | -# NPU cards for configuration. | 19 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 20 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | ||
| 21 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 22 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 23 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 24 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 19 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | 25 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" |
| 20 | 26 | ||
| 21 | -# A5-only fused ops; USE_GOLDEN=1 keeps the pure reference list. | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4}" |
| 22 | -if [[ "${USE_GOLDEN:-0}" != "1" ]]; then | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 23 | - export CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rope.asc_partial \ | 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 24 | - torchtitan_npu.override.deepseek_v4.compressor.asc \ | 30 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5_golden" |
| 25 | - torchtitan_npu.override.common.swiglu_group.asc \ | 31 | + else |
| 26 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts}" | 32 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5" |
| 33 | + fi | ||
| 27 | fi | 34 | fi |
| 35 | +NGPU="${NGPU:-8}" | ||
| 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 37 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 28 | 38 | ||
| 29 | -# A5 defaults to block-FP8 quantized training. Append | 39 | +MODULE="${MODULE}" \ |
| 30 | -# --extension.quantization.no-enable-quantized-training for BF16 training. | 40 | +CONFIG="${CONFIG}" \ |
| 31 | -# | 41 | +NGPU="${NGPU}" \ |
| 32 | -# fsdp-prequantize leaves fsdp-prequantize-fqns unset, so the recipe default | 42 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 33 | -# whitelist (all Block FP8 projections) applies. The runtime guard requires | 43 | +bash scripts/run_train.sh \ |
| 34 | -# each whitelisted weight's dp-sharded dim0 to stay 64-aligned: at this | 44 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 35 | -# script's DP_SHARD=8 every default entry is aligned (wkv dim0=512 -> 64 | 45 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 36 | -# rows/rank). At degrees where an entry breaks alignment (e.g. DP_SHARD=16: | 46 | + "$@" |
| 37 | -# wkv shards to 32 rows) training fails fast at startup with a fix hint; | ||
| 38 | -# narrow the whitelist by appending the default patterns minus the offending | ||
| 39 | -# one, e.g. excluding wkv (comma-separated in a single argument, matching the | ||
| 40 | -# 4K entry): | ||
| 41 | -# --extension.quantization.fsdp-prequantize-fqns .attention.wq_a,.attention.wq_b,.attention.wo_a,.attention.wo_b,.attention.indexer.wq_b,.moe.shared_experts.w1,.moe.shared_experts.w2,.moe.shared_experts.w3,.moe.routed_experts.inner_experts | ||
| 42 | -# A user whitelist fails fast on any pattern absent from the model, so drop | ||
| 43 | -# the .moe.shared_experts.* entries on a model without shared experts. | ||
| 44 | -QUANTIZATION_ARGS=( | ||
| 45 | - --extension.quantization.enable-quantized-training | ||
| 46 | - --extension.quantization.recipe all_block_fp8 | ||
| 47 | - --extension.quantization.enable-fsdp-prequantize | ||
| 48 | - --extension.quantization.li-quantization fp8 | ||
| 49 | - --extension.quantization.kv-norm-quantization.format mxfp8 | ||
| 50 | - --extension.quantization.kv-norm-quantization.fqns .attention.kv_norm,.attention.compressor.norm | ||
| 51 | - --extension.quantization.kv-norm-quantization.block-size 64 | ||
| 52 | -) | ||
| 53 | - | ||
| 54 | -# Disable swap optimizer for better performance | ||
| 55 | -export OPTIMIZER_OVERRIDES="" | ||
| 56 | - | ||
| 57 | -# Tyro treats activation-checkpoint:selective as a subcommand, so it must be | ||
| 58 | -# the final token after all regular options and override targets. | ||
| 59 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_8p_cpt_4k_a3.sh" \ | ||
| 60 | - --training.num-tokens-per-microbatch-per-dp-rank 8192 \ | ||
| 61 | - "${QUANTIZATION_ARGS[@]}" \ | ||
| 62 | - --debug.moe-force-load-balance \ | ||
| 63 | - "$@" \ | ||
| 64 | - activation-checkpoint:selective | ||
| @@ -4,42 +4,39 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Add batch C/V scheduling to the A5 training recipe. | 7 | + |
| 8 | -# Append CLI arguments to override training defaults, for example: | 8 | +# A5 batch C/V scheduling experiment on top of the GraphTrainer config. |
| 9 | -# bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel.sh --training.steps 10 | 9 | +# Requires the cv_parallel pass pipeline; see docs/feature_guides/graph_trainer_cv_parallel.md. |
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 10 | set -euo pipefail | 15 | set -euo pipefail |
| 11 | 16 | ||
| 12 | -export MODULE=torchtitan_npu.models.deepseek_v4 | ||
| 13 | -export CONFIG="${CONFIG:-graph_trainer_deepseek_v4_flash_43layers_16experts}" | ||
| 14 | -export NGPU="${NGPU:-8}" | ||
| 15 | 17 | ||
| 16 | -bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5.sh \ | 18 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 17 | - --parallelism.spmd-backend partial_dtensor \ | 19 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 18 | - --parallelism.data-parallel-shard-degree "${NGPU}" \ | 20 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| 19 | - --parallelism.data-parallel-replicate-degree 1 \ | 21 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" |
| 20 | - --parallelism.expert-parallel-degree "${NGPU}" \ | 22 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 21 | - --compile.mode aot_fx_trace \ | 23 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" |
| 22 | - --compile.enable-passes \ | 24 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. |
| 23 | - --compile.backend aot_eager \ | 25 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" |
| 24 | - --compile.inductor-compilation regional \ | 26 | + |
| 25 | - --compile.pass-pipeline cv_parallel \ | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.graph_trainer.deepseek_v4}" |
| 26 | - --compile.memory-policy full \ | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 27 | - --compile.ep-overlap.enabled \ | 29 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel" |
| 28 | - --compile.ep-overlap.chunk-dim batch \ | 30 | +fi |
| 29 | - --compile.ep-overlap.strategy graph \ | 31 | +NGPU="${NGPU:-8}" |
| 30 | - --compile.ep-overlap.module-fqn "layers.*" \ | 32 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" |
| 31 | - --compile.no-enable-autoparallel \ | 33 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" |
| 32 | - --compile.no-enable-fsdp-ag-rs-overlap \ | 34 | + |
| 33 | - --compile.no-enable-fsdp-dense-region-overlap \ | 35 | +MODULE="${MODULE}" \ |
| 34 | - --compile.no-numerics-changing-optim \ | 36 | +CONFIG="${CONFIG}" \ |
| 35 | - --override.imports \ | 37 | +NGPU="${NGPU}" \ |
| 36 | - torchtitan_npu.override.common.rms_norm.asc \ | 38 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 37 | - torchtitan_npu.override.common.rope.asc_partial \ | 39 | +bash scripts/run_train.sh \ |
| 38 | - torchtitan_npu.override.common.swiglu_group.asc \ | 40 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 39 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts \ | 41 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 40 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc \ | ||
| 41 | - torchtitan_npu.override.deepseek_v4.sparse_attn.asc \ | ||
| 42 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre \ | ||
| 43 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post \ | ||
| 44 | - torchtitan_npu.extensions.experiment.cv_parallel.batch_chunk_token_dispatcher.asc_dispatcher \ | ||
| 45 | "$@" | 42 | "$@" |
| @@ -4,32 +4,48 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Single-node A5 GraphTrainer debug recipe with sequence-based EP overlap. | 7 | + |
| 8 | -# Save shared/routed MoE W13 activations with the dsv4-mhc-moe-save policy. | 8 | +# Single-node A5 GraphTrainer debug CPT with the DSV4 MHC/MoE save policy. |
| 9 | -# Append CLI arguments to override defaults, for example --training.steps 5. | 9 | +# USE_GOLDEN=1 selects the reference operators. |
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 10 | set -euo pipefail | 15 | set -euo pipefail |
| 11 | 16 | ||
| 12 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 13 | 17 | ||
| 14 | -export CONFIG="${CONFIG:-graph_trainer_deepseek_v4_flash_43layers_16experts}" | ||
| 15 | export TORCHINDUCTOR_USE_TORCH_PROFILER_BENCHMARKER=1 | 18 | export TORCHINDUCTOR_USE_TORCH_PROFILER_BENCHMARKER=1 |
| 16 | export TORCHINDUCTOR_USE_EXPERIMENTAL_BENCHMARKER=0 | 19 | export TORCHINDUCTOR_USE_EXPERIMENTAL_BENCHMARKER=0 |
| 17 | export TORCH_NPU_USE_COMPATIBLE_IMPL=1 | 20 | export TORCH_NPU_USE_COMPATIBLE_IMPL=1 |
| 18 | 21 | ||
| 19 | -STEPS="${STEPS:-20}" | ||
| 20 | 22 | ||
| 21 | -EP_OVERLAP_ARGS=( | 23 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 22 | - --compile.ep_overlap.enabled | 24 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 23 | - --compile.ep_overlap.chunk_dim seq | 25 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| 24 | - --compile.ep_overlap.strategy graph | 26 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" |
| 25 | - --compile.ep_overlap.module_fqn "layers.*.moe" | 27 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 26 | - --compile.pass_pipeline mutation-functionalization+npu_auto_overlap | 28 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" |
| 27 | -) | 29 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. |
| 30 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 28 | 31 | ||
| 29 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_8p_cpt_4k_a5.sh" \ | 32 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.graph_trainer.deepseek_v4}" |
| 30 | - --debug.moe-force-load-balance \ | 33 | +if [[ -z "${CONFIG:-}" ]]; then |
| 31 | - --parallelism.spmd-backend partial_dtensor \ | 34 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 32 | - --compile.memory-policy dsv4-mhc-moe-save \ | 35 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5_graphtrainer_golden" |
| 33 | - --training.steps "${STEPS}" \ | 36 | + else |
| 34 | - "${EP_OVERLAP_ARGS[@]}" \ | 37 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5_graphtrainer" |
| 38 | + fi | ||
| 39 | +fi | ||
| 40 | +NGPU="${NGPU:-8}" | ||
| 41 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 42 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 43 | + | ||
| 44 | +MODULE="${MODULE}" \ | ||
| 45 | +CONFIG="${CONFIG}" \ | ||
| 46 | +NGPU="${NGPU}" \ | ||
| 47 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 48 | +bash scripts/run_train.sh \ | ||
| 49 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 50 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 35 | "$@" | 51 | "$@" |
| @@ -4,41 +4,43 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# A5 wrapper around the common DeepSeek-V4 Flash CPT launcher. Keep the shared | 7 | + |
| 8 | -# model, training, and parallelism defaults in the A3 script; this entrypoint | 8 | +# Single-node A5 8P debug CPT with HiF8 (current-tensor scaling) training. |
| 9 | -# only supplies A5-specific runtime, quantization, and recompute settings. | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | -# Append CLI arguments to override the defaults below: | 10 | +# |
| 11 | -# ./examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5_hif8.sh --training.steps 5 | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 12 | 14 | ||
| 13 | set -euo pipefail | 15 | set -euo pipefail |
| 14 | 16 | ||
| 15 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 16 | 17 | ||
| 17 | -# Use the command line `npu-smi info -t topo` to query the CPU affinity of the | 18 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 18 | -# NPU cards for configuration. | 19 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 20 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | ||
| 21 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 22 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 23 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 24 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 19 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | 25 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" |
| 20 | 26 | ||
| 21 | -# A5-only fused ops; USE_GOLDEN=1 keeps the pure reference list. | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4}" |
| 22 | -if [[ "${USE_GOLDEN:-0}" != "1" ]]; then | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 23 | - export CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rope.asc_partial \ | 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 24 | - torchtitan_npu.override.common.swiglu_group.asc \ | 30 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5_hif8_golden" |
| 25 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts}" | 31 | + else |
| 32 | + CONFIG="deepseek_v4_flash_8p_cpt_4k_a5_hif8" | ||
| 33 | + fi | ||
| 26 | fi | 34 | fi |
| 35 | +NGPU="${NGPU:-8}" | ||
| 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 37 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 27 | 38 | ||
| 28 | -# HiF8 (current tensor scaling) quantized training. | 39 | +MODULE="${MODULE}" \ |
| 29 | -# Append --extension.quantization.no-enable-quantized-training for BF16 | 40 | +CONFIG="${CONFIG}" \ |
| 30 | -# training. | 41 | +NGPU="${NGPU}" \ |
| 31 | - | 42 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 32 | -QUANTIZATION_ARGS=( | 43 | +bash scripts/run_train.sh \ |
| 33 | - --extension.quantization.enable-quantized-training | 44 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 34 | - --extension.quantization.recipe all_hif8 | 45 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 35 | - --extension.quantization.li-quantization hif8 | 46 | + "$@" |
| 36 | -) | ||
| 37 | - | ||
| 38 | -# Tyro treats activation-checkpoint:selective as a subcommand, so it must be | ||
| 39 | -# the final token after all regular options and override targets. | ||
| 40 | -bash "${SCRIPT_DIR}/deepseek_v4_flash_8p_cpt_4k_a3.sh" \ | ||
| 41 | - "${QUANTIZATION_ARGS[@]}" \ | ||
| 42 | - --debug.moe-force-load-balance \ | ||
| 43 | - "$@" \ | ||
| 44 | - activation-checkpoint:selective | ||
| @@ -1,20 +1,36 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | 2 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. |
| 3 | -# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| 4 | -# SPDX-License-Identifier: BSD-3-Clause | ||
| 5 | # | 3 | # |
| 6 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 7 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 8 | 6 | ||
| 9 | -# SFT wrapper around the 8p CPT launcher in this directory. | 7 | + |
| 8 | +# Single-node A3 8P DeepSeek-V4 Flash debug chat SFT. | ||
| 9 | +# USE_GOLDEN=1 selects the reference operators. | ||
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 10 | set -euo pipefail | 15 | set -euo pipefail |
| 11 | 16 | ||
| 12 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | 17 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4}" |
| 13 | -DATASET_PATH="${DATASET_PATH:-/path/to/train.jsonl}" | 18 | +if [[ -z "${CONFIG:-}" ]]; then |
| 19 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then | ||
| 20 | + CONFIG="deepseek_v4_flash_8p_sft_4k_a3_golden" | ||
| 21 | + else | ||
| 22 | + CONFIG="deepseek_v4_flash_8p_sft_4k_a3" | ||
| 23 | + fi | ||
| 24 | +fi | ||
| 25 | +NGPU="${NGPU:-8}" | ||
| 26 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 27 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 14 | 28 | ||
| 15 | -CONFIG="${CONFIG:-deepseek_v4_flash_43layers_16experts_sft}" \ | 29 | +MODULE="${MODULE}" \ |
| 16 | -DSV4_SFT_DATASET="${DATASET_PATH}" \ | 30 | +CONFIG="${CONFIG}" \ |
| 17 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_8p_cpt_4k_a3.sh" \ | 31 | +NGPU="${NGPU}" \ |
| 18 | - --checkpoint.enable \ | 32 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 19 | - --checkpoint.no-load-only \ | 33 | +bash scripts/run_train.sh \ |
| 34 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 35 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 20 | "$@" | 36 | "$@" |
| @@ -4,152 +4,34 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Run this script on a single node. | 7 | + |
| 8 | -# Append CLI arguments to override the defaults below: | 8 | +# Single-card DeepSeek-V4 debugmodel CPT (16-head fused sparse attention). |
| 9 | -# ./examples/deepseek_v4/debug/deepseek_v4_mini_1p_cpt_2k_a3.sh --training.steps 5 | ||
| 10 | # USE_GOLDEN=1 selects reference attention, the RoPE workaround and AdamW. | 9 | # USE_GOLDEN=1 selects reference attention, the RoPE workaround and AdamW. |
| 11 | -# For deterministic execution, append | 10 | +# |
| 12 | -# --debug.seed 42 --debug.deterministic to the command line. | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 13 | 14 | ||
| 14 | set -euo pipefail | 15 | set -euo pipefail |
| 15 | 16 | ||
| 16 | -NGPU="${NGPU:-1}" | 17 | +export PYTHONUNBUFFERED=1 |
| 17 | -WORLD_SIZE="${NGPU}" | 18 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4}" |
| 18 | - | 19 | +if [[ -z "${CONFIG:-}" ]]; then |
| 19 | -# Model | 20 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 20 | -MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4}" | 21 | + CONFIG="deepseek_v4_mini_1p_cpt_2k_a3_golden" |
| 21 | -CONFIG="${CONFIG:-deepseek_v4_debugmodel}" | 22 | + else |
| 22 | - | 23 | + CONFIG="deepseek_v4_mini_1p_cpt_2k_a3" |
| 23 | -# Dataloader & Checkpoint | 24 | + fi |
| 24 | -# Dataset selection and source paths belong to the selected MODULE/CONFIG recipe. | ||
| 25 | -HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" # your tokenizer path | ||
| 26 | -CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" # your model save/load ckpt path | ||
| 27 | - | ||
| 28 | -# Parallelism | ||
| 29 | -TP=1 | ||
| 30 | -PP=1 | ||
| 31 | -EP=1 | ||
| 32 | -CP="${CP:-1}" | ||
| 33 | -DP_SHARD=1 | ||
| 34 | -DP_REPLICATE=1 | ||
| 35 | -SPMD_BACKEND="spmd_types" | ||
| 36 | - | ||
| 37 | -# Training | ||
| 38 | -SEQ_LEN=2048 | ||
| 39 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=2048 | ||
| 40 | -NUM_TOKENS_PER_TRAIN_STEP=-1 | ||
| 41 | -STEPS=100 | ||
| 42 | - | ||
| 43 | -# Debug | ||
| 44 | -USE_GOLDEN="${USE_GOLDEN:-0}" | ||
| 45 | -DEBUG_ARGS=" | ||
| 46 | - --debug.print-config | ||
| 47 | -" | ||
| 48 | - | ||
| 49 | -# HF assets | ||
| 50 | -HF_ASSETS_ARGS=" | ||
| 51 | - --hf-assets-path ${HF_ASSETS_PATH} | ||
| 52 | -" | ||
| 53 | - | ||
| 54 | -# Parallelism | ||
| 55 | -PARALLELISM_ARGS=" | ||
| 56 | - --parallelism.spmd-backend ${SPMD_BACKEND} | ||
| 57 | - --parallelism.data-parallel-shard-degree ${DP_SHARD} | ||
| 58 | - --parallelism.data-parallel-replicate-degree ${DP_REPLICATE} | ||
| 59 | - --parallelism.expert-parallel-degree ${EP} | ||
| 60 | - --parallelism.tensor-parallel-degree ${TP} | ||
| 61 | - --parallelism.context-parallel-degree ${CP} | ||
| 62 | - --parallelism.context-parallel-load-balancer doc_chunk | ||
| 63 | - --parallelism.pipeline-parallel-degree ${PP} | ||
| 64 | -" | ||
| 65 | - | ||
| 66 | -# Training | ||
| 67 | -TRAINING_ARGS=" | ||
| 68 | - --training.num-tokens-per-microbatch-per-dp-rank ${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK} | ||
| 69 | - --training.num-tokens-per-train-step ${NUM_TOKENS_PER_TRAIN_STEP} | ||
| 70 | - --training.max-context-length ${SEQ_LEN} | ||
| 71 | - --training.steps ${STEPS} | ||
| 72 | - --training.disable-cuda-graphs | ||
| 73 | -" | ||
| 74 | - | ||
| 75 | -# Checkpoint | ||
| 76 | -# `checkpoint.folder` is the save/load root (`CKPT_SAVE_LOAD_PATH`). If it | ||
| 77 | -# already contains a valid step-* checkpoint, upstream TorchTitan resumes from | ||
| 78 | -# it; use a new/empty folder when starting a fresh run. | ||
| 79 | -CHECKPOINT_ARGS=" | ||
| 80 | - --checkpoint.no-enable | ||
| 81 | - --checkpoint.load-only | ||
| 82 | - --checkpoint.folder ${CKPT_SAVE_LOAD_PATH} | ||
| 83 | -" | ||
| 84 | - | ||
| 85 | -# Profiler | ||
| 86 | -PROFILER_ARGS=" | ||
| 87 | - --profiler.no-enable-profiling | ||
| 88 | - --profiler.save-traces-folder profiling_path | ||
| 89 | - --profiler.extension.no-enable-online-parse | ||
| 90 | - --profiler.extension.profiler-start 6 | ||
| 91 | - --profiler.extension.profiler-end 7 | ||
| 92 | - --profiler.extension.profile-ranks 0 | ||
| 93 | -" | ||
| 94 | - | ||
| 95 | -# Communication | ||
| 96 | -COMM_ARGS=" | ||
| 97 | - --comm.init-timeout-seconds 7200 | ||
| 98 | - --comm.train-timeout-seconds 600 | ||
| 99 | -" | ||
| 100 | - | ||
| 101 | -# Optimizer | ||
| 102 | -OPTIMIZER_ARGS=" | ||
| 103 | - --optimizer.name Muon | ||
| 104 | - --optimizer.lr 1.0e-5 | ||
| 105 | - --optimizer.beta1 0.9 | ||
| 106 | - --optimizer.beta2 0.95 | ||
| 107 | - --optimizer.eps 1.0e-8 | ||
| 108 | - --optimizer.weight_decay 1.0e-1 | ||
| 109 | - --optimizer.muon_momentum 0.95 | ||
| 110 | - --optimizer.muon_enable_nesterov | ||
| 111 | - --optimizer.muon_ns_steps 10 | ||
| 112 | - --optimizer.muon_adjust_lr_fn match_rms_adamw | ||
| 113 | -" | ||
| 114 | -OPTIMIZER_OVERRIDES=" | ||
| 115 | - torchtitan_npu.override.common.optimizer.swap_optimizer | ||
| 116 | -" | ||
| 117 | - | ||
| 118 | -if [[ "${USE_GOLDEN}" == "1" ]]; then | ||
| 119 | - OPTIMIZER_ARGS="--optimizer.name AdamW --optimizer.lr 1.0e-5" | ||
| 120 | - OPTIMIZER_OVERRIDES="" | ||
| 121 | - NPU_OPS_OVERRIDES=( | ||
| 122 | - torchtitan_npu.override.common.rope.workaround | ||
| 123 | - ) | ||
| 124 | -else | ||
| 125 | - NPU_OPS_OVERRIDES=( | ||
| 126 | - # Attention / DSA | ||
| 127 | - torchtitan_npu.override.common.rms_norm.asc | ||
| 128 | - torchtitan_npu.override.common.rope.asc_complex | ||
| 129 | - | ||
| 130 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc | ||
| 131 | - | ||
| 132 | - 'torchtitan_npu.override.deepseek_v4.sparse_attn.asc={"num_heads":16,"index_num_heads":8}' | ||
| 133 | - # MHC | ||
| 134 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre | ||
| 135 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post | ||
| 136 | - # MoE token dispatcher | ||
| 137 | - torchtitan_npu.override.common.token_dispatcher.asc | ||
| 138 | - ) | ||
| 139 | fi | 25 | fi |
| 26 | +NGPU="${NGPU:-1}" | ||
| 27 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 28 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 140 | 29 | ||
| 141 | MODULE="${MODULE}" \ | 30 | MODULE="${MODULE}" \ |
| 142 | CONFIG="${CONFIG}" \ | 31 | CONFIG="${CONFIG}" \ |
| 143 | NGPU="${NGPU}" \ | 32 | NGPU="${NGPU}" \ |
| 144 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | 33 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 145 | bash scripts/run_train.sh \ | 34 | bash scripts/run_train.sh \ |
| 146 | - $HF_ASSETS_ARGS \ | 35 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 147 | - $PARALLELISM_ARGS \ | 36 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 148 | - $TRAINING_ARGS \ | ||
| 149 | - $DEBUG_ARGS \ | ||
| 150 | - $OPTIMIZER_ARGS \ | ||
| 151 | - $PROFILER_ARGS \ | ||
| 152 | - $COMM_ARGS \ | ||
| 153 | - $CHECKPOINT_ARGS \ | ||
| 154 | - --override.imports "${NPU_OPS_OVERRIDES[@]}" $OPTIMIZER_OVERRIDES \ | ||
| 155 | "$@" | 37 | "$@" |
| @@ -4,17 +4,17 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Run this script on each participating node; NODE_IPS lists all node addresses. | 7 | + |
| 8 | -# Append CLI arguments to override the defaults below: | 8 | +# Four-node A5 DeepSeek-V4 Pro CPT: DP32/EP32, block-FP8, Muon. |
| 9 | -# NODE_IPS=192.168.1.10,192.168.1.11,192.168.1.12,192.168.1.13 \ | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | -# ./examples/deepseek_v4/debug/deepseek_v4_pro_32p_cpt_4k_a5.sh \ | 10 | +# |
| 11 | -# --checkpoint.initial-load-path /path/to/model_ckpt --training.steps 5 | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | -# USE_GOLDEN=1 selects the reference combination (the model's default attention). | 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. |
| 13 | -# For deterministic execution, append | 13 | +# Append CLI arguments to override the recipe; they are passed through last. |
| 14 | -# --debug.seed 42 --debug.deterministic to the command line. | ||
| 15 | 14 | ||
| 16 | set -euo pipefail | 15 | set -euo pipefail |
| 17 | 16 | ||
| 17 | + | ||
| 18 | export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" | 18 | export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 19 | export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" | 19 | export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 20 | export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | 20 | export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| @@ -22,163 +22,29 @@ export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | |||
| 22 | # Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | 22 | # Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 23 | export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | 23 | export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" |
| 24 | # Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | 24 | # Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. |
| 25 | -export CPU_AFFINITY_CONF=1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191 | 25 | +export CPU_AFFINITY_CONF=1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191} |
| 26 | 26 | ||
| 27 | -NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 28 | -NGPU="${NGPU:-8}" | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 29 | -NNODES=$(awk -F, '{print NF}' <<< "${NODE_IPS}") | 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 30 | -WORLD_SIZE=$((NGPU * NNODES)) | 30 | + CONFIG="deepseek_v4_pro_32p_cpt_4k_a5_golden" |
| 31 | - | 31 | + else |
| 32 | -# Model | 32 | + CONFIG="deepseek_v4_pro_32p_cpt_4k_a5" |
| 33 | -MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4}" | 33 | + fi |
| 34 | -CONFIG="${CONFIG:-deepseek_v4_pro_61layers_32experts}" | ||
| 35 | - | ||
| 36 | -# Dataloader & Checkpoint | ||
| 37 | -HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" # your tokenizer path | ||
| 38 | -CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" # your model save/load ckpt path | ||
| 39 | -CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" # your model initial load ckpt path | ||
| 40 | - | ||
| 41 | -# Parallelism | ||
| 42 | -TP="${TP:-1}" | ||
| 43 | -PP="${PP:-1}" | ||
| 44 | -EP="${EP:-32}" | ||
| 45 | -CP="${CP:-1}" | ||
| 46 | -DP_SHARD="${DP_SHARD:-32}" | ||
| 47 | -DP_REPLICATE=$((WORLD_SIZE / (DP_SHARD * CP * TP * PP))) | ||
| 48 | -SPMD_BACKEND="spmd_types" | ||
| 49 | - | ||
| 50 | -# Training | ||
| 51 | -SEQ_LEN=4096 | ||
| 52 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=4096 | ||
| 53 | -NUM_TOKENS_PER_TRAIN_STEP=1048576 | ||
| 54 | -STEPS="${STEPS:-100}" | ||
| 55 | - | ||
| 56 | -# Debug | ||
| 57 | -USE_GOLDEN="${USE_GOLDEN:-0}" | ||
| 58 | -DEBUG_ARGS=" | ||
| 59 | - --debug.no-moe-force-load-balance | ||
| 60 | - --debug.print-config | ||
| 61 | -" | ||
| 62 | - | ||
| 63 | -# A5 defaults to block-FP8 quantized training. Append | ||
| 64 | -# --extension.quantization.no-enable-quantized-training for BF16 training. | ||
| 65 | -QUANTIZATION_ARGS=" | ||
| 66 | - --extension.quantization.enable-quantized-training | ||
| 67 | - --extension.quantization.recipe all_block_fp8 | ||
| 68 | -" | ||
| 69 | - | ||
| 70 | -# HF assets | ||
| 71 | -HF_ASSETS_ARGS=" | ||
| 72 | - --hf-assets-path ${HF_ASSETS_PATH} | ||
| 73 | -" | ||
| 74 | - | ||
| 75 | -# Parallelism | ||
| 76 | -PARALLELISM_ARGS=" | ||
| 77 | - --parallelism.spmd-backend ${SPMD_BACKEND} | ||
| 78 | - --parallelism.data-parallel-shard-degree ${DP_SHARD} | ||
| 79 | - --parallelism.data-parallel-replicate-degree ${DP_REPLICATE} | ||
| 80 | - --parallelism.expert-parallel-degree ${EP} | ||
| 81 | - --parallelism.tensor-parallel-degree ${TP} | ||
| 82 | - --parallelism.context-parallel-degree ${CP} | ||
| 83 | - --parallelism.context-parallel-load-balancer doc_chunk | ||
| 84 | - --parallelism.pipeline-parallel-degree ${PP} | ||
| 85 | -" | ||
| 86 | - | ||
| 87 | -# Training | ||
| 88 | -TRAINING_ARGS=" | ||
| 89 | - --training.num-tokens-per-microbatch-per-dp-rank ${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK} | ||
| 90 | - --training.num-tokens-per-train-step ${NUM_TOKENS_PER_TRAIN_STEP} | ||
| 91 | - --training.max-context-length ${SEQ_LEN} | ||
| 92 | - --training.steps ${STEPS} | ||
| 93 | - --training.disable-cuda-graphs | ||
| 94 | -" | ||
| 95 | - | ||
| 96 | -# Checkpoint | ||
| 97 | -# `checkpoint.folder` is the output/resume root (`CKPT_SAVE_LOAD_PATH`). If it | ||
| 98 | -# already contains a valid step-* checkpoint, upstream TorchTitan resumes from | ||
| 99 | -# it and ignores `initial-load-path`; use a new/empty folder when cold-starting | ||
| 100 | -# from `CKPT_INIT_LOAD_PATH`. | ||
| 101 | -CHECKPOINT_ARGS=" | ||
| 102 | - --checkpoint.enable | ||
| 103 | - --checkpoint.load-only | ||
| 104 | - --checkpoint.folder ${CKPT_SAVE_LOAD_PATH} | ||
| 105 | - --checkpoint.initial-load-path ${CKPT_INIT_LOAD_PATH} | ||
| 106 | - --checkpoint.initial-load-in-hf | ||
| 107 | -" | ||
| 108 | - | ||
| 109 | -# Profiler | ||
| 110 | -PROFILER_ARGS=" | ||
| 111 | - --profiler.no-enable-profiling | ||
| 112 | - --profiler.save-traces-folder profiling_path | ||
| 113 | - --profiler.extension.no-enable-online-parse | ||
| 114 | - --profiler.extension.profiler-start 6 | ||
| 115 | - --profiler.extension.profiler-end 7 | ||
| 116 | - --profiler.extension.profile-ranks 0 | ||
| 117 | -" | ||
| 118 | - | ||
| 119 | -# Communication | ||
| 120 | -COMM_ARGS=" | ||
| 121 | - --comm.init-timeout-seconds 7200 | ||
| 122 | - --comm.train-timeout-seconds 600 | ||
| 123 | -" | ||
| 124 | - | ||
| 125 | -# Optimizer | ||
| 126 | -OPTIMIZER_ARGS=" | ||
| 127 | - --optimizer.name Muon | ||
| 128 | - --optimizer.lr 1.0e-5 | ||
| 129 | - --optimizer.beta1 0.9 | ||
| 130 | - --optimizer.beta2 0.95 | ||
| 131 | - --optimizer.eps 1.0e-8 | ||
| 132 | - --optimizer.weight_decay 1.0e-1 | ||
| 133 | - --optimizer.muon_momentum 0.95 | ||
| 134 | - --optimizer.muon_enable_nesterov | ||
| 135 | - --optimizer.muon_ns_steps 10 | ||
| 136 | - --optimizer.muon_adjust_lr_fn match_rms_adamw | ||
| 137 | -" | ||
| 138 | -OPTIMIZER_OVERRIDES=" | ||
| 139 | - torchtitan_npu.override.common.optimizer.swap_optimizer | ||
| 140 | -" | ||
| 141 | - | ||
| 142 | -if [[ "${USE_GOLDEN}" == "1" ]]; then | ||
| 143 | - NPU_OPS_OVERRIDES=( | ||
| 144 | - torchtitan_npu.override.common.rope.workaround | ||
| 145 | - ) | ||
| 146 | -else | ||
| 147 | - NPU_OPS_OVERRIDES=( | ||
| 148 | - # Attention / DSA | ||
| 149 | - torchtitan_npu.override.common.rms_norm.asc | ||
| 150 | - torchtitan_npu.override.common.rope.asc_partial | ||
| 151 | - torchtitan_npu.override.deepseek_v4.compressor.asc | ||
| 152 | - | ||
| 153 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc | ||
| 154 | - | ||
| 155 | - 'torchtitan_npu.override.deepseek_v4.sparse_attn.asc={"num_heads":128}' | ||
| 156 | - # MHC | ||
| 157 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre | ||
| 158 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post | ||
| 159 | - # MoE token dispatcher | ||
| 160 | - torchtitan_npu.override.common.token_dispatcher.asc | ||
| 161 | - # MoE SwiGLU Group | ||
| 162 | - torchtitan_npu.override.common.swiglu_group.asc | ||
| 163 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts | ||
| 164 | - ) | ||
| 165 | fi | 34 | fi |
| 35 | +NGPU="${NGPU:-8}" | ||
| 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 37 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 38 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 39 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 166 | 40 | ||
| 167 | -DSV4_PER_DOC_ALIGNMENT="${DSV4_PER_DOC_ALIGNMENT:-$((128 * CP))}" \ | ||
| 168 | MODULE="${MODULE}" \ | 41 | MODULE="${MODULE}" \ |
| 169 | CONFIG="${CONFIG}" \ | 42 | CONFIG="${CONFIG}" \ |
| 170 | -NODE_IPS="${NODE_IPS}" \ | ||
| 171 | NGPU="${NGPU}" \ | 43 | NGPU="${NGPU}" \ |
| 44 | +NODE_IPS="${NODE_IPS}" \ | ||
| 172 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | 45 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 173 | bash scripts/run_train_multinodes.sh \ | 46 | bash scripts/run_train_multinodes.sh \ |
| 174 | - $HF_ASSETS_ARGS \ | 47 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 175 | - $PARALLELISM_ARGS \ | 48 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 176 | - $TRAINING_ARGS \ | 49 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ |
| 177 | - $DEBUG_ARGS \ | ||
| 178 | - $QUANTIZATION_ARGS \ | ||
| 179 | - $OPTIMIZER_ARGS \ | ||
| 180 | - $PROFILER_ARGS \ | ||
| 181 | - $COMM_ARGS \ | ||
| 182 | - $CHECKPOINT_ARGS \ | ||
| 183 | - --override.imports "${NPU_OPS_OVERRIDES[@]}" $OPTIMIZER_OVERRIDES \ | ||
| 184 | "$@" | 50 | "$@" |
| @@ -5,8 +5,16 @@ | |||
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | +# Single-node A5 DeepSeek-V4 Pro CPT with parameter/gradient CPU offload. | ||
| 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. | ||
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 8 | set -euo pipefail | 15 | set -euo pipefail |
| 9 | 16 | ||
| 17 | + | ||
| 10 | export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" | 18 | export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 11 | export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" | 19 | export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 12 | export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | 20 | export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| @@ -14,153 +22,27 @@ export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | |||
| 14 | # Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | 22 | # Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 15 | export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | 23 | export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" |
| 16 | # Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | 24 | # Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. |
| 17 | -export CPU_AFFINITY_CONF=1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191 | 25 | +export CPU_AFFINITY_CONF=1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191} |
| 18 | 26 | ||
| 19 | -NGPU="${NGPU:-8}" | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 20 | -WORLD_SIZE="${NGPU}" | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 21 | - | 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 22 | -# Model | 30 | + CONFIG="deepseek_v4_pro_8p_cpt_4k_a5_cpuoffload_golden" |
| 23 | -MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4}" | 31 | + else |
| 24 | -CONFIG="${CONFIG:-deepseek_v4_pro_61layers_12experts}" | 32 | + CONFIG="deepseek_v4_pro_8p_cpt_4k_a5_cpuoffload" |
| 25 | - | 33 | + fi |
| 26 | -# Dataloader & Checkpoint | ||
| 27 | -HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" # your tokenizer path | ||
| 28 | -CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" # your model save/load ckpt path | ||
| 29 | -CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" # your model initial load ckpt path | ||
| 30 | - | ||
| 31 | -# Parallelism | ||
| 32 | -TP="${TP:-1}" | ||
| 33 | -PP="${PP:-1}" | ||
| 34 | -EP="${EP:-4}" | ||
| 35 | -CP="${CP:-1}" | ||
| 36 | -DP_SHARD="${DP_SHARD:-8}" | ||
| 37 | -DP_REPLICATE=$((WORLD_SIZE / (DP_SHARD * CP * TP * PP))) | ||
| 38 | -SPMD_BACKEND="spmd_types" | ||
| 39 | - | ||
| 40 | -# Training | ||
| 41 | -SEQ_LEN=4096 | ||
| 42 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=4096 | ||
| 43 | -NUM_TOKENS_PER_TRAIN_STEP=262144 | ||
| 44 | -STEPS="${STEPS:-100}" | ||
| 45 | - | ||
| 46 | -# Debug | ||
| 47 | -USE_GOLDEN="${USE_GOLDEN:-0}" | ||
| 48 | -DEBUG_ARGS=" | ||
| 49 | - --debug.no-moe-force-load-balance | ||
| 50 | - --debug.print-config | ||
| 51 | -" | ||
| 52 | - | ||
| 53 | -# HF assets | ||
| 54 | -HF_ASSETS_ARGS=" | ||
| 55 | - --hf-assets-path ${HF_ASSETS_PATH} | ||
| 56 | -" | ||
| 57 | - | ||
| 58 | -# Parallelism | ||
| 59 | -PARALLELISM_ARGS=" | ||
| 60 | - --parallelism.spmd-backend ${SPMD_BACKEND} | ||
| 61 | - --parallelism.data-parallel-shard-degree ${DP_SHARD} | ||
| 62 | - --parallelism.data-parallel-replicate-degree ${DP_REPLICATE} | ||
| 63 | - --parallelism.expert-parallel-degree ${EP} | ||
| 64 | - --parallelism.tensor-parallel-degree ${TP} | ||
| 65 | - --parallelism.context-parallel-degree ${CP} | ||
| 66 | - --parallelism.context-parallel-load-balancer doc_chunk | ||
| 67 | - --parallelism.pipeline-parallel-degree ${PP} | ||
| 68 | -" | ||
| 69 | - | ||
| 70 | -# Training | ||
| 71 | -TRAINING_ARGS=" | ||
| 72 | - --training.num-tokens-per-microbatch-per-dp-rank ${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK} | ||
| 73 | - --training.num-tokens-per-train-step ${NUM_TOKENS_PER_TRAIN_STEP} | ||
| 74 | - --training.max-context-length ${SEQ_LEN} | ||
| 75 | - --training.steps ${STEPS} | ||
| 76 | - --training.disable-cuda-graphs | ||
| 77 | - --training.enable-cpu-offload | ||
| 78 | -" | ||
| 79 | - | ||
| 80 | -# Checkpoint | ||
| 81 | -# `checkpoint.folder` is the output/resume root (`CKPT_SAVE_LOAD_PATH`). If it | ||
| 82 | -# already contains a valid step-* checkpoint, upstream TorchTitan resumes from | ||
| 83 | -# it and ignores `initial-load-path`; use a new/empty folder when cold-starting | ||
| 84 | -# from `CKPT_INIT_LOAD_PATH`. | ||
| 85 | -CHECKPOINT_ARGS=" | ||
| 86 | - --checkpoint.enable | ||
| 87 | - --checkpoint.load-only | ||
| 88 | - --checkpoint.folder ${CKPT_SAVE_LOAD_PATH} | ||
| 89 | - --checkpoint.initial-load-path ${CKPT_INIT_LOAD_PATH} | ||
| 90 | - --checkpoint.initial-load-in-hf | ||
| 91 | -" | ||
| 92 | - | ||
| 93 | -# Profiler | ||
| 94 | -PROFILER_ARGS=" | ||
| 95 | - --profiler.no-enable-profiling | ||
| 96 | - --profiler.save-traces-folder profiling_path | ||
| 97 | - --profiler.extension.no-enable-online-parse | ||
| 98 | - --profiler.extension.profiler-start 6 | ||
| 99 | - --profiler.extension.profiler-end 7 | ||
| 100 | - --profiler.extension.profile-ranks 0 | ||
| 101 | -" | ||
| 102 | - | ||
| 103 | -# Communication | ||
| 104 | -COMM_ARGS=" | ||
| 105 | - --comm.init-timeout-seconds 7200 | ||
| 106 | - --comm.train-timeout-seconds 600 | ||
| 107 | -" | ||
| 108 | - | ||
| 109 | -# Optimizer | ||
| 110 | -OPTIMIZER_ARGS=" | ||
| 111 | - --optimizer.name Muon | ||
| 112 | - --optimizer.lr 1.0e-5 | ||
| 113 | - --optimizer.beta1 0.9 | ||
| 114 | - --optimizer.beta2 0.95 | ||
| 115 | - --optimizer.eps 1.0e-8 | ||
| 116 | - --optimizer.weight_decay 1.0e-1 | ||
| 117 | - --optimizer.muon_momentum 0.95 | ||
| 118 | - --optimizer.muon_enable_nesterov | ||
| 119 | - --optimizer.muon_ns_steps 10 | ||
| 120 | - --optimizer.muon_adjust_lr_fn match_rms_adamw | ||
| 121 | -" | ||
| 122 | -OPTIMIZER_OVERRIDES=" | ||
| 123 | - torchtitan_npu.override.common.optimizer.swap_optimizer | ||
| 124 | -" | ||
| 125 | - | ||
| 126 | -if [[ "${USE_GOLDEN}" == "1" ]]; then | ||
| 127 | - NPU_OPS_OVERRIDES=( | ||
| 128 | - torchtitan_npu.override.common.rope.workaround | ||
| 129 | - ) | ||
| 130 | -else | ||
| 131 | - NPU_OPS_OVERRIDES=( | ||
| 132 | - # Attention / DSA | ||
| 133 | - torchtitan_npu.override.common.rms_norm.asc | ||
| 134 | - torchtitan_npu.override.common.rope.asc_partial | ||
| 135 | - torchtitan_npu.override.deepseek_v4.compressor.asc | ||
| 136 | - | ||
| 137 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc | ||
| 138 | - | ||
| 139 | - 'torchtitan_npu.override.deepseek_v4.sparse_attn.asc={"num_heads":128}' | ||
| 140 | - # MHC | ||
| 141 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre | ||
| 142 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post | ||
| 143 | - # MoE token dispatcher | ||
| 144 | - torchtitan_npu.override.common.token_dispatcher.asc | ||
| 145 | - # MoE SwiGLU Group | ||
| 146 | - torchtitan_npu.override.common.swiglu_group.asc | ||
| 147 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts | ||
| 148 | - ) | ||
| 149 | fi | 34 | fi |
| 35 | +NGPU="${NGPU:-8}" | ||
| 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 37 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 38 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 150 | 39 | ||
| 151 | -DSV4_PER_DOC_ALIGNMENT="${DSV4_PER_DOC_ALIGNMENT:-$((128 * CP))}" \ | ||
| 152 | MODULE="${MODULE}" \ | 40 | MODULE="${MODULE}" \ |
| 153 | CONFIG="${CONFIG}" \ | 41 | CONFIG="${CONFIG}" \ |
| 154 | NGPU="${NGPU}" \ | 42 | NGPU="${NGPU}" \ |
| 155 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | 43 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 156 | bash scripts/run_train.sh \ | 44 | bash scripts/run_train.sh \ |
| 157 | - $HF_ASSETS_ARGS \ | 45 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 158 | - $PARALLELISM_ARGS \ | 46 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 159 | - $TRAINING_ARGS \ | 47 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ |
| 160 | - $DEBUG_ARGS \ | ||
| 161 | - $OPTIMIZER_ARGS \ | ||
| 162 | - $PROFILER_ARGS \ | ||
| 163 | - $COMM_ARGS \ | ||
| 164 | - $CHECKPOINT_ARGS \ | ||
| 165 | - --override.imports "${NPU_OPS_OVERRIDES[@]}" $OPTIMIZER_OVERRIDES \ | ||
| 166 | "$@" | 48 | "$@" |
| @@ -1,19 +1,39 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | 2 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. |
| 3 | -# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| 4 | -# SPDX-License-Identifier: BSD-3-Clause | ||
| 5 | # | 3 | # |
| 6 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 7 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 8 | 6 | ||
| 9 | -# Eight-node SFT wrapper around the common DeepSeek-V4 Flash SFT launcher. | 7 | + |
| 8 | +# Eight-node A3 DeepSeek-V4 Flash 4K chat SFT (DP128/EP128). | ||
| 9 | +# | ||
| 10 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 11 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 12 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 13 | + | ||
| 10 | set -euo pipefail | 14 | set -euo pipefail |
| 11 | 15 | ||
| 12 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | 16 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 13 | - | 17 | +if [[ -z "${CONFIG:-}" ]]; then |
| 14 | -NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, \ | 18 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 15 | - xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | 19 | + CONFIG="deepseek_v4_flash_sft_8node_4k_a3_golden" |
| 20 | + else | ||
| 21 | + CONFIG="deepseek_v4_flash_sft_8node_4k_a3" | ||
| 22 | + fi | ||
| 23 | +fi | ||
| 16 | NGPU="${NGPU:-16}" | 24 | NGPU="${NGPU:-16}" |
| 17 | -export NODE_IPS NGPU | 25 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" |
| 26 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 27 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 28 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 18 | 29 | ||
| 19 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_sft_4k_a3.sh" "$@" | 30 | +MODULE="${MODULE}" \ |
| 31 | +CONFIG="${CONFIG}" \ | ||
| 32 | +NGPU="${NGPU}" \ | ||
| 33 | +NODE_IPS="${NODE_IPS}" \ | ||
| 34 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 35 | +bash scripts/run_train_multinodes.sh \ | ||
| 36 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 37 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 38 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ | ||
| 39 | + "$@" | ||
| @@ -4,23 +4,47 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# 1M sequence specialization. Reuse the A5 4K wrapper and override only the | 7 | + |
| 8 | -# Trainer configuration that differs from the 4K setup. User CLI arguments are | 8 | +# A5 DeepSeek-V4 Flash 1M-token CPT: CP128, 8M tokens per step, 16384-token |
| 9 | -# appended last and therefore can override these defaults. | 9 | +# document alignment. Requires 128 ranks. USE_GOLDEN=1 selects the reference operators. |
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 10 | 14 | ||
| 11 | set -euo pipefail | 15 | set -euo pipefail |
| 12 | 16 | ||
| 13 | -# Quantization defaults are inherited from the A5 4K wrapper. | ||
| 14 | 17 | ||
| 15 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | 18 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 19 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" | ||
| 20 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | ||
| 21 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 22 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 23 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 24 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 25 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 16 | 26 | ||
| 17 | -DSV4_PER_DOC_ALIGNMENT="${DSV4_PER_DOC_ALIGNMENT:-16384}" \ | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 18 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_cpt_4k_a5.sh" \ | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 19 | - --training.max-context-length 1048576 \ | 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 20 | - --training.num-tokens-per-microbatch-per-dp-rank 1048576 \ | 30 | + CONFIG="deepseek_v4_flash_cpt_1024k_a5_golden" |
| 21 | - --training.num-tokens-per-train-step 8388608 \ | 31 | + else |
| 22 | - --parallelism.context-parallel-degree 128 \ | 32 | + CONFIG="deepseek_v4_flash_cpt_1024k_a5" |
| 23 | - --parallelism.context-parallel-load-balancer doc_chunk \ | 33 | + fi |
| 24 | - --parallelism.data-parallel-shard-degree 1 \ | 34 | +fi |
| 25 | - --parallelism.data-parallel-replicate-degree 1 \ | 35 | +NGPU="${NGPU:-8}" |
| 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 37 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 38 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 39 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 40 | + | ||
| 41 | +MODULE="${MODULE}" \ | ||
| 42 | +CONFIG="${CONFIG}" \ | ||
| 43 | +NGPU="${NGPU}" \ | ||
| 44 | +NODE_IPS="${NODE_IPS}" \ | ||
| 45 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 46 | +bash scripts/run_train_multinodes.sh \ | ||
| 47 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 48 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 49 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ | ||
| 26 | "$@" | 50 | "$@" |
| @@ -4,174 +4,37 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Run this script on each participating node; NODE_IPS lists all node addresses. | 7 | + |
| 8 | -# Append CLI arguments to override the defaults below: | 8 | +# A3 full DeepSeek-V4 Flash 4K CPT: 128P, FSDP128/EP128, Muon, eager FullAC. |
| 9 | -# NODE_IPS=192.168.1.10,192.168.1.11,192.168.1.12,192.168.1.13,192.168.1.14,192.168.1.15,192.168.1.16,192.168.1.17 \ | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | -# ./examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a3.sh \ | 10 | +# |
| 11 | -# --checkpoint.initial-load-path /path/to/model_ckpt --training.steps 5 | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | -# USE_GOLDEN=1 selects the reference combination (the model's default attention). | 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. |
| 13 | -# For deterministic execution, append | 13 | +# Append CLI arguments to override the recipe; they are passed through last. |
| 14 | -# --debug.seed 42 --debug.deterministic to the command line. | ||
| 15 | 14 | ||
| 16 | set -euo pipefail | 15 | set -euo pipefail |
| 17 | 16 | ||
| 18 | -NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, \ | 17 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 19 | - xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | 18 | +if [[ -z "${CONFIG:-}" ]]; then |
| 20 | -NGPU="${NGPU:-16}" | 19 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 21 | -NNODES=$(awk -F, '{print NF}' <<< "${NODE_IPS}") | 20 | + CONFIG="deepseek_v4_flash_cpt_4k_a3_golden" |
| 22 | -WORLD_SIZE=$((NGPU * NNODES)) | 21 | + else |
| 23 | - | 22 | + CONFIG="deepseek_v4_flash_cpt_4k_a3" |
| 24 | -# Model | 23 | + fi |
| 25 | -MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4}" | ||
| 26 | -CONFIG="${CONFIG:-deepseek_v4_flash}" | ||
| 27 | - | ||
| 28 | -# Dataloader & Checkpoint | ||
| 29 | -HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" # your tokenizer path | ||
| 30 | -CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" # your model save/load ckpt path | ||
| 31 | -CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" # your model initial load ckpt path | ||
| 32 | - | ||
| 33 | -# Parallelism | ||
| 34 | -TP=1 | ||
| 35 | -PP=1 | ||
| 36 | -EP=128 | ||
| 37 | -CP="${CP:-1}" | ||
| 38 | -DP_SHARD=128 | ||
| 39 | -DP_REPLICATE=$((WORLD_SIZE / (DP_SHARD * CP * TP * PP))) | ||
| 40 | -SPMD_BACKEND="spmd_types" | ||
| 41 | - | ||
| 42 | -# Training | ||
| 43 | -SEQ_LEN=4096 | ||
| 44 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=4096 | ||
| 45 | -NUM_TOKENS_PER_TRAIN_STEP=4194304 | ||
| 46 | -STEPS=100 | ||
| 47 | - | ||
| 48 | -# Debug | ||
| 49 | -USE_GOLDEN="${USE_GOLDEN:-0}" | ||
| 50 | -DEBUG_ARGS=" | ||
| 51 | - --debug.no-moe-force-load-balance | ||
| 52 | - --debug.print-config | ||
| 53 | -" | ||
| 54 | - | ||
| 55 | -# HF assets | ||
| 56 | -HF_ASSETS_ARGS=" | ||
| 57 | - --hf-assets-path ${HF_ASSETS_PATH} | ||
| 58 | -" | ||
| 59 | - | ||
| 60 | -# The Grain dataset is configured by the recipe or an explicit override. | ||
| 61 | - | ||
| 62 | -# Parallelism | ||
| 63 | -PARALLELISM_ARGS=" | ||
| 64 | - --parallelism.spmd-backend ${SPMD_BACKEND} | ||
| 65 | - --parallelism.data-parallel-shard-degree ${DP_SHARD} | ||
| 66 | - --parallelism.data-parallel-replicate-degree ${DP_REPLICATE} | ||
| 67 | - --parallelism.expert-parallel-degree ${EP} | ||
| 68 | - --parallelism.tensor-parallel-degree ${TP} | ||
| 69 | - --parallelism.context-parallel-degree ${CP} | ||
| 70 | - --parallelism.context-parallel-load-balancer doc_chunk | ||
| 71 | - --parallelism.pipeline-parallel-degree ${PP} | ||
| 72 | -" | ||
| 73 | - | ||
| 74 | -# Compile | ||
| 75 | -COMPILE_ARGS=" | ||
| 76 | - --compile.enable | ||
| 77 | - --compile.components model | ||
| 78 | - --compile.backend inductor | ||
| 79 | -" | ||
| 80 | - | ||
| 81 | -# Training | ||
| 82 | -TRAINING_ARGS=" | ||
| 83 | - --training.num-tokens-per-microbatch-per-dp-rank ${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK} | ||
| 84 | - --training.num-tokens-per-train-step ${NUM_TOKENS_PER_TRAIN_STEP} | ||
| 85 | - --training.max-context-length ${SEQ_LEN} | ||
| 86 | - --training.steps ${STEPS} | ||
| 87 | - --training.disable-cuda-graphs | ||
| 88 | -" | ||
| 89 | - | ||
| 90 | -# Checkpoint | ||
| 91 | -# `checkpoint.folder` is the output/resume root (`CKPT_SAVE_LOAD_PATH`). If it | ||
| 92 | -# already contains a valid step-* checkpoint, upstream TorchTitan resumes from | ||
| 93 | -# it and ignores `initial-load-path`; use a new/empty folder when cold-starting | ||
| 94 | -# from `CKPT_INIT_LOAD_PATH`. | ||
| 95 | -CHECKPOINT_ARGS=" | ||
| 96 | - --checkpoint.enable | ||
| 97 | - --checkpoint.load-only | ||
| 98 | - --checkpoint.folder ${CKPT_SAVE_LOAD_PATH} | ||
| 99 | - --checkpoint.initial-load-path ${CKPT_INIT_LOAD_PATH} | ||
| 100 | - --checkpoint.initial-load-in-hf | ||
| 101 | -" | ||
| 102 | - | ||
| 103 | -# Profiler | ||
| 104 | -PROFILER_ARGS=" | ||
| 105 | - --profiler.no-enable-profiling | ||
| 106 | - --profiler.save-traces-folder profiling_path | ||
| 107 | - --profiler.extension.no-enable-online-parse | ||
| 108 | - --profiler.extension.profiler-start 6 | ||
| 109 | - --profiler.extension.profiler-end 7 | ||
| 110 | - --profiler.extension.profile-ranks 0 | ||
| 111 | -" | ||
| 112 | - | ||
| 113 | -# Communication | ||
| 114 | -COMM_ARGS=" | ||
| 115 | - --comm.init-timeout-seconds 7200 | ||
| 116 | - --comm.train-timeout-seconds 600 | ||
| 117 | -" | ||
| 118 | - | ||
| 119 | -# Optimizer | ||
| 120 | -OPTIMIZER_ARGS=" | ||
| 121 | - --optimizer.name Muon | ||
| 122 | - --optimizer.lr 1.0e-5 | ||
| 123 | - --optimizer.beta1 0.9 | ||
| 124 | - --optimizer.beta2 0.95 | ||
| 125 | - --optimizer.eps 1.0e-8 | ||
| 126 | - --optimizer.weight_decay 1.0e-1 | ||
| 127 | - --optimizer.muon_momentum 0.95 | ||
| 128 | - --optimizer.muon_enable_nesterov | ||
| 129 | - --optimizer.muon_ns_steps 10 | ||
| 130 | - --optimizer.muon_adjust_lr_fn match_rms_adamw | ||
| 131 | -" | ||
| 132 | -OPTIMIZER_OVERRIDES="${OPTIMIZER_OVERRIDES-torchtitan_npu.override.common.optimizer.swap_optimizer}" | ||
| 133 | - | ||
| 134 | -if [[ "${USE_GOLDEN}" == "1" ]]; then | ||
| 135 | - DEFAULT_CLI_OVERRIDES="" | ||
| 136 | - NPU_OPS_OVERRIDES=( | ||
| 137 | - torchtitan_npu.override.common.rope.workaround | ||
| 138 | - ) | ||
| 139 | -else | ||
| 140 | - DEFAULT_CLI_OVERRIDES="torchtitan_npu.override.common.rope.asc_complex" | ||
| 141 | - NPU_OPS_OVERRIDES=( | ||
| 142 | - # Attention / DSA | ||
| 143 | - torchtitan_npu.override.common.rms_norm.asc | ||
| 144 | - | ||
| 145 | - torchtitan_npu.override.deepseek_v4.lightning_indexer.asc | ||
| 146 | - | ||
| 147 | - torchtitan_npu.override.deepseek_v4.sparse_attn.asc | ||
| 148 | - # MHC | ||
| 149 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_pre | ||
| 150 | - torchtitan_npu.override.deepseek_v4.mhc.asc_hc_post | ||
| 151 | - # MoE token dispatcher | ||
| 152 | - torchtitan_npu.override.common.token_dispatcher.asc | ||
| 153 | - ) | ||
| 154 | fi | 24 | fi |
| 25 | +NGPU="${NGPU:-16}" | ||
| 26 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 27 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 28 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 29 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 155 | 30 | ||
| 156 | -# Wrapper defaults extend override.imports after the base targets. | ||
| 157 | -CLI_OVERRIDES="${CLI_OVERRIDES:-${DEFAULT_CLI_OVERRIDES}}" | ||
| 158 | - | ||
| 159 | -DSV4_PER_DOC_ALIGNMENT="${DSV4_PER_DOC_ALIGNMENT:-$((128 * CP))}" \ | ||
| 160 | MODULE="${MODULE}" \ | 31 | MODULE="${MODULE}" \ |
| 161 | CONFIG="${CONFIG}" \ | 32 | CONFIG="${CONFIG}" \ |
| 162 | -NODE_IPS="${NODE_IPS}" \ | ||
| 163 | NGPU="${NGPU}" \ | 33 | NGPU="${NGPU}" \ |
| 34 | +NODE_IPS="${NODE_IPS}" \ | ||
| 164 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | 35 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 165 | bash scripts/run_train_multinodes.sh \ | 36 | bash scripts/run_train_multinodes.sh \ |
| 166 | - $COMPILE_ARGS \ | 37 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 167 | - $HF_ASSETS_ARGS \ | 38 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 168 | - $PARALLELISM_ARGS \ | 39 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ |
| 169 | - $TRAINING_ARGS \ | ||
| 170 | - $DEBUG_ARGS \ | ||
| 171 | - $OPTIMIZER_ARGS \ | ||
| 172 | - $PROFILER_ARGS \ | ||
| 173 | - $COMM_ARGS \ | ||
| 174 | - $CHECKPOINT_ARGS \ | ||
| 175 | - --override.imports "${NPU_OPS_OVERRIDES[@]}" $OPTIMIZER_OVERRIDES \ | ||
| 176 | - $CLI_OVERRIDES \ | ||
| 177 | "$@" | 40 | "$@" |
| @@ -4,13 +4,16 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# A5 wrapper around the common DeepSeek-V4 Flash CPT launcher. Keep model, | 7 | + |
| 8 | -# training, and parallelism differences as CLI overrides so user-supplied | 8 | +# A5 full DeepSeek-V4 Flash 4K CPT: block-FP8 training and A5 fused operators. |
| 9 | -# arguments remain the final source of truth. | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 10 | 14 | ||
| 11 | set -euo pipefail | 15 | set -euo pipefail |
| 12 | 16 | ||
| 13 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 14 | 17 | ||
| 15 | export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" | 18 | export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 16 | export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" | 19 | export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| @@ -18,53 +21,30 @@ export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | |||
| 18 | export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | 21 | export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" |
| 19 | # Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | 22 | # Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 20 | export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | 23 | export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" |
| 21 | -# Override this for the host topology reported by `npu-smi info -t topo`. | 24 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. |
| 22 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | 25 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" |
| 23 | 26 | ||
| 24 | -# A5-only fused ops; USE_GOLDEN=1 keeps the pure reference list. | 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 25 | -if [[ "${USE_GOLDEN:-0}" != "1" ]]; then | 28 | +if [[ -z "${CONFIG:-}" ]]; then |
| 26 | - export CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rope.asc_partial \ | 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 27 | - torchtitan_npu.override.deepseek_v4.compressor.asc \ | 30 | + CONFIG="deepseek_v4_flash_cpt_4k_a5_golden" |
| 28 | - torchtitan_npu.override.common.swiglu_group.asc \ | 31 | + else |
| 29 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts}" | 32 | + CONFIG="deepseek_v4_flash_cpt_4k_a5" |
| 33 | + fi | ||
| 30 | fi | 34 | fi |
| 31 | - | ||
| 32 | -NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, \ | ||
| 33 | - xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 34 | NGPU="${NGPU:-8}" | 35 | NGPU="${NGPU:-8}" |
| 35 | -export NODE_IPS NGPU | 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" |
| 37 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 38 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 39 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 36 | 40 | ||
| 37 | -# A5 defaults to block-FP8 quantized training. A trailing | 41 | +MODULE="${MODULE}" \ |
| 38 | -# --extension.quantization.no-enable-quantized-training selects BF16 instead. | 42 | +CONFIG="${CONFIG}" \ |
| 39 | -# | 43 | +NGPU="${NGPU}" \ |
| 40 | -# The runtime guard requires each pre-quantized weight's dp-sharded dim0 to | 44 | +NODE_IPS="${NODE_IPS}" \ |
| 41 | -# stay 64-aligned, and the base script runs DP_SHARD=128 (dim0 must be a | 45 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 42 | -# multiple of 64*128=8192). For the default deepseek_v4_flash config that | 46 | +bash scripts/run_train_multinodes.sh \ |
| 43 | -# breaks the evenly-sharded dense projections -- wq_a (1024 -> 8 rows/rank), | 47 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 44 | -# wkv (512 -> 4), wo_b (4096 -> 32) and shared_experts w1/w3 (2048 -> 16) and | 48 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 45 | -# w2 (4096 -> 32) -- which fail fast at startup with a fix hint instead of | 49 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ |
| 46 | -# silently falling back to BF16 communication. fsdp-prequantize-fqns below | 50 | + "$@" |
| 47 | -# therefore narrows the whitelist to the projections that stay aligned: the | ||
| 48 | -# per-head/per-group BlockShard projections (wq_b, wo_a, indexer.wq_b) and | ||
| 49 | -# the expert-axis-sharded routed experts. At lower DP_SHARD degrees (e.g. 8, | ||
| 50 | -# where every default entry is aligned) drop that line to restore the recipe | ||
| 51 | -# default whitelist (all Block FP8 projections). | ||
| 52 | -QUANTIZATION_ARGS=( | ||
| 53 | - --extension.quantization.enable-quantized-training | ||
| 54 | - --extension.quantization.recipe all_block_fp8 | ||
| 55 | - --extension.quantization.enable-fsdp-prequantize | ||
| 56 | - --extension.quantization.fsdp-prequantize-fqns .attention.wq_b,.attention.wo_a,.attention.indexer.wq_b,.moe.routed_experts.inner_experts | ||
| 57 | - --extension.quantization.li-quantization fp8 | ||
| 58 | - --extension.quantization.kv-norm-quantization.format mxfp8 | ||
| 59 | - --extension.quantization.kv-norm-quantization.fqns .attention.kv_norm,.attention.compressor.norm | ||
| 60 | - --extension.quantization.kv-norm-quantization.block-size 64 | ||
| 61 | -) | ||
| 62 | - | ||
| 63 | -# Disable swap optimizer for better performance | ||
| 64 | -export OPTIMIZER_OVERRIDES="" | ||
| 65 | - | ||
| 66 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_cpt_4k_a3.sh" \ | ||
| 67 | - --training.num-tokens-per-microbatch-per-dp-rank 8192 \ | ||
| 68 | - "${QUANTIZATION_ARGS[@]}" \ | ||
| 69 | - "$@" \ | ||
| 70 | - activation-checkpoint:selective | ||
| @@ -4,32 +4,52 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Full-model A5 GraphTrainer recipe with sequence-based EP overlap. | 7 | + |
| 8 | -# Run this script on each participating node, as with the A5 eager recipe. | 8 | +# A5 GraphTrainer DeepSeek-V4 Flash 4K CPT with sequence-based MoE EP overlap. |
| 9 | -# Append CLI arguments to override defaults, for example --training.steps 5. | 9 | +# USE_GOLDEN=1 selects the reference operators. |
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 10 | set -euo pipefail | 15 | set -euo pipefail |
| 11 | 16 | ||
| 12 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 13 | 17 | ||
| 14 | -export CONFIG="${CONFIG:-graph_trainer_deepseek_v4_flash}" | ||
| 15 | export TORCHINDUCTOR_USE_TORCH_PROFILER_BENCHMARKER=1 | 18 | export TORCHINDUCTOR_USE_TORCH_PROFILER_BENCHMARKER=1 |
| 16 | export TORCHINDUCTOR_USE_EXPERIMENTAL_BENCHMARKER=0 | 19 | export TORCHINDUCTOR_USE_EXPERIMENTAL_BENCHMARKER=0 |
| 17 | export TORCH_NPU_USE_COMPATIBLE_IMPL=1 | 20 | export TORCH_NPU_USE_COMPATIBLE_IMPL=1 |
| 18 | 21 | ||
| 19 | -STEPS="${STEPS:-20}" | ||
| 20 | 22 | ||
| 21 | -EP_OVERLAP_ARGS=( | 23 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 22 | - --compile.ep_overlap.enabled | 24 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 23 | - --compile.ep_overlap.chunk_dim seq | 25 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| 24 | - --compile.ep_overlap.strategy graph | 26 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" |
| 25 | - --compile.ep_overlap.module_fqn "layers.*.moe" | 27 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 26 | - --compile.pass_pipeline mutation-functionalization+npu_auto_overlap | 28 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" |
| 27 | -) | 29 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. |
| 30 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 28 | 31 | ||
| 29 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_cpt_4k_a5.sh" \ | 32 | +MODULE="${MODULE:-torchtitan_npu_recipes.graph_trainer.deepseek_v4}" |
| 30 | - --training.num-tokens-per-train-step 2097152 \ | 33 | +if [[ -z "${CONFIG:-}" ]]; then |
| 31 | - --parallelism.spmd-backend partial_dtensor \ | 34 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 32 | - --training.steps "${STEPS}" \ | 35 | + CONFIG="deepseek_v4_flash_cpt_4k_a5_graphtrainer_golden" |
| 33 | - --debug.moe-force-load-balance \ | 36 | + else |
| 34 | - "${EP_OVERLAP_ARGS[@]}" \ | 37 | + CONFIG="deepseek_v4_flash_cpt_4k_a5_graphtrainer" |
| 38 | + fi | ||
| 39 | +fi | ||
| 40 | +NGPU="${NGPU:-8}" | ||
| 41 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 42 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 43 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 44 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 45 | + | ||
| 46 | +MODULE="${MODULE}" \ | ||
| 47 | +CONFIG="${CONFIG}" \ | ||
| 48 | +NGPU="${NGPU}" \ | ||
| 49 | +NODE_IPS="${NODE_IPS}" \ | ||
| 50 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 51 | +bash scripts/run_train_multinodes.sh \ | ||
| 52 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 53 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 54 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ | ||
| 35 | "$@" | 55 | "$@" |
| @@ -4,18 +4,37 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# LoRA wrapper around the common DeepSeek-V4 Flash CPT launcher. Keep model, | 7 | + |
| 8 | -# training, and parallelism differences as CLI overrides so user-supplied | 8 | +# A3 DeepSeek-V4 Flash 4K LoRA CPT with periodic adapter checkpoints and PEFT export. |
| 9 | -# arguments remain the final source of truth. | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe; the default keeps the fused list. |
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 10 | 14 | ||
| 11 | set -euo pipefail | 15 | set -euo pipefail |
| 12 | 16 | ||
| 13 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | 17 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 18 | +if [[ -z "${CONFIG:-}" ]]; then | ||
| 19 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then | ||
| 20 | + CONFIG="deepseek_v4_flash_lora_4k_a3_golden" | ||
| 21 | + else | ||
| 22 | + CONFIG="deepseek_v4_flash_lora_4k_a3" | ||
| 23 | + fi | ||
| 24 | +fi | ||
| 25 | +NGPU="${NGPU:-16}" | ||
| 26 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 27 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 28 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 29 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 14 | 30 | ||
| 15 | -export CONFIG="${CONFIG:-deepseek_v4_flash_lora}" | 31 | +MODULE="${MODULE}" \ |
| 16 | - | 32 | +CONFIG="${CONFIG}" \ |
| 17 | -# LoRA uses periodic native adapter checkpoints and final PEFT export. | 33 | +NGPU="${NGPU}" \ |
| 18 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_cpt_4k_a3.sh" \ | 34 | +NODE_IPS="${NODE_IPS}" \ |
| 19 | - --checkpoint.no-load-only \ | 35 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 20 | - --checkpoint.save-training-state \ | 36 | +bash scripts/run_train_multinodes.sh \ |
| 37 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
Resolved on ![]() ![]() | |||
| 38 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 39 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ | ||
| 21 | "$@" | 40 | "$@" |
| @@ -4,30 +4,47 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# QAT wrapper around the DeepSeek-V4 Flash CPT A5 launcher. Inherit the A5 | ||
| 8 | -# environment and training defaults, and override only quantization arguments. | ||
| 9 | 7 | ||
| 8 | +# A5 DeepSeek-V4 Flash 4K QAT: block-FP8 plus routed-expert MXFP4 fake quant. | ||
| 9 | +# USE_GOLDEN=1 selects the reference operators. | ||
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 10 | 14 | ||
| 11 | set -euo pipefail | 15 | set -euo pipefail |
| 12 | 16 | ||
| 13 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 14 | 17 | ||
| 15 | -NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, \ | 18 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 16 | - xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | 19 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 20 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | ||
| 21 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 22 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 23 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 24 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 25 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 26 | + | ||
| 27 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" | ||
| 28 | +if [[ -z "${CONFIG:-}" ]]; then | ||
| 29 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then | ||
| 30 | + CONFIG="deepseek_v4_flash_qat_4k_a5_golden" | ||
| 31 | + else | ||
| 32 | + CONFIG="deepseek_v4_flash_qat_4k_a5" | ||
| 33 | + fi | ||
| 34 | +fi | ||
| 17 | NGPU="${NGPU:-8}" | 35 | NGPU="${NGPU:-8}" |
| 18 | -export NODE_IPS NGPU | 36 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" |
| 37 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 38 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 39 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 19 | 40 | ||
| 20 | -#Introduction of relevant parameters, please refer to docs/user-guides/quickstart.md. | 41 | +MODULE="${MODULE}" \ |
| 21 | -QUANTIZATION_ARGS=( | 42 | +CONFIG="${CONFIG}" \ |
| 22 | - --extension.quantization.enable-quantized-training | 43 | +NGPU="${NGPU}" \ |
| 23 | - --extension.quantization.recipe all_block_fp8 | 44 | +NODE_IPS="${NODE_IPS}" \ |
| 24 | - --extension.quantization.enable-mxfp4-qat | 45 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 25 | - --extension.quantization.li-quantization mxfp4 | 46 | +bash scripts/run_train_multinodes.sh \ |
| 26 | -) | 47 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 27 | - | 48 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 28 | -# Disable swap optimizer for better performance | 49 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ |
| 29 | -export OPTIMIZER_OVERRIDES="" | ||
| 30 | - | ||
| 31 | -exec bash "${SCRIPT_DIR}/deepseek_v4_flash_cpt_4k_a5.sh" \ | ||
| 32 | - "${QUANTIZATION_ARGS[@]}" \ | ||
| 33 | "$@" | 50 | "$@" |
| @@ -1,21 +1,40 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | 2 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. |
| 3 | -# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| 4 | -# SPDX-License-Identifier: BSD-3-Clause | ||
| 5 | # | 3 | # |
| 6 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 7 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 8 | 6 | ||
| 9 | -# Reuse the CPT launcher with an SFT JSONL or JSON file. | 7 | + |
| 8 | +# A3 full DeepSeek-V4 Flash 4K chat SFT (one conversation per Grain batch). | ||
| 9 | +# USE_GOLDEN=1 selects the reference operators. | ||
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 10 | set -euo pipefail | 15 | set -euo pipefail |
| 11 | 16 | ||
| 12 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | 17 | +MODULE="${MODULE:-torchtitan_npu_recipes.models.deepseek_v4}" |
| 13 | -CPT_SCRIPT="${CPT_SCRIPT:-${SCRIPT_DIR}/deepseek_v4_flash_cpt_4k_a3.sh}" | 18 | +if [[ -z "${CONFIG:-}" ]]; then |
| 14 | -DATASET_PATH="${DATASET_PATH:-/path/to/train.jsonl}" | 19 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 20 | + CONFIG="deepseek_v4_flash_sft_4k_a3_golden" | ||
| 21 | + else | ||
| 22 | + CONFIG="deepseek_v4_flash_sft_4k_a3" | ||
| 23 | + fi | ||
| 24 | +fi | ||
| 25 | +NGPU="${NGPU:-16}" | ||
| 26 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV4_tokenizer}" | ||
| 27 | +NODE_IPS="${NODE_IPS:-xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx, xx.xx.xx.xx}" | ||
| 28 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 29 | +CKPT_INIT_LOAD_PATH="${CKPT_INIT_LOAD_PATH:-/path/to/init_load_ckpt}" | ||
| 15 | 30 | ||
| 16 | -CONFIG="${CONFIG:-deepseek_v4_flash_sft}" \ | 31 | +MODULE="${MODULE}" \ |
| 17 | -DSV4_SFT_DATASET="${DATASET_PATH}" \ | 32 | +CONFIG="${CONFIG}" \ |
| 18 | -exec bash "${CPT_SCRIPT}" \ | 33 | +NGPU="${NGPU}" \ |
| 19 | - --checkpoint.enable \ | 34 | +NODE_IPS="${NODE_IPS}" \ |
| 20 | - --checkpoint.no-load-only \ | 35 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 36 | +bash scripts/run_train_multinodes.sh \ | ||
| 37 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 38 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 39 | + --checkpoint.initial-load-path "${CKPT_INIT_LOAD_PATH}" \ | ||
| 21 | "$@" | 40 | "$@" |
| @@ -1,64 +1,119 @@ | |||
| 1 | # DeepSeek-V4 training examples | 1 | # DeepSeek-V4 training examples |
| 2 | 2 | ||
| 3 | -本目录只保留少量稳定入口,模型规模、序列长度、并行策略和量化方式优先通过 CLI 覆盖,不为每一种组合新增独立脚本。 | 3 | +本目录的脚本是薄 launcher:训练配置由 `torchtitan_npu_recipes/models/deepseek_v4.py` 中的具名 Python recipe |
| 4 | +提供,脚本只选择 recipe,并设置进程数、节点地址、CANN/HCCL 环境、资源路径和日志位置。新增组合应写成 | ||
| 5 | +recipe,而不是继续拼接 shell 参数。 | ||
| 4 | 6 | ||
| 5 | -## 入口关系 | 7 | +目录分工:`debug/` 的 CI-only 形状由 `torchtitan_npu_recipes.tests.models.deepseek_v4` 提供;GraphTrainer 组合在 `torchtitan_npu_recipes.graph_trainer.deepseek_v4`,其 debug 图 fixture 在 `torchtitan_npu_recipes.tests.graph_trainer.deepseek_v4`。 |
| 6 | 8 | ||
| 7 | -Flash 多机训练以 `deepseek_v4_flash_cpt_4k_a3.sh` 为公共基线: | 9 | +## launcher 与 recipe |
| 8 | 10 | ||
| 9 | -```text | 11 | +| launcher | recipe(`--config`) | 规模/并行 | 主要特性 | |
| 10 | -deepseek_v4_flash_cpt_4k_a3.sh | 12 | +| --- | --- | --- | --- | |
| 11 | -└── deepseek_v4_flash_cpt_4k_a5.sh | 13 | +| `deepseek_v4_flash_cpt_4k_a3.sh` | `deepseek_v4_flash_cpt_4k_a3` | 128P,FSDP128/EP128,4K | Muon、FullAC、inductor | |
| 12 | - └── deepseek_v4_flash_cpt_1024k_a5.sh | 14 | +| `deepseek_v4_flash_cpt_4k_a5.sh` | `deepseek_v4_flash_cpt_4k_a5` | 128P,A5 | block-FP8、A5 融合算子、selective AC | |
| 15 | +| `deepseek_v4_flash_cpt_1024k_a5.sh` | `deepseek_v4_flash_cpt_1024k_a5` | 128P,CP128 | 1M 上下文、16384 对齐、FSDP 预量化白名单 | | ||
| 16 | +| `deepseek_v4_flash_cpt_4k_a5_graphtrainer.sh` | `deepseek_v4_flash_cpt_4k_a5_graphtrainer` | 128P,A5 | GraphTrainer、序列级 EP overlap | | ||
| 17 | +| `deepseek_v4_flash_lora_4k_a3.sh` | `deepseek_v4_flash_lora_4k_a3` | 128P,A3 | LoRA、周期 adapter checkpoint、PEFT 导出 | | ||
| 18 | +| `deepseek_v4_flash_qat_4k_a5.sh` | `deepseek_v4_flash_qat_4k_a5` | 128P,A5 | block-FP8 + routed expert MXFP4 QAT | | ||
| 19 | +| `deepseek_v4_flash_sft_4k_a3.sh` | `deepseek_v4_flash_sft_4k_a3` | 128P,A3 | chat SFT、packing bins=1 | | ||
| 20 | +| `deepseek_v4_flash_8node_sft_4k_a3.sh` | `deepseek_v4_flash_sft_8node_4k_a3` | 128P,A3 | 八节点 chat SFT | | ||
| 21 | +| `debug/deepseek_v4_flash_8p_cpt_4k_a3.sh` | `deepseek_v4_flash_8p_cpt_4k_a3` | 8P,A3 | 43 层/16 专家 debug CPT | | ||
| 22 | +| `debug/deepseek_v4_flash_8p_cpt_4k_a5.sh` | `deepseek_v4_flash_8p_cpt_4k_a5` | 8P,A5 | FP8 + selective AC | | ||
| 23 | +| `debug/deepseek_v4_flash_8p_cpt_4k_a3_graphtrainer.sh` | `deepseek_v4_flash_8p_cpt_4k_a3_graphtrainer` | 8P,A3 | GraphTrainer | | ||
| 24 | +| `debug/deepseek_v4_flash_8p_cpt_4k_a5_graphtrainer.sh` | `deepseek_v4_flash_8p_cpt_4k_a5_graphtrainer` | 8P,A5 | GraphTrainer + MHC/MoE save 策略 | | ||
| 25 | +| `debug/deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel.sh` | `deepseek_v4_flash_8p_cpt_4k_a5_cv_parallel` | 8P,A5 | batch C/V 调度实验 | | ||
| 26 | +| `debug/deepseek_v4_flash_8p_cpt_4k_a5_hif8.sh` | `deepseek_v4_flash_8p_cpt_4k_a5_hif8` | 8P,A5 | HiF8 | | ||
| 27 | +| `debug/deepseek_v4_flash_8p_sft_4k_a3.sh` | `deepseek_v4_flash_8p_sft_4k_a3` | 8P,A3 | 43 层 chat SFT | | ||
| 28 | +| `debug/deepseek_v4_mini_1p_cpt_2k_a3.sh` | `deepseek_v4_mini_1p_cpt_2k_a3` | 1P,A3 | 2K debugmodel、16 head 融合 sparse attention | | ||
| 29 | +| `debug/deepseek_v4_pro_32p_cpt_4k_a5.sh` | `deepseek_v4_pro_32p_cpt_4k_a5` | 32P,A5 | Pro 61 层/32 专家 | | ||
| 30 | +| `debug/deepseek_v4_pro_8p_cpt_4k_a5_cpuoffload.sh` | `deepseek_v4_pro_8p_cpt_4k_a5_cpuoffload` | 8P,A5 | Pro 12 专家、参数/梯度 CPU offload | | ||
| 31 | + | ||
| 32 | +`USE_GOLDEN=1` 选择同名 `*_golden` recipe,把融合算子替换为模型默认的 reference 实现; | ||
| 33 | +它的数值和调度状态与融合路径分别记录,不能互相替代验证。launcher 仍支持 `MODULE`/`CONFIG` 覆盖, | ||
| 34 | +用于选择自定义 recipe。 | ||
| 35 | + | ||
| 36 | +## 选择 recipe 与自定义 recipe | ||
| 37 | + | ||
| 38 | +默认 launcher 使用 `MODULE=torchtitan_npu_recipes.models.deepseek_v4` 和上表的 `CONFIG`。自定义数据或 | ||
| 39 | +cluster 配置写在独立模块中: | ||
| 40 | + | ||
| 41 | +```python | ||
| 42 | +# my_company_configs/dsv4.py | ||
| 43 | +from torchtitan_npu_recipes.models import deepseek_v4 | ||
| 44 | + | ||
| 45 | + | ||
| 46 | +def dsv4_flash_cpt_local_4k(): | ||
| 47 | + return deepseek_v4.deepseek_v4_flash_cpt_4k_a3( | ||
| 48 | + text_dataset_path="/data/corpus/c4/train.jsonl", | ||
| 49 | + ) | ||
| 50 | + | ||
| 51 | + | ||
| 52 | +def dsv4_flash_sft_local_4k(): | ||
| 53 | + return deepseek_v4.deepseek_v4_flash_sft_4k_a3( | ||
| 54 | + dataset_path="/data/sft/train.jsonl", | ||
| 55 | + num_packing_bins=1, | ||
| 56 | + ) | ||
| 13 | ``` | 57 | ``` |
| 14 | 58 | ||
| 15 | -- `deepseek_v4_flash_cpt_4k_a3.sh`:公共训练参数、override、checkpoint、optimizer 等基线配置,默认通过 CLI 启用 model 编译,backend 为 `inductor`。 | 59 | +```sh |
| 16 | -- `deepseek_v4_flash_cpt_4k_a5.sh`:增加 A5 运行环境和默认 block-FP8 量化,其他配置复用 A3 基线。 | 60 | +MODULE=my_company_configs.dsv4 CONFIG=dsv4_flash_cpt_local_4k \ |
| 17 | -- `deepseek_v4_flash_cpt_1024k_a5.sh`:继续复用 A5 4K 入口,只通过 CLI 覆盖 1M 所需的 CP、DP、序列长度和 global batch size,量化默认随 A5 4K 入口继承。 | 61 | + NGPU=16 bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a3.sh |
| 18 | -- 用户普通 CLI 参数位于默认选项之后,因此可以覆盖默认值(A5 的 activation-checkpoint 子命令仍在末尾),包括使用 `--extension.quantization.no-enable-quantized-training` 切换到 BF16。 | 62 | +``` |
| 19 | 63 | ||
| 20 | -## 编译配置 | 64 | +recipe 的所有参数都有默认值,因此 `--config` 可以零参数调用;把需要变化的值写成 recipe 参数, |
| 65 | +不要通过环境变量选择数据源。文本数据使用 `text_dataset_path`,SFT 数据使用 `dataset_path`; | ||
| 66 | +`num_packing_bins` 控制同时打开的 packing 候选行数(`0` 关闭 packing)。 | ||
| 21 | 67 | ||
| 22 | -编译通过 CLI 配置。Flash A3/A5 默认使用 `inductor`,只编译 `model`。在示例命令末尾追加 | 68 | +## 运行环境与资源路径 |
| 23 | -`--compile.backend inductor` 可显式指定 backend,追加 `--compile.no-enable` 可关闭编译。 | ||
| 24 | -独立入口若未默认启用编译,需同时传入 `--compile.enable --compile.components model`。 | ||
| 25 | 69 | ||
| 26 | -## 常用环境变量 | 70 | +launcher 仍负责以下机器相关设置,可用环境变量覆盖: |
| 27 | - | ||
| 28 | -运行前至少根据环境设置以下路径和节点信息: | ||
| 29 | 71 | ||
| 30 | ```sh | 72 | ```sh |
| 31 | -export NODE_IPS="192.168.1.10,192.168.1.11,..." | 73 | +export NODE_IPS="192.168.1.10,192.168.1.11,..." # 多机必填 |
| 32 | export HF_ASSETS_PATH=/path/to/DeepSeekV4_tokenizer | 74 | export HF_ASSETS_PATH=/path/to/DeepSeekV4_tokenizer |
| 33 | export CKPT_SAVE_LOAD_PATH=/path/to/save_or_resume_ckpt | 75 | export CKPT_SAVE_LOAD_PATH=/path/to/save_or_resume_ckpt |
| 34 | export CKPT_INIT_LOAD_PATH=/path/to/init_hf_ckpt | 76 | export CKPT_INIT_LOAD_PATH=/path/to/init_hf_ckpt |
| 35 | ``` | 77 | ``` |
| 36 | 78 | ||
| 37 | -A5 默认每节点使用 8 张 NPU,A3 默认每节点使用 16 张 NPU;需要改变时设置 `NGPU`。 | 79 | +`NGPU` 默认为 A3 16 卡/节点、A5 8 卡/节点;`LOG_PREFIX` 控制日志文件名;`ASCEND_SET_ENV_PATH` |
| 38 | -训练参数在基础脚本中直接设置;派生入口通过 CLI 覆盖不同的默认值。命令末尾的 | 80 | +等 CANN 设置由 `scripts/run_train.sh` 统一处理。A5 脚本还设置 HCCL 超时、CPU 亲和性和 |
| 39 | -`--training.max-context-length`、`--training.num-tokens-per-microbatch-per-dp-rank` 和 | 81 | +`TORCHINDUCTOR_*` 环境,这些属于机器配置,不进入 recipe。 |
| 40 | -`--training.num-tokens-per-train-step` 可覆盖相应参数。单独修改上下文长度不会重算 microbatch, | 82 | + |
| 41 | -单独修改 microbatch 也不会重算每步预算;需要调整时应同时指定相关参数。 | 83 | +**世界大小必须与 recipe 的并行度乘积一致**。例如 `deepseek_v4_flash_cpt_4k_a3` 固定 |
| 42 | -每步预算须能被「每 rank microbatch token 数 × 有效 DP 度 × PP microbatch 数」整除。 | 84 | +`DP_SHARD=128, EP=128, CP=1, TP=1, PP=1`,需要 128 个 rank;只改 `NGPU` 而不改 recipe 会得到 |
| 43 | -例如 8 卡 Flash debug 的 A3 默认梯度累积 8 次,A5 默认梯度累积 4 次。 | 85 | +无效拓扑。需要其他拓扑时复制 recipe 并修改 `parallelism` 字段。 |
| 86 | + | ||
| 87 | +训练配置在 recipe 中,末尾 CLI 参数仍可覆盖,例如: | ||
| 88 | + | ||
| 89 | +```sh | ||
| 90 | +NODE_IPS="${NODE_IPS}" \ | ||
| 91 | +bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a3.sh \ | ||
| 92 | + --training.steps 500 | ||
| 93 | +``` | ||
| 94 | + | ||
| 95 | +单独修改 `--training.max-context-length` 不会重算 microbatch,单独修改 microbatch 也不会重算每步预算; | ||
| 96 | +需要调整时应同时指定相关参数。每步预算须能被「每 rank microbatch token 数 × 有效 DP 度 × PP | ||
| 97 | +microbatch 数」整除。 | ||
| 98 | + | ||
| 99 | +## 编译配置 | ||
| 100 | + | ||
| 101 | +A3/A5 4K recipe 默认启用 `inductor`,只编译 `model`。需要覆盖时在命令末尾追加 | ||
| 102 | +`--compile.backend aot_eager` 或 `--compile.no-enable`。GraphTrainer recipe 使用 | ||
| 103 | +`aot_fx_trace` 和对应的 pass pipeline;独立入口若 recipe 未启用编译,需同时传入 | ||
| 104 | +`--compile.enable --compile.components model`。 | ||
| 44 | 105 | ||
| 45 | ## 裁剪 Debug 模型 | 106 | ## 裁剪 Debug 模型 |
| 46 | 107 | ||
| 47 | -Debug/performance 验证优先使用等价裁剪模型,避免为了快速验证直接启动完整规模模型。这里统一放置不同规模的裁剪 Debug 入口,卡数不是这一节的分类依据。 | 108 | +Debug/performance 验证优先使用等价裁剪模型,避免为了快速验证直接启动完整规模模型。 |
| 48 | 109 | ||
| 49 | ### 1P mini 模型 | 110 | ### 1P mini 模型 |
| 50 | 111 | ||
| 51 | -固定 TorchTitan 基线使用展平的 token 布局:输入与标签为 `[T]`,隐藏状态为 | 112 | +recipe `deepseek_v4_mini_1p_cpt_2k_a3` 默认每步处理 2048 个 token,最大上下文 2048。`USE_GOLDEN=1` |
| 52 | -`[T, D]`。此入口默认每步处理 2048 个 token,最大上下文长度为 2048。 | 113 | +选择参考 attention、RoPE workaround 和 AdamW;默认融合组合使用 Muon。当前 Ascend A3 环境已完成 |
| 53 | -数据集及源文件由 `MODULE` / `CONFIG` 选择的 recipe 配置,入口不再读取 | 114 | +单卡、确定性 eager 前向、反向及 optimizer step;参考 indexer 的离散选择不提供 indexer 训练目标。 |
| 54 | -`DATASET` / `DATASET_PATH`。自定义数据源通过独立 recipe 指定。 | 115 | +融合算子组合另以 AdamW 完成两步功能验证;当前 CANN 的 `SparseFlashMlaGrad` 拒绝确定性模式, |
| 55 | - | 116 | +因此该功能验证未启用 `--debug.deterministic`,不能作为数值对齐证据。Muon、多卡及编译仍需独立验证。 |
| 56 | -`USE_GOLDEN=1` 选择模型默认的参考 attention、实数缓存 RoPE 和 AdamW。 | ||
| 57 | -在当前 Ascend A3 环境中,此组合已完成单卡、确定性 eager 前向、反向及 | ||
| 58 | -optimizer step;参考 indexer 的离散选择不提供 indexer 训练目标。 | ||
| 59 | -默认融合组合使用 Muon。融合算子组合另以 AdamW 完成两步功能验证;当前 | ||
| 60 | -CANN 的 `SparseFlashMlaGrad` 拒绝确定性模式,因此该功能验证未启用 | ||
| 61 | -`--debug.deterministic`,不能作为数值对齐证据。Muon、多卡及编译仍需独立验证。 | ||
| 62 | 117 | ||
| 63 | ```sh | 118 | ```sh |
| 64 | bash examples/deepseek_v4/debug/deepseek_v4_mini_1p_cpt_2k_a3.sh | 119 | bash examples/deepseek_v4/debug/deepseek_v4_mini_1p_cpt_2k_a3.sh |
| @@ -68,11 +123,7 @@ bash examples/deepseek_v4/debug/deepseek_v4_mini_1p_cpt_2k_a3.sh \ | |||
| 68 | --training.steps 2 --debug.seed 42 --debug.deterministic | 123 | --training.steps 2 --debug.seed 42 --debug.deterministic |
| 69 | ``` | 124 | ``` |
| 70 | 125 | ||
| 71 | -token 预算使用 `--training.num-tokens-per-microbatch-per-dp-rank` 和 | ||
| 72 | -`--training.num-tokens-per-train-step`;两者均统计 token slot。模型上下文 | ||
| 73 | -在 registry 构造时选定,recipe 同步设置 `training.max_context_length`。 | ||
| 74 | 单独覆盖训练上下文不会重新配置 RoPE;修改上下文长度需使用匹配的 recipe。 | 126 | 单独覆盖训练上下文不会重新配置 RoPE;修改上下文长度需使用匹配的 recipe。 |
| 75 | -其他入口的迁移与验证状态独立于本单卡 mini 记录。 | ||
| 76 | 127 | ||
| 77 | ### 8P Flash 16-expert Debug | 128 | ### 8P Flash 16-expert Debug |
| 78 | 129 | ||
| @@ -81,44 +132,33 @@ bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3.sh \ | |||
| 81 | --training.steps 10 | 132 | --training.steps 10 |
| 82 | ``` | 133 | ``` |
| 83 | 134 | ||
| 84 | -需要采集 profile 时显式追加: | 135 | +需要采集 profile 时显式追加 `--profiler.enable-profiling`。 |
| 85 | - | ||
| 86 | -```sh | ||
| 87 | ---profiler.enable-profiling | ||
| 88 | -``` | ||
| 89 | 136 | ||
| 90 | ### 32P Pro 32-expert Debug | 137 | ### 32P Pro 32-expert Debug |
| 91 | 138 | ||
| 92 | -Pro 32-expert 是独立的裁剪模型 debug/performance 入口,不与 8P Flash launcher 强制复用: | 139 | +Pro 32-expert 是独立的裁剪模型 debug/performance 入口: |
| 93 | 140 | ||
| 94 | ```sh | 141 | ```sh |
| 95 | NODE_IPS="${NODE_IPS}" \ | 142 | NODE_IPS="${NODE_IPS}" \ |
| 96 | bash examples/deepseek_v4/debug/deepseek_v4_pro_32p_cpt_4k_a5.sh \ | 143 | bash examples/deepseek_v4/debug/deepseek_v4_pro_32p_cpt_4k_a5.sh \ |
| 97 | - --compile.enable \ | ||
| 98 | - --compile.components model \ | ||
| 99 | - --compile.backend inductor \ | ||
| 100 | - --debug.moe-force-load-balance \ | ||
| 101 | --training.steps 20 | 144 | --training.steps 20 |
| 102 | ``` | 145 | ``` |
| 103 | 146 | ||
| 104 | -128K 场景不新增 launcher,只通过 CLI 改变并行和训练配置: | 147 | +128K 场景不新增 launcher,通过 CLI 改变并行和训练配置(recipe 保持 32P 默认拓扑): |
| 105 | 148 | ||
| 106 | ```sh | 149 | ```sh |
| 107 | -CP=32 NODE_IPS="${NODE_IPS}" \ | 150 | +NODE_IPS="${NODE_IPS}" \ |
| 108 | bash examples/deepseek_v4/debug/deepseek_v4_pro_32p_cpt_4k_a5.sh \ | 151 | bash examples/deepseek_v4/debug/deepseek_v4_pro_32p_cpt_4k_a5.sh \ |
| 109 | - --compile.enable \ | 152 | + --parallelism.context-parallel-degree 32 \ |
| 110 | - --compile.components model \ | ||
| 111 | - --compile.backend inductor \ | ||
| 112 | --parallelism.data-parallel-shard-degree 1 \ | 153 | --parallelism.data-parallel-shard-degree 1 \ |
| 113 | --parallelism.data-parallel-replicate-degree 1 \ | 154 | --parallelism.data-parallel-replicate-degree 1 \ |
| 114 | --training.max-context-length 131072 \ | 155 | --training.max-context-length 131072 \ |
| 115 | --training.num-tokens-per-microbatch-per-dp-rank 131072 \ | 156 | --training.num-tokens-per-microbatch-per-dp-rank 131072 \ |
| 116 | --training.num-tokens-per-train-step 1048576 \ | 157 | --training.num-tokens-per-train-step 1048576 \ |
| 117 | - --debug.moe-force-load-balance \ | ||
| 118 | --training.steps 20 | 158 | --training.steps 20 |
| 119 | ``` | 159 | ``` |
| 120 | 160 | ||
| 121 | -A5 脚本默认启用 block-FP8;如需 BF16,请在命令末尾追加后文的禁用选项。 | 161 | +A5 recipe 默认启用 block-FP8;如需 BF16,在命令末尾追加后文的禁用选项。 |
| 122 | 162 | ||
| 123 | ### 导出和加载 Debug Hugging Face checkpoint | 163 | ### 导出和加载 Debug Hugging Face checkpoint |
| 124 | 164 | ||
| @@ -135,7 +175,8 @@ bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3.sh \ | |||
| 135 | --debug.deterministic | 175 | --debug.deterministic |
| 136 | ``` | 176 | ``` |
| 137 | 177 | ||
| 138 | -从导出的 HF checkpoint 冷启动时,使用新的或空的 `checkpoint.folder`,避免已有 step checkpoint 优先触发 resume: | 178 | +从导出的 HF checkpoint 冷启动时,使用新的或空的 `checkpoint.folder`,避免已有 step checkpoint |
| 179 | +优先触发 resume: | ||
| 139 | 180 | ||
| 140 | ```sh | 181 | ```sh |
| 141 | bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3.sh \ | 182 | bash examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a3.sh \ |
| @@ -163,75 +204,59 @@ bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a3.sh \ | |||
| 163 | ```sh | 204 | ```sh |
| 164 | NODE_IPS="${NODE_IPS}" \ | 205 | NODE_IPS="${NODE_IPS}" \ |
| 165 | bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh \ | 206 | bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh \ |
| 166 | - --compile.enable \ | ||
| 167 | - --compile.components model \ | ||
| 168 | - --compile.backend inductor \ | ||
| 169 | - --debug.moe-force-load-balance \ | ||
| 170 | --training.steps 20 | 207 | --training.steps 20 |
| 171 | ``` | 208 | ``` |
| 172 | 209 | ||
| 173 | ### A5 64K | 210 | ### A5 64K |
| 174 | 211 | ||
| 175 | -64K 不需要新增 launcher,直接在 A5 4K 入口上覆盖训练和并行参数: | 212 | +64K 不新增 launcher,在原入口上覆盖训练和并行参数: |
| 176 | 213 | ||
| 177 | ```sh | 214 | ```sh |
| 178 | -CP=8 NODE_IPS="${NODE_IPS}" \ | 215 | +NODE_IPS="${NODE_IPS}" \ |
| 179 | bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh \ | 216 | bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh \ |
| 180 | - --compile.enable \ | 217 | + --parallelism.context-parallel-degree 8 \ |
| 181 | - --compile.components model \ | ||
| 182 | - --compile.backend inductor \ | ||
| 183 | --parallelism.data-parallel-shard-degree 16 \ | 218 | --parallelism.data-parallel-shard-degree 16 \ |
| 184 | --parallelism.data-parallel-replicate-degree 1 \ | 219 | --parallelism.data-parallel-replicate-degree 1 \ |
| 185 | --training.max-context-length 65536 \ | 220 | --training.max-context-length 65536 \ |
| 186 | --training.num-tokens-per-microbatch-per-dp-rank 131072 \ | 221 | --training.num-tokens-per-microbatch-per-dp-rank 131072 \ |
| 187 | --training.num-tokens-per-train-step 8388608 \ | 222 | --training.num-tokens-per-train-step 8388608 \ |
| 188 | - --debug.moe-force-load-balance \ | ||
| 189 | --training.steps 20 | 223 | --training.steps 20 |
| 190 | ``` | 224 | ``` |
| 191 | 225 | ||
| 192 | ### A5 1M | 226 | ### A5 1M |
| 193 | 227 | ||
| 194 | -1M wrapper 只提供该场景的默认 CLI 覆盖;仍可在命令末尾继续覆盖: | 228 | +`deepseek_v4_flash_cpt_1024k_a5` 固定 CP128、DP_SHARD1、16384 文档对齐和 8M tokens/step, |
| 229 | +需要 128 个 rank;末尾 CLI 仍可覆盖: | ||
| 195 | 230 | ||
| 196 | ```sh | 231 | ```sh |
| 197 | NODE_IPS="${NODE_IPS}" \ | 232 | NODE_IPS="${NODE_IPS}" \ |
| 198 | bash examples/deepseek_v4/deepseek_v4_flash_cpt_1024k_a5.sh \ | 233 | bash examples/deepseek_v4/deepseek_v4_flash_cpt_1024k_a5.sh \ |
| 199 | - --compile.enable \ | ||
| 200 | - --compile.components model \ | ||
| 201 | - --compile.backend inductor \ | ||
| 202 | - --debug.moe-force-load-balance \ | ||
| 203 | --training.steps 20 | 234 | --training.steps 20 |
| 204 | ``` | 235 | ``` |
| 205 | 236 | ||
| 206 | -等价的主要差异参数为: | ||
| 207 | - | ||
| 208 | -```sh | ||
| 209 | -CP=128 \ | ||
| 210 | ---parallelism.data-parallel-shard-degree 1 \ | ||
| 211 | ---parallelism.data-parallel-replicate-degree 1 \ | ||
| 212 | ---training.max-context-length 1048576 \ | ||
| 213 | ---training.num-tokens-per-microbatch-per-dp-rank 1048576 \ | ||
| 214 | ---training.num-tokens-per-train-step 8388608 | ||
| 215 | -``` | ||
| 216 | - | ||
| 217 | ## A5 量化与 BF16 | 237 | ## A5 量化与 BF16 |
| 218 | 238 | ||
| 219 | -所有 A5 脚本(`*_a5.sh`)默认启用 block-FP8 量化训练,等价于自动追加: | 239 | +A5 recipe 默认启用 block-FP8 量化训练,等价于: |
| 220 | 240 | ||
| 221 | ```sh | 241 | ```sh |
| 222 | --extension.quantization.enable-quantized-training \ | 242 | --extension.quantization.enable-quantized-training \ |
| 223 | --extension.quantization.recipe all_block_fp8 | 243 | --extension.quantization.recipe all_block_fp8 |
| 224 | ``` | 244 | ``` |
| 225 | 245 | ||
| 226 | -例如 A5 64K、1M 和 Pro 32P 命令均默认使用该量化配置。其中 Flash CPT 的 A5 入口(多机 4K 及其派生 64K/1M、8P debug)在此基础上还默认启用 FSDP 权重预量化(`--extension.quantization.enable-fsdp-prequantize`)。多机 4K 入口默认 DP_SHARD=128,64K/1M 通过 CP/DP 覆盖得到的有效 FSDP 切分度同为 128;该切分度下均分切分的投影(wq_a、wkv、wo_b、shared experts)无法满足预量化的 64 对齐约束、启动即报错,因此 4K 入口将 `fsdp-prequantize-fqns` 收窄为任何切分度下都保持对齐的投影(wq_b、wo_a、indexer.wq_b、routed experts)。8P debug 入口在 DP_SHARD=8 下使用 recipe 默认白名单。对齐约束及“结构性 no-op 回退 / 对齐失败报错”的区别详见 `docs/feature_guides/low_precision_training.md`。 | 246 | +Flash 多机 A5 CPT(4K、1M)和 GraphTrainer 入口在此基础上启用 FSDP 权重预量化,并把 |
| 247 | +`fsdp-prequantize-fqns` 收窄为在 128 切分度下仍保持 64 对齐的投影(wq_b、wo_a、indexer.wq_b、 | ||
| 248 | +routed experts)。8P debug 入口在 DP_SHARD=8 下使用 recipe 默认白名单。对齐约束以及 | ||
| 249 | +「结构性 no-op 回退 / 对齐失败报错」的区别见 `docs/feature_guides/low_precision_training.md`。 | ||
| 227 | 250 | ||
| 228 | -需要保留 BF16 训练方案时,在命令末尾追加以下选项,覆盖脚本默认值: | 251 | +需要保留 BF16 训练时,在命令末尾追加: |
| 229 | 252 | ||
| 230 | ```sh | 253 | ```sh |
| 231 | --extension.quantization.no-enable-quantized-training | 254 | --extension.quantization.no-enable-quantized-training |
| 232 | ``` | 255 | ``` |
| 233 | 256 | ||
| 234 | -A3 脚本不默认启用量化;如需 A3 量化训练,请显式传入上面的 enable 和 recipe 参数。 | 257 | +A3 recipe 不默认启用量化;如需 A3 量化,显式传入上面的 enable 和 recipe 参数。QAT、HiF8 |
| 258 | +分别由 `deepseek_v4_flash_qat_4k_a5`、`deepseek_v4_flash_8p_cpt_4k_a5_hif8` 表达,不通过 | ||
| 259 | +环境变量切换。 | ||
| 235 | 260 | ||
| 236 | ## Profiling | 261 | ## Profiling |
| 237 | 262 | ||
| @@ -241,7 +266,7 @@ A3 脚本不默认启用量化;如需 A3 量化训练,请显式传入上面 | |||
| 241 | --profiler.enable-profiling | 266 | --profiler.enable-profiling |
| 242 | ``` | 267 | ``` |
| 243 | 268 | ||
| 244 | -公共 A3 基线提供如下 schedule,A5 Flash 直接继承,用户仍可通过 CLI 覆盖: | 269 | +recipe 提供如下 schedule,用户可通过 CLI 覆盖: |
| 245 | 270 | ||
| 246 | ```sh | 271 | ```sh |
| 247 | --profiler.profile-freq 1 \ | 272 | --profiler.profile-freq 1 \ |
| @@ -251,7 +276,7 @@ A3 脚本不默认启用量化;如需 A3 量化训练,请显式传入上面 | |||
| 251 | --profiler.profiler-skip-first 4 | 276 | --profiler.profiler-skip-first 4 |
| 252 | ``` | 277 | ``` |
| 253 | 278 | ||
| 254 | -如需不依赖 recipe 固定单次采样窗口,请在命令末尾完整追加: | 279 | +如需固定单次采样窗口,在命令末尾完整追加: |
| 255 | 280 | ||
| 256 | ```sh | 281 | ```sh |
| 257 | --profiler.enable-profiling \ | 282 | --profiler.enable-profiling \ |
| @@ -264,17 +289,15 @@ A3 脚本不默认启用量化;如需 A3 量化训练,请显式传入上面 | |||
| 264 | 289 | ||
| 265 | ## Checkpoint 说明 | 290 | ## Checkpoint 说明 |
| 266 | 291 | ||
| 267 | -Flash 多机 CPT 基线默认启用 `--checkpoint.load-only`,即只负责加载,不会保存新的训练 checkpoint。需要保存时必须显式覆盖: | 292 | +Flash 多机 CPT recipe 默认启用 `--checkpoint.load-only`,即只负责加载,不会保存新的训练 |
| 268 | - | 293 | +checkpoint。需要保存时必须显式覆盖为 `--checkpoint.no-load-only`。当 `checkpoint.folder` 已存在有效的 |
| 269 | -```sh | 294 | +`step-*` checkpoint 时,TorchTitan 会优先 resume;从 `initial-load-path` 冷启动请使用新的或空的 |
| 270 | ---checkpoint.no-load-only | 295 | +`checkpoint.folder`。 |
| 271 | -``` | ||
| 272 | - | ||
| 273 | -当 `checkpoint.folder` 已存在有效的 `step-*` checkpoint 时,TorchTitan 会优先 resume,该情况下 `checkpoint.initial-load-path` 不作为冷启动来源;要从 `initial-load-path` 冷启动,请使用新的或空的 `checkpoint.folder`。 | ||
| 274 | 296 | ||
| 275 | ## LoRA 微调 | 297 | ## LoRA 微调 |
| 276 | 298 | ||
| 277 | -完整 Flash 模型的 BF16 LoRA 训练复用 A3 4K 公共入口,节点、数据和基座路径使用上面的环境变量: | 299 | +完整 Flash 模型的 BF16 LoRA 训练选择 `deepseek_v4_flash_lora_4k_a3` recipe(dense/expert rank 16、 |
| 300 | +alpha 32),并开启 checkpoint 保存。周期 checkpoint 用于续跑,最后一步导出 PEFT adapter: | ||
| 278 | 301 | ||
| 279 | ```sh | 302 | ```sh |
| 280 | NODE_IPS="${NODE_IPS}" \ | 303 | NODE_IPS="${NODE_IPS}" \ |
| @@ -284,6 +307,10 @@ bash examples/deepseek_v4/deepseek_v4_flash_lora_4k_a3.sh \ | |||
| 284 | --checkpoint.interval 100 | 307 | --checkpoint.interval 100 |
| 285 | ``` | 308 | ``` |
| 286 | 309 | ||
| 287 | -该入口使用 `deepseek_v4_flash_lora` recipe(dense/expert rank 16、alpha 32),并开启 checkpoint 保存。优化器沿用 CPT 默认值,传入 `--optimizer.name` 可覆盖。周期 checkpoint 用于续跑,最后一步导出 PEFT adapter。模型规模、并行配置和其余默认参数继承 A3 公共入口,命令末尾的 CLI 参数仍可覆盖默认值。A5 使用 `CONFIG=deepseek_v4_flash_lora bash examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh --checkpoint.no-load-only --checkpoint.save-training-state`,继承 A5 CPT 的 block-FP8 默认配置。 | 310 | +该 launcher 默认选择融合算子版本 `deepseek_v4_flash_lora_4k_a3`;`USE_GOLDEN=1` 选择 |
| 311 | +reference 算子的 `deepseek_v4_flash_lora_4k_a3_golden`。A5 LoRA 使用 | ||
| 312 | +`MODULE=torchtitan_npu_recipes.models.deepseek_v4 CONFIG=deepseek_v4_flash_lora_4k_a3` 搭配 | ||
| 313 | +`examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh` 的机器设置即可,量化随 A5 recipe 继承。 | ||
| 288 | 314 | ||
| 289 | -配置、部分参数训练、native checkpoint 恢复、PEFT 导出和离线合并见 [LoRA 功能指南](../../docs/feature_guides/deepseek_v4_lora.md)。 | 315 | +配置、部分参数训练、native checkpoint 恢复、PEFT 导出和离线合并见 |
| 316 | +[LoRA 功能指南](../../docs/feature_guides/deepseek_v4_lora.md)。 | ||
| @@ -4,180 +4,37 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Run this script on a single node. | 7 | + |
| 8 | -# Append CLI arguments to override the defaults below: | 8 | +# Single-node A3 8P DeepSeek-V4.1 debug multimodal CPT (16 experts). |
| 9 | -# ./examples/deepseek_v4_1/debug/deepseek_v4_1_flash_8p_cpt_4k_a3.sh --training.steps 5 | 9 | +# USE_GOLDEN=1 selects the reference-operator recipe. |
| 10 | -# USE_GOLDEN=1 selects Golden. For deterministic execution, append | 10 | +# |
| 11 | -# --debug.seed 42 --debug.deterministic to the command line. | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 12 | 14 | ||
| 13 | set -euo pipefail | 15 | set -euo pipefail |
| 16 | + | ||
| 17 | + | ||
| 18 | +# The Host Engram table is a device-memory choice, not a recipe knob. | ||
| 14 | export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" | 19 | export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" |
| 15 | 20 | ||
| 16 | -NGPU="${NGPU:-8}" | 21 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4_1}" |
| 17 | -WORLD_SIZE="${NGPU}" | 22 | +if [[ -z "${CONFIG:-}" ]]; then |
| 18 | - | 23 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 19 | -# Model | 24 | + CONFIG="deepseek_v4_1_flash_8p_cpt_4k_a3_golden" |
| 20 | -MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4_1}" | 25 | + else |
| 21 | -CONFIG="${CONFIG:-deepseek_v4_1_flash_40layers_16experts_multimodal}" | 26 | + CONFIG="deepseek_v4_1_flash_8p_cpt_4k_a3" |
| 22 | - | 27 | + fi |
| 23 | -# Dataloader & Checkpoint | ||
| 24 | -DATASET="${DATASET:-cc12m-test}" | ||
| 25 | -DATASET_PATH="${DATASET_PATH:-}" # optional; unset keeps the upstream dataset source | ||
| 26 | -HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" # your tokenizer path | ||
| 27 | -CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" # your model save/load ckpt path | ||
| 28 | - | ||
| 29 | -# Parallelism | ||
| 30 | -TP=1 | ||
| 31 | -PP=1 | ||
| 32 | -EP=8 | ||
| 33 | -CP=1 | ||
| 34 | -DP_SHARD=8 | ||
| 35 | -DP_REPLICATE=$((WORLD_SIZE / (DP_SHARD * CP * TP * PP))) | ||
| 36 | -SPMD_BACKEND="spmd_types" | ||
| 37 | - | ||
| 38 | -# Training | ||
| 39 | -# Retain the validated eager / Muon / FullAC resource crop. | ||
| 40 | -SEQ_LEN=4096 | ||
| 41 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=4096 | ||
| 42 | -NUM_TOKENS_PER_TRAIN_STEP=32768 | ||
| 43 | -STEPS=40 | ||
| 44 | - | ||
| 45 | -# Debug | ||
| 46 | -USE_GOLDEN="${USE_GOLDEN:-0}" | ||
| 47 | -DEBUG_ARGS=" | ||
| 48 | - --debug.print-config | ||
| 49 | - --debug.moe-force-load-balance | ||
| 50 | -" | ||
| 51 | - | ||
| 52 | -# HF assets | ||
| 53 | -HF_ASSETS_ARGS=" | ||
| 54 | - --hf-assets-path ${HF_ASSETS_PATH} | ||
| 55 | -" | ||
| 56 | - | ||
| 57 | -# Native Grain dataset configuration is selected when the recipe is constructed. | ||
| 58 | -export DATASET DATASET_PATH | ||
| 59 | -export PACKING_BUFFER_SIZE="${PACKING_BUFFER_SIZE:-0}" | ||
| 60 | - | ||
| 61 | -# Parallelism | ||
| 62 | -PARALLELISM_ARGS=" | ||
| 63 | - --parallelism.spmd-backend ${SPMD_BACKEND} | ||
| 64 | - --parallelism.data-parallel-shard-degree ${DP_SHARD} | ||
| 65 | - --parallelism.data-parallel-replicate-degree ${DP_REPLICATE} | ||
| 66 | - --parallelism.expert-parallel-degree ${EP} | ||
| 67 | - --parallelism.tensor-parallel-degree ${TP} | ||
| 68 | - --parallelism.context-parallel-degree ${CP} | ||
| 69 | - --parallelism.pipeline-parallel-degree ${PP} | ||
| 70 | - --parallelism.fsdp-reshard-after-forward always | ||
| 71 | - --parallelism.context-parallel-load-balancer doc_chunk | ||
| 72 | - --parallelism.enable-sequence-parallel | ||
| 73 | -" | ||
| 74 | - | ||
| 75 | -# Compile | ||
| 76 | -COMPILE_ARGS=" | ||
| 77 | - --compile.enable | ||
| 78 | - --compile.components model | ||
| 79 | - --compile.backend inductor | ||
| 80 | -" | ||
| 81 | - | ||
| 82 | -# Training | ||
| 83 | -TRAINING_ARGS=" | ||
| 84 | - --training.num-tokens-per-microbatch-per-dp-rank ${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK} | ||
| 85 | - --training.num-tokens-per-train-step ${NUM_TOKENS_PER_TRAIN_STEP} | ||
| 86 | - --training.max-context-length ${SEQ_LEN} | ||
| 87 | - --training.steps ${STEPS} | ||
| 88 | - --training.disable-cuda-graphs | ||
| 89 | - --metrics.log-freq 1 | ||
| 90 | -" | ||
| 91 | - | ||
| 92 | -# LR scheduler | ||
| 93 | -LR_SCHEDULER_ARGS=" | ||
| 94 | - --lr-scheduler.warmup-steps 2 | ||
| 95 | - --lr-scheduler.total-steps ${STEPS} | ||
| 96 | - --lr-scheduler.decay-ratio 1.0 | ||
| 97 | - --lr-scheduler.decay-type cosine | ||
| 98 | - --lr-scheduler.min-lr-factor 0.01 | ||
| 99 | -" | ||
| 100 | - | ||
| 101 | -# Checkpoint | ||
| 102 | -# `checkpoint.folder` is the save/load root (`CKPT_SAVE_LOAD_PATH`). If it | ||
| 103 | -# already contains a valid step-* checkpoint, upstream TorchTitan resumes from | ||
| 104 | -# it; use a new/empty folder when starting a fresh run. | ||
| 105 | -CHECKPOINT_ARGS=" | ||
| 106 | - --checkpoint.no-enable | ||
| 107 | - --checkpoint.load-only | ||
| 108 | - --checkpoint.interval 10 | ||
| 109 | - --checkpoint.folder ${CKPT_SAVE_LOAD_PATH} | ||
| 110 | -" | ||
| 111 | - | ||
| 112 | -# Profiler | ||
| 113 | -PROFILER_ARGS=" | ||
| 114 | - --profiler.no-enable-profiling | ||
| 115 | - --profiler.profile-freq 10 | ||
| 116 | - --profiler.profiler-active 10 | ||
| 117 | - --profiler.profiler-warmup 0 | ||
| 118 | -" | ||
| 119 | - | ||
| 120 | -# Communication | ||
| 121 | -COMM_ARGS=" | ||
| 122 | - --comm.init-timeout-seconds 7200 | ||
| 123 | - --comm.train-timeout-seconds 600 | ||
| 124 | -" | ||
| 125 | - | ||
| 126 | -# Optimizer | ||
| 127 | -# AdamW hyperparameters come from the recipe, not from CLI flags. | ||
| 128 | -OPTIMIZER_ARGS=" | ||
| 129 | - --optimizer.name Muon | ||
| 130 | - --optimizer.lr 1.0e-5 | ||
| 131 | - --optimizer.beta1 0.9 | ||
| 132 | - --optimizer.beta2 0.95 | ||
| 133 | - --optimizer.eps 1.0e-8 | ||
| 134 | - --optimizer.weight-decay 1.0e-1 | ||
| 135 | - --optimizer.muon_momentum 0.95 | ||
| 136 | - --optimizer.muon_enable_nesterov | ||
| 137 | - --optimizer.muon_ns_steps 10 | ||
| 138 | - --optimizer.muon_adjust_lr_fn match_rms_adamw | ||
| 139 | -" | ||
| 140 | -OPTIMIZER_OVERRIDES="${OPTIMIZER_OVERRIDES-torchtitan_npu.override.common.optimizer.swap_optimizer}" | ||
| 141 | - | ||
| 142 | -# The text-rope entry is a hardware choice: A3 defaults to asc_complex; the A5 | ||
| 143 | -# wrapper supplies asc_partial through the same CLI_OVERRIDES channel. The fused | ||
| 144 | -# sparse attention and its selector also ride this channel, so a wrapper that | ||
| 145 | -# already names them does not add a second copy. Set the defaults in both branches | ||
| 146 | -# so `set -u` never sees them unbound. | ||
| 147 | -if [[ "${USE_GOLDEN}" == "1" ]]; then | ||
| 148 | - NPU_OPS_OVERRIDES=(torchtitan_npu.override.common.rope.workaround) | ||
| 149 | - DEFAULT_TEXT_ROPE_OVERRIDE="" | ||
| 150 | - DEFAULT_FUSED_OVERRIDES="" | ||
| 151 | -else | ||
| 152 | - DEFAULT_TEXT_ROPE_OVERRIDE="torchtitan_npu.override.common.rope.asc_complex" | ||
| 153 | - DEFAULT_FUSED_OVERRIDES="torchtitan_npu.override.deepseek_v4_1.sparse_attn.asc torchtitan_npu.override.deepseek_v4_1.lightning_indexer.asc" | ||
| 154 | - MHC_POST_OVERRIDE="${MHC_POST_OVERRIDE:-torchtitan_npu.override.deepseek_v4_1.mhc.asc_hc_post}" | ||
| 155 | - NPU_OPS_OVERRIDES=( | ||
| 156 | - torchtitan_npu.override.common.rms_norm.asc | ||
| 157 | - torchtitan_npu.override.common.rope.asc_half_rotation | ||
| 158 | - torchtitan_npu.override.common.token_dispatcher.asc | ||
| 159 | - ${MHC_POST_OVERRIDE} | ||
| 160 | - ) | ||
| 161 | fi | 28 | fi |
| 162 | - | 29 | +NGPU="${NGPU:-8}" |
| 163 | -# Wrapper defaults extend override.imports after the base targets. | 30 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" |
| 164 | -CLI_OVERRIDES="${CLI_OVERRIDES:-${DEFAULT_TEXT_ROPE_OVERRIDE} ${DEFAULT_FUSED_OVERRIDES}}" | 31 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" |
| 165 | 32 | ||
| 166 | MODULE="${MODULE}" \ | 33 | MODULE="${MODULE}" \ |
| 167 | CONFIG="${CONFIG}" \ | 34 | CONFIG="${CONFIG}" \ |
| 168 | NGPU="${NGPU}" \ | 35 | NGPU="${NGPU}" \ |
| 169 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | 36 | LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 170 | bash scripts/run_train.sh \ | 37 | bash scripts/run_train.sh \ |
| 171 | - $COMPILE_ARGS \ | 38 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 172 | - $HF_ASSETS_ARGS \ | 39 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 173 | - $PARALLELISM_ARGS \ | ||
| 174 | - $TRAINING_ARGS \ | ||
| 175 | - $DEBUG_ARGS \ | ||
| 176 | - $OPTIMIZER_ARGS \ | ||
| 177 | - $LR_SCHEDULER_ARGS \ | ||
| 178 | - $PROFILER_ARGS \ | ||
| 179 | - $COMM_ARGS \ | ||
| 180 | - $CHECKPOINT_ARGS \ | ||
| 181 | - --override.imports "${NPU_OPS_OVERRIDES[@]}" $OPTIMIZER_OVERRIDES \ | ||
| 182 | - $CLI_OVERRIDES \ | ||
| 183 | "$@" | 40 | "$@" |
| @@ -4,51 +4,49 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# A5 wrapper around the common DeepSeek-V4.1 Flash CPT launcher. Keep the shared | 7 | + |
| 8 | -# training and parallelism defaults in the A3 script; this entrypoint selects | 8 | +# Single-node A5 8P DeepSeek-V4.1 debug multimodal CPT (24 experts, FP8). |
| 9 | -# 24 experts and supplies A5-specific runtime and fused-operator settings. | 9 | +# USE_GOLDEN=1 selects the reference operators; USE_TILELANG=1 selects TileLang mHC. |
| 10 | -# Append CLI arguments to override the defaults below: | 10 | +# |
| 11 | -# ./examples/deepseek_v4_1/debug/deepseek_v4_1_flash_8p_cpt_4k_a5.sh --training.steps 5 | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 12 | 14 | ||
| 13 | set -euo pipefail | 15 | set -euo pipefail |
| 14 | 16 | ||
| 15 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 16 | 17 | ||
| 17 | -export CONFIG="${CONFIG:-deepseek_v4_1_flash_40layers_24experts_multimodal}" | 18 | +# The Host Engram table is a device-memory choice, not a recipe knob. |
| 19 | +export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" | ||
| 18 | 20 | ||
| 19 | -# Use the command line `npu-smi info -t topo` to query the CPU affinity of the | 21 | + |
| 20 | -# NPU cards for configuration. | 22 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 23 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" | ||
| 24 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | ||
| 25 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 26 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 27 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 28 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 21 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | 29 | export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" |
| 22 | 30 | ||
| 23 | -# A5-only fused ops; USE_GOLDEN=1 keeps the pure reference list. | 31 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4_1}" |
| 24 | -# USE_TILELANG=1 swaps the mHC pre/post entries to the TileLang overrides | 32 | +if [[ -z "${CONFIG:-}" ]]; then |
| 25 | -# (swiglu/sparse-attn keep the asc fused path; the PR730/731 tilelang swiglu | 33 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then |
| 26 | -# and topk adapters are single-rank-validated and reject the EP>1 DTensor | 34 | + CONFIG="deepseek_v4_1_flash_8p_cpt_4k_a5_golden" |
| 27 | -# weights this 8p recipe produces). | 35 | + elif [[ "${USE_TILELANG:-0}" == "1" ]]; then |
| 28 | -if [[ "${USE_GOLDEN:-0}" != "1" ]]; then | 36 | + CONFIG="deepseek_v4_1_flash_8p_cpt_4k_a5_tilelang" |
| 29 | - if [[ "${USE_TILELANG:-0}" == "1" ]]; then | ||
| 30 | - export MHC_POST_OVERRIDE=torchtitan_npu.override.deepseek_v4_1.tilelang.tilelang_hc_post | ||
| 31 | - export CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rope.asc_partial \ | ||
| 32 | - torchtitan_npu.override.deepseek_v4_1.tilelang.tilelang_hc_pre \ | ||
| 33 | - torchtitan_npu.override.common.swiglu_group.asc \ | ||
| 34 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts \ | ||
| 35 | - torchtitan_npu.override.deepseek_v4_1.sparse_attn.asc \ | ||
| 36 | - torchtitan_npu.override.deepseek_v4_1.lightning_indexer.asc}" | ||
| 37 | else | 37 | else |
| 38 | - export CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rope.asc_partial \ | 38 | + CONFIG="deepseek_v4_1_flash_8p_cpt_4k_a5" |
| 39 | - torchtitan_npu.override.common.swiglu_group.asc \ | ||
| 40 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts \ | ||
| 41 | - torchtitan_npu.override.deepseek_v4_1.sparse_attn.asc \ | ||
| 42 | - torchtitan_npu.override.deepseek_v4_1.lightning_indexer.asc \ | ||
| 43 | - torchtitan_npu.override.deepseek_v4_1.mhc.asc_sinkhorn}" | ||
| 44 | fi | 39 | fi |
| 45 | fi | 40 | fi |
| 41 | +NGPU="${NGPU:-8}" | ||
| 42 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" | ||
| 43 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 46 | 44 | ||
| 47 | -QUANTIZATION_ARGS=( | 45 | +MODULE="${MODULE}" \ |
| 48 | - --extension.quantization.enable-quantized-training | 46 | +CONFIG="${CONFIG}" \ |
| 49 | - --extension.quantization.recipe all_block_fp8 | 47 | +NGPU="${NGPU}" \ |
| 50 | -) | 48 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 51 | - | 49 | +bash scripts/run_train.sh \ |
| 52 | -exec bash "${SCRIPT_DIR}/deepseek_v4_1_flash_8p_cpt_4k_a3.sh" \ | 50 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 53 | - "${QUANTIZATION_ARGS[@]}" \ | 51 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ |
| 54 | - "$@" \ | 52 | + "$@" |
| @@ -4,38 +4,47 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# A5 wrapper around the common DeepSeek-V4.1 Flash CPT launcher. Keep the shared | 7 | + |
| 8 | -# model, training, and parallelism defaults in the A3 script; this entrypoint | 8 | +# Single-node A5 8P DeepSeek-V4.1 QAT CPT: MXFP4 routed experts and quantized |
| 9 | -# only supplies A5-specific runtime and fused-operator settings. | 9 | +# sparse attention. USE_GOLDEN=1 selects the reference operators. |
| 10 | -# This entry enables routed-expert MXFP4 fake quant, V4.1 QLI/QSLI, and | 10 | +# |
| 11 | -# sparse-attention/KV-source Compressor quantization. | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 12 | -# Append CLI arguments to override the defaults below: | 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. |
| 13 | -# ./examples/deepseek_v4_1/debug/deepseek_v4_1_flash_8p_qat_4k_a5.sh --training.steps 5 | 13 | +# Append CLI arguments to override the recipe; they are passed through last. |
| 14 | 14 | ||
| 15 | set -euo pipefail | 15 | set -euo pipefail |
| 16 | 16 | ||
| 17 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 18 | 17 | ||
| 19 | -# The quantized sparse attention (torchao_npu's QuantV41SparseAttention) is its own backend: | 18 | +# The Host Engram table is a device-memory choice, not a recipe knob. |
| 20 | -# its converter-installed config builds the attention entry, so this entry launches no per-layer | 19 | +export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" |
| 21 | -# metadata operator. It replaces the node `sparse_attn.asc` targets, so that override (kept | ||
| 22 | -# below for the unquantized variants of this list) is a no-op here. | ||
| 23 | -# The override list is the non-tilelang fused branch of | ||
| 24 | -# deepseek_v4_1_flash_8p_cpt_4k_a5.sh -- keep the two lists in sync. | ||
| 25 | -export CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rope.asc_partial \ | ||
| 26 | - torchtitan_npu.override.common.swiglu_group.asc \ | ||
| 27 | - torchtitan_npu.override.common.swiglu_group.asc_shared_experts \ | ||
| 28 | - torchtitan_npu.override.deepseek_v4_1.sparse_attn.asc \ | ||
| 29 | - torchtitan_npu.override.deepseek_v4_1.lightning_indexer.asc}" | ||
| 30 | 20 | ||
| 31 | -QUANTIZATION_ARGS=( | ||
| 32 | - --extension.quantization.enable-quantized-training | ||
| 33 | - --extension.quantization.recipe all_block_fp8 | ||
| 34 | - --extension.quantization.enable-mxfp4-qat | ||
| 35 | - --extension.quantization.li-quantization mxfp4 | ||
| 36 | - --extension.quantization.enable-sparse-attention-quantization | ||
| 37 | -) | ||
| 38 | 21 | ||
| 39 | -exec bash "${SCRIPT_DIR}/deepseek_v4_1_flash_8p_cpt_4k_a5.sh" \ | 22 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 40 | - "${QUANTIZATION_ARGS[@]}" \ | 23 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 41 | - "$@" \ | 24 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| 25 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 26 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 27 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 28 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 29 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 30 | + | ||
| 31 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4_1}" | ||
| 32 | +if [[ -z "${CONFIG:-}" ]]; then | ||
| 33 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then | ||
| 34 | + CONFIG="deepseek_v4_1_flash_8p_qat_4k_a5_golden" | ||
| 35 | + else | ||
| 36 | + CONFIG="deepseek_v4_1_flash_8p_qat_4k_a5" | ||
| 37 | + fi | ||
| 38 | +fi | ||
| 39 | +NGPU="${NGPU:-8}" | ||
| 40 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" | ||
| 41 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 42 | + | ||
| 43 | +MODULE="${MODULE}" \ | ||
| 44 | +CONFIG="${CONFIG}" \ | ||
| 45 | +NGPU="${NGPU}" \ | ||
| 46 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 47 | +bash scripts/run_train.sh \ | ||
| 48 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 49 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 50 | + "$@" | ||
| @@ -4,11 +4,37 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Vision-language SFT wrapper around the 8p CPT launcher in this directory. | 7 | + |
| 8 | +# Single-node A3 8P DeepSeek-V4.1 debug vision-language SFT. | ||
| 9 | +# USE_GOLDEN=1 selects the reference operators. | ||
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 8 | set -euo pipefail | 15 | set -euo pipefail |
| 9 | 16 | ||
| 10 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 11 | -export DSV41_SFT_DATASET="${DSV41_SFT_DATASET:-${DATASET_PATH:-/path/to/train.jsonl}}" | ||
| 12 | -export CONFIG="${CONFIG:-deepseek_v4_1_flash_40layers_16experts_multimodal_sft}" | ||
| 13 | 17 | ||
| 14 | -exec bash "${SCRIPT_DIR}/deepseek_v4_1_flash_8p_cpt_4k_a3.sh" "$@" | 18 | +# The Host Engram table is a device-memory choice, not a recipe knob. |
| 19 | +export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" | ||
| 20 | + | ||
| 21 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4_1}" | ||
| 22 | +if [[ -z "${CONFIG:-}" ]]; then | ||
| 23 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then | ||
| 24 | + CONFIG="deepseek_v4_1_flash_8p_sft_4k_a3_golden" | ||
| 25 | + else | ||
| 26 | + CONFIG="deepseek_v4_1_flash_8p_sft_4k_a3" | ||
| 27 | + fi | ||
| 28 | +fi | ||
| 29 | +NGPU="${NGPU:-8}" | ||
| 30 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" | ||
| 31 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 32 | + | ||
| 33 | +MODULE="${MODULE}" \ | ||
| 34 | +CONFIG="${CONFIG}" \ | ||
| 35 | +NGPU="${NGPU}" \ | ||
| 36 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 37 | +bash scripts/run_train.sh \ | ||
| 38 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 39 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 40 | + "$@" | ||
| @@ -4,11 +4,47 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Vision-language SFT wrapper around the 8p A5 CPT launcher in this directory. | 7 | + |
| 8 | +# Single-node A5 8P DeepSeek-V4.1 debug vision-language SFT (24 experts, FP8). | ||
| 9 | +# USE_GOLDEN=1 selects the reference operators. | ||
| 10 | +# | ||
| 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in | ||
| 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. | ||
| 13 | +# Append CLI arguments to override the recipe; they are passed through last. | ||
| 14 | + | ||
| 8 | set -euo pipefail | 15 | set -euo pipefail |
| 9 | 16 | ||
| 10 | -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| 11 | -export DSV41_SFT_DATASET="${DSV41_SFT_DATASET:-${DATASET_PATH:-/path/to/train.jsonl}}" | ||
| 12 | -export CONFIG="${CONFIG:-deepseek_v4_1_flash_40layers_24experts_multimodal_sft}" | ||
| 13 | 17 | ||
| 14 | -exec bash "${SCRIPT_DIR}/deepseek_v4_1_flash_8p_cpt_4k_a5.sh" "$@" | 18 | +# The Host Engram table is a device-memory choice, not a recipe knob. |
| 19 | +export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" | ||
| 23 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" | ||
| 24 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" | ||
| 25 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" | ||
| 26 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. | ||
| 27 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 28 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 29 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 30 | + | ||
| 31 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4_1}" | ||
| 32 | +if [[ -z "${CONFIG:-}" ]]; then | ||
| 33 | + if [[ "${USE_GOLDEN:-0}" == "1" ]]; then | ||
| 34 | + CONFIG="deepseek_v4_1_flash_8p_sft_4k_a5_golden" | ||
| 35 | + else | ||
| 36 | + CONFIG="deepseek_v4_1_flash_8p_sft_4k_a5" | ||
| 37 | + fi | ||
| 38 | +fi | ||
| 39 | +NGPU="${NGPU:-8}" | ||
| 40 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" | ||
| 41 | +CKPT_SAVE_LOAD_PATH="${CKPT_SAVE_LOAD_PATH:-/path/to/save_ckpt}" | ||
| 42 | + | ||
| 43 | +MODULE="${MODULE}" \ | ||
| 44 | +CONFIG="${CONFIG}" \ | ||
| 45 | +NGPU="${NGPU}" \ | ||
| 46 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ | ||
| 47 | +bash scripts/run_train.sh \ | ||
| 48 | + --hf-assets-path "${HF_ASSETS_PATH}" \ | ||
| 49 | + --checkpoint.folder "${CKPT_SAVE_LOAD_PATH}" \ | ||
| 50 | + "$@" | ||
| @@ -4,71 +4,42 @@ | |||
| 4 | # This source code is licensed under the BSD-style license found in the | 4 | # This source code is licensed under the BSD-style license found in the |
| 5 | # LICENSE file in the root directory of this source tree. | 5 | # LICENSE file in the root directory of this source tree. |
| 6 | 6 | ||
| 7 | -# Single-card DeepSeek-V4.1 with the fused ds41 LightningIndexer. | 7 | + |
| 8 | +# Single-card DeepSeek-V4.1 stripped-model CPT reaching every fused-selector branch. | ||
| 9 | +# USE_GOLDEN=1 selects the reference operators and disables FP8 training. | ||
| 8 | # | 10 | # |
| 9 | -# The flavor behind this wrapper (`deepseek_v4_1_stripped`) is the flash model with six | 11 | +# The training configuration is `MODULE`/`CONFIG` below (a recipe in |
| 10 | -# layers instead of forty; ``dim``, the attention heads and both released geometries are | 12 | +# torchtitan_npu_recipes); this launcher only selects it and sets up the machine. |
| 11 | -# untouched, because the MLA attention and the ds41 indexer are both fixed by their kernels. | 13 | +# Append CLI arguments to override the recipe; they are passed through last. |
| 12 | -# See ``_stripped`` in ``torchtitan_npu/models/deepseek_v4_1/__init__.py``. | ||
| 13 | -# | ||
| 14 | -# Six layers is the smallest count that still reaches all three branches of the fused | ||
| 15 | -# selector: layer 2 is Full Mode at ratio 2 with the pool off, layer 3 is the Full Mode pool | ||
| 16 | -# source at ratio 1, and layer 4 is the Reindex Mode searcher that reads what layer 3 built. | ||
| 17 | -# The candidate pool is a ratio-1 mechanism in the released model too -- its source sits at | ||
| 18 | -# the first ratio-1 layer -- so this shape does not invent a combination the model lacks. | ||
| 19 | -# | ||
| 20 | -# Run from the repository root: | ||
| 21 | -# NGPU=1 bash examples/deepseek_v4_1/debug/deepseek_v4_1_mini_1p_cpt_a5.sh --training.steps 5 | ||
| 22 | -# | ||
| 23 | -# Append CLI arguments to override the defaults below. `QUANTIZATION_ARGS` enables | ||
| 24 | -# the all_block_fp8 training recipe. | ||
| 25 | 14 | ||
| 26 | set -euo pipefail | 15 | set -euo pipefail |
| 27 | 16 | ||
| 28 | -export NGPU="${NGPU:-1}" | 17 | + |
| 29 | -export MODULE="${MODULE:-torchtitan_npu.models.deepseek_v4_1}" | 18 | +# The Host Engram table is a device-memory choice, not a recipe knob. |
| 30 | -export CONFIG="${CONFIG:-deepseek_v4_1_stripped}" | ||
| 31 | -export PYTHONUNBUFFERED=1 | ||
| 32 | export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" | 19 | export TORCHTITAN_ENGRAM_TABLE_ROWS="${TORCHTITAN_ENGRAM_TABLE_ROWS:-100000}" |
| 33 | 20 | ||
| 34 | -# The fused operators this flavor exists to exercise. `sparse_attn.asc` is not optional | ||
| 35 | -# alongside `lightning_indexer.asc`: the indexer is trained purely through the teacher that | ||
| 36 | -# SMLA's backward emits, and the model refuses a half-fused stack rather than training an | ||
| 37 | -# indexer that never receives a gradient. | ||
| 38 | -# | ||
| 39 | -LIGHTNING_INDEXER_OVERRIDE="torchtitan_npu.override.deepseek_v4_1.lightning_indexer.asc" | ||
| 40 | 21 | ||
| 41 | -# Enable block FP8 quantized training. | 22 | +export HCCL_CONNECT_TIMEOUT="${HCCL_CONNECT_TIMEOUT:-7200}" |
| 42 | -QUANTIZATION_ARGS=( | 23 | +export HCCL_EXEC_TIMEOUT="${HCCL_EXEC_TIMEOUT:-17330}" |
| 43 | - --extension.quantization.enable-quantized-training | 24 | +export ACL_DEVICE_SYNC_TIMEOUT="${ACL_DEVICE_SYNC_TIMEOUT:-2147480}" |
| 44 | - --extension.quantization.recipe all_block_fp8 | 25 | +export HCCL_EVENT_TIMEOUT="${HCCL_EVENT_TIMEOUT:-2147480}" |
| 45 | -) | 26 | +# Disable the HCCL watchdog for long checkpoint loading on the A5 setup. |
| 27 | +export HCCL_ASYNC_ERROR_HANDLING="${HCCL_ASYNC_ERROR_HANDLING:-0}" | ||
| 28 | +# Use the command line `npu-smi info -t topo` to query the CPU Affinity of the NPU cards for configuration. | ||
| 29 | +export CPU_AFFINITY_CONF="${CPU_AFFINITY_CONF:-1,npu0:288-311,npu1:312-335,npu2:336-359,npu3:360-383,npu4:96-119,npu5:120-143,npu6:144-167,npu7:168-191}" | ||
| 46 | 30 | ||
| 47 | -CLI_OVERRIDES="${CLI_OVERRIDES:-torchtitan_npu.override.common.rms_norm.asc \ | 31 | +export PYTHONUNBUFFERED=1 |
| 48 | - torchtitan_npu.override.common.rope.asc_complex \ | 32 | +MODULE="${MODULE:-torchtitan_npu_recipes.tests.models.deepseek_v4_1}" |
| 49 | - torchtitan_npu.override.deepseek_v4_1.mhc.asc_hc_post \ | 33 | +if [[ -z "${CONFIG:-}" ]]; then |
| 50 | - ${LIGHTNING_INDEXER_OVERRIDE} \ | 34 | + CONFIG="deepseek_v4_1_mini_1p_cpt_a5" |
| 51 | - torchtitan_npu.override.deepseek_v4_1.sparse_attn.asc}" | 35 | +fi |
| 36 | +NGPU="${NGPU:-1}" | ||
| 37 | +HF_ASSETS_PATH="${HF_ASSETS_PATH:-/path/to/DeepSeekV41_tokenizer}" | ||
| 52 | 38 | ||
| 53 | -SEQ_LEN=2048 | 39 | +MODULE="${MODULE}" \ |
| 54 | -NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK=2048 | 40 | +CONFIG="${CONFIG}" \ |
| 55 | -NUM_TOKENS_PER_TRAIN_STEP=2048 | 41 | +NGPU="${NGPU}" \ |
| 56 | - | 42 | +LOG_PREFIX="${LOG_PREFIX:-${CONFIG}}" \ |
| 57 | -exec bash scripts/run_train.sh \ | 43 | +bash scripts/run_train.sh \ |
| 58 | - --hf-assets-path "${HF_ASSETS_PATH:-tests/assets/deepseek_v3}" \ | 44 | + --hf-assets-path "${HF_ASSETS_PATH}" \ |
| 59 | - --training.num-tokens-per-microbatch-per-dp-rank "${NUM_TOKENS_PER_MICROBATCH_PER_DP_RANK}" \ | ||
| 60 | - --training.num-tokens-per-train-step "${NUM_TOKENS_PER_TRAIN_STEP}" \ | ||
| 61 | - --training.max-context-length "${SEQ_LEN}" \ | ||
| 62 | - --training.steps "${STEPS:-5}" \ | ||
| 63 | - --parallelism.data-parallel-shard-degree 1 \ | ||
| 64 | - --parallelism.data-parallel-replicate-degree 1 \ | ||
| 65 | - --parallelism.expert-parallel-degree 1 \ | ||
| 66 | - --parallelism.tensor-parallel-degree 1 \ | ||
| 67 | - --parallelism.pipeline-parallel-degree 1 \ | ||
| 68 | - --parallelism.context-parallel-degree 1 \ | ||
| 69 | - --compile.no-enable \ | ||
| 70 | - --checkpoint.no-enable \ | ||
| 71 | - --metrics.log-freq 1 \ | ||
| 72 | - --override.imports ${CLI_OVERRIDES} \ | ||
| 73 | - "${QUANTIZATION_ARGS[@]}" \ | ||
| 74 | "$@" | 45 | "$@" |
Rtests/unit_tests/override/test_a3_workaround.py→tests/unit_tests/models/common/test_a3_workaround.py+1-1
Rtests/unit_tests/override/common/test_token_dispatch_ops.py→tests/unit_tests/models/common/test_token_dispatch_ops.py+1-1
Rtests/unit_tests/override/common/test_external_rope.py→tests/unit_tests/overrides/common/test_external_rope.py+2-2
Rtests/unit_tests/override/common/test_moe_score_absorption.py→tests/unit_tests/overrides/common/test_moe_score_absorption.py+2-2
Rtests/unit_tests/override/common/test_optimizer.py→tests/unit_tests/overrides/common/test_optimizer.py+12-10
Rtests/unit_tests/override/common/test_partial_rope.py→tests/unit_tests/overrides/common/test_partial_rope.py+1-1
Rtests/unit_tests/override/common/test_rms_norm_buffer.py→tests/unit_tests/overrides/common/test_rms_norm_buffer.py+1-1
Rtests/unit_tests/override/common/test_rope_compile.py→tests/unit_tests/overrides/common/test_rope_compile.py+1-1
Rtests/unit_tests/override/common/test_swap_optimizer.py→tests/unit_tests/overrides/common/test_swap_optimizer.py+11-11
Rtests/unit_tests/override/common/test_swiglu_group.py→tests/unit_tests/overrides/common/test_swiglu_group.py+12-6
Rtests/unit_tests/override/deepseek_v4/__init__.py→tests/unit_tests/overrides/deepseek_v4/__init__.py+0-0
Rtests/unit_tests/override/deepseek_v4/test_compressor.py→tests/unit_tests/overrides/deepseek_v4/test_compressor.py+9-9
Rtests/unit_tests/override/deepseek_v4/test_lightning_indexer_fused.py→tests/unit_tests/overrides/deepseek_v4/test_lightning_indexer_fused.py+6-6
Rtests/unit_tests/override/deepseek_v4/test_moe_router.py→tests/unit_tests/overrides/deepseek_v4/test_moe_router.py+2-2
Rtests/unit_tests/override/deepseek_v4/test_smla_teacher.py→tests/unit_tests/overrides/deepseek_v4/test_smla_teacher.py+1-1
Rtests/unit_tests/override/deepseek_v4/test_sparse_attn_buffers.py→tests/unit_tests/overrides/deepseek_v4/test_sparse_attn_buffers.py+2-2
Rtests/unit_tests/override/deepseek_v4_1/conftest.py→tests/unit_tests/overrides/deepseek_v4_1/conftest.py+2-5
Rtests/unit_tests/override/deepseek_v4_1/test_asc_metadata_reuse.py→tests/unit_tests/overrides/deepseek_v4_1/test_asc_metadata_reuse.py+7-8
Rtests/unit_tests/override/deepseek_v4_1/test_cp_frames.py→tests/unit_tests/overrides/deepseek_v4_1/test_cp_frames.py+11-10
Rtests/unit_tests/override/deepseek_v4_1/test_engram_ascendc.py→tests/unit_tests/overrides/deepseek_v4_1/test_engram_ascendc.py+5-5
Rtests/unit_tests/override/deepseek_v4_1/test_fused_geometry.py→tests/unit_tests/overrides/deepseek_v4_1/test_fused_geometry.py+4-4
Rtests/unit_tests/override/deepseek_v4_1/test_lightning_indexer_fused.py→tests/unit_tests/overrides/deepseek_v4_1/test_lightning_indexer_fused.py+19-19
Rtests/unit_tests/override/deepseek_v4_1/test_mhc_adapters.py→tests/unit_tests/overrides/deepseek_v4_1/test_mhc_adapters.py+6-6
Rtests/unit_tests/override/deepseek_v4_1/test_smla_teacher.py→tests/unit_tests/overrides/deepseek_v4_1/test_smla_teacher.py+1-1
Rtests/unit_tests/override/deepseek_v4_1/test_sparse_fused_indices.py→tests/unit_tests/overrides/deepseek_v4_1/test_sparse_fused_indices.py+2-2
Rtests/unit_tests/override/qwen3_5/test_gated_delta.py→tests/unit_tests/overrides/qwen3_5/test_gated_delta.py+6-6
Rtests/unit_tests/override/qwen3_5/test_parallelize.py→tests/unit_tests/overrides/qwen3_5/test_parallelize.py+1-1
Rtests/unit_tests/override/qwen3_5/test_varlen_attention.py→tests/unit_tests/overrides/qwen3_5/test_varlen_attention.py+2-2
Rtorchtitan_npu/override/common/swiglu_group/ascendc.py→torchtitan_npu/models/common/swiglu_group.py+0-0
Rtorchtitan_npu/override/common/token_dispatcher.py→torchtitan_npu/models/common/token_dispatcher.py+6-183
Rtorchtitan_npu/override/deepseek_v4/metadata.py→torchtitan_npu/models/deepseek_v4/ascendc_metadata.py+280-2
Rtorchtitan_npu/override/deepseek_v4_1/sparse_attn/ascendc.py→torchtitan_npu/models/deepseek_v4_1/ascendc_metadata.py+200-265
Rtorchtitan_npu/models/qwen3_5/config_registry.py→torchtitan_npu/models/qwen3_5/dataloader.py+39-102
Rtorchtitan_npu/override/common/optimizer.py→torchtitan_npu_recipes/overrides/common/optimizer.py+5-220
Rtorchtitan_npu/override/common/swiglu_group/__init__.py→torchtitan_npu_recipes/overrides/common/swiglu_group/__init__.py+1-1
Rtorchtitan_npu/override/deepseek_v3_2/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v3_2/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v3_2/sparse_attn/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v3_2/sparse_attn/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v3_2/sparse_attn/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v3_2/sparse_attn/ascendc.py+0-0
Rtorchtitan_npu/override/deepseek_v4/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4/compressor/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4/compressor/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4/compressor/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v4/compressor/ascendc.py+0-0
Rtorchtitan_npu/override/deepseek_v4/lightning_indexer/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4/lightning_indexer/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4/lightning_indexer/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v4/lightning_indexer/ascendc.py+5-3
Rtorchtitan_npu/override/deepseek_v4/lightning_indexer/pypto.py→torchtitan_npu_recipes/overrides/deepseek_v4/lightning_indexer/pypto.py+5-3
Rtorchtitan_npu/override/deepseek_v4/lightning_indexer/pypto_pro.py→torchtitan_npu_recipes/overrides/deepseek_v4/lightning_indexer/pypto_pro.py+6-6
Rtorchtitan_npu/override/deepseek_v4/mhc/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4/mhc/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4/mhc/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v4/mhc/ascendc.py+3-1
Rtorchtitan_npu/override/deepseek_v4/mhc/tilelang.py→torchtitan_npu_recipes/overrides/deepseek_v4/mhc/tilelang.py+3-1
Rtorchtitan_npu/override/deepseek_v4/mhc/triton.py→torchtitan_npu_recipes/overrides/deepseek_v4/mhc/triton.py+0-0
Rtorchtitan_npu/override/deepseek_v4/moe_router.py→torchtitan_npu_recipes/overrides/deepseek_v4/moe_router.py+0-0
Rtorchtitan_npu/override/deepseek_v4/sparse_attn/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4/sparse_attn/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4/sparse_attn/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v4/sparse_attn/ascendc.py+9-291
Rtorchtitan_npu/override/deepseek_v4_1/engram/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/engram/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4_1/engram/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/engram/ascendc.py+0-0
Rtorchtitan_npu/override/deepseek_v4_1/engram/compile.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/engram/compile.py+0-0
Rtorchtitan_npu/override/deepseek_v4_1/engram/mxfp8.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/engram/mxfp8.py+0-0
Rtorchtitan_npu/override/deepseek_v4_1/lightning_indexer/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/lightning_indexer/__init__.py+1-1
Rtorchtitan_npu/override/deepseek_v4_1/lightning_indexer/ascendc.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/lightning_indexer/ascendc.py+4-82
Rtorchtitan_npu/override/deepseek_v4_1/mhc.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/mhc.py+0-0
Rtorchtitan_npu/override/deepseek_v4_1/sparse_attn/__init__.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/sparse_attn/__init__.py+0-0
Rtorchtitan_npu/override/deepseek_v4_1/tilelang.py→torchtitan_npu_recipes/overrides/deepseek_v4_1/tilelang.py+0-0
Rtorchtitan_npu/override/qwen3_5/gated_delta.py→torchtitan_npu_recipes/overrides/qwen3_5/gated_delta.py+2-2
Rtorchtitan_npu/override/qwen3_5/varlen_attention.py→torchtitan_npu_recipes/overrides/qwen3_5/varlen_attention.py+1-1


The golden switch defaults to a CPT factory in either branch when
CONFIGis unset. Could any A5 LoRA documentation name the explicit adapter recipe and verify that its first update uses the intended block-FP8 policy for frozen weights and BF16 adapter tensors? The default CPT run covers its own configuration.