This document is relevant for: Trn2, Trn3

Troubleshooting: NKI compile configuration#

Overview#

This topic lists the errors and symptoms that 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 Deep dive: NKI compile configuration.

Configuration errors#

CompileConfig and nki.jit() raise these errors before compilation.

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 Allocation and scheduling modes.

For the modes in which each option is valid, see Options by mode.

Out-of-memory errors#

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 Allocation 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 Allocation 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 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 Effect on the SBUF allocation 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 nki_alloc_fallback). In both cases, the kernel loses NKI allocation and NKI scheduling.

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 Sizing the prefetch region).

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 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.

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 HBM under 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#

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 register_load_reuse).

Options that have no effect#

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 Options by mode).

  • 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 Reference: NKI CompileConfig options.