pytorch - ✅(Solved) Fix Batching rule not implemented for `aten::view.dtype` [1 pull requests, 1 comments, 1 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#180727Fetched 2026-04-18 05:51:22
View on GitHub
Comments
1
Participants
1
Timeline
40
Reactions
0
Author
Participants
Timeline (top)
mentioned ×16subscribed ×16labeled ×6commented ×1

Error Message

Traceback (most recent call last): File "bug.py", line 7, in <module> view(torch.empty(1, 1)) ~~~~^^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_functorch/apis.py", line 220, in wrapped return vmap_impl( # pyrefly: ignore[bad-argument-type] ...<6 lines>... **kwargs, ) File "/.../lib/python3.14/site-packages/torch/_functorch/vmap.py", line 316, in vmap_impl return _flat_vmap( func, ...<6 lines>... **kwargs, ) File "/.../lib/python3.14/site-packages/torch/_functorch/vmap.py", line 507, in _flat_vmap batched_outputs = func(*batched_inputs, **kwargs) File "bug.py", line 5, in view return t.view(torch.uint8) ~~~~~~^^^^^^^^^^^^^ RuntimeError: Batching rule not implemented for aten::view.dtype; the fallback path doesn't work on out= or view ops.

Fix Action

Fixed

PR fix notes

PR #180728: Add batching rule for aten::view.dtype

Description (problem / solution / changelog)

Closes #180727.

Changed files

  • aten/src/ATen/functorch/BatchRulesViews.cpp (modified, +15/-0)
  • test/functorch/test_vmap.py (modified, +11/-0)

Code Example

import torch

@torch.vmap
def view(t: torch.Tensor) -> torch.Tensor:
    return t.view(torch.uint8)

view(torch.empty(1, 1))

---

Traceback (most recent call last):
  File "bug.py", line 7, in <module>
    view(torch.empty(1, 1))
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_functorch/apis.py", line 220, in wrapped
    return vmap_impl(
        # pyrefly: ignore[bad-argument-type]
    ...<6 lines>...
        **kwargs,
    )
  File "/.../lib/python3.14/site-packages/torch/_functorch/vmap.py", line 316, in vmap_impl
    return _flat_vmap(
        func,
    ...<6 lines>...
        **kwargs,
    )
  File "/.../lib/python3.14/site-packages/torch/_functorch/vmap.py", line 507, in _flat_vmap
    batched_outputs = func(*batched_inputs, **kwargs)
  File "bug.py", line 5, in view
    return t.view(torch.uint8)
           ~~~~~~^^^^^^^^^^^^^
RuntimeError: Batching rule not implemented for aten::view.dtype; the fallback path doesn't work on out= or view ops.

---

Collecting environment information...
PyTorch version: 2.13.0.dev20260417
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 26.3.1 (arm64)
GCC version: Could not collect
Clang version: 17.0.0 (clang-1700.6.3.2)
CMake version: version 4.2.3
Libc version: N/A

Python version: 3.14.2 (v3.14.2:df793163d58, Dec  5 2025, 12:18:06) [Clang 16.0.0 (clang-1600.0.26.6)] (64-bit runtime)
Python platform: macOS-26.3.1-arm64-arm-64bit-Mach-O
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Apple M4 Pro

Versions of relevant libraries:
[pip3] Could not collect
[conda] Could not collect
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

import torch

@torch.vmap
def view(t: torch.Tensor) -> torch.Tensor:
    return t.view(torch.uint8)

view(torch.empty(1, 1))

Error logs

Traceback (most recent call last):
  File "bug.py", line 7, in <module>
    view(torch.empty(1, 1))
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_functorch/apis.py", line 220, in wrapped
    return vmap_impl(
        # pyrefly: ignore[bad-argument-type]
    ...<6 lines>...
        **kwargs,
    )
  File "/.../lib/python3.14/site-packages/torch/_functorch/vmap.py", line 316, in vmap_impl
    return _flat_vmap(
        func,
    ...<6 lines>...
        **kwargs,
    )
  File "/.../lib/python3.14/site-packages/torch/_functorch/vmap.py", line 507, in _flat_vmap
    batched_outputs = func(*batched_inputs, **kwargs)
  File "bug.py", line 5, in view
    return t.view(torch.uint8)
           ~~~~~~^^^^^^^^^^^^^
RuntimeError: Batching rule not implemented for aten::view.dtype; the fallback path doesn't work on out= or view ops.

Versions

Collecting environment information...
PyTorch version: 2.13.0.dev20260417
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 26.3.1 (arm64)
GCC version: Could not collect
Clang version: 17.0.0 (clang-1700.6.3.2)
CMake version: version 4.2.3
Libc version: N/A

Python version: 3.14.2 (v3.14.2:df793163d58, Dec  5 2025, 12:18:06) [Clang 16.0.0 (clang-1600.0.26.6)] (64-bit runtime)
Python platform: macOS-26.3.1-arm64-arm-64bit-Mach-O
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Apple M4 Pro

Versions of relevant libraries:
[pip3] Could not collect
[conda] Could not collect

cc @zou3519 @Chillee @samdow @kshitij12345

extent analysis

TL;DR

The issue is likely due to the torch.vmap decorator not supporting the view method with a dtype argument, and a workaround is to remove the torch.vmap decorator or modify the view method to not use the dtype argument.

Guidance

  • The error message indicates that the batching rule is not implemented for the aten::view.dtype operation, which suggests that the issue is related to the torch.vmap decorator.
  • Try removing the torch.vmap decorator from the view function to see if it resolves the issue.
  • If the torch.vmap decorator is necessary, consider modifying the view method to not use the dtype argument, or use a different method that is supported by torch.vmap.
  • Verify that the issue is resolved by running the code without the torch.vmap decorator or with the modified view method.

Example

import torch

def view(t: torch.Tensor) -> torch.Tensor:
    return t.view(torch.uint8)

view(torch.empty(1, 1))

Notes

The issue may be specific to the version of PyTorch being used (2.13.0.dev20260417), and it's possible that the issue has been resolved in a later version.

Recommendation

Apply workaround: Remove the torch.vmap decorator or modify the view method to not use the dtype argument, as this is the most straightforward way to resolve the issue without upgrading to a potentially unstable version of PyTorch.

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 - ✅(Solved) Fix Batching rule not implemented for `aten::view.dtype` [1 pull requests, 1 comments, 1 participants]