pytorch - 💡(How to fix) Fix torch.meshgrid raises RuntimeError if no arrays passed [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#181576Fetched 2026-04-28 06:24:38
View on GitHub
Comments
1
Participants
2
Timeline
60
Reactions
0
Author
Participants
Timeline (top)
mentioned ×27subscribed ×27labeled ×5commented ×1

Code Example

import torch

torch.meshgrid()

---

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

OS: macOS 26.4.1 (arm64)
GCC version: Could not collect
Clang version: 22.1.4
CMake version: version 4.3.2
Libc version: N/A

Python version: 3.14.4 (main, Apr 14 2026, 14:46:33) [Clang 22.1.3 ] (64-bit runtime)
Python platform: macOS-26.4.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 M1 Pro

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

🐛 Describe the bug

import torch

torch.meshgrid()

This raises a RuntimeError which is inconsistent with the documented behaviour and the array-api-standard: https://github.com/data-apis/array-api-compat/issues/424

Versions

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

OS: macOS 26.4.1 (arm64)
GCC version: Could not collect
Clang version: 22.1.4
CMake version: version 4.3.2
Libc version: N/A

Python version: 3.14.4 (main, Apr 14 2026, 14:46:33) [Clang 22.1.3 ] (64-bit runtime)
Python platform: macOS-26.4.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 M1 Pro

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

cc @malfet @mruberry @rgommers @asmeurer @leofang @AnirudhDagar @asi1024 @emcastillo @kmaehashi

extent analysis

TL;DR

The issue can be resolved by passing input tensors to the torch.meshgrid() function, as the error is likely due to the function being called without any arguments.

Guidance

  • The torch.meshgrid() function requires input tensors, so passing these tensors may resolve the RuntimeError.
  • Verify that the input tensors are correctly defined and passed to the torch.meshgrid() function.
  • Check the PyTorch documentation for the correct usage of torch.meshgrid() and ensure that the code aligns with the documented behavior.
  • If the issue persists, consider testing the code with a different PyTorch version or environment to rule out any version-specific bugs.

Example

import torch

x = torch.linspace(0, 10, 5)
y = torch.linspace(0, 10, 5)
xx, yy = torch.meshgrid(x, y)

Notes

The provided code snippet only shows the function call without any arguments, which is likely the cause of the error. The actual fix may depend on the specific use case and the desired output of the torch.meshgrid() function.

Recommendation

Apply workaround: The issue can likely be resolved by passing the required input tensors to the torch.meshgrid() function, as shown in the example code snippet.

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