.. meta::
   :description: The Neuron Graph Compiler (neuronx-cc) compiles PyTorch and JAX models into NEFF files for AWS Trainium (Trn2, Trn3) and Inferentia2. Find the CLI reference, how-tos, FAQ, and error codes.
   :keywords: Neuron Graph Compiler, neuronx-cc, NEFF, TorchNeuron, torch.compile, JAX, Trn2, Trn3, Inf2, AWS Neuron
   :date-modified: 2026-11-16

.. _neuron_cc:

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:** :ref:`TorchNeuron <about-pytorch-neuron>` compiles operations in eager mode, and compiles graphs that you capture with ``torch.compile(backend="neuron")``. For training at scale, :ref:`TorchTitan Neuron <torchtitan-neuron-landing>` uses TorchNeuron.
* **JAX:** :ref:`JAX NeuronX <jax-neuron-main>` 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 :ref:`neuron-cc-index`.

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 :ref:`neuronx-cc-training-mixed-precision` 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 :ref:`torchneuron-torch-distributed-guide`.

* **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 :ref:`neuronx-cc-training-mixed-precision` for guidance.

The framework calls the compiler for you, so compilation is usually transparent. The compiler writes a NEFF file, which the :doc:`Neuron Runtime </neuron-runtime/index>` loads and runs on Neuron devices. To pass compiler options from TorchNeuron, set ``NEURON_CC_FLAGS`` (see :ref:`torch-compile-ref`).

.. grid:: 1 
   :gutter: 3

   .. grid-item-card:: Neuron Graph Compiler Component Release Notes
      :link: /release-notes/components/compiler
      :link-type: doc

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

Compiler documentation
----------------------

.. grid:: 1 1 2 2
   :gutter: 3

   .. grid-item-card:: About neuronx-cc
      :link: /compiler/about-neuronx-cc
      :link-type: doc

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

   .. grid-item-card:: About compiler artifacts
      :link: neuronx-cc-artifacts-overview
      :link-type: ref

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

   .. grid-item-card:: CLI reference guide
      :link: neuron-compiler-cli-reference-guide
      :link-type: ref

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

   .. grid-item-card:: How to generate a NEFF file
      :link: neuronx-cc-generate-neff-how-to
      :link-type: ref

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

   .. grid-item-card:: Error code reference
      :link: ncc-errors-home
      :link-type: ref

      Causes and fixes for compiler error codes.

   .. grid-item-card:: Compiler FAQ
      :link: neuronx_compiler_faq
      :link-type: ref

      Frequently asked questions about ``neuronx-cc``.

.. toctree::
    :maxdepth: 2
    :hidden:

    About neuronx-cc </compiler/about-neuronx-cc>
    About compiler artifacts </compiler/about-compiler-artifacts>
    /compiler/neuronx-cc
    Error Codes </compiler/error-codes/index>
    Release Notes </release-notes/components/compiler>
