.. meta::
   :description: Troubleshoot AWS Neuron NKI CompileConfig errors: invalid option combinations, NKI allocation out-of-memory errors, the prefetch region error, nested kernel configuration, and options that have no effect.
   :keywords: NKI, CompileConfig, troubleshooting, ValueError, TypeError, NkiValidationError, out of memory, Out of DMA prefetch region, nki_alloc_fallback, sbuf_allocation_fallback, NKI_PREFETCH_RING_SIZE, AWS Neuron, Trainium
   :date-modified: 2026-11-13

.. _nki-compile-config-tshoot:

.. _nki-compile-config-troubleshooting:

==============================================
Troubleshooting: NKI compile configuration
==============================================

Overview
========

This topic lists the errors and symptoms that :class:`nki.compiler.CompileConfig`
options can cause, and what to do for each. Consult it when a kernel with a
``CompileConfig`` fails to compile, runs out of memory, or does not change as
you expect. The terminology follows
:ref:`Deep dive: NKI compile configuration <nki-compile-config>`.

Configuration errors
====================

``CompileConfig`` and :func:`nki.jit` raise these errors before compilation.

.. list-table::
   :header-rows: 1
   :widths: 45 55

   * - Message
     - What to do
   * - ``ValueError: scheduling=True needs an allocation; set
       allocation=Allocation.LINEAR as well.`` or ``ValueError:
       scheduling=True needs allocation=Allocation.LINEAR, got
       allocation=...``
     - Set ``allocation=Allocation.LINEAR`` with ``scheduling=True``.
   * - ``ValueError: <option> acts only when NKI allocates; it cannot be set
       with allocation=Allocation.COLORING.``
     - "NKI allocates" means NKI allocation. Remove the option, or use
       ``allocation=Allocation.LINEAR``.
   * - ``ValueError: <option> acts only when NKI schedules; set
       scheduling=True as well.``
     - "NKI schedules" means NKI scheduling. Set ``scheduling=True`` and
       ``allocation=Allocation.LINEAR``, or remove the option.
   * - ``TypeError: <option> must be an nki.compiler.AllocationMode or None``
       (or ``SchedulingHeuristic``, ``Allocation``, ``OptLevel``), or
       ``TypeError: address_rotation must be an
       nki.compiler.AddressRotation``
     - Pass a member of the named enum, such as ``AllocationMode.FAST``, not a
       string.
   * - ``NkiValidationError: Kernel '<name>' is called from inside another
       kernel but sets compile config that disagrees with the top-level
       kernel``
     - Give the nested kernel the same configuration as the top-level kernel,
       set the configuration only on the top-level kernel, or set
       ``SpecializationConfig(allow_nested_config_override=True)`` on the
       top-level kernel. See the "Nested kernels" section of
       :ref:`nki-compile-config-compile-flow`.

For the modes in which each option is valid, see
:ref:`nki-compile-config-nki-flow-options`.

.. _nki-compile-config-out-of-memory:

Out-of-memory errors
====================

.. rubric:: ``error: Out of memory in sbuf while allocating ...``

NKI allocation ran out of SBUF under the SBUF strategy of the kernel. With
``sbuf_allocation_fallback=True``, every strategy that NKI allocation tried
ran out of SBUF. NKI allocation uses only the strategy that the kernel selects
(``RING`` by default, see :ref:`nki-compile-config-sbuf-strategies`), and does
not try another strategy on its own. The error names the largest live tensor
and lists the changes that can make the kernel fit, best performance first.
Do these steps in order:

1. Change the kernel so that it fits, for example with smaller tiles or fewer
   tensors live at the same time. The kernel keeps NKI allocation, NKI
   scheduling, and the overlap of loads and compute that its strategy gives.
2. Select a more compact strategy for the memory that ran out, at some cost in
   performance:

   * Set ``experimental_sbuf_allocation_mode`` or
     ``experimental_hbm_allocation_mode`` to ``AllocationMode.FAST`` or
     ``AllocationMode.MAX_REUSE``. These strategies use less memory, with less
     overlap of loads and compute. For PSUM,
     ``experimental_psum_allocation_mode`` helps only for a tensor that spans
     several banks (see :ref:`nki-compile-config-sbuf-strategies`).
   * Or set ``sbuf_allocation_fallback=True``, so that NKI allocation tries
     these strategies in turn. For HBM, it tries only ``MAX_REUSE``. It does
     not retry PSUM (see :ref:`nki-compile-config-sbuf-allocation-fallback`).
   * With ``prefetch_auto``, which ``OptLevel.O2`` turns on, and no
     ``NKI_PREFETCH_RING_SIZE``, the SBUF strategy does not change where SBUF
     tensors go. Also set ``prefetch_auto=False`` or
     ``NKI_PREFETCH_RING_SIZE`` (see
     :ref:`nki-compile-config-prefetch-strategy`).

3. Use neuronx-cc allocation. ``allocation=Allocation.COLORING`` selects it
   for every compilation. ``nki_alloc_fallback=True`` selects it only when NKI
   allocation runs out of memory (see
   :ref:`nki-compile-config-nki-alloc-fallback`). In both cases, the kernel
   loses NKI allocation and NKI scheduling.

.. rubric:: ``error: Out of DMA prefetch region in sbuf while allocating ...``

A prefetch tensor does not fit in the fixed prefetch region that
``NKI_PREFETCH_RING_SIZE`` sets. Increase ``NKI_PREFETCH_RING_SIZE``. With
``prefetch_auto``, you can also unset the variable to use the default layout,
whose bounds are soft (see :ref:`nki-compile-config-prefetch-auto-ring-size`).

.. rubric:: Warning: ``Kernel '<name>': NKI memory allocation ran out of memory; the kernel was recompiled with neuronx-cc allocation.``

``nki_alloc_fallback=True`` compiled the kernel with neuronx-cc allocation
(see :ref:`nki-compile-config-nki-alloc-fallback`). Make the kernel fit with
the steps for the SBUF out-of-memory error, or remove
``nki_alloc_fallback=True`` to get the error itself.

.. rubric:: The kernel compiles, then fails with a device out-of-memory error when it is loaded or run

The kernel uses NKI allocation and allocates many or large HBM tensors.
``RING`` reuses freed HBM only after it has used all the DRAM of the core (see
:ref:`nki-compile-config-hbm-ring`). Set
``experimental_hbm_allocation_mode=AllocationMode.FAST`` or
``AllocationMode.MAX_REUSE``. A write into reused HBM waits for the reads of
the tensor that used it before, so compare the runtime with and without the
change.

Other compile errors
====================

.. rubric:: A compile error that too many registers are live at the same time

neuronx-cc reports this error as ``NCC_IGCA094``. The kernel uses NKI
scheduling, and the reuse of register loads keeps more registers live than an
engine has. neuronx-cc cannot spill registers to
memory. Set ``register_load_reuse=False`` (see
:ref:`nki-compile-config-register-load-reuse`).

Options that have no effect
===========================

.. rubric:: An option has no effect, and there is no error

Possible causes:

* The option needs a mode that the kernel does not use. For example,
  ``prefetch_auto`` has no effect with neuronx-cc allocation (see
  :ref:`nki-compile-config-nki-flow-options`).
* ``nki_alloc_fallback=True`` compiled the kernel with neuronx-cc allocation.
  Look for the fallback warning in the compiler output.
* The waits or copies that the option removes are not on the critical path,
  so the runtime does not change.

To fix the first two causes, set ``allocation=Allocation.LINEAR``, and also
``scheduling=True`` for a scheduling option. To confirm that the option acts,
use the "How to check it" section of the option in
:ref:`nki-compile-config-ref`.

Related topics
==============

* :ref:`NKI CompileConfig options reference <nki-compile-config-ref>`
* :ref:`How to tune a NKI kernel with CompileConfig <nki-compile-config-tuning-how-to>`
* :ref:`Deep dive: NKI compile configuration <nki-compile-config>`
