SuperAPI AI 工具集

tripy-constraints

通用与其它

查看项目

更新于 10-16 02:34

技能介绍

用途:为 nvtripy 算子编写类型约束,定义 @wrappers.interface 的 input_requirements 与 output_guarantees,调试运行时约束校验错误,并理解自动类型转换行为。约束系统位于 nvtripy/frontend/constraints/,包含 fetcher.py(从参数或返回值提取值)、logic.py(用布尔运算组合约束)、base.py(约束抽象基类)以及 wrappers.py 中的 @interface 装饰器。

主要能力:用 GetInput("name") 取函数参数、GetReturn(0) 取返回值,并通过 .dtype 获取数据类型。逻辑类包括 OneOf(值须在列表中)、Equal(==)、NotEqual(!=)、And(&)、Or(|)、If(cond, then, else_)、AlwaysTrue、AlwaysFalse,可用 ~ 取反。@wrappers.interface 支持 input_requirements(执行前校验,若类型不匹配且可自动转换则自动转换)、output_guarantees(执行后校验)、convert_to_tensors 与 conversion_preprocess_func。

使用方式:在算子函数上使用 @wrappers.interface 装饰器,用 OneOf 限定合法 dtype,用 == 约束多输入 dtype 一致,用 If(GetInput("x") != None, ...) 处理可选参数,用 & 组合多个要求,并在 output_guarantees 中声明输出 dtype 关系。约束失败时错误信息形如 Expected 'input' to be one of [float32, float16, bfloat16] (but it was 'int32')。

适用场景:新增或修改 nvtripy 算子、编写类型约束、排查约束校验错误。限制:资料未提供安装命令、版本要求、性能数据与收费信息。