This document is relevant for: Inf1, Inf2, Trn1, Trn2, Trn3

Neuron Graph Compiler#

The Neuron Graph Compiler (neuronx-cc) compiles machine learning models into code for AWS Trainium and Inferentia2. It analyzes the model graph, applies hardware-specific optimizations, and writes a NEFF (Neuron Executable File Format) file that the Neuron Runtime loads and runs.

neuronx-cc supports NeuronCore-v2 through NeuronCore-v4: Trn2, Trn3, Trn1, Trn1n, and Inf2. It is the only current Neuron compiler.

You usually do not call the compiler directly. The framework calls it for you:

  • PyTorch: TorchNeuron compiles operations in eager mode, and compiles graphs that you capture with torch.compile(backend="neuron"). For training at scale, TorchTitan Neuron uses TorchNeuron.

  • JAX: JAX NeuronX gives the compiler an XLA HLO graph.

Note

neuron-cc, the compiler for Inf1 (NeuronCore-v1), is a retired component. For its archived documentation, see Neuron Compiler for Inf1 (neuron-cc, archived).

Key capabilities of the Neuron Graph Compiler include:

  • Performance optimization: Optionally converts FP32 operations to more efficient formats (BF16/FP16/TF32/FP8) with configurable precision-performance tradeoffs. By default, neuronx-cc compiles matrix multiplication operations in the model’s own datatype (--auto-cast=none), and --enable-mixed-precision-accumulation is enabled by default. These defaults changed in neuronx-cc 2.22.12471.0 (Neuron SDK 2.27.0); earlier versions cast FP32 matrix multiplication operations to BF16 by default. To enable BF16 casting for matrix multiplication operations, explicitly pass --auto-cast=matmult --auto-cast-type=bf16. See Mixed Precision and Performance-accuracy Tuning (neuronx-cc) for guidance.

  • Model-specific optimizations: Provides specialized optimizations for different model architectures: * Generic: Applies general optimizations suitable for all model types * Transformer: Implements specific optimizations for transformer-based architectures like BERT, GPT, and other attention-based models * U-Net: Applies specialized memory optimizations for U-Net architectures to prevent performance-impacting data transfers

  • Distributed workloads: Compiles the sharded graphs of distributed training and inference. For distributed training with TorchNeuron, see How to use torch.distributed on Neuron.

  • Advanced memory management: Optimizes memory usage for large models through techniques like model sharding across multiple NeuronCores, with configurable logical NeuronCore settings to control sharding degree.

  • Optimization levels: Provides multiple optimization levels (1-3) to balance compilation time against runtime performance, allowing users to choose the appropriate tradeoff for their workflow.

  • Mixed precision support: Offers fine-grained control over precision and performance through auto-casting options, supporting multiple numeric formats (FP32, TF32, FP16, BF16, FP8) with different strengths in dynamic range and numeric precision.

Note

The compiler’s default precision behavior changed in neuronx-cc 2.22.12471.0 (Neuron SDK 2.27.0). If you rely on default behavior and upgrade the SDK version, verify your --auto-cast settings. Models compiled without an explicit --auto-cast value now run matrix multiplication operations in FP32 instead of BF16, which can reduce inference throughput and increase compiled model size. To keep the earlier behavior, set --auto-cast=matmult --auto-cast-type=bf16 explicitly. See Mixed Precision and Performance-accuracy Tuning (neuronx-cc) for guidance.

The framework calls the compiler for you, so compilation is usually transparent. The compiler writes a NEFF file, which the Neuron Runtime loads and runs on Neuron devices. To pass compiler options from TorchNeuron, set NEURON_CC_FLAGS (see torch.compile backend reference).

Neuron Graph Compiler Component Release Notes

Review the Neuron Graph Compiler release notes for all versions of the Neuron SDK.

Compiler documentation#

About neuronx-cc

What the compiler does, how TorchNeuron and JAX call it, and the files it writes.

About compiler artifacts

The files that TorchNeuron and the compiler write: IR dumps, NEFF files, and compile caches.

CLI reference guide

The neuronx-cc command line, its options, and their valid values.

How to generate a NEFF file

Compile an XLA HLO graph into a NEFF file with neuronx-cc as a standalone tool.

Error code reference

Causes and fixes for compiler error codes.

Compiler FAQ

Frequently asked questions about neuronx-cc.

This document is relevant for: Inf1, Inf2, Trn1, Trn2, Trn3