Skip to content

[xpu][test] Port distributed _shard tests cases on Intel GPUs - #195952

Closed
madhumitha0102 wants to merge 30 commits into
pytorch:mainfrom
madhumitha0102:feature_checkpoint_pp
Closed

madhumitha0102 wants to merge 30 commits into
pytorch:mainfrom
madhumitha0102:feature_checkpoint_pp

Conversation

@madhumitha0102

Copy link
Copy Markdown
Contributor

For #114850, we will port distributed tests to Intel GPU.
We will enable Intel GPU with following methods and keep the original code styles:

Example: "torch.accelerator.current_accelerator()" to determine the accelerator backend

enabled XPU for the following files:

  1. test/distributed/checkpoint/_experimental/test_staging.py
  2. test/distributed/checkpoint/e2e/test_e2e_save_and_load.py
  3. test/distributed/checkpoint/test_file_system_checkpoint_cpu.py
  4. test/distributed/checkpoint/test_state_dict_stager.py
  5. test/distributed/checkpoint/test_state_dict_utils.py
  6. test/distributed/flight_recorder/test_fr_analysis.py
  7. test/distributed/optim/test_zero_redundancy_optimizer.py
  8. test/distributed/pipelining/test_backward.py
  9. test/distributed/pipelining/test_microbatch.py
  10. test/distributed/pipelining/test_schedule_multiproc.py

cc @gujinghui @EikanWang @fengyuan14 @guangyey

@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

This PR makes the distributed checkpoint, pipelining and flight-recorder tests
device-generic so they run on XPU. Every inline request from maintainer etaf is
now reflected in the code: DeterministicGuard replaces the looser tolerances,
the unrelated files were dropped, and hw_classification and the continuous base
class are back. What remains is minor robustness: a cpu branch that never runs,
an import-time backend lookup, and a `cpu:N` device string.

Findings (3):

[minor] test/distributed/checkpoint/test_state_dict_stager.py:966
etaf said this cpu branch isn't needed. The author replied that without it the
string becomes a duplicate cpu:gloo, but the class is skipped when there are
fewer than 4 accelerators (line 955), so device_type=='cpu' never reaches here.
Drop the branch or link the CI failure it fixes.

[minor] test/distributed/flight_recorder/test_fr_analysis.py:21
get_default_backend_for_device runs at import time. On builds without
distributed it raises AttributeError, and on accelerators with no registered
default (hpu, privateuse1) it raises ValueError. Either way the whole module
fails to import, including tests that don't need the backend; fall back to a
literal backend name.

[minor] test/distributed/checkpoint/test_file_system_checkpoint_cpu.py:432
On CPU-only machines rank 1 builds the device 'cpu:1', which trips a debug-only
assertion in c10::Device. The .to(device) call also does nothing, because
MyShardedModel3 has no params or buffers, so it can simply be removed.

Reviewed commit: a152458 (NOT the current head b0a833e)

Review run

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195952

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (5 Unrelated Failures)

As of commit b0a833e with merge base 2bc3d41 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@madhumitha0102 madhumitha0102 changed the title Feature checkpoint pp [xpu][test] Port distributed _shard tests cases on Intel GPUs Sep 3, 2026
@daisyden

daisyden commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

@newtdms could you please help review this test port / refactor PR? Thanks!

@etaf etaf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the CI failure first.

Comment thread torch/testing/_internal/common_utils.py Resolved
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Sep 30, 2026
@daisyden
daisyden requested a review from jansel September 30, 2026 02:12
@madhumitha0102
madhumitha0102 marked this pull request as ready for review September 30, 2026 02:44
@madhumitha0102
madhumitha0102 requested a review from etaf September 30, 2026 04:34
@albanD albanD added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module and removed ci-no-td Do not run TD on this PR labels Sep 30, 2026
@albanD
albanD requested a review from guangyey September 30, 2026 14:33
@jansel jansel added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 8, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of dbcf39b: changes requested before human review.

Test-only PR that makes distributed checkpoint, flight recorder and pipelining tests device-agnostic for XPU. The pipelining DeterministicGuard changes and the stager backend change look sound. However, TestNoCPU now fails instead of skipping on hosts that have the CUDA/XPU dist backend compiled in but fewer accelerators than world_size, because the new decorator only checks that the backend is available, not how many devices there are.

🔴 1 blocking finding is attached to the code below.

⚪ 2 non-blocking findings

backend = torch.distributed.get_default_backend_for_device(device_type)

This module-level get_default_backend_for_device() call makes a pure-data test depend on the host machine. It raises at import (ValueError) on accelerators with no registered default backend (MTIA, privateuse1, HPU without the plugin), and with AttributeError on USE_DISTRIBUTED=0 builds, so every test in the file fails to collect. It adds no coverage, since FlightRecorderOpBackendTest already covers per-backend parsing. Keep a fixed backend constant instead.


@unittest.skipIf(TEST_XPU, "XPU does not support pin_memory from cudart")

Only the share_memory=True + pin_memory=True case uses the cudart pin path (torch.cuda._pin_memory_utils), but this skip drops the whole test on XPU, including the default, pin-only and share-only cases. Guard just that sub-case. If the whole test stays excluded, use expectedFailure rather than skipIf, since the failure is deterministic.

Please address the findings and push; a new commit normally gets a fresh automated review.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

return dist.get_default_backend_for_device(self.device_type)

@with_comms
@requires_accelerator_dist_backend()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Regression: before, backend was hardcoded to 'nccl', so init_pg skipped the test (multi-device-N) when there were too few GPUs. Now backend comes from self.device_type, which _get_device_type sets to 'cpu' when DEVICE_COUNT < world_size, so backend becomes gloo. @ requires_accelerator_dist_backend() only checks that NCCL/XCCL is compiled in. On a CUDA build with 0 or 1 GPUs, the test therefore runs on gloo, async_save does not raise, and assertRaisesRegex fails. Fix: skip on device count (e.g. @ skip_if_lt_x_gpu(NUM_DEVICES)) or skip when self.device_type == 'cpu'. The backend override is n

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of a152458: nothing blocking; ready for human review.

This PR makes the distributed checkpoint, pipelining and flight-recorder tests device-generic so they run on XPU. Every inline request from maintainer etaf is now reflected in the code: DeterministicGuard replaces the looser tolerances, the unrelated files were dropped, and hw_classification and the continuous base class are back. What remains is minor robustness: a cpu branch that never runs, an import-time backend lookup, and a cpu:N device string.

⚪ 3 non-blocking findings

etaf said this cpu branch isn't needed. The author replied that without it the string becomes a duplicate cpu:gloo, but the class is skipped when there are fewer than 4 accelerators (line 955), so device_type=='cpu' never reaches here. Drop the branch or link the CI failure it fixes.


backend = torch.distributed.get_default_backend_for_device(device_type)

get_default_backend_for_device runs at import time. On builds without distributed it raises AttributeError, and on accelerators with no registered default (hpu, privateuse1) it raises ValueError. Either way the whole module fails to import, including tests that don't need the backend; fall back to a literal backend name.


device = f"{device_type}:{dist.get_rank()}"

On CPU-only machines rank 1 builds the device 'cpu:1', which trips a debug-only assertion in c10::Device. The .to(device) call also does nothing, because MyShardedModel3 has no params or buffers, so it can simply be removed.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

@github-actions
github-actions Bot dismissed their stale review October 9, 2026 01:27

Withdrawn: the automated review of a152458 found nothing blocking.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 9, 2026
@madhumitha0102

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
…h#195952)

For pytorch#114850, we will port distributed tests to Intel GPU.
We will enable Intel GPU with following methods and keep the original code styles:

Example: "torch.accelerator.current_accelerator()" to determine the accelerator backend

enabled XPU for the following files:

1. test/distributed/checkpoint/_experimental/test_staging.py
2. test/distributed/checkpoint/e2e/test_e2e_save_and_load.py
3. test/distributed/checkpoint/test_file_system_checkpoint_cpu.py
4. test/distributed/checkpoint/test_state_dict_stager.py
5. test/distributed/checkpoint/test_state_dict_utils.py
6. test/distributed/flight_recorder/test_fr_analysis.py
7. test/distributed/optim/test_zero_redundancy_optimizer.py
8. test/distributed/pipelining/test_backward.py
9. test/distributed/pipelining/test_microbatch.py
10. test/distributed/pipelining/test_schedule_multiproc.py

Pull Request resolved: pytorch#195952
Approved by: https://github.com/newtdms, https://github.com/etaf, https://github.com/jansel
xjbanana258 added a commit to xjbanana258/pytorch that referenced this pull request Oct 13, 2026
Rebased onto latest main, resolving conflicts with pytorch#197704 and pytorch#195952:
TestCheckpointOrderingAndOverwrite (upstream) now owns
test_different_ordered_state_dict_keys and test_overwrite, so this PR
no longer moves test_overwrite into TestInitStateDict, and
test_different_ordered_state_dict_keys keeps only the
device_type = self.device_type fix on top of upstream's copy.

Review fixes for can-gaa-hou's latest comments:

TestNoCPU is now classified ACCELERATOR instead of GENERIC. With pytorch#195952
landed, its backend resolves via get_default_backend_for_device and the
test is gated by skip_if_lt_x_gpu(NUM_DEVICES), so it is
accelerator-generic rather than CUDA-specific; GENERIC contradicted both
the skip gating and the taxonomy.

except_for=("cpu",) is removed from instantiate_device_type_tests. It
was requested by fffrog earlier but reintroduced by a later commit.
Every test method in TestE2ESaveAndLoad is gated by
skip_if_lt_x_gpu(4), so CPU variants skip cleanly without it.

TestCheckpointOrderingAndOverwrite is annotated ACCELERATOR for
consistency with the rest of this file.

Assisted-by: Claude (Anthropic)

Test Plan:
- python3 -m py_compile test/distributed/checkpoint/e2e/test_e2e_save_and_load.py
- ruff check --config pyproject.toml test/distributed/checkpoint/e2e/test_e2e_save_and_load.py
- CI on the PR (4-GPU distributed suites).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks keep-going Don't stop on first failure, keep running tests until the end Merged open source ready for review Automated review passed, ready for a final review by a maintainer. release notes: distributed (checkpoint) topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

8 participants