Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192208
Note: Links to docs will display an error until the docs builds have been completed.
|
|
|
5629bd6 to
e0a07eb
Compare
e0a07eb to
f9491a2
Compare
|
@pytorchbot label "module: tests/distributed" |
f9491a2 to
7b01c96
Compare
| instantiate_device_type_tests( | ||
| TestTPFSDPIntegration, | ||
| globals(), | ||
| except_for="cpu", |
There was a problem hiding this comment.
The original device_type in this file is defined as:
device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu"
which means current test class could work on cpu device. So please confirm again whether we should exclude cpu here.
There was a problem hiding this comment.
device_type in current test class mainly used in init_device_mesh, and device mesh supprots cpu device.
|
|
||
| @property | ||
| def world_size(self) -> int: | ||
| return min(4, _get_device_module(self.device_type).device_count()) |
There was a problem hiding this comment.
In original logic, world_size whose value is DEVICE_COUNT is defined as min(4, max(2, torch.cuda.device_count())) only for ROCM device. So please check whether is right to always return min(4, _get_device_module(self.device_type).device_count()).
|
Thanks for the review! Pushed 1. Got it — looked back at the original implementation and the clamp is now dropped. The 2. Removed. The CPU variant is now generated (not excluded) and skipped at runtime by |
5d95581 to
73751a9
Compare
| @@ -477,7 +532,12 @@ def assert_local_shard_across_ranks(local_tensor, group, check_equal=True): | |||
| assert_local_shard_across_ranks(local_buf, dp_group, check_equal=True) | |||
|
|
|||
|
|
|||
| instantiate_parametrized_tests(TestTPFSDPIntegration) | |||
| instantiate_device_type_tests( | |||
There was a problem hiding this comment.
The test method has annotation of requires_world_size, we need except cpu in instantiate_device_type_tests.
There was a problem hiding this comment.
Done — added except_for="cpu" in commit 087146a, consistent with the other migrated files in this series. The CPU variants are no longer instantiated.
|
Thanks for the review! Replying to each point below. 1.
|
|
@claude review this pr with pr review skill |
|
Claude finished @can-gaa-hou's task in 23m 38s —— View job Reviewed with the Full PR review — #192208PR Review: #192208SummaryMigrates Infrastructure1. except ValueError:
return DISTRIBUTED_BACKEND
This is not a clean skip: the return value flows to 2. The file cannot import on current
Compounding it: Separately, Code Quality3.
cls.device_type = torch._C._get_privateuse1_backend_name()
If that holds, the helper and its six call sites are pure indirection and 4. @property
def world_size(self) -> int:
return _get_device_module(self.device_type).device_count()Given #3 this is currently fine, but it is the one place that would break loudly ( 5. The injected The prior discussion settled on keeping the parameter for signature uniformity, which is fine. But the body then re-derives what the framework already computed; 6. Base-class docstring — lines 92-102 Eleven lines of docstring for a three-member class, and it hard-codes Note that this class also stays in TestingNo new coverage is expected for a refactor, and the three test bodies are behavior-preserving. The gap is verification rather than test count: with RecommendationRequest Changes Finding 1 is a real correctness defect and should be fixed regardless of landing order. Finding 2 is a sequencing constraint: merging before #192694 converts three CUDA-only tests into three tests that skip everywhere except CUDA, which is a net coverage loss versus |
…ice resolution Addresses the /pr-review feedback on pytorch#192208: 1. `backend_str()` no longer falls back to the module-level `DISTRIBUTED_BACKEND` constant from `common_fsdp`. That constant is computed at import time from the host's TEST_CUDA/TEST_HPU/TEST_XPU flags, so on a mixed host it can return e.g. "nccl" for an HPU variant. Instead, a `ValueError` from `get_default_backend_for_device()` now raises a `unittest.SkipTest` naming the device, so a variant with no registered default collective backend is skipped rather than run on the wrong transport. 2. Drop `_resolved_device_type()` and its six call sites. Verified on Ascend NPU that `PrivateUse1TestBase.setUpClass` already resolves `device_type` from "privateuse1" to the backend name (e.g. "npu") before any test body runs, so the `privateuse1` branch was dead code. Call sites now read `self.device_type` directly. 3. Trim the base-class docstring and remove the cross-PR `pytorch#192051` reference. 4. Add missing `import unittest`.
|
Thanks for the thorough review @can-gaa-hou — all feedback is now addressed in commit Finding 1 — @classmethod
def backend_str(cls) -> str:
try:
return dist.get_default_backend_for_device(cls.device_type)
except ValueError as e:
raise unittest.SkipTest(
f"no default distributed backend registered for device {cls.device_type}: {e}"
) from eA Finding 2 — dependency ordering: acknowledged. The PR body already documents that Finding 3 — Finding 4 — Finding 5 — discarded Finding 6 — base-class docstring: trimmed from eleven lines to the one non-local fact (why the intermediate base holds Verification: on a PrivateUse1 accelerator host, |
…ice resolution Addresses the /pr-review feedback on pytorch#192208: 1. `backend_str()` no longer falls back to the module-level `DISTRIBUTED_BACKEND` constant from `common_fsdp`. That constant is computed at import time from the host's TEST_CUDA/TEST_HPU/TEST_XPU flags, so on a mixed host it can return e.g. "nccl" for an HPU variant. Instead, a `ValueError` from `get_default_backend_for_device()` now raises a `unittest.SkipTest` naming the device, so a variant with no registered default collective backend is skipped rather than run on the wrong transport. 2. Drop `_resolved_device_type()` and its six call sites. Verified on Ascend NPU that `PrivateUse1TestBase.setUpClass` already resolves `device_type` from "privateuse1" to the backend name (e.g. "npu") before any test body runs, so the `privateuse1` branch was dead code. Call sites now read `self.device_type` directly. 3. Trim the base-class docstring and remove the cross-PR `pytorch#192051` reference. 4. Add missing `import unittest`.
cc5306e to
54b6c46
Compare
|
Update on commit Rationale: Finding 3 confirmed the privateuse1 branch is dead code on any host where
The |
…agnostic (#192694) `requires_world_size` is the world-size gate that capability-gated FSDP test migrations (e.g. #192208 and the `test_fsdp_*` series) are migrating **to** from `skip_if_lt_x_gpu`. It hardcodes `torch.cuda.device_count()`, so on any non-CUDA accelerator (XPU/HPU/PrivateUse1) every `@requires_world_size(n)` test is skipped even when devices are present. Generalizes the skip to `torch.accelerator.current_accelerator(check_available=True)` + `torch.get_device_module(acc.type).device_count()`, mirroring `skip_if_lt_x_gpu`'s generalization in #187650. Without this, #187650 alone does not unblock the migrated tests because they call `requires_world_size`, not `skip_if_lt_x_gpu`; #187650 generalized the old function while the migrations target the new one. Sibling to #187650. Independent of the capability foundation PRs #190846/#191919/#192043 (this changes `common_distributed.requires_world_size`, they change `common_device_type.py`). ## Test plan Validated on Ascend 910B (PrivateUse1, `torch.accelerator.device_count()=4`): `@requires_world_size(2)` tests run instead of being skipped ("requires 2 accelerators, found 4"); the 6 capability-gated `test_fsdp_*` files pass on 4-card NPU (56 tests, 0 failures). Container-side shims of the foundation PRs (#190846/#191919) were applied only to provide the Capability/requires_capabilities imports (not yet on main); this change is independent of those. Pull Request resolved: #192694 Approved by: https://github.com/wjlFlyer, https://github.com/fffrog
66d3dce to
6336a8b
Compare
|
@weifengpy @fduwjj It’s been a few days since this PR was opened. Could you please take a look when you have time? |
| return dt | ||
|
|
||
| @classmethod | ||
| def backend_str(cls) -> str: |
There was a problem hiding this comment.
I’d like this override to accept the device argument that the current test harness passes when it starts the workers.
AI-assisted review. I tested the clean merge of
afc9d37aedwith main ataccceec6ad. The shared fixture callscls.backend_str(device), but this override takes onlycls. All three FSDP/TP tests raisedTypeErrorbefore spawning a worker in a controlled four-device setup. The PR head with its original fixture and main on its own both reached the spawn request. Could the override acceptdeviceand use it when choosing the backend?
There was a problem hiding this comment.
Thanks for catching the harness signature mismatch. backend_str now accepts the device argument supplied by the harness and uses it when selecting the default backend.
…agnostic collection Rebuild the change on top of current main, which added the cached _get_dp_tp_mesh helper to this file, and drop the capability-gate reference that is not on main yet. Keeps: the device-agnostic base, the accelerator-aware world_size / backend_str, the HardwareClassification.ACCELERATOR tag, and instantiate_device_type_tests (except_for="cpu") so non-CUDA accelerator variants are generated.
…ration - Move hw_classification onto the class that defines the test methods; the linter only reads that class body, so the copy on the intermediate base was invisible (TEST_LINTER [hw_classification]). - Derive the device type from the collected `device` parameter so the tests use the device they are handed (ACCELERATOR rule). - Drop the file from test_linter_allowlist.json, as REVIEW.md Rule 7 asks.
_get_dp_tp_mesh now takes the device type instead of reading it off the class, so every test that builds the mesh exercises the device it is handed. The mesh is still built once and cached, preserving the /dev/shm budget fix from pytorch#200632. The cached mesh keeps this honest only because all variants of this class target one device type per run; the type assertion is implicit in the call.
``MultiProcessTestCase.backend_str`` takes ``device`` and the fixtures call it as ``cls.backend_str(device_type)``. The override here declared only ``cls``, so every device variant raised ``TypeError`` before the workers were spawned. Accept the argument and use it to pick the backend.
Resolve backend and rank devices from the instantiated variant rather than using the host-default accelerator. Use the injected device for FSDP initialization and model construction. Test Plan: ``` lintrunner -a --take TEST_LINTER,RUFF,PYFMT,FLAKE8,NEWLINE,TABS,SPACES <target> tools/linter/adapters/test_linter_allowlist.json ``` A5x NPU tests passed for this PR (torch 2.16 + torch_npu 2.16, with main's backend_str(device) fixture contract). Authored with the assistance of an AI assistant (Claude Code).
2e36292 to
bf31750
Compare
DeviceTypeTestBase already resolves PrivateUse1 for instantiated variants. Keep the variant-specific backend and rank initialization, and remove stale base-class documentation. Test Plan: lintrunner -a --take TEST_LINTER,RUFF,PYFMT,FLAKE8,NEWLINE,TABS,SPACES test/distributed/fsdp/test_fsdp_tp_integration.py tools/linter/adapters/test_linter_allowlist.json A5x torch 2.16 + torch_npu 2.16 compatibility run of the NPU variant. Authored with the assistance of an AI assistant (Claude Code).
Summary
Migrate
TestTPFSDPIntegrationto the device-agnostic pattern from the testcase-refactoring initiative (#185590), so it runs on out-of-tree PrivateUse1 backends without patchingcommon_fsdpmodule globals.Changes
TPFSDPIntegrationTestBase(FSDPTestContinuous)holding_resolved_device_type()(resolves the genericprivateuse1token to the registered backend name),backend_str(viadist.get_default_backend_for_device, resolving each device to its registered default backend without hardcoding), and an accelerator-awareworld_sizeproperty. Follows the existing intermediate-base pattern used elsewhere in the testcase-refactoring series.hw_classification = HardwareClassification.ACCELERATOR— all three methods exercise multi-device FSDP x TP collectives on an accelerator.@skip_if_lt_x_gpu(4)with@requires_world_size(4).device_typeglobal; its 6 call sites useself._resolved_device_type(). The nestedTestModelcaptures the resolved device via closure (itsselfis thenn.Module, not the test instance).instantiate_parametrized_testsforinstantiate_device_type_tests(except_for="cpu", allow_xpu=True)so the framework generates per-device variants for every accelerator (cuda/hpu/xpu/privateuse1) and auto-discovers registered PrivateUse1 backends.Motivation
skip_if_lt_x_gpuandcommon_fsdp'sDEVICE_TYPE/DEVICE_COUNT/DISTRIBUTED_BACKENDglobals only recognize cuda/hpu/xpu, so on any other accelerator backend these tests were silently skipped (or required hacking the framework globals to run).instantiate_device_type_tests+_resolved_device_typemake the test device-agnostic so out-of-tree PrivateUse1 backends are picked up automatically.Capability gating
The
@requires_capabilities(...)gates are deliberately not part of this revision. Thecapability-gate mechanism is still being settled upstream, and referencing its namespace here
would make this file fail to import on
main. The change is otherwise complete: thedevice-agnostic base, the accelerator-aware
world_size/backend_str, theexcept_for="cpu"instantiation, and theHardwareClassification.ACCELERATORtag are all inplace. Once the mechanism lands, the gates can be
added as a small follow-up on top of this file (one decorator per test, no other edit), so
nothing here needs to be reverted for that.
Test Plan
Device-agnostic collection verified on 2x Ascend 910B4 (torch 2.15.0.dev, torch_npu same build):
instantiate_device_type_tests(..., except_for="cpu")generatesTestTPFSDPIntegrationPRIVATEUSE1and all three methods are discovered and executed, instead of the pre-change behaviour where
instantiate_parametrized_testsproduced no accelerator variant at all.Note on the host used: its installed
torchbuild predates therequires_world_sizehardware-agnostic generalization now on
main, so that decorator still readtorch.cuda.device_count()(0 on this host) and skipped the tests. Restoring the currentmainsemantics for that one line was enough for the tests to be discovered and executed.
Related
Part of #185590.
Authored with the assistance of an AI assistant (Claude Code).