Open
fix: 修复 loss_compare 的 TorchAO-NPU worktree 源码加载 #1228
1Fire4Add on 26 days ago
fix: 修复 loss_compare 的 TorchAO-NPU worktree 源码加载 #1228
Open
Total: 2 files changed+24-5
| @@ -494,7 +494,13 @@ def training_env( | |||
| 494 | env.update(extra_env) | 494 | env.update(extra_env) |
| 495 | if ngpus is not None: | 495 | if ngpus is not None: |
| 496 | env["NGPU"] = str(ngpus) | 496 | env["NGPU"] = str(ngpus) |
| 497 | - roots = [str(root.resolve()) for root in (repo_root, upstream) if root is not None] | 497 | + source_roots = [repo_root] |
| 498 | + if repo_root is not None: | ||
| 499 | + torchao_npu_root = repo_root / "experiments" / "torchao-npu" | ||
| 500 | + if (torchao_npu_root / "torchao_npu").is_dir(): | ||
| 501 | + source_roots.append(torchao_npu_root) | ||
| 502 | + source_roots.append(upstream) | ||
| 503 | + roots = [str(root.resolve()) for root in source_roots if root is not None] | ||
| 498 | if roots: | 504 | if roots: |
| 499 | env["PYTHONPATH"] = os.pathsep.join(filter(None, (*roots, env.get("PYTHONPATH", "")))) | 505 | env["PYTHONPATH"] = os.pathsep.join(filter(None, (*roots, env.get("PYTHONPATH", "")))) |
| 500 | if config_api == "native": | 506 | if config_api == "native": |
| @@ -23,8 +23,11 @@ CLI = Path(loss_compare.__file__).resolve() | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | def test_loss_compare_supports_independent_sequence_apis_and_upstreams(tmp_path): | 25 | def test_loss_compare_supports_independent_sequence_apis_and_upstreams(tmp_path): |
| 26 | - (tmp_path / "torchtitan").mkdir() | 26 | + upstream_root = tmp_path / "upstream" |
| 27 | - (tmp_path / "torchtitan" / "__init__.py").touch() | 27 | + (upstream_root / "torchtitan").mkdir(parents=True) |
| 28 | + (upstream_root / "torchtitan" / "__init__.py").touch() | ||
| 29 | + torchao_npu_root = tmp_path / "experiments" / "torchao-npu" / "torchao_npu" | ||
| 30 | + torchao_npu_root.mkdir(parents=True) | ||
| 28 | common = dict(steps=100, options="", seed_checkpoint=None, seq_len=512) | 31 | common = dict(steps=100, options="", seed_checkpoint=None, seq_len=512) |
| 29 | old = loss_compare.build_training_command(tmp_path / "run.sh", tmp_path / "old", training_api="legacy", **common) | 32 | old = loss_compare.build_training_command(tmp_path / "run.sh", tmp_path / "old", training_api="legacy", **common) |
| 30 | new = loss_compare.build_training_command(tmp_path / "run.sh", tmp_path / "new", **common) | 33 | new = loss_compare.build_training_command(tmp_path / "run.sh", tmp_path / "new", **common) |
| @@ -32,8 +35,18 @@ def test_loss_compare_supports_independent_sequence_apis_and_upstreams(tmp_path) | |||
| 32 | assert "--training.seq-len=512" in old | 35 | assert "--training.seq-len=512" in old |
| 33 | assert "--training.max-context-length=512" in new | 36 | assert "--training.max-context-length=512" in new |
| 34 | assert not any(arg.startswith("--training.seq-len") for arg in new) | 37 | assert not any(arg.startswith("--training.seq-len") for arg in new) |
| 35 | - env = loss_compare.training_env(2, {"PYTHONPATH": "/independent/npu"}, upstream=tmp_path) | 38 | + env = loss_compare.training_env( |
| 36 | - assert env["PYTHONPATH"].split(os.pathsep) == [str(tmp_path.resolve()), "/independent/npu"] | 39 | + 2, |
| 40 | + {"PYTHONPATH": "/independent/npu"}, | ||
| 41 | + upstream=upstream_root, | ||
| 42 | + repo_root=tmp_path, | ||
| 43 | + ) | ||
| 44 | + assert env["PYTHONPATH"].split(os.pathsep) == [ | ||
| 45 | + str(tmp_path.resolve()), | ||
| 46 | + str(torchao_npu_root.parent.resolve()), | ||
| 47 | + str(upstream_root.resolve()), | ||
| 48 | + "/independent/npu", | ||
| 49 | + ] | ||
| 37 | 50 | ||
| 38 | 51 | ||
| 39 | def test_loss_compare_bitwise_rejects_signed_zero(): | 52 | def test_loss_compare_bitwise_rejects_signed_zero(): |