Repository navigation
Open
Labels
bugSomething isn't workingSomething isn't workingdependency component: oneAPIHost DPC++ / icpx build-time failureHost DPC++ / icpx build-time failureduplicateThis issue or pull request already existsThis issue or pull request already existsfunctionalityFunctional defect: error/assert/hang/timeout (non-numeric)Functional defect: error/assert/hang/timeout (non-numeric)module: distributedFor distributed feature issueFor distributed feature issueskippedUsed for temp UT failure to parallel fixUsed for temp UT failure to parallel fixtest: utUnit-test failure surfaceUnit-test failure surfaceut_upstreamUpstream unit-test dependencyUpstream unit-test dependency
Milestone
Description
🐛 Describe the bug
Cases:
xpu_distributed,test.distributed.checkpoint.test_state_dict_stager.TestStateDictStager,test_tensor_pinned_and_shared
please get wheels from https://github.com/intel/torch-xpu-ops/actions/runs/19563892858 or use gh download
gh run download 19563892858 --repo intel/torch-xpu-ops --name Torch-XPU-Wheel-1826-19563892858-1 --dir path --pattern "*.zip"
git clone -b distributed_2.10 https://github.com/daisyden/pytorch.git
cd pytorch
pip install -r requirements.txt
pip install pytest expecttest
pytest -v test/distributed/checkpoint/test_state_dict_stager.py::TestStateDictStager::test_tensor_pinned_and_shared
=================================== FAILURES ===================================
_ TestStateDictStager.test_tensor_pinned_and_shared (pin_memory=True, share_memory=False) _
Traceback (most recent call last):
File "/tmp/xpu-tool/Python/3.10.19/x64/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
yield
File "/tmp/xpu-tool/Python/3.10.19/x64/lib/python3.10/unittest/case.py", line 498, in subTest
yield
File "/home/jenkins/actions-runner/_work/torch-xpu-ops/torch-xpu-ops/pytorch/test/distributed/checkpoint/test_state_dict_stager.py", line 766, in test_tensor_pinned_and_shared
self.assertEqual(
File "/tmp/xpu-tool/Python/3.10.19/x64/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 4291, in assertEqual
raise error_metas.pop()[0].to_error( # type: ignore[index]
AssertionError: Booleans mismatch: False is not True
Tensor pinned status should be True
_ TestStateDictStager.test_tensor_pinned_and_shared (pin_memory=True, share_memory=True) _
Traceback (most recent call last):
File "/tmp/xpu-tool/Python/3.10.19/x64/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
yield
File "/tmp/xpu-tool/Python/3.10.19/x64/lib/python3.10/unittest/case.py", line 498, in subTest
yield
File "/home/jenkins/actions-runner/_work/torch-xpu-ops/torch-xpu-ops/pytorch/test/distributed/checkpoint/test_state_dict_stager.py", line 766, in test_tensor_pinned_and_shared
self.assertEqual(
File "/tmp/xpu-tool/Python/3.10.19/x64/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 4291, in assertEqual
raise error_metas.pop()[0].to_error( # type: ignore[index]
AssertionError: Booleans mismatch: False is not True
Versions
https://github.com/daisyden/pytorch/tree/distributed_2.10
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdependency component: oneAPIHost DPC++ / icpx build-time failureHost DPC++ / icpx build-time failureduplicateThis issue or pull request already existsThis issue or pull request already existsfunctionalityFunctional defect: error/assert/hang/timeout (non-numeric)Functional defect: error/assert/hang/timeout (non-numeric)module: distributedFor distributed feature issueFor distributed feature issueskippedUsed for temp UT failure to parallel fixUsed for temp UT failure to parallel fixtest: utUnit-test failure surfaceUnit-test failure surfaceut_upstreamUpstream unit-test dependencyUpstream unit-test dependency
Activity
newtdms commentedon Jan 16, 2026
Looked into the issue briefly. The test case randomly initializes two tensors on the device and then converts into cpu_state_dict based on different pin_memory and shared_memory config. The test case fails for multi-rank config, even for single rank. The single-rank case should be resolved first. @madhumitha0102 can you please confirm the failure for single-rank?
madhumitha0102 commentedon Jan 21, 2026
I ran it on single rank and I see this failure for single rank as well
newtdms commentedon Jan 22, 2026
I created a single-rank reproducer. Can you please open an internal PyTorch JIRA to further investigate?
ut2404.py
madhumitha0102 commentedon Jan 26, 2026
@riverliuintel we see this issue on single rank as well. Please assign it to appropriate person. Thanks
riverliuintel commentedon Feb 4, 2026
@yucai-intel take it back from distributed, if this issue also exist in single rank.
18 remaining items
ZhaoqiongZ commentedon Sep 8, 2026
Hi @astachowiczhabana , I just tested the functionality of torchxpubot fix on those not yet PR created issues, not mean to take this issue, please keep your follow up on it. Thanks!
astachowiczhabana commentedon Sep 8, 2026
Sure @ZhaoqiongZ, no problem. I'm removing the debug comments then (my own agent session get's confused by them :)
ZhaoqiongZ commentedon Oct 28, 2026
@torchxpubot fix
torchxpubot commentedon Oct 28, 2026
Starting automated fix on this issue. Follow progress in the workflow run.
Stage 1 - Triage
single-bug, reproducer present. Target repo is upstreampytorch/pytorch(
torch/distributed/checkpoint/_state_dict_stager.pyplus the XPU pinned-memoryplumbing in ATen), not this repo.
Stage 2 - Reproduce: REPRODUCED
Reproduced on the nightly XPU wheel
2.16.0.dev20261027+xpuusing the upstream testfile (no third-party fork needed), on BMG (
Intel(R) Arc(TM) Pro B60 Graphics),oneAPI 2026.1.1:
Stage 3 - Root cause
Two layers, matching the analysis already in this thread:
StateDictStager.__init__gates pinning ontorch.cuda.is_available()and pinsthrough
torch.cuda._pin_memory_utils, which callscudaHostRegister. On anXPU-only box the gate silently drops
pin_memory, sois_pinned()isFalsefor both failing sub-tests.
cudaHostRegisterin PyTorch. XPU'sisPinnedPtr()only answerssycl::get_pointer_type(...) == usm::alloc::host,which holds only for memory SYCL itself allocated, so in-place pinning of an
already-allocated (and, for
share_memory=True, shm-backed) buffer cannot beobserved.
I measured the SYCL side directly rather than assuming (standalone DPC++ program,
oneAPI 2026.1.1, BMG):
prepare_for_device_copyon aMAP_SHAREDmappingmallocpointerget_pointer_typeafter registeringunknownqueue.memcpyinto the registered rangerelease_from_device_copyafter the host buffer is freedSo the page-locking primitive already exists and already works on shared memory;
the only missing piece is that SYCL's USM table cannot be told about it.
Stage 4 - Fix
Have PyTorch keep its own record of host-registered ranges rather than wait for
SYCL to expose one - which is in effect what CUDA does too, since the table behind
cudaPointerGetAttributesbelongs to the CUDA runtime, not to any allocator:at::xpu::hostRegister/hostUnregister/isHostRegisteredwrapprepare_for_device_copy/release_from_device_copyand keep an ordered map ofthe registered ranges (ordered, so an interior address answers too, as it does on
CUDA - XPU's copy fast path in this repo queries
isPinnedPtr()with offsetpointers).
XPUHooks::isPinnedPtr()consults it after the USM-type query.torch._C._xpu_hostRegister/_xpu_hostUnregister, withtorch/xpu/_pin_memory_utils.pymirroring the CUDA module of the same name._pin_memory_utilsfromtorch.acceleratorinstead ofhardcoding CUDA, which is what
staging.pynext to it already does. A backendshipping no such module keeps the old warn-and-disable behaviour.
This needs no compiler update, so
pin=True, share=Trueis fixed now ratherthan waiting on CMPLRLLVM-70326. 7 files, ~115 lines, all in
pytorch/pytorch;nothing in this repo, so there is no second patch to land.
Stage 5 - Verify: PASSED
Source build
torch 2.16.0a0+gitc5c9a00,TORCH_XPU_ARCH_LIST=bmg,pvc,oneAPI 2026.1.1, BMG:
test_tensor_pinned_and_shared2 failed, 16 passed16 passed, 16 subtests passedBoth runs are on the same build - the "before" column was produced by reverting
only the two Python files, so collection and binaries are identical and the
comparison is apples to apples.
lintrunner -areports no lint issues on thechanged files.
Summary
Both failing sub-tests come from one bug with two layers: checkpoint staging only
pinned memory when CUDA was available, and PyTorch had no XPU counterpart of
cudaHostRegisterunderneath it. The fix makes the stager resolve its pinninghelpers from
torch.accelerator, and addsat::xpu::hostRegisteron top ofsycl::ext::oneapi::experimental::prepare_for_device_copywith PyTorch keepingits own ordered map of registered ranges, which
isPinnedPtr()consults - theone piece SYCL cannot provide, and the reason this thread was waiting on a new
SYCL API. Taking that route fixes the
share_memory=Truecase too, on theshipping 2026.1 compiler rather than a future one, so the fix no longer depends on
CMPLRLLVM-70326. Verified on a source build: the whole file goes from
2 failed, 16 passedto16 passed, 16 subtests passed, with the before runtaken on the same binaries so nothing else moved.
One related spot was deliberately left alone as out of scope and is worth a
human's eye:
torch/distributed/_state_dict_utils.py::_create_cpu_state_dictstill imports
torch.cuda._pin_memory_utilsdirectly for itsshare-plus-pin path, which the same accelerator-generic treatment would fix.
agent/fix-issue-2404(in apytorch/pytorchcheckout)c5c9a00715c54fdf9e3498c529cd8e7fe714d636aten/src/ATen/xpu/CachingHostAllocator.cpp,aten/src/ATen/xpu/CachingHostAllocator.h,aten/src/ATen/xpu/detail/XPUHooks.cpp,torch/_C/__init__.pyi.in,torch/csrc/xpu/Module.cpp,torch/distributed/checkpoint/_state_dict_stager.py,torch/xpu/_pin_memory_utils.pyto review and apply.
Generated by fix job.
Review
Copy into a new comment, keep ONE verdict, add a note. Two verdicts in
one comment are dropped as ambiguous.
On a batch run add
item=<pytorch issue>to say which sub-item theverdict is about, in the bold text and in the marker -- the marker
is invisible, so the bold line is all a reader sees. One comment per
sub-item, since a bare verdict on a batch does not say which test it
means and is dropped.
run=<id>only when judging a run other than thenewest, in both places too.
A CI DISABLED sub-item,
item=from the fan-out table:Another sub-item of the same batch, judged on an earlier run:
An
[xpu-alignment]issue that should not have been filed -- one issueper difference, so no
item=:[DCP] Support pin_memory in StateDictStager without CUDA
daisyden commentedon Nov 11, 2026
label-issue: #2404
Root cause: checkpoint stager forces
pin_memory=Falseon XPU because it gates pinning ontorch.cuda.is_available()(pytorchtorch/distributed/checkpoint/_state_dict_stager.py:36), sois_pinned()stays False.typeBugtesttest: utpytest test/distributed/checkpoint/test_state_dict_stager.py.modulemodule: distributedpriorityMediumdtypedependency componentdependency component: oneAPIfunctionalityduplicateWarning
apply_labels.py flagged items that need a human:
Applied to this issue. Generated by a local
label-issuerun.