pytorch/pytorch

LocalTensorMode: all_to_all_single crashes with uneven split sizes

Closed

#177,371 opened on Mar 13, 2026

 (1 comment) (1 reaction) (0 assignees)Python (28,709 forks)batch import
bot-triagedgood first issueoncall: distributedoncall: distributed infraptd-bot-triaged

Repository metrics

Stars
 (102,187 stars)
PR merge metrics
 (Avg merge 1d 10h) (42 merged PRs in 30d)

Description

🐛 Describe the bug

Description

LocalTensorMode's all_to_all_single implementation crashes when using uneven split sizes. It tries to reshape a tensor to an incompatible shape.

Reproduction

import torch                                                                                                                                                                                                       
import torch.distributed as dist                                                                                                                                                                                   
from torch.distributed._local_tensor import LocalTensor, LocalTensorMode                                                                                                                                           
from torch.distributed._local_tensor._testing import FakeStore                                                                                                                                                     
                                                                                                                                                                                                                   
WORLD_SIZE = 3                                                                                                                                                                                                     
                                                                                                                                                                                                                   
store = FakeStore()                                                                                                                                                                                                
dist.init_process_group("fake", rank=0, world_size=WORLD_SIZE, store=store)                                                                                                                                        
pg = dist.new_group(range(WORLD_SIZE), backend="fake")                                                                                                                                                             
                                                                                                                                                                                                                   
mode = LocalTensorMode(list(range(WORLD_SIZE)))                                                                                                                                                                    
with mode:                                                                                                                                                                                                         
    x = mode.rank_map(                                                                                                                                                                                             
        lambda r: torch.arange(24, dtype=torch.float).reshape(6, 4) + r * 100                                                                                                                                      
    )                                                                                                                                                                                                              
                                                                                                                                                                                                                   
    output_split_sizes = [3, 2, 1]                                                                                                                                                                                 
    input_split_sizes = [2, 2, 2]                                                                                                                                                                                  
                                                                                                                                                                                                                   
    output = x.new_empty([sum(output_split_sizes)] + list(x.shape[1:]))                                                                                                                                            
    dist.all_to_all_single(                                                                                                                                                                                        
        output,                                                                                                                                                                                                    
        x,                                                                                                                                                                                                         
        output_split_sizes=output_split_sizes,                                                                                                                                                                     
        input_split_sizes=input_split_sizes,                                                                                                                                                                       
        group=pg,                                                                                                                                                                                                  
    )                                                                                                                                                                                                              
                                                                                                                                                                                                                   
Error                                                                                                                                                                                                              
                                                                                                                                                                                                                   
RuntimeError: shape '[3, 4]' is invalid for input of size 8                                                                                                                                                        
                                                                                                                                                                                                                   
at torch/distributed/_local_tensor/_c10d.py in _local_functional_all_to_all_single, where it attempts:                                                                                                             
if split_tensor.size() != output_section.size():                                                                                                                                                                   
    split_tensor = split_tensor.view(output_section.size())                                                                                                                                                        
                                                                                                                                                                                                                   
Expected Behavior                                                                                                                                                                                                  
                                                                                                                                                                                                                   
all_to_all_single with uneven split sizes should work correctly in LocalTensorMode, simulating the data exchange across ranks the same way dist.all_to_all (list-based) does.                                      
                                                                                                                                                                                                                   


### Versions

Collecting environment information...
PyTorch version: 2.10.0a0+git366b450
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: CentOS Stream 9 (x86_64)
GCC version: (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14)
Clang version: Could not collect
CMake version: version 3.30.2
Libc version: glibc-2.34

Python version: 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:43:22) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-6.4.3-0_fbk20_zion_2830_g3e5ab162667d-x86_64-with-glibc2.34
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: 
GPU 0: NVIDIA H100
GPU 1: NVIDIA H100
GPU 2: NVIDIA H100
GPU 3: NVIDIA H100
GPU 4: NVIDIA H100
GPU 5: NVIDIA H100
GPU 6: NVIDIA H100
GPU 7: NVIDIA H100

Nvidia driver version: 535.183.06
cuDNN version: Probably one of the following:
/usr/lib64/libcudnn.so.8.9.7
/usr/lib64/libcudnn_adv_infer.so.8.9.7
/usr/lib64/libcudnn_adv_train.so.8.9.7
/usr/lib64/libcudnn_cnn_infer.so.8.9.7
/usr/lib64/libcudnn_cnn_train.so.8.9.7
/usr/lib64/libcudnn_ops_infer.so.8.9.7
/usr/lib64/libcudnn_ops_train.so.8.9.7
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:                      52 bits physical, 57 bits virtual
Byte Order:                         Little Endian
CPU(s):                             384
On-line CPU(s) list:                0-383
Vendor ID:                          AuthenticAMD
Model name:                         AMD EPYC 9654 96-Core Processor
CPU family:                         25
Model:                              17
Thread(s) per core:                 2
Core(s) per socket:                 96
Socket(s):                          2
Stepping:                           1
Frequency boost:                    enabled
CPU(s) scaling MHz:                 98%
CPU max MHz:                        3707.8120
CPU min MHz:                        1500.0000
BogoMIPS:                           4792.43
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                     AMD-V
L1d cache:                          6 MiB (192 instances)
L1i cache:                          6 MiB (192 instances)
L2 cache:                           192 MiB (192 instances)
L3 cache:                           768 MiB (24 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-95,192-287
NUMA node1 CPU(s):                  96-191,288-383
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 Retbleed:             Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Vulnerable: eIBRS with unprivileged eBPF
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] ncclx_trainer_context==0.0.0
[pip3] numpy==1.26.4
[pip3] optree==0.17.0
[pip3] torch==2.10.0a0+git366b450
[pip3] torchaudio==2.6.0a0+ea5de17
[pip3] torchcodec==0.5.0a0
[pip3] torchcomms==0.1.0
[pip3] torchcomms_mccl==0.0.1
[pip3] torchdata==0.11.0
[pip3] torchvision==0.25.0a0+617079d
[pip3] triton==3.4.0+git3f1f55e0
[conda] mkl                       2024.0.0         ha957f24_49657    conda-forge
[conda] mkl-include               2024.0.0         ha957f24_49657    conda-forge
[conda] nccl                      2.27.100             0a78bfb4_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea
[conda] ncclx-trainer-context     0.0.0                    pypi_0    pypi
[conda] numpy                     1.26.4          py312h2809609_0    main
[conda] numpy-base                1.26.4          py312he1a6c75_0    main
[conda] optree                    0.17.0                   pypi_0    pypi
[conda] pytorch                   2.10.0               366b4507_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea
[conda] tbb                       2021.8.0             hf52228f_0    conda-forge
[conda] torchaudio                2.5.0a0              ea5de177_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea
[conda] torchcodec                trunk                cfd1d4a0_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea
[conda] torchcomms                trunk                0a78bfb4_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea
[conda] torchdata                 0.11.0                   pypi_0    pypi
[conda] torchvision               0.20.0a0             617079d9_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea
[conda] triton                    3.5.0                3f1f55e0_0    https://interncache-all.fbcdn.net/manifold/conda_pkgs/tree/channels/81ce7a030675bdca3f03a350097bf7d3f36ec17e128c39b33ee935ea145c2989_64b7fb40243ea


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

Contributor guide