mcgatom/codex-cannbot/ops-spec-gen
Claude Code and agent skill by mcgatom/codex-cannbot
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
生成或校验算子 spec.yaml(算子的 L0 数学约束唯一真值)。当用户提及:生成 spec.yaml、新算子 spec 骨架、scaffold spec、validate spec.yaml、spec schema 校验、算子规格校验 时触发。
Install
npx vskill@latest install mcgatom/codex-cannbot/ops-spec-genSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
算子 spec.yaml 生成与校验
为 CANNBot 算子产出符合 schema 的 spec.yaml,并对其执行完整 9-stage L0 校验:
- stage 1 schema_static — JSON Schema 字段静态校验
- stage 2 category_paradigm_consistency — category↔paradigm 一致性 + 4 套白名单 + paradigm 内部约束
- stage 3 shape_closure — numpy_expr 求值
outputs[].shape_rule(含data_dependent分流;折叠/显式维 +np.broadcast_shapes) - stage 4 dtype_closure — dtype DSL 推导 vs supported_combinations 显式表交叉验证
- stage 5 broadcast_legality — broadcast.kind/rules 模拟(numpy / none / explicit)
- stage 6 boundary_min_set — 按 paradigms 检查 boundary/extreme case 是否覆盖最低集
- stage 7 tolerance_coverage —
numerical_tolerance.per_dtype覆盖输出 dtype + 紧度启发式 - stage 8 formula_smoke_eval — 把 formula 在小 shape (
[2,3]) 上跑通,沙箱 numpy 执行 - stage 9 oracle_reachable — 真 import framework + getattr 链找 api + 占位符校验
1. 何时使用
| 场景 | 使用分支 | |
|---|---|---|
| 新算子起手,需要 spec.yaml 骨架 | 生成器(§3) | |
| 已有 spec.yaml,CI/PR 校验或 Designer Agent 重生成回灌 | 校验器(§4) | |
| 不清楚 25 category × 27 paradigm 怎么填 | 看 references/spec-cheatsheet.md | |
| 想看完整范例(add / softmax / matmul,全部 PASS 校验) | 看 examples/ |
2. 输入与输出
| 项 | 说明 | |
|---|---|---|
| 入参(生成) | 算子名、category、paradigms[]、inputs(带 dtype_set)、outputs | |
| 出参(生成) | <output_dir>/spec.yaml(含 TODO 占位符,需手填 formula / oracle.api / supported_combinations / boundary cases) | |
| 入参(校验) | spec.yaml 路径 | |
| 出参(校验) | 9-stage findings;返回码 0=PASS / 1=FAIL(含 internal_error)/ 2=YAML 解析错;--strict 时 warning 也退 1 |
3. 生成 spec.yaml
3.1 交互式向导(推荐)
向导会问:op 名称、category(25 类单选)、paradigms(在 category 必含基础上自由追加)、每个 input/output 名+dtype、promotion / broadcast / accumulation_order。
3.2 非交互式(CI / 脚本)
注:--inputs 多个时用 ; 分隔(避免与 dtype_set 的 , 冲突),如 "a:float16,float32;b:float16,float32"。
3.3 自动注入
按 op.paradigms 自动注入:
Reduction(且无Recurrence)⇒ 添加dimattribute(int_in_range_relative_to_rank)Quantization⇒ 添加scale/zero_pointattributeRandomSampling⇒ 添加seedattributeStateful⇒ 第一个 input 标role: stateCollectiveCommunication⇒op.platform_constraints.requires_hccl: truecategory=contraction/category=reduction_composite/paradigms含NumericalStable+Reduction⇒ 添加accumulator_dtype: float32FusedComposite⇒ 添加composition.primitives(2 条占位)+dataflow.no_leak: trueNumericalStable⇒numerical_stability.required: true+ 一条 technique 占位
更多注入提示见 registries/category_paradigm_map.yaml 的 paradigm_inject_hints 段。
3.4 必须手填的 TODO
生成器只产骨架 + 按 paradigm 自动注入的 boundary/extreme case。算子 owner 必须手填:
outputs[].shape_rule— numpy 子集表达式(如c.shape = np.broadcast_shapes(a.shape, b.shape))。
若是 VariableOutput 范式的算子(shape 由输入值决定),改声明 shape_rule_kind: data_dependent + shape_rule_description + shape_bounds.max_elements,不写表达式。
outputs[].dtype_rule— numpy 子集表达式(如c.dtype = np.promote_types(a.dtype, b.dtype)、
y.dtype = x.dtype、y.dtype = np.int32)
math_semantics.formula— numpy 可 eval 的表达式math_semantics.reference_oracle.api— 真实的 torch/numpy/scipy API 全限定名dtype_policy.supported_combinations— 显式枚举 (input dtypes) → output dtypesnumerical_tolerance.per_dtype— 覆盖 supported_combinations 中所有 output dtype
按需补充(生成器已自动注入按 paradigm 必含的最低 case,stage 6 通过;下面这些是把生成器的占位描述改成项目语境下的真值):
boundary_conditions— 校核 / 补全自动注入的退化 case 描述(详见 cheatsheet §B6)extreme_inputs— 校核 / 补全 NaN / Inf / 全零三类
4. 校验 spec.yaml
4.1 stage 1 — schema_static
按 schemas/op-spec.json(Draft 2020-12)逐字段校验:必填、类型、enum、pattern、additionalProperties。
4.2 stage 2 — category_paradigm_consistency
校验 category↔paradigm 必含映射 + 4 套白名单 + paradigm 内部约束:
| 子规则 | 检查内容 | |
|---|---|---|
required_paradigm_missing | category → 必含 paradigm 是否齐全 | |
fused_composite_basics | category=fused_composite ⇒ ≥ 2 条基础 paradigm | |
mutually_exclusive | ScatterUpdate 与 AtomicUpdate 不得共存 | |
paradigm_constraint.numerical_stable | NumericalStable ⇒ numerical_stability.required: true | |
paradigm_constraint.fused_composite_* | FusedComposite ⇒ composition 必填、primitives ≥ 2、op 在白名单、中间不泄漏、dataflow 闭合 | |
paradigm_constraint.reduction_axis_missing | Reduction(无 Recurrence)⇒ 必有 axis/dim/axes | |
paradigm_constraint.argreduce_dtype | ArgReduce ⇒ 输出 dtype_rule 经 numpy_expr 求值得到 int32 或 int64(典型:y.dtype = np.int64) | |
paradigm_constraint.stateful_state_or_inplace | Stateful ⇒ 至少一项 input.role=state 或 output.aliasing=inplace_with(...) | |
paradigm_constraint.quantization_attrs | Quantization ⇒ scale + zero_point | |
paradigm_constraint.variable_output_flag | VariableOutput ⇒ outputs[].data_dependent_shape: true | |
paradigm_constraint.random_sampling_seed | RandomSampling ⇒ seed 属性 | |
paradigm_constraint.collective_hccl | CollectiveCommunication ⇒ op.platform_constraints.requires_hccl: true | |
invariant_kind_resolved.* | invariants[].kind 在白名单 + required_fields + tolerance_inherit 约束(structural 必为 false) | |
machine_check_kind_unknown | boundary/extreme 的 machine_check.kind 在白名单 | |
error_type_unknown | raises_error.error_type 在错误语义类别枚举内 | |
synthesize_pattern_unknown | extreme_inputs.synthesize.patterns[].pattern 在白名单 | |
synthesize_legacy_format | 旧顶层 pattern: 写法 ⇒ WARN | |
composition_without_fused_composite | composition 存在但 paradigms 不含 FusedComposite ⇒ WARN |
4.3 stage 3 — shape_closure(numpy_expr 求值)
按 outputs[].shape_rule_kind 分流:
- `numpy_expr`(默认)— 在受限 AST 沙箱中执行
outputs[].shape_rule(numpy 子集表达式),求出每个输出的 SymbolicShape。 - `data_dependent` — 输出 shape 由输入数据值决定(nonzero / unique / masked_select 等);不求解,但强制校验
data_dependent_shape: true+shape_bounds.max_elements+ 建议配shape_rule_description。
shape_rule 的 numpy_expr 示例(matmul):
data_dependent 示例(nonzero):
| 子规则 | 检查内容 | |
|---|---|---|
shape_closure.shape_rule_kind_missing | outputs[].shape_rule_kind 未声明 | |
shape_closure.shape_rule_kind_unknown | 非 numpy_expr / data_dependent | |
shape_closure.dsl_parse_error | numpy_expr 语法错 | |
shape_closure.dsl_eval_error | 求值时 AttributeError / TypeError / 沙箱拒绝 | |
shape_closure.unresolved_symbol | 引用了未声明的 input / attribute 名 | |
shape_closure.incompatible_dims | 显式维冲突(如 matmul K 维同名约束失败) | |
shape_closure.folded_dim_misuse | 折叠维 ...x 重复或不在首位 | |
shape_closure.unregistered_symbol | WARN — 显式维未在 shape_constraints.symbols 登记 | |
shape_closure.rank_overflow | 输出 rank 超过 inputs[].rank_range 上限 | |
shape_closure.data_dependent_flag_missing | data_dependent 但未配 data_dependent_shape: true | |
shape_closure.data_dependent_missing_bounds | data_dependent 但未配 shape_bounds.max_elements | |
shape_closure.data_dependent_missing_description | WARN — 建议补 shape_rule_description |
numpy_expr 支持的子集(按需可扩展,见 scripts/evaluators/shape_eval.py):
x.shape/x.shape[-1]/x.shape[:-2](切片 + 负索引)tuple拼接+((a.shape[-1],) + (b.shape[-1],))np.broadcast_shapes(*shapes)(numpy 标准 API 签名)IfExp:a if cond else b(cond 从 attribute 默认值解析为 bool)
沙箱规则同 stage 8:禁 import / def / class / for / while / lambda / dunder attribute;5 秒超时。
4.4 stage 4 — dtype_closure
对 dtype_policy.supported_combinations 的每一行,执行 outputs[].dtype_rule(numpy 子集表达式)推导输出 dtype,与显式表交叉比对。常见形式:
| 子规则 | 检查内容 | |
|---|---|---|
dtype_closure.combination_mismatch | dtype_rule 推得 X 但显式表写 Y(典型:"锁定意图"机制:当 numpy promote 表升级时,spec 不会被静默改语义) | |
dtype_closure.combination_missing_output | 组合行未声明某 output 的 dtype | |
dtype_closure.dsl_parse_error / dsl_eval_error | 表达式语法错 / 求值错 | |
dtype_closure.unresolved_symbol | dtype_rule 引用的 input 不在该组合内 | |
dtype_closure.dtype_rule_kind_unknown | 非 numpy_expr 的 dtype_rule_kind |
numpy 子集支持:
x.dtype(input 的 dtype 字符串)np.promote_types(a, b)/np.result_type(*xs)— 复用 promote 表np.int8 / int16 / int32 / int64 / uint8 / uint16 / uint32 / uint64 / float16 / float32 / float64 / bfloat16 / complex64 / complex128 / bool_dtype 常量- 比较与 IfExp:
a.dtype == np.float32、x if cond else y
Promotion 表覆盖 fp16 / fp32 / fp64 / bf16 / int8 / int16 / int32 / int64 / uint* / bool / complex64 / complex128 + 窄浮点 fp4_e2m1 / fp8_e4m3fn / fp8_e5m2 / hifloat8(见 scripts/evaluators/promote.py)。
4.5 stage 5 — broadcast_legality
按 broadcast.kind 模拟输入 shape 之间的对齐。
| 子规则 | 检查内容 | |
|---|---|---|
broadcast_legality.numpy_violation | kind: none 但输入 shape 实际需要广播 | |
broadcast_legality.incompatible_dims | kind: numpy 下显式维冲突(不可右对齐) | |
broadcast_legality.explicit_rules_uncovered | kind: explicit 的 rules 未覆盖输入全部维度 |
v1 已实现:numpy(含折叠维)/ none / explicit(broadcast.rules 必须恰好一条 scope: trailing + 一条 scope: leading,policy 各支持 numpy / no_broadcast,覆盖 matmul 形式)。explicit 的高阶组合(多于 2 个 input、scope: axis)留待扩展。
4.6 stage 6 — boundary_min_set
按 op.paradigms 检查 boundary_conditions[] / extreme_inputs[] 是否覆盖该范式必含的最低 case 集。数据源:registries/boundary_min_cases.yaml。
| 子规则 | 检查内容 | |
|---|---|---|
boundary_min_set.missing_required_case | 例如 Reduction ⇒ 必含"reduce 轴长=1 / rank=0 / 空 Tensor";NumericalStable ⇒ 必含 fp16 上溢 extreme case;DynamicShape ⇒ shape_set ≥ 3 个 |
匹配方式:每条 requirement 用 match_any 关键词列表与 case 描述做子串包含;任一命中即算覆盖。结构性约束(如 shape_set 数量)走 special_check 直接检查。
覆盖的 paradigms:Reduction / NumericalStable / SlidingWindow / Padding / IndexGather / ScatterUpdate / AtomicUpdate / MaskPredicate / SortSelect / ArgReduce / Histogram / Spectral / DynamicShape / RandomSampling / Quantization / Stateful。其他 paradigms 当前无强制最低 case。
4.7 stage 7 — tolerance_coverage
| 子规则 | 检查内容 | |
|---|---|---|
tolerance_coverage.uncovered_output_dtype | dtype_policy.supported_combinations 中所有出现的输出 dtype 必须在 numerical_tolerance.per_dtype 中声明容差(FAIL) | |
tolerance_coverage.tolerance_too_tight | rtol 显著低于 dtype 单步舍入量级(fp32 < 1e-7、fp16 < 1e-4、bf16 < 1e-3)⇒ WARN |
注:本 skill 用 stage 4 输出 dtype 集合(在 stage 4 实现前用 supported_combinations 显式枚举作为代理);两者通常一致。
4.8 stage 8 — formula_smoke_eval
把 math_semantics.formula 在小 shape(默认 [2,3])上用 numpy 跑一遍,确认能跑通且产出预期 dtype。
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/ops-spec-gen/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mcgatom/codex-cannbot/ops-spec-gen)