Skip to content

Add operator-verify skill for offline Lean 4 operator verification - #15

Draft
Libre908 wants to merge 2 commits into
FreedomIntelligence:mainfrom
Libre908:feat/operator-verify
Draft

Libre908 wants to merge 2 commits into
FreedomIntelligence:mainfrom
Libre908:feat/operator-verify

Conversation

@Libre908

Copy link
Copy Markdown

Summary

Add the sixth installable skill, operator-verify, providing offline Lean 4 formal verification for discrete accelerator operator invariants (Triton-Ascend, Ascend C, Triton, CUDA) on a single localized operator without requiring target NPU/GPU hardware.

operator-verify is intentionally scoped as a crisp single-operator mirror to operator-optimize and precision-compare:

  • precision-compare / operator-optimize: on-device quantitative floating-point rounding accuracy (vs FP64) and paired runtime speed (kernel_check.py).
  • operator-verify: offline qualitative/discrete safety and equivalence proofs (index_and_mask, resource_capacity, pipeline_sync, semantic_equivalence) plus machine-checked counterexamples for bugs that routine dense/power-of-2 unit tests routinely miss (triage.py + lean_check.py + lean_lib/AscendLean/).

What's Added

  • skills/operator-verify/SKILL.md and references/{taxonomy,handoff,tcb}.md:
    • Defines the verification boundary (index_and_mask, resource_capacity, pipeline_sync, semantic_equivalence vs numeric_rounding routed back to dynamic tools), JSON schemas (verify-request.json, verify-report.json), two single-operator entry modes (standalone and numericbridge_companion accepting result/optimize/<operator>/handoff.json), and explicit TCB disclosure rules.
  • Zero-dependency stdlib CLI scripts (skills/operator-verify/scripts/):
    • triage.py: scope classifier and verify-request.json builder (routes numeric_rounding back to precision-compare).
    • lean_check.py: Lean 4 type-checker and soundness auditor (rejects empty/theorem-less files, sorry/sorryAx/admit, custom axiom, native_decide/unsafe/opaque/implemented_by/extern/ofReduceBool/trustCompiler, and compiler sorry warnings; records SHA-256 provenance, toolchain version, public theorems, preconditions, and TCB assumptions).
  • Zero-dependency Lean 4 model library (skills/operator-verify/lean_lib/AscendLean/) (leanprover/lean4:v4.36.0, pure Lean 4 core with no Mathlib so lake build completes in seconds offline):
    • PipeModel.lean: 4 Ascend DaVinci pipelines (PIPE_MTE2, PIPE_V, PIPE_MTE3, PIPE_S) and all 12 directed FIFO HardEvents detecting cross-pipe RAW/WAR/WAW hazards, wait underflow, and leaked tokens.
    • UBModel.lean: Ascend A3 (192 KiB) / A5 (248 KiB) UB capacity bounds, INT32_MAX/INT64_MAX, unbounded nextPow2 with le_nextPow2, le_ceilDiv_mul, alignUp32, ubDisjoint, ubCastSafe (mixed-width & partial-overlap UB aliasing), and AscendC packed vector mask model.
    • TritonModel.lean: BitVec 64 bitwise select, ExtInt tiled reductions, IEEE-754 online-softmax (-inf) - (-inf) = NaN abstract domain (runOnline_fixed_all_neginf), masked-load LaneVal UB padding taint (sumRow, sumRow_zero_padded, sumRow_undef_poisons), and indexedLoadSafe.
  • Packaging & top-level docs synced to 6 skills:
    • Updated .gitignore (ignore .lake/), scripts/install.py (bundle operator-verify, exclude .lake/ and __pycache__/), AGENTS.md, README.md, README.zh-CN.md, docs/project-architecture.md, and tools/README.md.

Verification

  • cd skills/operator-verify/lean_lib && lake build — passed (10/10 jobs).
  • python3 -B -m scripts validate — passed (6 skills valid; checked 246 local links in 41 Markdown files.).
  • python3 -B -m scripts smoke-install — passed (Clean installation of 6 skills...).
  • tools/anonymize_scan.py on all 14 source files in skills/operator-verify/ — clean (0 findings).
  • Validated across 20 real Ascend C, Triton-Ascend, and Triton kernels from sgl-kernel-npu, vllm-ascend, RL-Kernel, and FlagGems (40 paired Lean 4 refutations and universal proofs, 133 public theorems / 144 total including private helpers, zero sorry / custom axioms).

Optional Follow-ups for Maintainer Alignment (Non-blocking)

This Draft PR intentionally leaves skills/numericbridge/references/workflow.md and server-side community schemas untouched to stay zero-invasive. Would appreciate alignment on two optional next steps:

  1. Main workflow routing (skills/numericbridge/references/workflow.md): Whether to add an optional offline pre-gate jump to operator-verify during Diagnose / Precision optimization (including when operator-optimize authors a new Triton/Ascend C kernel) when discrete structural/boundary/sync invariants apply, or keep operator-verify explicitly invoked for now.
  2. Community record schema (operator-verification evidence & badge): Today community/ accepts native-runtime / retained-measurements and operator-optimization bundles. In a follow-up, would it make sense to add an optional operator-verification evidence bundle type pointing to verify-report.json (schema in skills/operator-verify/references/handoff.md) so #/cases can surface formal verification receipts alongside dynamic runs?

…and AscendLean models

- Narrow operator-verify to standalone and numericbridge_companion single-operator modes (remove heuristic audit_scan.py and repo_audit mode) to mirror operator-optimize
- Expand AscendLean.UBModel (alignUp32, ubDisjoint, ubCastSafe) and AscendLean.TritonModel (runOnline_fixed_all_neginf, sumRow lemmas)
- Enrich L1-L4 taxonomy and harden triage.py classification priority and input validation
- Harden lean_check.py against guillemet-quoted axioms and debug.skipKernelTC, support attributed theorems, and probe toolchain versions in project cwd
- Sync top-level docs (AGENTS.md, README*.md, docs/project-architecture.md) and references (tcb.md, handoff.md)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant