Repository navigation
[Testcase Refactoring][FSDP] Run backend-independent GradScaler tests - #191178
danieldale2026 wants to merge 5 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/191178
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "module: tests/distributed" |
…device capability Builds on pytorch#190846 (now in main) to add: - distributed.backend/dtensor/fsdp, memory.non_blocking_copy, stream.generic, lib.safetensors capability namespaces with _check_capabilities preflight in DeviceTypeTestBase.setUp (cooperative super() for MultiProcessTestCase) - dtype.fp64: CPU/CUDA=True, XPU=dynamic via has_fp64, HPU=False - HPU distributed backend+fsdp declarations (nested setdefault to preserve inherited capabilities) so HPU reaches FP64 unsupported skip instead of missing-capability assertion - OpenReg capability regression: supported executes, unsupported SkipTest, missing AssertionError; CPU/CUDA/HPU FP64 declarations and XPU dynamic Test Plan: - py_compile, FLAKE8, RUFF, git diff --check pass - OpenReg: 21 passed, 6 skipped, 2 xfailed (capability three-state verified) - NPU (69231fe + v2 overlay): 23 distributed test files, 18 PASS / 1 FAIL (CANN version) / 2 PARTIAL (NPU FP64 + torchdistX) / 2 SKIP
6e691d5 to
8b6783c
Compare
Temporary dependency equivalent to pytorch#187650 for this provisional consumer topic.
This commit was authored with AI assistance and reviewed by the contributor. Test Plan: ``` PYTHONPYCACHEPREFIX=/tmp/pr-split-23-pycache /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/python -m py_compile test/distributed/fsdp/test_fsdp_sharded_grad_scaler.py uvx --python 3.10 [email protected] -a --skip PYREFLY test/distributed/fsdp/test_fsdp_sharded_grad_scaler.py git diff --cached --check ```
8b6783c to
15fcbef
Compare
| pg = DummyProcessGroup(0, 1) | ||
| scaler = ShardedGradScaler( | ||
| device=device_type, init_scale=2.0, process_group=pg, enabled=True | ||
| device="cpu", init_scale=2.0, process_group=pg, enabled=True |
There was a problem hiding this comment.
I reviewed and verified the current implementation. This response was prepared with Codex assistance.
device="cpu"is intentional. These three tests use only CPU tensors andDummyProcessGroup, so keeping the scaler on CPU makes them genuinely backend-independent and avoids reintroducing accelerator coupling.
There was a problem hiding this comment.
I rechecked the implementation and data flow at the current head and take responsibility for the statements below, which were prepared with agent assistance. The quoted reply is relevant because it directly answers whether pinning the scaler to CPU is intentional.
device="cpu"is intentional here.TestShardGradScaleris a GENERIC single-process test usingDummyProcessGroup; all tensors, gradients, optimizer parameters, and losses are on CPU.ShardedGradScaleralso uses its configured device when synchronizing CPUfound_inftensors, so using the ambient accelerator type would reintroduce an unnecessary accelerator dependency. Keeping the scaler on CPU is therefore consistent with the behavior this class tests.
| instantiate_device_type_tests( | ||
| TestShardedGradScalerParityWithDDP, | ||
| globals(), | ||
| only_for=("cuda", "xpu", "privateuse1"), |
There was a problem hiding this comment.
We could only use except_for, not only_for when current class is tagged accelerator.
There was a problem hiding this comment.
I reviewed and verified the current implementation. This response was prepared with Codex assistance.
Updated the accelerator test instantiation to use
except_for=("cpu", "hpu")while retainingallow_xpu=True. This keeps the requested HPU exclusion and allows supported accelerator and PrivateUse1 implementations to participate through the device-type harness.
Keep the explicit HPU exclusion while allowing supported accelerator and PrivateUse1 test bases through except_for. The CPU-only scaler tests remain fixed to CPU. Test Plan: ``` PYTHONPYCACHEPREFIX=/tmp/pr191178-review-fix-20260904-pycache /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/python test/distributed/fsdp/test_fsdp_sharded_grad_scaler.py TestShardGradScaler -v PYTHONPYCACHEPREFIX=/tmp/pr191178-review-fix-20260904-pycache /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/python test/distributed/fsdp/test_fsdp_sharded_grad_scaler.py TestShardedGradScalerParityWithDDPCUDA -v python3 -m py_compile test/distributed/fsdp/test_fsdp_sharded_grad_scaler.py git diff --check /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/spin fixlint ``` The CPU tests passed 3/3. The CUDA parity collection ran 17 tests, all skipped because this host has one GPU. spin fixlint was attempted but could not bootstrap because uvx is unavailable. Authored with Codex assistance and reviewed by the contributor.
| instantiate_device_type_tests( | ||
| TestShardedGradScalerParityWithDDP, | ||
| globals(), | ||
| except_for=("cpu", "hpu"), |
There was a problem hiding this comment.
why exclude hpu here? I didn't find related logic in original code.
There was a problem hiding this comment.
I rechecked the pre-change implementation and the current head and take responsibility for the statements below, which were prepared with agent assistance. The quoted reply is relevant because it directly answers why HPU should not be excluded and which runtime remains unvalidated.
You're right. I found no source-based reason to exclude HPU: the original parity tests admitted HPU through the explicit
TEST_HPUbranch inskip_if_lt_x_gpuand theDEVICE_TYPE="hpu:0"/DISTRIBUTED_BACKEND="hccl"path incommon_fsdp.py. The exclusion was carried over when the earlieronly_forwhitelist was converted toexcept_for; it did not preserve the original admission behavior.I changed the instantiation to
except_for=("cpu",)while retainingallow_xpu=True, and the fix is pushed at the current head. HPU execution is still gated by its distributed backend/FSDP capabilities and the two-device requirement. I do not have HPU runtime validation, so this conclusion is based on source and admission-path reconciliation rather than an HPU runtime pass.
The original FSDP parity tests admit HPU through the existing backend/FSDP capabilities and multi-device gate. Remove the consumer-level HPU exclusion while retaining CPU exclusion and allow_xpu=True. HPU runtime was not available locally; validation used source-consistent CPU tests and static admission checks.
I reviewed the code at the current head, the review threads, and the validation evidence, and take responsibility for this submission and the statements in the quoted body. The quoted body was prepared with agent assistance; it is relevant because it summarizes the exact current-head change and its validation so reviewers can verify both directly. The title is unchanged.