pytorch - 💡(How to fix) Fix [DTensor] Inconsistent output placements of sharded DTensor indexing [7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#179448Fetched 2026-04-08 02:51:38
View on GitHub
Comments
7
Participants
4
Timeline
53
Reactions
0
Author
Timeline (top)
mentioned ×21subscribed ×21commented ×7labeled ×4

Fix Action

Fix / Workaround

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 192 On-line CPU(s) list: 0-191 Vendor ID: GenuineIntel Model name: INTEL(R) XEON(R) PLATINUM 8558 CPU family: 6 Model: 207 Thread(s) per core: 2 Core(s) per socket: 48 Socket(s): 2 Stepping: 2 CPU max MHz: 4000.0000 CPU min MHz: 800.0000 BogoMIPS: 4200.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 4.5 MiB (96 instances) L1i cache: 3 MiB (96 instances) L2 cache: 192 MiB (96 instances) L3 cache: 520 MiB (2 instances) NUMA node(s): 4 NUMA node0 CPU(s): 0-23,96-119 NUMA node1 CPU(s): 24-47,120-143 NUMA node2 CPU(s): 48-71,144-167 NUMA node3 CPU(s): 72-95,168-191 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Retpolines; IBPB conditional; IBRS_FW; STIBP conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI Retpoline Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Code Example

torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))
mesh = init_device_mesh("cuda", (2,), mesh_dim_names=("model",))

x = DTensor.from_local(torch.ones(8, 8192, device="cuda", dtype=torch.float32), device_mesh=mesh, placements=(Shard(1),)).requires_grad_()
i = DTensor.from_local(torch.tensor([1, 3, 5], device="cuda", dtype=torch.long), device_mesh=mesh, placements=(Replicate(),))

y = x[:, i]
# y = DTensor(local_tensor=tensor([[1., 1., 1.],
#        [1., 1., 1.],
#        [1., 1., 1.],
#        [1., 1., 1.]], device='cuda:0'), device_mesh=DeviceMesh((model=2), 'cuda', stride=(1,)), placements=(Shard(dim=0),))

---

torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))
mesh = init_device_mesh("cuda", (2,), mesh_dim_names=("model",))

x = DTensor.from_local(torch.ones(8, 8, device="cuda", dtype=torch.float32), device_mesh=mesh, placements=(Shard(1),)).requires_grad_()
i = DTensor.from_local(torch.tensor([1, 3, 5], device="cuda", dtype=torch.long), device_mesh=mesh, placements=(Replicate(),))

y = x[:, i]
# DTensor(local_tensor=tensor([[1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.]], device='cuda:0'), device_mesh=DeviceMesh((model=2), 'cuda', stride=(1,)), placements=(Replicate(),))

---

Collecting environment information...
PyTorch version: 2.12.0.dev20260405+cu130
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: glibc-2.35

Python version: 3.11.13 (main, Jun  4 2025, 17:37:17) [Clang 20.1.4 ] (64-bit runtime)
Python platform: Linux-5.15.0-119-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: 
GPU 0: NVIDIA H100 80GB HBM3
GPU 1: NVIDIA H100 80GB HBM3

Nvidia driver version: 570.124.06
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        46 bits physical, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               192
On-line CPU(s) list:                  0-191
Vendor ID:                            GenuineIntel
Model name:                           INTEL(R) XEON(R) PLATINUM 8558
CPU family:                           6
Model:                                207
Thread(s) per core:                   2
Core(s) per socket:                   48
Socket(s):                            2
Stepping:                             2
CPU max MHz:                          4000.0000
CPU min MHz:                          800.0000
BogoMIPS:                             4200.00
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization:                       VT-x
L1d cache:                            4.5 MiB (96 instances)
L1i cache:                            3 MiB (96 instances)
L2 cache:                             192 MiB (96 instances)
L3 cache:                             520 MiB (2 instances)
NUMA node(s):                         4
NUMA node0 CPU(s):                    0-23,96-119
NUMA node1 CPU(s):                    24-47,120-143
NUMA node2 CPU(s):                    48-71,144-167
NUMA node3 CPU(s):                    72-95,168-191
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; IBRS_FW; STIBP conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI Retpoline
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] Could not collect
[conda] libopenvino-pytorch-frontend            2025.0.0         h5888daf_3             conda-forge
[conda] numpy                                   2.3.3            pypi_0                 pypi
[conda] nvidia-cublas-cu12                      12.8.4.1         pypi_0                 pypi
[conda] nvidia-cuda-cupti-cu12                  12.8.90          pypi_0                 pypi
[conda] nvidia-cuda-nvrtc-cu12                  12.8.93          pypi_0                 pypi
[conda] nvidia-cuda-runtime-cu12                12.8.90          pypi_0                 pypi
[conda] nvidia-cudnn-cu12                       9.10.2.21        pypi_0                 pypi
[conda] nvidia-cufft-cu12                       11.3.3.83        pypi_0                 pypi
[conda] nvidia-curand-cu12                      10.3.9.90        pypi_0                 pypi
[conda] nvidia-cusolver-cu12                    11.7.3.90        pypi_0                 pypi
[conda] nvidia-cusparse-cu12                    12.5.8.93        pypi_0                 pypi
[conda] nvidia-cusparselt-cu12                  0.7.1            pypi_0                 pypi
[conda] nvidia-nccl-cu12                        2.27.5           pypi_0                 pypi
[conda] nvidia-nvjitlink-cu12                   12.8.93          pypi_0                 pypi
[conda] nvidia-nvtx-cu12                        12.8.90          pypi_0                 pypi
[conda] tbb                                     2022.3.0         h8d10470_1             conda-forge
[conda] torch                                   2.9.0            pypi_0                 pypi
[conda] triton                                  3.5.0            pypi_0                 pypi
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

When a large sharded DTensor is indexed by a replicated index, it'll produce unreasonable sharded output at dim 0:

torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))
mesh = init_device_mesh("cuda", (2,), mesh_dim_names=("model",))

x = DTensor.from_local(torch.ones(8, 8192, device="cuda", dtype=torch.float32), device_mesh=mesh, placements=(Shard(1),)).requires_grad_()
i = DTensor.from_local(torch.tensor([1, 3, 5], device="cuda", dtype=torch.long), device_mesh=mesh, placements=(Replicate(),))

y = x[:, i]
# y = DTensor(local_tensor=tensor([[1., 1., 1.],
#        [1., 1., 1.],
#        [1., 1., 1.],
#        [1., 1., 1.]], device='cuda:0'), device_mesh=DeviceMesh((model=2), 'cuda', stride=(1,)), placements=(Shard(dim=0),))

where the behavior is inconsistent with a smaller sharded DTensor, which produces replicated output:

torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))
mesh = init_device_mesh("cuda", (2,), mesh_dim_names=("model",))

x = DTensor.from_local(torch.ones(8, 8, device="cuda", dtype=torch.float32), device_mesh=mesh, placements=(Shard(1),)).requires_grad_()
i = DTensor.from_local(torch.tensor([1, 3, 5], device="cuda", dtype=torch.long), device_mesh=mesh, placements=(Replicate(),))

y = x[:, i]
# DTensor(local_tensor=tensor([[1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.],
#         [1., 1., 1.]], device='cuda:0'), device_mesh=DeviceMesh((model=2), 'cuda', stride=(1,)), placements=(Replicate(),))

It seems this issue is related to the total size (numel) of the input, e.g. torch.ones(8, 8192) and torch.ones(4, 16384) both produce sharded outputs, but torch.ones(4, 8192) produces replicated output.

IMO the replicated output should be expected since the index is replicated, and this is also the behavior in JAX.

Versions

Collecting environment information...
PyTorch version: 2.12.0.dev20260405+cu130
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: glibc-2.35

Python version: 3.11.13 (main, Jun  4 2025, 17:37:17) [Clang 20.1.4 ] (64-bit runtime)
Python platform: Linux-5.15.0-119-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: 
GPU 0: NVIDIA H100 80GB HBM3
GPU 1: NVIDIA H100 80GB HBM3

Nvidia driver version: 570.124.06
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        46 bits physical, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               192
On-line CPU(s) list:                  0-191
Vendor ID:                            GenuineIntel
Model name:                           INTEL(R) XEON(R) PLATINUM 8558
CPU family:                           6
Model:                                207
Thread(s) per core:                   2
Core(s) per socket:                   48
Socket(s):                            2
Stepping:                             2
CPU max MHz:                          4000.0000
CPU min MHz:                          800.0000
BogoMIPS:                             4200.00
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization:                       VT-x
L1d cache:                            4.5 MiB (96 instances)
L1i cache:                            3 MiB (96 instances)
L2 cache:                             192 MiB (96 instances)
L3 cache:                             520 MiB (2 instances)
NUMA node(s):                         4
NUMA node0 CPU(s):                    0-23,96-119
NUMA node1 CPU(s):                    24-47,120-143
NUMA node2 CPU(s):                    48-71,144-167
NUMA node3 CPU(s):                    72-95,168-191
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; IBRS_FW; STIBP conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI Retpoline
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] Could not collect
[conda] libopenvino-pytorch-frontend            2025.0.0         h5888daf_3             conda-forge
[conda] numpy                                   2.3.3            pypi_0                 pypi
[conda] nvidia-cublas-cu12                      12.8.4.1         pypi_0                 pypi
[conda] nvidia-cuda-cupti-cu12                  12.8.90          pypi_0                 pypi
[conda] nvidia-cuda-nvrtc-cu12                  12.8.93          pypi_0                 pypi
[conda] nvidia-cuda-runtime-cu12                12.8.90          pypi_0                 pypi
[conda] nvidia-cudnn-cu12                       9.10.2.21        pypi_0                 pypi
[conda] nvidia-cufft-cu12                       11.3.3.83        pypi_0                 pypi
[conda] nvidia-curand-cu12                      10.3.9.90        pypi_0                 pypi
[conda] nvidia-cusolver-cu12                    11.7.3.90        pypi_0                 pypi
[conda] nvidia-cusparse-cu12                    12.5.8.93        pypi_0                 pypi
[conda] nvidia-cusparselt-cu12                  0.7.1            pypi_0                 pypi
[conda] nvidia-nccl-cu12                        2.27.5           pypi_0                 pypi
[conda] nvidia-nvjitlink-cu12                   12.8.93          pypi_0                 pypi
[conda] nvidia-nvtx-cu12                        12.8.90          pypi_0                 pypi
[conda] tbb                                     2022.3.0         h8d10470_1             conda-forge
[conda] torch                                   2.9.0            pypi_0                 pypi
[conda] triton                                  3.5.0            pypi_0                 pypi

cc @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @msaroufim @dcci @aditvenk @xmfan

extent analysis

TL;DR

The issue can be potentially resolved by ensuring that the input size to the DTensor operation does not exceed a certain threshold, as the behavior seems to be inconsistent for larger inputs.

Guidance

  • Investigate the relationship between the input size (numel) and the output behavior to determine if there's a specific threshold beyond which the output becomes sharded instead of replicated.
  • Verify if the issue persists with different input sizes and shapes to confirm the hypothesis that the input size is the cause of the inconsistent behavior.
  • Consider filing a bug report or seeking further assistance from the PyTorch community if the issue is confirmed to be related to the input size.
  • Check if there are any existing issues or discussions related to DTensor and replicated indices that may provide insight into the problem.

Example

No specific code example can be provided without further information, but the investigation should involve modifying the input size and shape to observe the effect on the output behavior.

Notes

The root cause of the issue is unclear, and further investigation is needed to determine the relationship between the input size and the output behavior. The provided information suggests that the issue may be related to the input size, but more testing and verification are required to confirm this hypothesis.

Recommendation

Apply a workaround by ensuring that the input size to the DTensor operation does not exceed the threshold beyond which the output becomes sharded. This may involve modifying the input data or adjusting the model architecture to avoid large input sizes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix [DTensor] Inconsistent output placements of sharded DTensor indexing [7 comments, 4 participants]