tripy-debugging

작성자: nvidia

Debug and diagnose errors in nvtripy code. Use when: interpreting TripyException stack traces, enabling MLIR/TensorRT debug output, understanding error…

npx skills add https://github.com/nvidia/tensorrt-incubator --skill tripy-debugging

Debugging and Error Reporting in nvtripy

When to Use

  • Interpreting TripyException error messages and stack traces
  • Enabling debug output for MLIR or TensorRT compilation
  • Understanding the stack info system for precise error locations
  • Adding error handling to new ops or modules
  • Diagnosing compilation or runtime failures

Error Reporting System

raise_error — The Primary Error Function

From 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
    ],
)
  • First argument: The main error message (string)
  • details: A list of strings and/or tensors. Tensors will have their stack info rendered.
  • Raises TripyException

Stack Info System

Every 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 reporting
  • STACK_DEPTH_OF_FROM_TRACE_TENSOR = 4 — the default depth in create_op
  • stack_depth_offset parameter in create_op adjusts for wrapper functions

Exception Hierarchy

TripyException (main user-facing exception)
└── Raised by raise_error() with formatted stack info

Debug Configuration

Environment Variables

Set these before running to enable debug output:

VariableDefaultDescription
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

Runtime Configuration

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"]

Test Helper for Config Changes

from tests import helper

with helper.config("enable_input_validation", False):
    # Code runs with validation disabled
    ...
# Automatically restored after the block

Logging System

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.

Diagnosing Common Issues

Constraint Validation Errors

Error pattern: Expected 'input' to be one of [...] (but it was '...')

This comes from the constraint system. Check:

  1. The input_requirements in the @wrappers.interface decorator
  2. The actual dtypes of the inputs being passed
  3. Whether auto-casting should handle this case

Compilation Errors

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

Shape Mismatch Errors

The trace system tracks shapes through infer_rank on trace ops. Check:

  1. The infer_rank policy on the trace op
  2. Whether broadcasting is handled correctly
  3. Dynamic dimensions (DYNAMIC_DIM = -1) vs static shapes

Runtime Errors from Compiled Functions

Enable TensorRT debug output:

TRIPY_TRT_DEBUG_ENABLED=1 python my_script.py

Check:

  • Input shapes fall within the InputInfo bounds
  • Dynamic shapes are correctly configured with min/opt/max

Adding Error Handling to New Code

In Frontend Ops

def 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
            ],
        )

In Modules

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}",
            ],
        )

Testing Errors

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 type
  • match: Regex pattern to match against error message
  • has_stack_info_for: Verify that specific tensors' stack info appears in the error

Checklist

  • Use raise_error() instead of raw raise for user-facing errors
  • Include relevant tensors in details for stack info rendering
  • Error message is actionable (says what went wrong AND what to do)
  • Test error cases with helper.raises(tp.TripyException, match=...)
  • Debug env vars documented if adding new debug output

nvidia의 다른 스킬

compileiq-debug
nvidia
Use when something is wrong: Search() hangs, all evaluations return INVALID_SCORE, scores aren't improving, every config returns the same number, ptxas errors…
official
create-github-pr
nvidia
gh CLI를 사용하여 GitHub 풀 리퀘스트를 생성합니다. 사용자가 새 PR을 만들거나, 코드 리뷰를 제출하거나, 풀 리퀘스트를 열고자 할 때 사용합니다. 트리거 키워드 -…
official
diagnose-perf
nvidia
First-responder performance triage for Isaac Sim and Isaac Lab. Identifies bottleneck category (GPU-bound, CPU-bound, VRAM, loading) using nvidia-smi and…
official
eagle3-review-logs
nvidia
Review EAGLE3 pipeline experiment logs from the launcher's experiments/ directory. Summarizes pass/fail status for all 4 tasks, diagnoses failures with root…
official
nemoclaw-maintainer-cross-issue-sweep
nvidia
다른 열린 이슈들을 스캔하여 주어진 PR이 함께 수정하거나 실수로 망가뜨릴 수 있는 이슈를 찾습니다. 인접 수정 기회와 모순 위험을 file:line…과 함께 출력합니다.
official
karpathy-guidelines
nvidia
일반적인 LLM 코딩 실수를 줄이기 위한 행동 지침입니다. 코드 작성, 검토 또는 리팩토링 시 과도한 복잡성을 피하고 정밀한 변경을 위해 사용하세요.
official
fhir-basics
nvidia
에이전트에게 FHIR R4 API의 작동 방식, 사용 가능한 리소스, 검색 매개변수를 사용한 쿼리 방법, 모든 응답 형식을 올바르게 파싱하는 방법을 가르칩니다…
official
underdeclared-agent
nvidia
A helpful assistant agent
official