npx skills add ...
npx skills add nvidia/tensorrt-incubator --skill tripy-constraints
Author input/output constraints for nvtripy operations using the declarative constraint DSL. Use when: defining input_requirements or output_guarantees, writing @wrappers.interface decorators, auto-casting dtypes, using GetInput/GetReturn/OneOf/If/Equal, debugging constraint validation errors.
npx skills add nvidia/tensorrt-incubator --skill tripy-constraints
input_requirements or output_guarantees for @wrappers.interfaceThe constraint system lives in nvtripy/frontend/constraints/ and consists of:
fetcher.py): Extract values from function arguments or return valueslogic.py): Compose constraints with boolean operatorsbase.py): Abstract base class for all constraintsnvtripy/frontend/wrappers.py): The @interface decorator that applies constraints| Class | Usage | Description |
|---|---|---|
OneOf(fetcher, options) | OneOf(GetInput("x").dtype, [dt.float32, dt.float16]) | Value must be in the list |
Equal | GetInput("a").dtype == GetInput("b").dtype | Two values must be equal (created via ==) |
NotEqual | GetInput("dtype") != None | Two values must not be equal (created via !=) |
And | constraint1 & constraint2 | Both must be satisfied (created via &) |
Or | constraint1 | constraint2 | At least one must be satisfied (created via |) |
If(cond, then, else_) | If(GetInput("dtype") != None, then_constraint) | Conditional constraint |
AlwaysTrue | AlwaysTrue() | Always passes |
AlwaysFalse | AlwaysFalse() | Always fails |
@wrappers.interfaceThe @wrappers.interface decorator from nvtripy/frontend/wrappers.py accepts:
input_requirements: Checked BEFORE the function runs. If a dtype mismatch is found and auto-casting can fix it, the system will automatically cast inputs.output_guarantees: Checked AFTER the function runs. Verifies the output properties match expectations.When input_requirements include dtype constraints via OneOf:
OneOf optionsThis means users don't need to manually cast, e.g., tp.ones((2,), dtype=tp.float16) + tp.ones((2,), dtype=tp.float32) will auto-cast.
When constraints fail, the system generates an error like:
The error text comes from the __str__ and doc_str methods of each Logic class.
input_requirements covers all valid input dtypes with OneOf== constraintsIf(GetInput("x") != None, ...)output_guarantees specify the output dtype relationship& used to combine multiple requirements (not nested And() calls)