pytorch - 💡(How to fix) Fix `torch.export.export` raises `RuntimeError: Unhandled FakeTensor Device Propagation` for CUDA/MPS example inputs instead of a clear user-facing error

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…

Error Message

import torch

class TwoLayerMLP(torch.nn.Module): def init(self, d): super().init() self.fc1 = torch.nn.Linear(d, d) self.fc2 = torch.nn.Linear(d, d)

def forward(self, x):
    return self.fc2(torch.relu(self.fc1(x)))

d = 8 module = TwoLayerMLP(d) # parameters on CPU (default) example_input = torch.randn(1, d, device="cuda") # input on CUDA

print(f"module params device: {next(module.parameters()).device}") print(f"example input device: {example_input.device}")

try: ep = torch.export.export(module, (example_input,)) print(f"exported: {type(ep).name}") except Exception as e: print(f"{type(e).name}: {e}")

Reference: CPU export works fine

ep_cpu = torch.export.export(TwoLayerMLP(d), (torch.randn(1, d),)) print(f"cpu export: ok ({type(ep_cpu).name})")

Code Example

import torch

class TwoLayerMLP(torch.nn.Module):
    def __init__(self, d):
        super().__init__()
        self.fc1 = torch.nn.Linear(d, d)
        self.fc2 = torch.nn.Linear(d, d)

    def forward(self, x):
        return self.fc2(torch.relu(self.fc1(x)))

d = 8
module = TwoLayerMLP(d)                           # parameters on CPU (default)
example_input = torch.randn(1, d, device="cuda")  # input on CUDA

print(f"module params device: {next(module.parameters()).device}")
print(f"example input device: {example_input.device}")

try:
    ep = torch.export.export(module, (example_input,))
    print(f"exported: {type(ep).__name__}")
except Exception as e:
    print(f"{type(e).__name__}: {e}")

# Reference: CPU export works fine
ep_cpu = torch.export.export(TwoLayerMLP(d), (torch.randn(1, d),))
print(f"cpu export: ok ({type(ep_cpu).__name__})")

---

module params device: cpu
example input device: cuda:0
RuntimeError: Unhandled FakeTensor Device Propagation for aten.mm.default,
  found two different devices cpu, cuda:0
cpu export: ok (ExportedProgram)

---

module params device: cpu
example input device: cuda:0
ValueError: Module parameters are on cpu but example inputs are on cuda:0.
  Move the module to the target device before exporting:
  module = module.to('cuda') and re-run torch.export.export.
cpu export: ok (ExportedProgram)

---

# MPS repro
module = torch.nn.Linear(4, 4)                    # params on CPU
example_input = torch.randn(4, 4, device="mps")
torch.export.export(module, (example_input,))
# RuntimeError: Unhandled FakeTensor Device Propagation for aten.mm.default,
#   found two different devices cpu, mps:0

---

PyTorch version: 2.13.0.dev20260512+cu130
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.4 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 3.28.3
Libc version: glibc-2.39

Python version: 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.14.0-37-generic-x86_64-with-glibc2.39
Is CUDA available: True
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 5090
Nvidia driver version: 590.48.01

[pip3] numpy==2.4.4
[pip3] torch==2.13.0.dev20260512+cu130
[pip3] triton==3.7.0+git88b227e2
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.export.export raises an internal RuntimeError when the example inputs are on an accelerator device (CUDA or MPS) while the module parameters remain on CPU (the default for nn.Module). Instead of catching this mismatch at argument validation and providing a clear message, the error surfaces deep in FakeTensor device propagation with an opaque implementation-internal string.

Minimal reproducer

import torch

class TwoLayerMLP(torch.nn.Module):
    def __init__(self, d):
        super().__init__()
        self.fc1 = torch.nn.Linear(d, d)
        self.fc2 = torch.nn.Linear(d, d)

    def forward(self, x):
        return self.fc2(torch.relu(self.fc1(x)))

d = 8
module = TwoLayerMLP(d)                           # parameters on CPU (default)
example_input = torch.randn(1, d, device="cuda")  # input on CUDA

print(f"module params device: {next(module.parameters()).device}")
print(f"example input device: {example_input.device}")

try:
    ep = torch.export.export(module, (example_input,))
    print(f"exported: {type(ep).__name__}")
except Exception as e:
    print(f"{type(e).__name__}: {e}")

# Reference: CPU export works fine
ep_cpu = torch.export.export(TwoLayerMLP(d), (torch.randn(1, d),))
print(f"cpu export: ok ({type(ep_cpu).__name__})")

Observed output

module params device: cpu
example input device: cuda:0
RuntimeError: Unhandled FakeTensor Device Propagation for aten.mm.default,
  found two different devices cpu, cuda:0
cpu export: ok (ExportedProgram)

Expected output

module params device: cpu
example input device: cuda:0
ValueError: Module parameters are on cpu but example inputs are on cuda:0.
  Move the module to the target device before exporting:
  module = module.to('cuda') and re-run torch.export.export.
cpu export: ok (ExportedProgram)

Why this is a bug

Exporting a model for GPU deployment is a standard workflow. The error message "Unhandled FakeTensor Device Propagation for aten.mm.default" is an internal implementation detail that gives the user no actionable information. A proper validation error at the start of torch.export.export — before tracing begins — would tell the user exactly what to fix and how.

The same failure occurs on MPS:

# MPS repro
module = torch.nn.Linear(4, 4)                    # params on CPU
example_input = torch.randn(4, 4, device="mps")
torch.export.export(module, (example_input,))
# RuntimeError: Unhandled FakeTensor Device Propagation for aten.mm.default,
#   found two different devices cpu, mps:0

Crash statistics: 24 crashes on CUDA (out of ~48 inputs), 120 crashes on MPS (out of ~160 inputs), Specialized generator.

Versions

PyTorch version: 2.13.0.dev20260512+cu130
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.4 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 3.28.3
Libc version: glibc-2.39

Python version: 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.14.0-37-generic-x86_64-with-glibc2.39
Is CUDA available: True
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 5090
Nvidia driver version: 590.48.01

[pip3] numpy==2.4.4
[pip3] torch==2.13.0.dev20260512+cu130
[pip3] triton==3.7.0+git88b227e2

cc @chauhang @penguinwu @avikchaudhuri @zhxchen17 @tugsbayasgalan @angelayi @ydwu4

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