pytorch - ๐Ÿ’ก(How to fix) Fix Unexpected storage from MSE loss output

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โ€ฆ

Code Example

import torch
import torch.nn.functional as F

x = torch.rand(3, 256, 256)
recon = torch.rand(3, 256, 256)

l2_loss = F.mse_loss(x, recon, reduction='mean')
print(l2_loss)
print(l2_loss.untyped_storage().nbytes())
print(l2_loss._base)

---

tensor(0.1674)
786432
None
RAW_BUFFERClick to expand / collapse

๐Ÿ› Describe the bug

MSE loss output takes up more storage than expected even though its not a view.

import torch
import torch.nn.functional as F

x = torch.rand(3, 256, 256)
recon = torch.rand(3, 256, 256)

l2_loss = F.mse_loss(x, recon, reduction='mean')
print(l2_loss)
print(l2_loss.untyped_storage().nbytes())
print(l2_loss._base)

Output:

tensor(0.1674)
786432
None

This behavior doesn't occur with other reductions and some other losses (e.g., F.l1_loss).

Versions

PyTorch version: 2.9.0 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

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

Python version: 3.11.13 (main, Jun 3 2025, 18:38:25) [Clang 17.0.0 (clang-1700.0.13.3)] (64-bit runtime) Python platform: macOS-15.6.1-arm64-arm-64bit 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 M3

Versions of relevant libraries: [pip3] mypy_extensions==1.1.0 [pip3] numpy==2.2.5 [pip3] torch==2.9.0 [pip3] torch-fidelity==0.3.0 [pip3] torchaudio==2.9.0 [pip3] torchcodec==0.9.1 [pip3] torchvision==0.24.0 [pip3] torchviz==0.0.3 [conda] Could not collect

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 Unexpected storage from MSE loss output