.. meta::
   :description: Overview of the files that the Neuron Graph Compiler (neuronx-cc) and TorchNeuron write when they compile a PyTorch model: IR dumps, the compiler working directory, NEFF files, and the compile caches.
   :keywords: neuronx-cc, compiler artifacts, NEFF, NEFF cache, HLO cache, StableHLO, TorchNeuron, torch.compile, TORCH_NEURONX_DEBUG_DIR, TORCH_NEURONX_NEFF_CACHE_DIR, compiler_args.txt, log-neuron-cc.txt, Trn2, Trn3
   :date-modified: 2026-11-16

.. _neuronx-cc-artifacts-overview:

=======================================
What are Neuron Compiler artifacts?
=======================================

When TorchNeuron compiles a PyTorch model, it writes files to disk. These files are the
*compiler artifacts*. They include the intermediate representations (IR) of each graph, the
working directory of each ``neuronx-cc`` call, the compiled NEFF (Neuron Executable File
Format) files, and the caches that let later runs skip compilation.

You do not need the artifacts to run a model. Use them to find out what was compiled, to
confirm the compiler options, to debug a compilation failure, and to reuse compiled programs
across runs and instances.

Applies to
----------

This concept is applicable to:

- TorchNeuron (``torch-neuronx``) in eager mode and with ``torch.compile(backend="neuron")``
- Trn2 and Trn3 instances

How TorchNeuron produces the artifacts
--------------------------------------

Eager mode and ``torch.compile`` use the same job-based artifact hierarchy. For each graph,
TorchNeuron does these steps:

1. It captures the graph as a PyTorch FX graph, and then transforms the FX graph for Neuron.
2. It lowers the graph through torch-mlir to StableHLO.
3. It calls ``neuronx-cc`` in a working directory of its own. The compiler writes a NEFF file.
4. It stores the NEFF in the persistent NEFF cache. The Neuron Runtime loads the NEFF and runs
   it on the NeuronCores.

Each step writes files. TorchNeuron writes the files of steps 1 to 3 under the debug
directory, ``TORCH_NEURONX_DEBUG_DIR`` (default ``/tmp/neuron_backend``). By default,
TorchNeuron removes these files after execution. To keep them, set
``TORCH_NEURONX_PRESERVE_COMPILATION_ARTIFACTS=1``.

Graph artifacts
---------------

TorchNeuron writes the IR of each graph under
``{TORCH_NEURONX_DEBUG_DIR}/torch_neuronx/rank{rank}/{job_id}/``. There is one directory for
each rank and job:

.. list-table::
   :header-rows: 1
   :widths: 35 65

   * - Directory
     - Contents
   * - ``fx_graphs/``
     - The FX graph that TorchNeuron captured (``{model}_{ts}.fx.txt``).
   * - ``transformed_fx/``
     - The FX graph after the Neuron transformations (``{model}_{ts}.transformed.fx.txt``).
   * - ``raw/``
     - The raw torch-mlir output (``{model}_{ts}.torch_raw.mlir``).
   * - ``stablehlo/``
     - The StableHLO module (``{model}_{ts}.stablehlo.mlir``).
   * - ``torch_mlir_error/``
     - The module that torch-mlir could not lower. TorchNeuron writes this directory only when
       torch-mlir fails.
   * - ``inputs/``, ``outputs/``
     - The inputs and outputs of each compiled graph, as pickled NumPy arrays. TorchNeuron writes
       these directories only when ``TORCH_NEURONX_DYNAMO_TENSOR_DUMPS`` is set.

Compiler artifacts
------------------

Each ``neuronx-cc`` call has its own working directory,
``{TORCH_NEURONX_DEBUG_DIR}/neuronx-cc/{hash}/``:

.. list-table::
   :header-rows: 1
   :widths: 35 65

   * - File
     - Contents
   * - ``module.mlir``
     - The module that TorchNeuron gave to the compiler.
   * - ``module.neff``
     - The compiled NEFF file.
   * - ``compiler_args.txt``
     - The arguments of the compiler call. Use this file to confirm the options that you set in
       ``NEURON_CC_FLAGS``.
   * - ``log-neuron-cc.txt``
     - The compiler log. If the compilation fails, look here first.
   * - ``metadata.txt``
     - Metadata about the compiler call.

The number of ``neuronx-cc`` directories tells you how many graphs TorchNeuron compiled. If
there are more than you expect, look for graph breaks or recompilations. See
:ref:`torch-compile-optimize-howto`.

The NEFF file
-------------

The NEFF is the executable that the Neuron Runtime loads. It contains the program that runs on
the NeuronCores. A NEFF is built for one target instance family and one Logical NeuronCore
(LNC) configuration, so a NEFF for ``trn2`` does not run on ``trn3``.

To compile NEFFs on a host with no Neuron device, set ``TORCH_NEURONX_COMPILE_ONLY=1`` and set
the target with ``NEURON_PLATFORM_TARGET_OVERRIDE`` (for example, ``trn2`` or ``trn3``).

Compile caches
--------------

TorchNeuron keeps compiled results in caches on disk, so that a later run does not compile the
same graph again:

.. list-table::
   :header-rows: 1
   :widths: 30 25 45

   * - Cache
     - Location (default)
     - Contents
   * - NEFF cache
     - ``TORCH_NEURONX_NEFF_CACHE_DIR`` (``/tmp/neff_cache``)
     - Compiled NEFF files. Point this directory at a shared mount, such as Amazon FSx, to reuse
       NEFFs across runs and instances.
   * - Lock and scratch directory
     - ``TORCH_NEURONX_NEFF_LOCAL_CACHE_DIR`` (``/tmp/local_cache``)
     - File locks and scratch files only. Keep this directory on a local POSIX file system,
       because file locks are not reliable on NFS or Lustre.
   * - HLO cache
     - ``TORCH_NEURONX_HLO_CACHE_DIR`` (``/tmp/hlo_cache``)
     - The lowered HLO of eager operations and ``torch.compile`` graphs.
   * - NKI trace cache
     - ``/var/tmp/nki-trace-cache-uid<uid>/``, or ``NKI_TRACE_CACHE_URL``
     - The compiled NKI kernels.

The NEFF cache key includes the ``torch-neuronx`` version, the compiler version, the target
platform, the LNC configuration, and the compiler flags in ``NEURON_CC_FLAGS``. A change to any of these values makes a new key,
and TorchNeuron compiles the graph again. To get cache hits in production, pin the versions of
``torch-neuronx`` and ``neuronx-cc``.

To turn off the NEFF cache, set ``TORCH_NEURONX_NEFF_DISABLE_CACHE=1``. Every compilation then
runs from the start.

Profile files
-------------

When you capture a profile of a NEFF, the Neuron Runtime writes profile files. Neuron Explorer
reads these files. For the file types, see :ref:`neuron-explorer-profile-artifacts`.

Related concepts
----------------

- :ref:`What is the Neuron Graph Compiler (neuronx-cc)? <neuronx-cc-overview>`
- :ref:`TorchNeuron <about-pytorch-neuron>`
- :ref:`torch.compile with TorchNeuron <about-torchneuron-torch-compile>`

Further reading
---------------

- :ref:`TorchNeuron environment variables <torchneuron-env-vars>`
- :ref:`How to optimize a model with torch.compile <torch-compile-optimize-howto>`
- :ref:`How to generate a NEFF file <neuronx-cc-generate-neff-how-to>`
- :ref:`Neuron Explorer <neuron-explorer-home>`
