nvidia/tripy-debugging
Debug and diagnose errors in nvtripy code. Use when: interpreting TripyException stack traces, enabling MLIR/TensorRT debug output, understanding error reporting with stack_info, using raise_error, configuring debug environment variables, tracing compilation failures.
npx skills add https://github.com/NVIDIA/TensorRT-Incubator --skill tripy-debugging
TripyException error messages and stack tracesraise_error — The Primary Error FunctionFrom nvtripy/common/exception.py:
from nvtripy.common.exception import raise_error
raise_error(
"Brief description of the error.",
details=[
"Additional context line 1.",
"Additional context line 2.",
some_tensor, # Will include the tensor's creation stack info
],
)
details: A list of strings and/or tensors. Tensors will have their stack info rendered.TripyExceptionEvery tensor captures its creation stack trace (_stack_info) for precise error reporting. This is managed in nvtripy/utils/stack_info.py.
When a tensor appears in raise_error details, the system renders the exact line and column where the tensor was created, helping users trace back to the problematic code.
Key points:
Tensor.from_trace_tensor(out, include_code_index=stack_depth) — sets the stack depth for error reportingSTACK_DEPTH_OF_FROM_TRACE_TENSOR = 4 — the default depth in create_opstack_depth_offset parameter in create_op adjusts for wrapper functionsTripyException (main user-facing exception)
└── Raised by raise_error() with formatted stack info
Set these before running to enable debug output:
| Variable | Default | Description |
|----------|---------|-------------|
| TRIPY_MLIR_DEBUG_ENABLED | "0" | Enable MLIR debug output |
| TRIPY_MLIR_DEBUG_TYPES | "-translate-to-tensorrt" | Comma-separated MLIR pass types to debug |
| TRIPY_MLIR_DEBUG_PATH | "/tripy/mlir-dumps" | Directory for MLIR debug dumps |
| TRIPY_TRT_DEBUG_ENABLED | "0" | Enable TensorRT debug output |
| TRIPY_TRT_DEBUG_PATH | "/tripy/tensorrt-dumps" | Directory for TensorRT debug dumps |
| TRIPY_EXTRA_ERROR_INFORMATION | "" | Comma-separated extra error info |
From nvtripy/config.py:
import nvtripy as tp
# Timing cache (speeds up repeated compilations)
tp.config.timing_cache_file_path # Default: /tmp/tripy-cache
# Input validation (disable for performance in production)
tp.config.enable_input_validation = False
# Extra error information
tp.config.extra_error_information = ["detailed"]
from tests import helper
with helper.config("enable_input_validation", False):
# Code runs with validation disabled
...
# Automatically restored after the block
The logging system (nvtripy/logging/) provides granular control:
import nvtripy as tp
# The global logger
logger = tp.logger
# Set verbosity for specific modules
logger.verbosity_trie.set("nvtripy.backend", "verbose")
The VerbosityTrie allows setting different log levels for different module paths, using a trie data structure for efficient prefix matching.
Error pattern: Expected 'input' to be one of [...] (but it was '...')
This comes from the constraint system. Check:
input_requirements in the @wrappers.interface decoratorEnable MLIR debug output:
TRIPY_MLIR_DEBUG_ENABLED=1 python my_script.py
Check the dumps in /tripy/mlir-dumps/ for the MLIR IR at each pass.
The trace system tracks shapes through infer_rank on trace ops. Check:
infer_rank policy on the trace opDYNAMIC_DIM = -1) vs static shapesEnable TensorRT debug output:
TRIPY_TRT_DEBUG_ENABLED=1 python my_script.py
Check:
InputInfo boundsdef my_op(input, dim):
if input.rank < 2:
raise_error(
f"Input must have rank >= 2, but got rank: {input.rank}",
details=[
"Input is expected to have shape (N, *) where N is the batch size.",
input, # This renders the tensor's creation location
],
)
def forward(self, x):
if self.quant_dtype is not None and self.weight_quant_dim == 1:
raise_error(
"Unsupported quantization parameters.",
[
"weight_quant_dim cannot be 1 when input_scale is provided.",
f"input_scale={self.input_scale}, weight_quant_dim={self.weight_quant_dim}",
],
)
Use the helper.raises context manager:
from tests import helper
import nvtripy as tp
def test_invalid_dtype_fails():
a = tp.Tensor([1.0, 2.0])
b = tp.ones((2,), dtype=tp.float16)
with helper.raises(tp.TripyException, match="Expected.*one of"):
c = a + b
The raises helper supports:
ExcType: Expected exception typematch: Regex pattern to match against error messagehas_stack_info_for: Verify that specific tensors' stack info appears in the errorraise_error() instead of raw raise for user-facing errorsdetails for stack info renderinghelper.raises(tp.TripyException, match=...)Take nvidia/tripy-debugging from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.