Skip to content

Operator task guide

How to debug torch.compile, Inductor, Triton, and CUDA graph errors

torch.compile stacks three layers: Dynamo (Python graph capture), Inductor (graph lowering and CUDA graph wrapping), and Triton (GPU kernel compilation). Pinpoint which layer failed by testing backend="eager" first, then TORCH_LOGS="recompiles,graph_breaks" or TORCH_COMPILE_DEBUG=1.

Triton CUDA errors such as invalid argument, misaligned address, or out of resources usually reflect dynamic tensor shapes exceeding shared memory, non-contiguous tensor strides, or CUDA stream-capture restrictions when mode="reduce-overhead" enables CUDAGraphTrees.

Reviewed . Reference guidance is not a diagnosis of your workload.

Step-by-step method

  1. 1

    Isolate Dynamo graph capture vs Inductor/Triton codegen

    Reproduce the failure with backend="eager" (tests Dynamo alone) vs mode="default" without CUDA graphs (disables reduce-overhead CUDAGraphTrees) so you know which compiler stage broke.

    TORCH_LOGS="+dynamo,recompiles,graph_breaks" python3 train.py
    # Or capture full Inductor/Triton artifacts for a minimal reproducer:
    TORCH_COMPILE_DEBUG=1 python3 repro.py
  2. 2

    Fix CUDAGraphTrees stream-capture and OOM errors (reduce-overhead)

    mode="reduce-overhead" wraps compiled regions in CUDA graphs, which forbid CPU-GPU syncs (.item(), .cpu()) and allocate persistent memory pools per distinct input shape.

    # Test disabling cudagraphs inside Inductor to isolate graph capture OOM/errors
    TORCHINDUCTOR_CUDAGRAPHS=0 python3 train.py
  3. 3

    Debug Triton invalid argument, out of memory, and context destroyed

    If a Triton kernel throws CUDA invalid argument or illegal instruction, run with CUDA_LAUNCH_BLOCKING=1 and verify tensor .is_contiguous() and GPU compute capability alignment.

    CUDA_LAUNCH_BLOCKING=1 python3 repro.py
    compute-sanitizer --tool memcheck python3 repro.py
  4. 4

    Eliminate excessive dynamic-shape recompiles

    Variable sequence lengths without dynamic=True or padding cause repeated Inductor compilations that spike host RAM and stall distributed ranks past NCCL watchdog timeouts.

    # Pad/bucket variable sequence lengths or test dynamic=True on stable shapes

torch.compile error localization matrix

Signals, meanings and actions for how to debug torch.compile, inductor, triton, and cuda graph errors.
SignalWhat it meansNext action
Passes with backend="eager", fails with default InductorBug in Inductor lowering or generated Triton kernel.Capture TORCH_COMPILE_DEBUG=1 output and test TORCHINDUCTOR_CUDAGRAPHS=0.
Fails with mode="reduce-overhead" OOM or stream-capture errorCUDAGraphTrees retained too many shape pools or hit a forbidden CPU sync.Pad sequence shapes to fixed buckets or switch to mode="default".
Triton Error: CUDA invalid argument or misaligned addressKernel grid exceeded limits or received non-contiguous/zero-size tensor.Check tensor shapes/contiguity and inspect generated Triton code with TORCH_COMPILE_DEBUG=1.
Distributed job hits NCCL timeout on step 1 or shape changeOne rank spent minutes recompiling Inductor kernels while peers timed out.Pre-warm cache, pad shapes uniformly, and share Inductor cache or adjust init timeout.

Evidence checklist

  • PyTorch, Triton, and CUDA versions
  • torch.compile mode/backend flags (default, reduce-overhead, max-autotune)
  • TORCH_LOGS="recompiles,graph_breaks" output
  • Comparison run with TORCHINDUCTOR_CUDAGRAPHS=0 and backend="eager"
  • Exact tensor shapes and dtypes triggering Triton failure

Common mistakes

Using mode="reduce-overhead" with unpadded variable sequence lengths

Every new token length triggers a fresh CUDA graph pool capture until GPU VRAM hits OOM.

Debugging Triton async CUDA errors without CUDA_LAUNCH_BLOCKING=1

Asynchronous kernel errors surface lines later at unrelated PyTorch ops.

Ignoring host RAM spikes during parallel Inductor compilation

Large compile worker pools inside containers can trigger cgroup OOMKill during cold start.

Frequently asked questions

Why does torch.compile cause CUDA out of memory only with mode="reduce-overhead"?

reduce-overhead enables CUDA graphs, which allocate persistent private memory pools for each captured input shape. Variable sequence lengths or batch sizes multiply these pools until VRAM is exhausted.

What causes Triton error: CUDA error: invalid argument?

Common causes are empty tensors, non-contiguous strides, launch grid/block dimensions exceeding CUDA hardware limits, or exceeding per-block shared memory.

How do I disable CUDA graphs inside torch.compile without turning off Inductor?

Pass options={"triton.cudagraphs": False} to torch.compile or set mode="default" instead of "reduce-overhead".

Why does torch.compile trigger an NCCL timeout during distributed training?

If one rank triggers an unexpected Dynamo recompile while peer ranks do not, that rank blocks in Python/C++ compilation long enough for other ranks to hit the NCCL watchdog timeout.

Live diagnosis, no signup

Upload your GPU log. Find what happened first.

Get the likely cause, supporting evidence, and next safe steps with the same cloud reasoning used by paid plans. A crash the engine recognizes is answered in seconds, then checked by an independent AI review that updates this page when it finishes. A crash it does not recognize waits for the AI's own answer, which can take a few minutes. No account, card, or installation. Logs are masked at Denpex API ingress and are not saved to account history.

Before uploading, review cloud data handling and local options.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free cloud diagnoses per day

Try Denpex for 30 days. FREE.

No credit card. No automatic subscription. See whether Denpex helps with an incident you already understand.

Start your free 30-day Team evaluation

Up to 50 diagnoses a day for 30 days. Verify your work email to activate an eligible company evaluation, then replay a resolved incident and compare the evidence and next steps with your team's confirmed cause.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.

Apply the method to your incident

Use the three free diagnoses to review your error and relevant evidence. Keep reference guidance separate from the cause and recovery status of your own workload.

Diagnose your incident