npx skills add ...
npx skills add nvidia/tensorrt-incubator --skill tripy-new-operation
Add a new operation to nvtripy. Use when: implementing a new op, adding a frontend op, creating a trace op, registering an op in the API. Covers the full Frontend → Trace → MLIR pipeline including export decorators, constraint definitions, and init registration.
npx skills add nvidia/tensorrt-incubator --skill tripy-new-operation
Operations in nvtripy follow a Frontend → Trace → MLIR pipeline:
nvtripy/trace/ops/): Defines the computational graph node — rank inference, dtype inference, and MLIR code generation.nvtripy/frontend/ops/): The public API function — exports, constraints, docstring, and bridges to the trace op via create_op().__init__.py files must be updated so the op is discoverable.Create a file in nvtripy/trace/ops/<op_name>.py:
Key base class requirements (from TraceOp):
infer_rank (required): Set output rank. Use policies from InferRankPolicies:
same_as_input(idx=0) — output rank matches input[idx]same_shape_as_input(idx=0) — output has same shape (not just rank)same_as_shape_of_shape_input(idx=0) — rank from a shape tensormax_of_inputs() — rank is max across all inputsto_mlir(self, inputs, outputs) (required): Return list of MLIR operationsinfer_dtypes() (optional): Default propagates from inputs[0]. Override for multi-dtype ops.infer_devices() (optional): Default sets all outputs to GPU.get_num_outputs() (optional): Default is 1. Override for multi-output ops.str_skip_fields() (optional): Fields to omit from string representation.Factory pattern for families of similar ops (see trace/ops/unary.py):
Create a file in nvtripy/frontend/ops/<op_name>.py:
Key decorator details:
@export.public_api(document_under="..."): Registers in public API and docs hierarchy. Common paths:
"operations/functions" — general tensor ops"operations/initializers" — tensor creation ops (ones, zeros, full)"operations/modules" — nn module classes@wrappers.interface(...): Defines input constraints and output guarantees (see constraint skill)op_utils.create_op(TraceOpClass, [inputs], **kwargs)__init__.py Filesnvtripy/frontend/ops/__init__.py: Add import so auto-discovery finds the module.
nvtripy/trace/ops/__init__.py: Usually empty — trace ops are imported directly by frontend ops.
If the op should be callable as tensor.my_op(), register it in the TENSOR_METHOD_REGISTRY via the frontend tensor metaclass system. Check nvtripy/frontend/tensor.py for the pattern.
Trace op (nvtripy/trace/ops/softmax.py):
Frontend op (nvtripy/frontend/ops/softmax.py):
nvtripy/trace/ops/ with infer_rank and to_mlirnvtripy/frontend/ops/ with @export.public_api and @wrappers.interface.. code-block:: python example__init__.py updated if needed for auto-discoverytests/frontend/ops/ and tests/trace/ops/ (see testing skill)**