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 |
|---|---|
|
Set |
|
“NKI allocates” means NKI allocation. Remove the option, or use
|
|
“NKI schedules” means NKI scheduling. Set |
|
Pass a member of the named enum, such as |
|
Give the nested kernel the same configuration as the top-level kernel,
set the configuration only on the top-level kernel, or set
|
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:
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.
Select a more compact strategy for the memory that ran out, at some cost in performance:
Set
experimental_sbuf_allocation_modeorexperimental_hbm_allocation_modetoAllocationMode.FASTorAllocationMode.MAX_REUSE. These strategies use less memory, with less overlap of loads and compute. For PSUM,experimental_psum_allocation_modehelps 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 onlyMAX_REUSE. It does not retry PSUM (see sbuf_allocation_fallback).With
prefetch_auto, whichOptLevel.O2turns on, and noNKI_PREFETCH_RING_SIZE, the SBUF strategy does not change where SBUF tensors go. Also setprefetch_auto=FalseorNKI_PREFETCH_RING_SIZE(see Effect on the SBUF allocation strategy).
Use neuronx-cc allocation.
allocation=Allocation.COLORINGselects it for every compilation.nki_alloc_fallback=Trueselects 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_autohas no effect with neuronx-cc allocation (see Options by mode).nki_alloc_fallback=Truecompiled 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.