pytorch - ✅(Solved) Fix `vmap(f, out_dims=-1)` crashes with corrupted shape when output is independent of vmapped input [1 pull requests, 1 comments, 2 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#178425Fetched 2026-04-08 01:30:29
View on GitHub
Comments
1
Participants
2
Timeline
27
Reactions
0
Author
Participants
Timeline (top)
mentioned ×8subscribed ×8labeled ×5cross-referenced ×2

Error Message

torch.Size([3, 2]) torch.Size([1, 2, 3]) Traceback (most recent call last): File "mwe.py", line 16, in <module> print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... File ".../torch/_functorch/predispatch.py", line 56, in _remove_batch_dim res = _remove_batch_dim_impl(self, level, batch_size, out_dim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: expand(torch.FloatTensor{[2, 3]}, size=[34359738370]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

Fix Action

Fix / Workaround

Output:

torch.Size([3, 2])
torch.Size([1, 2, 3])
Traceback (most recent call last):
  File "mwe.py", line 16, in <module>
    print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ...
  File ".../torch/_functorch/predispatch.py", line 56, in _remove_batch_dim
    res = _remove_batch_dim_impl(self, level, batch_size, out_dim)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: expand(torch.FloatTensor{[2, 3]}, size=[34359738370]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

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):                                  64
On-line CPU(s) list:                     0-63
Vendor ID:                               GenuineIntel
Model name:                              Intel(R) Xeon(R) Silver 4314 CPU @ 2.40GHz
CPU family:                              6
Model:                                   106
Thread(s) per core:                      2
Core(s) per socket:                      16
Socket(s):                               2
Stepping:                                6
CPU(s) scaling MHz:                      42%
CPU max MHz:                             3400.0000
CPU min MHz:                             800.0000
BogoMIPS:                                4800.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 pni pclmulqdq dtes64 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 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow 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 wbnoinvd dtherm ida arat pln pts vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization:                          VT-x
L1d cache:                               1.5 MiB (32 instances)
L1i cache:                               1 MiB (32 instances)
L2 cache:                                40 MiB (32 instances)
L3 cache:                                48 MiB (2 instances)
NUMA node(s):                            2
NUMA node0 CPU(s):                       0-15,32-47
NUMA node1 CPU(s):                       16-31,48-63
Vulnerability Gather data sampling:      Mitigation; Microcode
Vulnerability Indirect target selection: Vulnerable
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Mitigation; Clear CPU buffers; SMT vulnerable
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
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

PR fix notes

PR #178495: [functorch] Fix vmap out_dims=-1 crash with input-independent output

Description (problem / solution / changelog)

What does this PR do?

Fix a crash when calling vmap(f, out_dims=-1) where f's output does not depend on the vmapped input.

Root Cause

The root cause was a broken shape calculation in the C++ _remove_batch_dim function. The line expanded_sizes.insert(expanded_sizes.begin() + out_dim, batch_size) computed an invalid insertion index for out_dims=-1 with input-independent outputs, leading to a corrupted tensor shape.

Solution

This change fixes the issue by adding proper dimension wrapping: Calculate the number of dimensions of expanded_sizes, compute a valid wrapped dimension, insert the batch size at the wrapped index, then expand the tensor with the corrected shape.

    int64_t ndim = expanded_sizes.size();
    int64_t wrapped_out_dim = at::maybe_wrap_dim(out_dim, ndim + 1);
    expanded_sizes.insert(expanded_sizes.begin() + wrapped_out_dim, batch_size);
    auto result = self.unsqueeze(wrapped_out_dim).expand_symint(expanded_sizes);

Related Issue

Fixes #178425

Test Cases

Added a unit test to verify the fix (in test/functorch/test_vmap.py/TestVmapAPI):

    def test_vmap_out_dims_negative_one_independent_output(self):
        t = torch.randn(2, 3)
        t_scalar = torch.randn([])

        def f_dep(x):
            return x

        def f_ind(x):
            return t

        def f_ind_scalar(x):
            return t_scalar

        res_dep_neg1 = vmap(f_dep, in_dims=0, out_dims=-1)(t)
        self.assertEqual(res_dep_neg1.shape, torch.Size([3, 2]))

        res_ind_neg1 = vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1))
        self.assertEqual(res_ind_neg1.shape, torch.Size([2, 3, 1]))

        res_ind_scalar_neg1 = vmap(f_ind_scalar, in_dims=0, out_dims=-1)(torch.zeros(5))
        self.assertEqual(res_ind_scalar_neg1.shape, torch.Size([5]))
import torch
from torch.func import vmap

t = torch.randn(2, 3)

# Dependent output: out_dims=-1 works
def f_dep(x):
    return x

print(vmap(f_dep, in_dims=0, out_dims=-1)(t).shape)  # (3, 2) ✓

# Independent output: out_dims=0 works
def f_ind(x):
    return t

print(vmap(f_ind, in_dims=0, out_dims=0)(torch.zeros(1)).shape)   # (1, 2, 3) ✓

# Independent output: out_dims=-1 crashes
print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape)  # expected (2, 3, 1)

torch.Size([3, 2])
torch.Size([1, 2, 3])
torch.Size([2, 3, 1])

Changed files

  • test/functorch/test_vmap.py (modified, +22/-0)
  • torch/csrc/functorch/init.cpp (modified, +4/-2)

Code Example

import torch
from torch.func import vmap

t = torch.randn(2, 3)

# Dependent output: out_dims=-1 works
def f_dep(x):
    return x

print(vmap(f_dep, in_dims=0, out_dims=-1)(t).shape)  # (3, 2)
# Independent output: out_dims=0 works
def f_ind(x):
    return t

print(vmap(f_ind, in_dims=0, out_dims=0)(torch.zeros(1)).shape)   # (1, 2, 3)
# Independent output: out_dims=-1 crashes
print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape)  # expected (2, 3, 1)

---

torch.Size([3, 2])
torch.Size([1, 2, 3])
Traceback (most recent call last):
  File "mwe.py", line 16, in <module>
    print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ...
  File ".../torch/_functorch/predispatch.py", line 56, in _remove_batch_dim
    res = _remove_batch_dim_impl(self, level, batch_size, out_dim)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: expand(torch.FloatTensor{[2, 3]}, size=[34359738370]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

---

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

OS: Ubuntu 24.04.3 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.39

Python version: 3.11.15 | packaged by conda-forge | (main, Mar  5 2026, 16:45:40) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-100-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: 
GPU 0: NVIDIA RTX A6000
GPU 1: NVIDIA RTX A6000

Nvidia driver version: 580.95.05
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):                                  64
On-line CPU(s) list:                     0-63
Vendor ID:                               GenuineIntel
Model name:                              Intel(R) Xeon(R) Silver 4314 CPU @ 2.40GHz
CPU family:                              6
Model:                                   106
Thread(s) per core:                      2
Core(s) per socket:                      16
Socket(s):                               2
Stepping:                                6
CPU(s) scaling MHz:                      42%
CPU max MHz:                             3400.0000
CPU min MHz:                             800.0000
BogoMIPS:                                4800.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 pni pclmulqdq dtes64 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 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow 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 wbnoinvd dtherm ida arat pln pts vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization:                          VT-x
L1d cache:                               1.5 MiB (32 instances)
L1i cache:                               1 MiB (32 instances)
L2 cache:                                40 MiB (32 instances)
L3 cache:                                48 MiB (2 instances)
NUMA node(s):                            2
NUMA node0 CPU(s):                       0-15,32-47
NUMA node1 CPU(s):                       16-31,48-63
Vulnerability Gather data sampling:      Mitigation; Microcode
Vulnerability Indirect target selection: Vulnerable
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Mitigation; Clear CPU buffers; SMT vulnerable
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
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Versions of relevant libraries:
[pip3] backpack-for-pytorch==1.7.1
[pip3] curvlinops-for-pytorch==0.0.0
[pip3] numpy==2.4.3
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] torch==2.10.0
[pip3] torchvision==0.25.0
[pip3] triton==3.6.0
[conda] backpack-for-pytorch      1.7.1                    pypi_0    pypi
[conda] curvlinops-for-pytorch    0.0.0                    pypi_0    pypi
[conda] numpy                     2.4.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] torch                     2.10.0                   pypi_0    pypi
[conda] torchvision               0.25.0                   pypi_0    pypi
[conda] triton                    3.6.0                    pypi_0    pypi
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

vmap(f, out_dims=-1) crashes when f's output does not depend on the vmapped input. The C++ _remove_batch_dim produces a corrupted tensor shape (34359738370 = 0x800000002). The same call works with out_dims=0, and out_dims=-1 works when the output depends on the input.

MWE:

import torch
from torch.func import vmap

t = torch.randn(2, 3)

# Dependent output: out_dims=-1 works
def f_dep(x):
    return x

print(vmap(f_dep, in_dims=0, out_dims=-1)(t).shape)  # (3, 2) ✓

# Independent output: out_dims=0 works
def f_ind(x):
    return t

print(vmap(f_ind, in_dims=0, out_dims=0)(torch.zeros(1)).shape)   # (1, 2, 3) ✓

# Independent output: out_dims=-1 crashes
print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape)  # expected (2, 3, 1)

Output:

torch.Size([3, 2])
torch.Size([1, 2, 3])
Traceback (most recent call last):
  File "mwe.py", line 16, in <module>
    print(vmap(f_ind, in_dims=0, out_dims=-1)(torch.zeros(1)).shape)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ...
  File ".../torch/_functorch/predispatch.py", line 56, in _remove_batch_dim
    res = _remove_batch_dim_impl(self, level, batch_size, out_dim)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: expand(torch.FloatTensor{[2, 3]}, size=[34359738370]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

Versions

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

OS: Ubuntu 24.04.3 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.39

Python version: 3.11.15 | packaged by conda-forge | (main, Mar  5 2026, 16:45:40) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-100-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: 
GPU 0: NVIDIA RTX A6000
GPU 1: NVIDIA RTX A6000

Nvidia driver version: 580.95.05
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):                                  64
On-line CPU(s) list:                     0-63
Vendor ID:                               GenuineIntel
Model name:                              Intel(R) Xeon(R) Silver 4314 CPU @ 2.40GHz
CPU family:                              6
Model:                                   106
Thread(s) per core:                      2
Core(s) per socket:                      16
Socket(s):                               2
Stepping:                                6
CPU(s) scaling MHz:                      42%
CPU max MHz:                             3400.0000
CPU min MHz:                             800.0000
BogoMIPS:                                4800.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 pni pclmulqdq dtes64 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 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow 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 wbnoinvd dtherm ida arat pln pts vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization:                          VT-x
L1d cache:                               1.5 MiB (32 instances)
L1i cache:                               1 MiB (32 instances)
L2 cache:                                40 MiB (32 instances)
L3 cache:                                48 MiB (2 instances)
NUMA node(s):                            2
NUMA node0 CPU(s):                       0-15,32-47
NUMA node1 CPU(s):                       16-31,48-63
Vulnerability Gather data sampling:      Mitigation; Microcode
Vulnerability Indirect target selection: Vulnerable
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Mitigation; Clear CPU buffers; SMT vulnerable
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
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Versions of relevant libraries:
[pip3] backpack-for-pytorch==1.7.1
[pip3] curvlinops-for-pytorch==0.0.0
[pip3] numpy==2.4.3
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] torch==2.10.0
[pip3] torchvision==0.25.0
[pip3] triton==3.6.0
[conda] backpack-for-pytorch      1.7.1                    pypi_0    pypi
[conda] curvlinops-for-pytorch    0.0.0                    pypi_0    pypi
[conda] numpy                     2.4.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] torch                     2.10.0                   pypi_0    pypi
[conda] torchvision               0.25.0                   pypi_0    pypi
[conda] triton                    3.6.0                    pypi_0    pypi

cc @zou3519 @Chillee @samdow @kshitij12345

extent analysis

Fix Plan

To fix the issue with vmap(f, out_dims=-1) crashing when the output of f does not depend on the vmapped input, we need to modify the vmap function call to handle this case correctly.

Here are the steps to fix the issue:

  • Check if the output of f depends on the input. If not, use out_dims=0 instead of out_dims=-1.
  • Modify the vmap function to handle the case where the output does not depend on the input.

Example code:

import torch
from torch.func import vmap

def f_ind(x):
    return torch.randn(2, 3)  # output does not depend on input

def f_dep(x):
    return x  # output depends on input

t = torch.randn(2, 3)

# Use out_dims=0 for independent output
print(vmap(f_ind, in_dims=0, out_dims=0)(torch.zeros(1)).shape)

# Use out_dims=-1 for dependent output
print(vmap(f_dep, in_dims=0, out_dims=-1)(t).shape)

Verification

To verify that the fix worked, run the example code and check that it does not crash and produces the expected output.

Extra Tips

  • Always check the documentation of the vmap function to ensure that you are using it correctly.
  • Be careful when using out_dims=-1, as it can cause issues if the output does not depend on the input.
  • Consider adding error handling to your code to catch and handle any potential errors that may occur when using vmap.

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