nvidia/tripy-compilation
Work with the nvtripy compilation pipeline. Use when: using tp.compile, creating InputInfo or DimensionInputInfo, understanding the Trace → MLIR → TensorRT flow, configuring optimization levels, working with Executable objects, debugging compilation, using dynamic shapes or NamedDimension.
npx skills add https://github.com/NVIDIA/TensorRT-Incubator --skill tripy-compilation
tp.compile()InputInfo and DimensionInputInfoExecutable objectsUser Function → Trace (graph) → MLIR (IR) → TensorRT (engine) → Executable
tensorrt dialectExecutable objecttp.compile() — The Main Entry Pointcompiled_fn = tp.compile(
func, # Function or Module to compile
optimization_level=3, # 0-5, higher = better runtime, longer compile
args=[...], # Positional arguments
kwargs={...}, # Keyword arguments
)
| Argument Type | Behavior |
|---------------|----------|
| InputInfo(shape, dtype) | Becomes a runtime input to the executable |
| DimensionInputInfo(value_bounds) | Becomes a runtime scalar dimension input |
| Tensor | Baked in as a compile-time constant |
| Any other type | Baked in as a compile-time constant |
The compiled Executable only accepts parameters that were InputInfo/DimensionInputInfo in the original compile() call.
InputInfo — Tensor Runtime Inputs# Static shape
inp = tp.InputInfo(shape=(2, 4), dtype=tp.float32)
# shape_bounds: min=(2,4), opt=(2,4), max=(2,4)
# Dynamic dimensions (min, opt, max)
inp = tp.InputInfo(shape=((1, 2, 3), 4), dtype=tp.float32)
# First dim: min=1, opt=2, max=3; second dim: fixed at 4
# shape_bounds: min=(1,4), opt=(2,4), max=(3,4)
# Named dimensions (must be equal at runtime)
window = tp.NamedDimension("window", 3, 5, 7)
inp = tp.InputInfo(shape=(1, window, window), dtype=tp.float32)
# Both dims named "window" must have the same value at runtime
DimensionInputInfo — Scalar Dimension InputsFor functions that take scalar shape values as parameters:
dim_info = tp.DimensionInputInfo(value_bounds=(1, 2, 4))
# min=1, opt=2, max=4
Used when a function parameter controls a reshape or dynamic shape operation.
Executable — Running Compiled Functions# The executable's signature matches the InputInfo parameters
compiled_fn = tp.compile(add, args=[
tp.InputInfo((2, 4), dtype=tp.float32), # "a"
tp.InputInfo((2, 4), dtype=tp.float32), # "b"
])
# Call with evaluated tensors
a = tp.ones((2, 4), dtype=tp.float32).eval()
b = tp.ones((2, 4), dtype=tp.float32).eval()
result = compiled_fn(a, b)
Executable propertiesinput_infos: Dict of parameter name → InputInfostream: The CUDA stream used for execution__signature__: Compatible with inspect.signature() for introspection.eval() for inputsRuntime inputs to compiled functions should be evaluated tensors (not lazy). Use .eval() to force evaluation before passing to the executable.
class MyModel(tp.Module):
def __init__(self):
super().__init__()
self.linear = tp.Linear(3, 4)
def forward(self, x):
return self.linear(x)
model = MyModel()
# Load real weights before compiling
model.linear.weight = tp.Tensor(weight_data)
model.linear.bias = tp.Tensor(bias_data)
compiled_model = tp.compile(
model,
args=[tp.InputInfo(shape=(2, 3), dtype=tp.float32)],
)
When compiling a Module:
state_dict() entries are named for readable tracesInputInfo arguments become runtime inputscompiled_add = tp.compile(
add,
args=[
tp.InputInfo(shape=((1, 2, 3), 2), dtype=tp.float32),
tp.InputInfo(shape=((1, 2, 3), 2), dtype=tp.float32),
],
)
# Works for any first-dim size in [1, 3]:
small = compiled_add(tp.ones((1, 2)).eval(), tp.ones((1, 2)).eval())
big = compiled_add(tp.ones((3, 2)).eval(), tp.ones((3, 2)).eval())
window_size = tp.NamedDimension("window_size", 3, 5, 7)
inp = tp.InputInfo((1, window_size, window_size), dtype=tp.float32)
# Both dimensions named "window_size" must be equal at runtime
def dynamic_reshape(x, s):
return tp.reshape(x, (-1, s))
compiled_reshape = tp.compile(
dynamic_reshape,
args=[
tp.InputInfo(shape=(3, (2, 4, 6)), dtype=tp.float32),
tp.DimensionInputInfo(value_bounds=(1, 2, 4)),
],
)
result = compiled_reshape(tp.ones((3, 4)).eval(), tp.DimensionSize(2))
assert result.shape == (6, 2)
| Level | Description |
|-------|-------------|
| 0 | Minimal optimization, fastest compile |
| 1–2 | Moderate optimization |
| 3 | Default — good balance |
| 4–5 | Maximum optimization, slowest compile |
tp.config.timing_cache_file_path = "/path/to/cache"
The timing cache stores kernel profiling data across compilations, significantly speeding up repeated compilations with similar operations.
The MLIR compiler (nvtripy/backend/mlir/compiler.py) uses these options:
--tensorrt-timing-cache-path: Path to timing cache--tensorrt-builder-opt-level: Optimization level (0-5)--force-entrypoints-return-allocs: Memory management--mlir-elide-elementsattrs-if-larger: Debug readability--tensorrt-layer-info-dir: TensorRT layer debug infotp.compileThe function passed to compile() must:
print, assert, file I/O)Tensor return types supportedList[Tensor] or Dict[str, Tensor] will be frozen as constants*args and **kwargs are frozen at compile timeInputInfo used for all runtime tensor inputsDimensionInputInfo used for scalar shape parameters(min, opt, max) tuplestp.compile().eval()'d before passing to executableTake nvidia/tripy-compilation 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.