This document is relevant for: Trn2, Trn3
Supported PyTorch APIs and operators#
This topic explains which PyTorch APIs run on TorchNeuron, how the
torch-neuronx compatibility table classifies them, and how to find out
which operators in your own model run on CPU instead of on the device. The
per-API detail lives in the
torch-neuronx operator compatibility table,
which is regenerated for each torch-neuronx release.
Applies to#
torch-neuronx(TorchNeuron) on Trn2 and Trn3 Trainium instances.Eager mode and
torch.compile(backend="neuron").
How support is classified#
The compatibility table lists the public PyTorch API surface, namespace by
namespace (torch, torch.Tensor, torch.nn, torch.distributed,
and so on), and marks each entry with one of three values:
Value |
Meaning |
|---|---|
|
Supported on Neuron. The |
|
Works, but the named ATen operator runs on the CPU and the result is copied
back to the Neuron device. The model runs; the operation is slower. The
|
|
Not supported on Neuron. Quantized operator variants, non-Neuron backends
under |
Support by namespace#
Counts below are taken from the compatibility table as published with
torch-neuronx 2.34.0. Later releases change the numbers; the table on
GitHub is the source of record.
Section |
APIs listed |
|
|
|
|---|---|---|---|---|
|
472 |
362 |
94 |
16 |
|
359 |
312 |
39 |
8 |
|
112 |
75 |
37 |
0 |
|
2 |
2 |
0 |
0 |
|
530 |
393 |
110 |
27 |
Tensor Attributes |
4 |
4 |
0 |
0 |
|
62 |
57 |
2 |
3 |
|
21 |
18 |
0 |
3 |
|
43 |
13 |
0 |
30 |
|
90 |
84 |
3 |
3 |
|
9 |
9 |
0 |
0 |
|
45 |
45 |
0 |
0 |
|
14 |
14 |
0 |
0 |
|
9 |
9 |
0 |
0 |
|
31 |
31 |
0 |
0 |
|
68 |
37 |
31 |
0 |
|
10 |
10 |
0 |
0 |
|
41 |
8 |
33 |
0 |
|
11 |
10 |
1 |
0 |
|
56 |
13 |
43 |
0 |
|
15 |
14 |
1 |
0 |
|
60 |
58 |
1 |
1 |
DDP Communication Hooks |
17 |
13 |
2 |
2 |
Pipeline Parallelism |
21 |
21 |
0 |
0 |
Quantization |
219 |
139 |
36 |
44 |
|
6 |
6 |
0 |
0 |
|
98 |
90 |
0 |
8 |
|
19 |
19 |
0 |
0 |
Type Info |
2 |
2 |
0 |
0 |
Removed APIs |
8 |
0 |
0 |
8 |
All sections |
2454 |
1868 |
433 |
153 |
CPU_FALLBACK entries are spread across the table. The largest groups by
count are torch.Tensor (110), torch APIs (94), torch.special (43),
torch.nn (39), and torch.nn.functional (37). In proportion to their
size, torch.linalg (33 of 41), torch.special (43 of 56), and
torch.distributions (31 of 68) rely on the CPU fallback most. Of the 153
N entries, 44 are in Quantization and 30 are non-Neuron backends under
torch.backends.
What happens to an unsupported operator#
The behavior depends on the execution path:
Eager mode. An ATen operator with no Neuron implementation runs on the CPU: inputs are copied to the host, the operator runs there, and the result is copied back. The model keeps running. By default, an operator that fails on the device also falls back to CPU; set
TORCH_NEURONX_FALLBACK_ONLY_FOR_UNIMPLEMENTED_OPS=1to raise execution errors instead and fall back only for operators that have no Neuron implementation. Some operators also route specific inputs to the CPU on purpose, for exampletopkonint64inputs; thelimitationscolumn of the compatibility table records these cases, and they run on the CPU regardless of the variable. See TorchNeuron environment variables.torch.compile. With
backend="neuron", TorchDynamo breaks the graph at an operator the backend cannot lower, in addition to the breaks it inserts for constructs it cannot capture. Each captured segment compiles independently, and the operator at the break runs through eager dispatch, so it falls back to the CPU if it has no Neuron implementation, as in eager mode. Withfullgraph=True, such an operator raises an error (or a warning, for some operators) instead of breaking the graph. If an operator the backend cannot lower still reaches compilation inside a captured graph, compilation fails by default; setTORCH_NEURONX_DISABLE_FALLBACK_EXECUTION=0to run the original graph eagerly instead. See torch.compile backend reference.
Find the fallbacks in your model#
torch-neuronx tracks, per process, which operators ran on the device and
which ran on the CPU. Clear the counters, run one step, and read them back:
import torch
import torch_neuronx
model = MyModel().to("neuron")
x = torch.randn(8, 1024, device="neuron")
torch_neuronx.clear_op_tracking()
model(x)
torch.neuron.synchronize()
print("Ran on Neuron:", torch_neuronx.get_executed_ops())
print("Ran on CPU: ", torch_neuronx.get_fallback_ops())
get_fallback_ops() returns the ATen operator names that fell back, in the
aten:: namespace with the overload name where one exists. Operators that
torch.compile left out of a graph and that then fell back in eager dispatch
are included. A name with a bracketed suffix, such as
aten::copy_[noncontiguous_scatter_cpu_bounce] or
<op>[epilogue_cpu_roundtrip], marks an operator that ran on the
device but moved a non-contiguous input or output through the host; it is not a
whole-operator fallback. Look each bare name up in the compatibility table to
see whether a supported alternative exists.
A torch.profiler trace captured with Neuron Explorer also shows the host
time these round trips cost; see Capture PyTorch profiles with Neuron Explorer.