Open
[fix] Adapt SDC smoke tests and docs to TorchTitan 0.4.0 compile.model #1482
[fix] Adapt SDC smoke tests and docs to TorchTitan 0.4.0 compile.model #1482
Open
jiangna1111Add on 2 days ago
Total: 4 files changed+21-28
@@ -48,9 +48,7 @@ torchrun --nproc_per_node=8 -m torchtitan_npu.train \
48 --sdc.gradient-enabled \48 --sdc.gradient-enabled \
49 --sdc.with-checksum \49 --sdc.with-checksum \
50 --sdc.hccl-mode 2 \50 --sdc.hccl-mode 2 \
51- --compile.enable \51+ --compile.model.backend inductor
52- --compile.components model \
53- --compile.backend inductor
54```52```
55 53 
56typed SDC 参数说明如下:54typed SDC 参数说明如下:
@@ -86,8 +84,7 @@ pass/custom op 调用 `torch_npu.matmul_checksum`,把 native checksum 调用
86 84 
87compiled SDC 要求:85compiled SDC 要求:
88 86 
89-- `compile.enable=true`,且 `compile.components` 包含 `model`。87+- `compile.model` 已配置,且 `compile.model.backend=inductor`。
90-- `compile.backend=inductor`。
91- `parallelism.pipeline_parallel_degree=1`,不支持流水线并行。88- `parallelism.pipeline_parallel_degree=1`,不支持流水线并行。
92- HCCL 检测在模型构建完成后一次性启用,覆盖此后的 forward、backward 和训练步骤间89- HCCL 检测在模型构建完成后一次性启用,覆盖此后的 forward、backward 和训练步骤间
93 collective,不覆盖 Trainer 构造期间的初始化通信。启用 HCCL SDC 可能带来额外性能损耗。90 collective,不覆盖 Trainer 构造期间的初始化通信。启用 HCCL SDC 可能带来额外性能损耗。
@@ -17,14 +17,13 @@ import torch
17import torch.nn as nn17import torch.nn as nn
18from torchtitan.trainer import Trainer18from torchtitan.trainer import Trainer
xuyujun
xuyujunxuyujun2 days ago

用户指南里的接入示例在 0.4.0 上跑不起来。这里用 Trainer.Config() 再给 compile 赋值,实际会先报少了必填的 model;就算绕过构造,上游配置也没有 compile 字段,赋值还是会报错。这是改之前就有的问题,不过这个 PR 正好改了这几行(含 L25–26)。建议像 smoke 和 CPU 单测那样,用 SimpleNamespace 构造这份配置。

likedislike
19 19 
20+from torchtitan_npu.config.configs import CompileConfig, ModelCompileConfig
20from torchtitan_npu.extensions.components.sdc import SDC21from torchtitan_npu.extensions.components.sdc import SDC
21 22 
22# 1. 配置 compiled SDC 的训练约束。23# 1. 配置 compiled SDC 的训练约束。
23# trainer_config 用于校验当前训练配置满足 compiled SDC 的约束。24# trainer_config 用于校验当前训练配置满足 compiled SDC 的约束。
24trainer_config = Trainer.Config()25trainer_config = Trainer.Config()
25-trainer_config.compile.enable = True26+trainer_config.compile = CompileConfig(model=ModelCompileConfig(backend="inductor"))
26-trainer_config.compile.components = ["model"]
27-trainer_config.compile.backend = "inductor"
28trainer_config.parallelism.pipeline_parallel_degree = 127trainer_config.parallelism.pipeline_parallel_degree = 1
29 28 
30sdc_config = SDC.Config(29sdc_config = SDC.Config(
@@ -13,16 +13,7 @@ from packaging.version import InvalidVersion, Version
13 13 
14_CPP17_TRITON_RELEASES = frozenset({"3.2.1", "3.2.2", "3.2.2.post2", "3.6.0", "3.6.0.post2"})14_CPP17_TRITON_RELEASES = frozenset({"3.2.1", "3.2.2", "3.2.2.post2", "3.6.0", "3.6.0.post2"})
15_SMOKE_ROOT = Path(__file__).resolve().parent15_SMOKE_ROOT = Path(__file__).resolve().parent
16-_DEFERRED_SMOKE_TESTS = frozenset(16+_DEFERRED_SMOKE_TESTS: frozenset[str] = frozenset()
17- {
18- "sdc/test_sdc_smoke.py::test_compiled_controls_are_typed_without_installing_the_eager_wrapper",
19- "sdc/test_sdc_smoke.py::test_invalid_compiled_sdc_business_config_is_rejected",
20- "sdc/test_sdc_smoke.py::test_compiled_gradient_checks_real_bf16_gradients",
21- "sdc/test_sdc_smoke.py::test_compiled_hccl_covers_forward_and_backward_collectives",
22- "sdc/test_sdc_smoke.py::test_three_gradient_strikes_activate_checksum_without_recompiling",
23- "sdc/test_sdc_smoke.py::test_fp32_checksum_preserves_compiled_results_and_detects_output_faults",
24- }
25-)
26 17 
27 18 
28def _triton_launcher_skip_reason():19def _triton_launcher_skip_reason():
@@ -25,6 +25,7 @@ logger = logging.getLogger(__name__)
25 25 
26_THIS_FILE = Path(__file__).resolve()26_THIS_FILE = Path(__file__).resolve()
27_NO_NPU_EXIT_CODE = 7727_NO_NPU_EXIT_CODE = 77
28+_FP32_BRANCH_PREFIX = "FP32 native checksum branch:"
28_CONTROL_ENVIRONMENT = (29_CONTROL_ENVIRONMENT = (
29 "NPU_ASD_CONFIG",30 "NPU_ASD_CONFIG",
30 "NPU_ASD_ENABLE",31 "NPU_ASD_ENABLE",
@@ -97,8 +98,16 @@ def _run_worker(scenario: str) -> None:
97 f"isolated SDC worker failed for {scenario!r}\nstdout:\n{completed.stdout}\nstderr:\n{completed.stderr}"98 f"isolated SDC worker failed for {scenario!r}\nstdout:\n{completed.stdout}\nstderr:\n{completed.stderr}"
98 )99 )
99 if scenario == "fp32-checksum-results":100 if scenario == "fp32-checksum-results":
100- branches = [line for line in completed.stdout.splitlines() if line.startswith("FP32 native checksum branch:")]101+ # Distributed/runtime logs may prepend rank prefixes or partial lines before the marker.
101- assert len(branches) == 1, "The FP32 worker must report its actual native checksum branch"102+ branches = []
103+ for line in completed.stdout.splitlines():
104+ _, marker, suffix = line.partition(_FP32_BRANCH_PREFIX)
105+ if marker:
106+ branches.append(f"{marker}{suffix}".strip())
107+ assert len(branches) == 1, (
108+ "The FP32 worker must report its actual native checksum branch\n"
109+ f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}"
110+ )
102 print(branches[0])111 print(branches[0])
103 112 
104 113 
@@ -161,14 +170,11 @@ def _set_scenario_environment(scenario: str) -> None:
161 170 
162 171 
163def _config(*, compiled: bool = True) -> SimpleNamespace:172def _config(*, compiled: bool = True) -> SimpleNamespace:
173+ from torchtitan_npu.config.configs import CompileConfig, ModelCompileConfig
174+ 
164 return SimpleNamespace(175 return SimpleNamespace(
165- compile=SimpleNamespace(176+ compile=CompileConfig(model=ModelCompileConfig(backend="inductor") if compiled else None),
166- enable=compiled,
167- components=("model",) if compiled else (),
168- backend="inductor",
169- ),
170 parallelism=SimpleNamespace(pipeline_parallel_degree=1),177 parallelism=SimpleNamespace(pipeline_parallel_degree=1),
171- model_spec=SimpleNamespace(model=SimpleNamespace(enable_weight_tying=False)),
172 )178 )
173 179 
174 180 
@@ -262,7 +268,7 @@ def _check_invalid_config() -> None:
262 gradient_accumulation_steps=1,268 gradient_accumulation_steps=1,
263 )269 )
264 except (RuntimeError, ValueError) as error:270 except (RuntimeError, ValueError) as error:
265- assert "compile.enable" in str(error)271+ assert "compile.model" in str(error)
266 return272 return
267 raise AssertionError("SDC accepted a configuration without a compiled model")273 raise AssertionError("SDC accepted a configuration without a compiled model")
268 274 
@@ -425,7 +431,7 @@ def _check_fp32_checksum_results(torch: Any, torch_npu: Any) -> None:
425 checksum_module = sys.modules[original_checksum.__module__]431 checksum_module = sys.modules[original_checksum.__module__]
426 abft_available = _get_private_runtime_interface(checksum_module, "_abft_available_cache")432 abft_available = _get_private_runtime_interface(checksum_module, "_abft_available_cache")
427 assert type(abft_available) is bool, "The native checksum branch must have been probed"433 assert type(abft_available) is bool, "The native checksum branch must have been probed"
428- print(f"FP32 native checksum branch: {'V-ABFT' if abft_available else 'Python fallback'}")434+ print(f"\n{_FP32_BRANCH_PREFIX} {'V-ABFT' if abft_available else 'Python fallback'}", flush=True)
429 if abft_available is False:435 if abft_available is False:
430 torch.testing.assert_close(corrupted.cpu().double(), expected, rtol=0, atol=1e-5)436 torch.testing.assert_close(corrupted.cpu().double(), expected, rtol=0, atol=1e-5)
431 torch.ops.torchtitan_npu.sdc_matmul_checksum.default(left, right, expected.to(device=device, dtype=torch.float32))437 torch.ops.torchtitan_npu.sdc_matmul_checksum.default(left, right, expected.to(device=device, dtype=torch.float32))