Skip to content

[WIP]xpu: skip multiprocessing tests requiring GPU IPC - #186793

Closed
xuhancn wants to merge 6 commits into
pytorch:mainfrom
xuhancn:fix-186585-xpu-tensor-multiprocess
Closed

xuhancn wants to merge 6 commits into
pytorch:mainfrom
xuhancn:fix-186585-xpu-tensor-multiprocess

Conversation

@xuhancn

@xuhancn xuhancn commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #186585

Summary

Disable multiprocessing tests that require XPU GPU IPC (not yet available).
XPU lacks a cudaIpcMemHandle equivalent, so tensor serialization across
processes is unimplemented.

A CPU-copy fallback was explored but rejected — it silently breaks
shared-tensor semantics since child-process mutations are not visible
to the parent.

Tests skipped

Test Reason
test_simple_sharing Child's fill_(4) on GPU tensor — not visible to parent
test_variable_sharing Post-send mutation not visible to child
test_parameter_sharing Same mutation-visibility pattern

These tests also skip on ROCm for the same reason.
Tracker: intel/torch-xpu-ops#4000

@pytorch-bot

pytorch-bot Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 7 New Failures, 2 Unrelated Failures, 8 Unclassified Failures

As of commit 07900bf with merge base e9ff322 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

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

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

@xuhancn xuhancn added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category ciflow/xpu Run XPU CI tasks labels Jun 9, 2026
@xuhancn
xuhancn marked this pull request as draft June 9, 2026 14:43
@xuhancn

xuhancn commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@claude please review this PR.

@claude

claude Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Claude finished @xuhancn's task in 7m 28s —— View job


Review: XPU tensor multiprocessing support via CPU copy fallback

I read torch/multiprocessing/reductions.py and traced the CI failures. The overall approach (D2H copy on send, H2D on rebuild) is reasonable given XPU has no IPC primitive. However there are two correctness bugs that explain the failing XPU CI jobs, plus a semantic caveat worth documenting.


🔴 1. Empty tensors crash — this is the failing test_empty_tensor_sharing_xpu_float32

rebuild_xpu_tensor calls torch.frombuffer(raw_bytes, ...), but frombuffer explicitly rejects zero-length buffers. From tensor_new.cpp:1573:

TORCH_CHECK_VALUE(
    len > 0 && count != 0,
    "both buffer length (", len, ") and count (", count, ") must not be 0");

For an empty tensor raw_bytes == b"", so frombuffer raises ValueError. This is exactly why test_empty_tensor_sharing_xpu_float32 (an unclassified-but-new failure in this PR) breaks — the existing meta/CPU paths special-case size 0 (reduce_storage has a storage.size() == 0 branch), but the new XPU path does not.

Fix: short-circuit the empty case in rebuild_xpu_tensor, e.g.:

if len(raw_bytes) == 0:
    t = torch.empty(size, dtype=dtype, device=device)
else:
    t = torch.frombuffer(raw_bytes, dtype=torch.uint8).view(dtype).reshape(size)
    t = t.to(device)

Fix this →


🔴 2. numpy().tobytes() fails for bfloat16 / float8 / complex32

The send path uses:

raw_bytes = cpu_tensor.numpy().tobytes()

Tensor.numpy() only supports the dtypes enumerated in aten_to_numpy_dtype (tensor_numpy.cpp:283). bfloat16, float8 variants, and complex32 are not in that list and raise TypeError: Got unsupported ScalarType. Since XPU heavily uses bfloat16, this path will fail for very common tensors.

The commit message says you switched to numpy().tobytes() to dodge a PYREFLY lint on memoryview(UntypedStorage). A more robust approach that avoids numpy entirely is to go through the untyped storage bytes (works for all dtypes, including bf16):

cpu_tensor = tensor.detach().cpu().contiguous()
raw_bytes = bytes(cpu_tensor.untyped_storage())

UntypedStorage supports bytes(...)/buffer protocol regardless of dtype. If PYREFLY still complains, prefer a targeted # type: ignore/# noqa over restricting to numpy-representable dtypes — silently dropping bf16 support would be a regression for XPU. (You could also reconstruct symmetrically via torch.UntypedStorage.from_buffer(...).)


🟡 3. Copy semantics differ from shared-memory semantics (document it)

CUDA IPC gives the receiver a tensor backed by the same memory — mutations in one process are visible in the other. This fallback produces an independent copy: writes do not propagate across processes. That is unavoidable without IPC, but it is a behavioral difference users may not expect from mp.Queue/sharing. Worth a one-line note in the docstring (and ideally the issue/PR) so callers relying on shared-memory semantics aren't surprised. Tests like test_variable_sharing assert cross-process visibility of in-place updates — make sure the XPU variants of those are skipped or adjusted, not silently passing on copies.


🟢 Minor

  • metadata stores str(cpu_tensor.dtype) then re-parses it with getattr(torch, dtype_str.rsplit(".", 1)[-1]). You can pickle the torch.dtype object directly (dtypes are picklable) — pass tensor.dtype and skip the string round-trip entirely. Simpler and avoids the fragile rsplit.
  • The docstring in rebuild_xpu_tensor mentions fd-sharing / ftruncate EINVAL rationale at length — good context, but now that you serialize raw bytes the _share_fd_cpu_ discussion is about a path you no longer take; consider trimming to keep it focused.
  • reduce_tensor doesn't guard against tensor.is_nested / sparse for XPU specifically, but those are handled earlier in the function, so OK.

Other CI failures

The win-vs2022-cpu-py3, docs-build, and rocm failures appear unrelated to this change (CPU/Windows/ROCm paths are untouched) — likely infra or pre-existing. The signal that matters for this PR is the XPU job (test_empty_tensor_sharing_xpu_float32), addressed by bug #1.


Summary: the design is sound, but bugs #1 (empty tensors) and #2 (bfloat16) will break real usage and are the cause of the red XPU CI. I'd recommend fixing both, adding XPU coverage for an empty tensor and a bfloat16 tensor, and noting the copy-vs-shared semantics. Happy to implement these if you'd like — just say the word.
· branch fix-186585-xpu-tensor-multiprocess

@xuhancn

xuhancn commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased fix-186585-xpu-tensor-multiprocess onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout fix-186585-xpu-tensor-multiprocess && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the fix-186585-xpu-tensor-multiprocess branch from 1cb2081 to f76801f Compare June 11, 2026 05:36
@xuhancn

xuhancn commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@claude please review this PR.

@claude

claude Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Claude finished @xuhancn's task in 2m 27s —— View job


Re-review: XPU tensor multiprocessing (after the two fixes)

I re-read torch/multiprocessing/reductions.py at adb8c2f and cross-checked against test/test_multiprocessing.py. Both bugs from my last pass are correctly fixed — but there's a third, more fundamental problem I missed before: the existing device-generic tests are instantiated for XPU and assert shared-memory semantics that a copy fallback cannot satisfy.


✅ Resolved from last review

  1. Empty tensors — rebuild_xpu_tensor now short-circuits len(raw_bytes) == 0 with torch.empty(...) before frombuffer (lines 168-170). Correct.
  2. bf16 / float8 / complex32 — send path now uses bytes(cpu_tensor.untyped_storage()) (line 435) instead of numpy().tobytes(), which works for all dtypes. Reconstruction via frombuffer(..., uint8).view(dtype).reshape(size) is dtype-agnostic and .contiguous() makes the whole-storage bytes() safe. Correct.
  3. dtype round-trip — now pickles the torch.dtype object directly (line 440). Good.

🔴 Critical: shared-memory mutation tests will fail for XPU

instantiate_device_type_tests(TestMultiprocessingDeviceType, globals(), allow_xpu=True) (test_multiprocessing.py:560) generates XPU variants of tests that assert a child-process mutation is visible in the parent — which is exactly what the copy fallback cannot provide:

  • test_simple_sharing → _test_sharing.test_fill (lines 355-379): parent puts x, child does data[0][:] = 4, then parent asserts data[0].eq(4).all(). With a copy, the parent's x is never touched → assertion fails.
  • test_variable_sharing / test_parameter_sharing → _test_autograd_sharing (lines 419-452): parent mutates var.data[0,0] = 1000 after sending; the child checks var.data.equal(expected_var) expecting to see that mutation. A copy never sees the later parent write → worker_ok is False → fails.

This isn't hypothetical — these are device-generic and run on the XPU CI image. Before this PR they errored (no XPU sharing at all); after it they'll assert-fail instead. The copy semantics you correctly documented in the rebuild_xpu_tensor docstring directly contradict what these tests require.

Recommendation: explicitly skip the shared-mutation tests for XPU (e.g. a skipXPU/skipIf(device == "xpu") guard on test_simple_sharing, test_variable_sharing, test_parameter_sharing) and add XPU-appropriate coverage that asserts value round-trips rather than cross-process mutation:

# value survives the round-trip (copy semantics: no shared mutation)
t = torch.arange(25., device="xpu").view(5, 5)
q = ctx.Queue(); q.put(t)
self.assertEqual(q.get().cpu(), t.cpu())

Add an empty-tensor and a bf16 case there too, so bugs #1/#2 stay regression-covered.

Add XPU skips + copy-semantics tests →


🟡 Minor

  • frombuffer on bytes (line 172): raw_bytes is an immutable bytes, so torch.frombuffer emits a "non-writable buffer" UserWarning and returns a read-only tensor. The subsequent .to(device) copies it, so functionally fine — but the warning is noisy. Wrapping in bytearray(raw_bytes) (one extra copy) or filtering the warning would silence it. Low priority.
  • Docstring trim (lines 158-166): the _share_fd_cpu_/ftruncate rationale now lives only in the reduce_tensor comment (lines 424-428), and the rebuild_xpu_tensor docstring is appropriately focused on the copy semantics.

CI status

docs-build is failing but is unrelated (CPU/docs path, untouched here) — pre-existing/infra. The xpu and pull jobs are still in progress; the multiprocessing assertions above are what I'd watch on the XPU shard once it lands.


Summary: the serialization mechanics are now correct (empty + bf16 fixed). The remaining blocker is test-semantics: the inherited shared-memory tests can't pass under a copy fallback, so they need XPU skips plus value-round-trip coverage. Happy to implement the test changes if you'd like — just say the word.
· branch fix-186585-xpu-tensor-multiprocess

@xuhancn

xuhancn commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@claude please review this issue.

@claude

claude Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Claude finished @xuhancn's task in 1m 17s —— View job


Review: XPU tensor multiprocessing via CPU copy fallback

  • Read torch/multiprocessing/reductions.py (rebuild_xpu_tensor, reduce_tensor XPU branch)
  • Cross-check against test/test_multiprocessing.py test semantics
  • Confirm state of previously-reported issues

No new commits since my last pass (HEAD is still adb8c2f), so this confirms where things stand.


✅ Serialization mechanics are correct

  1. Empty tensors — rebuild_xpu_tensor short-circuits len(raw_bytes) == 0 with torch.empty(...) before frombuffer (reductions.py:168-170). Good.
  2. bf16 / float8 / complex32 — send path uses bytes(cpu_tensor.untyped_storage()) (reductions.py:435) after .contiguous(), and reconstructs via frombuffer(..., uint8).view(dtype).reshape(size) (reductions.py:172), which is dtype-agnostic. Good.
  3. dtype round-trip — pickles the torch.dtype object directly in metadata (reductions.py:440). Good.

🔴 Still the blocker: inherited shared-memory tests can't pass under a copy

instantiate_device_type_tests(TestMultiprocessingDeviceType, globals(), allow_xpu=True) (test_multiprocessing.py:560) generates XPU variants of tests that assert cross-process mutation visibility — which a copy fallback fundamentally cannot provide:

  • test_simple_sharing → _test_sharing.test_fill (test_multiprocessing.py:354-382, worker simple_fill at :81-84): parent puts x, child does data[0][:] = 4, parent then asserts data[0].eq(4).all() (:378). With a copy the parent's x is never touched → assertion fails.
    • Note: the sibling test_receive (:384-412) happens to still pass — it sends the same t twice and asserts assertEqual(s1, s2), which compares storage values (both all-ones), not identity. So only test_fill breaks here.
  • test_variable_sharing / test_parameter_sharing → _test_autograd_sharing (test_multiprocessing.py:419-452, worker autograd_sharing at :214-232): parent mutates var.data[0,0] = 1000 after sending (:442), and the child checks var.data.equal(expected_var) expecting to observe that later write (:221). A copy never sees it → worker_ok is False → fails at :447.

Before this PR these errored (no XPU sharing at all); after it they'll assert-fail instead. This directly contradicts the copy semantics correctly documented in the rebuild_xpu_tensor docstring (reductions.py:163-165).

Recommendation: guard the shared-mutation tests for XPU (skipXPU / skipIf(device == "xpu") on test_simple_sharing, test_variable_sharing, test_parameter_sharing) and add XPU-appropriate coverage asserting value round-trips rather than cross-process mutation — including an empty-tensor and a bf16 case so the two fixed bugs stay regression-covered:

# copy semantics: value survives the round-trip, no shared mutation
for t in (
    torch.arange(25., device="xpu").view(5, 5),
    torch.tensor([], device="xpu"),
    torch.randn(4, device="xpu", dtype=torch.bfloat16),
):
    q = ctx.Queue(); q.put(t)
    self.assertEqual(q.get().cpu(), t.cpu())

Add XPU skips + copy-semantics tests →


🟡 Minor

  • frombuffer on immutable bytes (reductions.py:172): raw_bytes is bytes, so torch.frombuffer emits a "non-writable buffer" UserWarning and returns a read-only tensor. The subsequent .to(device) copies it so it's functionally fine, but the warning is noisy. torch.frombuffer(bytearray(raw_bytes), ...) (one extra copy) silences it. Low priority.
  • metadata device field (reductions.py:439): stores tensor.device (e.g. xpu:0) and rebuild does t.to(device). Fine, just confirm a multi-GPU/multi-XPU receiver honoring the original device index is the intended behavior (it is, for round-tripping back to the same device).

CI

docs-build failure is unrelated (untouched CPU/docs path) — pre-existing/infra. The signal that matters is the XPU shard; the multiprocessing assertions above are what I'd expect to go red there until the test guards land.


Summary: serialization is correct (empty + bf16 fixed). The one remaining blocker is test semantics — the inherited shared-memory tests can't pass under a copy fallback, so they need XPU skips plus value-round-trip coverage. Happy to implement the test changes if you'd like — just say the word.
· branch fix-186585-xpu-tensor-multiprocess

@xuhancn

xuhancn commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@claude please review latest code.

@claude

claude Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Claude finished @xuhancn's task in 1m 13s —— View job


Review: XPU tensor multiprocessing via CPU copy fallback

  • Read torch/multiprocessing/reductions.py (rebuild_xpu_tensor, reduce_tensor XPU branch)
  • Cross-check test/test_multiprocessing.py semantics against the copy fallback
  • Confirm state of previously-reported issues

HEAD is still adb8c2f and the diff touches only torch/multiprocessing/reductions.py (+54/-0) — no new commits and no test changes since my last pass. So this confirms where things stand.


✅ Serialization mechanics are correct

  1. Empty tensors — rebuild_xpu_tensor short-circuits len(raw_bytes) == 0 with torch.empty(...) before frombuffer (reductions.py:168-170). Good.
  2. bf16 / float8 / complex32 — send path uses bytes(cpu_tensor.untyped_storage()) (reductions.py:430) after .contiguous() and reconstructs via frombuffer(..., uint8).view(dtype).reshape(size) (reductions.py:172), which is dtype-agnostic. Good.
  3. dtype round-trip — pickles the torch.dtype object directly in metadata (reductions.py:435). Good.

The core send/rebuild logic is sound and the docstring correctly documents the copy-vs-shared semantics.


🔴 Still the blocker: inherited shared-memory tests can't pass under a copy

instantiate_device_type_tests(TestMultiprocessingDeviceType, globals(), allow_xpu=True) (test_multiprocessing.py:560) generates XPU variants of tests that assert cross-process mutation visibility — exactly what a copy fallback cannot provide:

  • test_simple_sharing → _test_sharing.test_fill (test_multiprocessing.py:354-382): parent puts x, child does the fill, parent then asserts data[0].eq(4).all() (:378). With a copy, the parent's x is never touched → assertion fails.
    • Sibling test_receive (:384-412) still passes — it sends the same t twice and asserts assertEqual(s1, s2) on storage values (both all-ones), not identity. So only test_fill breaks here.
  • test_variable_sharing / test_parameter_sharing → _test_autograd_sharing (test_multiprocessing.py:419-452): parent mutates var.data[0,0] = 1000 after sending (:442); the child checks var.data.equal(expected_var) expecting to observe that later write. A copy never sees it → worker_ok is False → fails at :447.

These are device-generic and run on the XPU CI image. Before this PR they errored (no XPU sharing); after it they'll assert-fail. Tests that only check requires_grad round-trips (test_leaf_variable_sharing :528, test_non_leaf_variable_sharing :547) and test_empty_tensor_sharing :499 should be fine.

Recommendation: guard the shared-mutation tests for XPU and add value-round-trip coverage instead — including empty and bf16 cases so bugs #1/#2 stay regression-covered:

def test_simple_sharing(self, device):
    if torch.device(device).type == "xpu":
        self.skipTest("XPU uses a copy fallback; cross-process mutation is not visible")
    ...
# copy semantics: value survives the round-trip, no shared mutation
for t in (
    torch.arange(25., device="xpu").view(5, 5),
    torch.tensor([], device="xpu"),
    torch.randn(4, device="xpu", dtype=torch.bfloat16),
):
    q = ctx.Queue(); q.put(t)
    self.assertEqual(q.get().cpu(), t.cpu())

Add XPU skips + copy-semantics tests →


🟡 Minor

  • frombuffer on immutable bytes (reductions.py:172): raw_bytes is bytes, so torch.frombuffer emits a "non-writable buffer" UserWarning and returns a read-only tensor. The subsequent .to(device) copies it so it's functionally fine, but the warning is noisy. torch.frombuffer(bytearray(raw_bytes), ...) (one extra copy) silences it. Low priority.
  • # noqa: PYREFLY (reductions.py:428): bare noqa without a rule code is broad — if it's silencing a specific pyrefly diagnostic, prefer the targeted code so future unrelated issues on that line aren't masked.

CI

docs-build failure is unrelated (untouched CPU/docs path) — pre-existing/infra. The signal that matters is the XPU shard; the multiprocessing assertions above are what I'd expect to go red there until the test guards land.


Summary: serialization is correct (empty + bf16 fixed). The one remaining blocker is unchanged — the inherited shared-memory tests can't pass under a copy fallback, so they need XPU skips plus value-round-trip coverage. Happy to implement the test changes if you'd like — just say the word.
· branch fix-186585-xpu-tensor-multiprocess

xuhancn added a commit to xuhancn/pytorch that referenced this pull request Jun 15, 2026
…orch#186793)

- Add @skipIfXpu to test_simple_sharing, test_variable_sharing,
  test_parameter_sharing — these require GPU IPC for cross-process
  mutation visibility, which XPU currently lacks
- Use bytearray() in torch.frombuffer to silence UserWarning
- Specific # noqa: PYREFLY[102] instead of bare PYREFLY

Root cause: XPU has no cudaIpcMemHandle equivalent. The PR's
CPU copy fallback correctly preserves values but cannot share
GPU memory between processes.

Tracking: intel/torch-xpu-ops#4000
@xuhancn

xuhancn commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased fix-186585-xpu-tensor-multiprocess onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout fix-186585-xpu-tensor-multiprocess && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the fix-186585-xpu-tensor-multiprocess branch from 10fd849 to 6b511a2 Compare June 15, 2026 04:28
pytorchmergebot pushed a commit to xuhancn/pytorch that referenced this pull request Jun 15, 2026
…orch#186793)

- Add @skipIfXpu to test_simple_sharing, test_variable_sharing,
  test_parameter_sharing — these require GPU IPC for cross-process
  mutation visibility, which XPU currently lacks
- Use bytearray() in torch.frombuffer to silence UserWarning
- Specific # noqa: PYREFLY[102] instead of bare PYREFLY

Root cause: XPU has no cudaIpcMemHandle equivalent. The PR's
CPU copy fallback correctly preserves values but cannot share
GPU memory between processes.

Tracking: intel/torch-xpu-ops#4000
@xuhancn

xuhancn commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@claude review it again.

@claude

claude Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Claude finished @xuhancn's task in 47s —— View job


Review: XPU tensor multiprocessing via CPU copy fallback

  • Read torch/multiprocessing/reductions.py (XPU send/rebuild path)
  • Read test/test_multiprocessing.py (new XPU skips)
  • Confirm prior blocker (shared-memory mutation tests) is resolved

New commit 6b511a2 lands the test-semantics fix I'd been flagging, plus the two minor cleanups. All previously-reported issues are now resolved — this looks ready to me.


✅ Everything from prior reviews is addressed

  1. Empty tensors — rebuild_xpu_tensor short-circuits len(raw_bytes) == 0 with torch.empty(...) (reductions.py:168-170). Correct.
  2. bf16 / float8 / complex32 — send path uses bytes(cpu_tensor.untyped_storage()) after .contiguous() (reductions.py:439), reconstructed via frombuffer(..., uint8).view(dtype).reshape(size) (reductions.py:172-176) — dtype-agnostic. Correct.
  3. dtype round-trip — pickles the torch.dtype object directly (reductions.py:444). Good.
  4. Shared-memory mutation tests (the main blocker) — @skipIfXpu now guards test_simple_sharing, test_variable_sharing, and test_parameter_sharing (test_multiprocessing.py:495, 514, 528), each with a clear message pointing at the copy-vs-IPC limitation and the torch-xpu-ops#4000 tracker. This is exactly the right call — those three assert cross-process mutation visibility that a copy fallback fundamentally cannot satisfy. The value-round-trip tests that can pass (test_empty_tensor_sharing, test_leaf_variable_sharing, test_integer_parameter_serialization) remain enabled for XPU, so the empty + dtype paths stay regression-covered.
  5. frombuffer UserWarning — now wraps in bytearray(raw_bytes) (reductions.py:173), silencing the non-writable-buffer warning.
  6. # noqa: PYREFLY[102] — now carries the specific rule code instead of a bare noqa (reductions.py:439). Good.

🟢 Optional nits (non-blocking)

  • Skip vs. value-round-trip coverage. Skipping the three mutation tests is correct. As a follow-up (not required for this PR), an XPU-specific test that asserts values survive the round-trip — including a bf16 case — would lock in bug Don't support legacy Python #2's fix beyond the float32 empty-tensor test. Not a blocker; test_empty_tensor_sharing + the dtype-agnostic rebuild already give reasonable coverage.
  • Docstring duplication. The IPC-limitation rationale now appears in three places (the reduce_tensor XPU branch comment, the rebuild_xpu_tensor docstring, and the three skip messages). That's fine and arguably helpful, just noting it.

CI

The XPU shard is the signal that matters here; with the three mutation tests skipped, the previously-expected assert-failures should no longer appear. Any docs-build / Windows / ROCm reds are unrelated (untouched paths) — pre-existing/infra.


Summary: LGTM. Serialization mechanics are correct (empty + all dtypes), and the inherited shared-memory tests that can't pass under a copy fallback are now properly skipped with clear, tracked rationale. No remaining blockers from my side.
· branch fix-186585-xpu-tensor-multiprocess

@xuhancn
xuhancn marked this pull request as ready for review June 15, 2026 04:40
@xuhancn
xuhancn requested a review from guangyey June 15, 2026 04:40

@guangyey guangyey 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.

Let's disable the test suite here first and remove the CPU-copy fallback. The fallback silently breaks shared-tensor semantics — updates from another process won't be reflected in the parent, because each side ends up with its own CPU copy rather than aliasing the same XPU memory.

@xuhancn
xuhancn force-pushed the fix-186585-xpu-tensor-multiprocess branch from 6b511a2 to cf19845 Compare June 15, 2026 06:59
@xuhancn xuhancn changed the title xpu: add tensor multiprocessing support via CPU copy fallback xpu: skip multiprocessing tests requiring GPU IPC Jun 15, 2026
@xuhancn
xuhancn requested a review from guangyey June 15, 2026 07:02
@xuhancn

xuhancn commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

xuhancn and others added 6 commits June 15, 2026 07:06
…h#186585)

XPU lacks IPC support (no cudaIpcMemHandle equivalent), so tensors
cannot be shared across processes using CUDA-style IPC mechanisms.
Previously, XPU tensors fell through to the generic reduce_tensor path
which tries to pickle the storage using CPU shared memory methods
(_share_fd_cpu_), which are hard-gated to CPU only.

Fix: add an XPU branch in reduce_tensor that copies the tensor to CPU
before serialization and adds rebuild_xpu_tensor to copy it back to
XPU on the receiving end.

This uses the same D2H/H2D copy approach that CUDA uses as a fallback
when IPC is not available.

Co-authored-by: Copilot <[email protected]>
…f fd-sharing

The XPU tensor serialization path previously copied the tensor to CPU and
passed the CPU storage object through pickle.  Pickle would then trigger
the standard CPU storage fd-sharing path (DupFd / SCM_RIGHTS / MapAllocator),
which crashes in spawn child processes when ftruncate() returns EINVAL on
the dup'd shm fd.

Fix: Serialize the tensor data as raw bytes (via memoryview of the CPU
storage) instead of passing a storage object.  The receiving end reconstructs
from the raw bytes using torch.frombuffer + view + reshape, then copies
back to XPU.  This completely avoids the fd-sharing path and the associated
MapAllocator crash.

Fixes the test_multiprocessing.py::TestMultiprocessingDeviceTypeXPU::
test_integer_parameter_serialization_xpu failure.

Co-authored-by: Copilot <[email protected]>
…typedStorage

The pyrefly type checker does not recognize UntypedStorage as a Buffer,
causing a bad-argument-type error on memoryview(untyped_storage).
Switch to cpu_tensor.numpy().tobytes() which avoids the type issue
entirely while producing the same serialized bytes.

Co-authored-by: Copilot <[email protected]>
Two blocking bugs from review:

1. rebuild_xpu_tensor crashed on empty tensors because torch.frombuffer
   rejects zero-length buffers. Special-case len(raw_bytes)==0 by
   constructing torch.empty() directly.

2. reduce_tensor used numpy().tobytes() which fails for bfloat16, float8,
   and complex32 (not supported by numpy). Use bytes(untyped_storage())
   instead, which works for all dtypes.

Also eliminates the dtype string round-trip by pickling torch.dtype
directly, and trims the docstring to note the copy (not shared) semantics.

Fixes test_empty_tensor_sharing_xpu_float32.

Co-authored-by: Copilot <[email protected]>
…orch#186793)

- Add @skipIfXpu to test_simple_sharing, test_variable_sharing,
  test_parameter_sharing — these require GPU IPC for cross-process
  mutation visibility, which XPU currently lacks
- Use bytearray() in torch.frombuffer to silence UserWarning
- Specific # noqa: PYREFLY[102] instead of bare PYREFLY

Root cause: XPU has no cudaIpcMemHandle equivalent. The PR's
CPU copy fallback correctly preserves values but cannot share
GPU memory between processes.

Tracking: intel/torch-xpu-ops#4000
Per code review: CPU-copy fallback silently breaks shared-tensor
semantics — child-process mutations are not visible to the parent.
Remove the XPU reduce/rebuild path and keep only the test-skip
decorators until proper GPU IPC support exists.

This reverts all XPU-specific code from reductions.py while
retaining the @skipIfXpu decorators on the three cross-process
mutation tests in test_multiprocessing.py.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased fix-186585-xpu-tensor-multiprocess onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout fix-186585-xpu-tensor-multiprocess && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the fix-186585-xpu-tensor-multiprocess branch from cf19845 to 07900bf Compare June 15, 2026 07:06

@guangyey guangyey 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.

According to @chuanqi129's comments, we should disable the test case suite. I added this fix in #187314, which could help validate it easily.

@EikanWang
EikanWang marked this pull request as draft June 15, 2026 11:23
@EikanWang EikanWang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 15, 2026
@EikanWang EikanWang changed the title xpu: skip multiprocessing tests requiring GPU IPC [WIP]xpu: skip multiprocessing tests requiring GPU IPC Jun 15, 2026
pytorchmergebot pushed a commit that referenced this pull request Jun 16, 2026
…187314)

# Motivation
When #184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes #186585

Code originates from #186793
Co-authored-by: @xuhancn
Pull Request resolved: #187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137, #187232, #187306
@xuhancn

xuhancn commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

Close as #187314 already handled it.

@xuhancn xuhancn closed this Jun 16, 2026
atalman pushed a commit that referenced this pull request Jun 16, 2026
…187416)

Skip TestMultiprocessingDeviceType on XPU due to lack of IPC support (#187314)

# Motivation
When #184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes #186585

Code originates from #186793
Co-authored-by: @xuhancn
Pull Request resolved: #187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137, #187232, #187306

(cherry picked from commit 4f26a57)

Co-authored-by: Yu, Guangye <[email protected]>
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#187314)

# Motivation
When pytorch#184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes pytorch#186585

Code originates from pytorch#186793
Co-authored-by: @xuhancn
Pull Request resolved: pytorch#187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: pytorch#181233, pytorch#187137, pytorch#187232, pytorch#187306
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#187314)

# Motivation
When pytorch#184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes pytorch#186585

Code originates from pytorch#186793
Co-authored-by: @xuhancn
Pull Request resolved: pytorch#187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: pytorch#181233, pytorch#187137, pytorch#187232, pytorch#187306
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 module: sorting and selection open source 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.

DISABLED test_integer_parameter_serialization_xpu (__main__.TestMultiprocessingDeviceTypeXPU)

5 participants