Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
!/scripts/
/skills/*
!/skills/operator-optimize/
!/skills/operator-verify/
!/skills/framework-adapt/
!/skills/numericbridge/
!/skills/precision-compare/
Expand All @@ -26,6 +27,7 @@
/research/
__pycache__/
*.pyc
.lake/

# Historical local deliveries are not part of the results-only publication.
/community/site/evidence/deepseek41-*.zip
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Layout

- `skills/numericbridge/` is the entrypoint for the full workflow. It owns stage transitions and handoffs and links to the installable `framework-adapt`, `precision-compare`, `precision-repair` and `operator-optimize` skills for execution methods. Load those methods on demand. Export the suite with `python -B -m scripts install --output NEW_DIRECTORY` to bundle the shared `tools/` once in Compare. Reuse workload execution, verified resources, inputs/state, collectors and results. `skills/operator-optimize/` owns operator optimization after diagnosis: configuration, backend and kernel variants measured against FP64 with paired timing (`scripts/kernel_check.py`).
- `skills/numericbridge/` is the entrypoint for the full workflow. It owns stage transitions and handoffs and links to the installable `framework-adapt`, `precision-compare`, `precision-repair`, `operator-optimize` and `operator-verify` skills for execution methods. Load those methods on demand. Export the suite with `python -B -m scripts install --output NEW_DIRECTORY` to bundle the shared `tools/` once in Compare. Reuse workload execution, verified resources, inputs/state, collectors and results. `skills/operator-optimize/` owns operator optimization after diagnosis: configuration, backend and kernel variants measured against FP64 with paired timing (`scripts/kernel_check.py`). `skills/operator-verify/` owns offline Lean 4 formal verification (`scripts/triage.py`, `scripts/lean_check.py`, `lean_lib/AscendLean/`) for discrete operator invariants.

- `research/` is retained local RSI research, Git-ignored and excluded from both the public repository and normal Skill installation. Preserve its local code, state and recorded experiments. It owns task/iteration orchestration over existing workflow tools and an external harness. Index successful/incomplete task evidence; keep full traces and datasets private. The independent improver builds candidates. Evaluate exact tool/context/procedure bundles on independent task families before activation; label dataset outcomes at task scope. Pin task versions, preserve raw usage and reuse comparable baseline receipts. Native checks remain task-owned. Agent-weight training and operator search are extension points.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ skills="numericbridge-skills-$version"
shasum -a 256 -c "$archive.sha256" && mkdir "$skills" && unzip "$archive" -d "$skills"
```

On Linux you can use `sha256sum -c "$archive.sha256"` in place of `shasum -a 256 -c "$archive.sha256"`. Point your agent client at the directory containing the five skills, or copy the five skill folders together into its skills directory. New Skills ZIP builds include the shared tools, but no community records or search index; older releases may include a snapshot. [Updates and checkout-based installation](tools/README.md#portable-skills)
On Linux you can use `sha256sum -c "$archive.sha256"` in place of `shasum -a 256 -c "$archive.sha256"`. Point your agent client at the directory containing the six skills, or copy the six skill folders together into its skills directory. New Skills ZIP builds include the shared tools, but no community records or search index; older releases may include a snapshot. [Updates and checkout-based installation](tools/README.md#portable-skills)

**Develop from source.** Use `git clone --depth 1 https://github.com/FreedomIntelligence/NumericBridge.git` for a clean current checkout without the historical catalog objects. Full Git history still contains independently published older revisions.

Expand All @@ -52,7 +52,7 @@ For your workload, start with the [NumericBridge Skill](skills/numericbridge/SKI

## Workflow and skills

The [workflow](skills/numericbridge/references/workflow.md) loads only the method it needs: [Framework Adapt](skills/framework-adapt/SKILL.md) for native setup, [Precision Compare](skills/precision-compare/SKILL.md) for measurement, [Precision Repair](skills/precision-repair/SKILL.md) for supported-path failures or numerical findings that warrant diagnosis, and [Operator Optimize](skills/operator-optimize/SKILL.md) for operators that diagnosis finds outside their FP64 bound, reporting each variant's precision and speed. Each stage reuses the confirmed request and evidence.
The [workflow](skills/numericbridge/references/workflow.md) loads only the method it needs: [Framework Adapt](skills/framework-adapt/SKILL.md) for native setup, [Precision Compare](skills/precision-compare/SKILL.md) for measurement, [Precision Repair](skills/precision-repair/SKILL.md) for supported-path failures or numerical findings that warrant diagnosis, [Operator Optimize](skills/operator-optimize/SKILL.md) for operators that diagnosis finds outside their FP64 bound, reporting each variant's precision and speed, and [Operator Verify](skills/operator-verify/SKILL.md) for offline Lean 4 formal verification of discrete operator invariants (masks, UB capacity, pipeline synchronization, and algebraic/control-flow equivalence). Each stage reuses the confirmed request and evidence.

Task recipes: [Inference](skills/precision-compare/references/inference.md) · [SFT](skills/precision-compare/references/sft.md) · [RL](skills/precision-compare/references/rl.md).

Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ skills="numericbridge-skills-$version"
shasum -a 256 -c "$archive.sha256" && mkdir "$skills" && unzip "$archive" -d "$skills"
```

在 Linux 上也可以用 `sha256sum -c "$archive.sha256"` 代替 `shasum -a 256 -c "$archive.sha256"`。让 Agent 客户端从解压后的目录加载五个 Skill,或将五个 Skill 文件夹一起复制到客户端的 Skill 目录。新版 Skills ZIP 包含共享工具,但不附带社区记录或检索索引;旧版可能包含快照。[更新与从仓库安装](tools/README.md#portable-skills)
在 Linux 上也可以用 `sha256sum -c "$archive.sha256"` 代替 `shasum -a 256 -c "$archive.sha256"`。让 Agent 客户端从解压后的目录加载六个 Skill,或将六个 Skill 文件夹一起复制到客户端的 Skill 目录。新版 Skills ZIP 包含共享工具,但不附带社区记录或检索索引;旧版可能包含快照。[更新与从仓库安装](tools/README.md#portable-skills)

**需要源码时**,用 `git clone --depth 1 https://github.com/FreedomIntelligence/NumericBridge.git` 获取干净的当前版本;完整 Git 历史仍保留以前公开发布过的记录。

Expand All @@ -52,7 +52,7 @@ python -B "$skills/precision-compare/examples/compare_gradients.py"

## 工作流与 Skill

[工作流](skills/numericbridge/references/workflow.md)按需加载各阶段的 Skill:[Framework Adapt](skills/framework-adapt/SKILL.md) 准备原生环境,[Precision Compare](skills/precision-compare/SKILL.md) 采集和对比,支持的路径运行失败或发现值得调查的数值差异时,进入 [Precision Repair](skills/precision-repair/SKILL.md);诊断发现算子超出 FP64 误差范围时,进入 [Operator Optimize](skills/operator-optimize/SKILL.md),给出每个方案的精度和速度。每一步沿用已确认的需求和证据。
[工作流](skills/numericbridge/references/workflow.md)按需加载各阶段的 Skill:[Framework Adapt](skills/framework-adapt/SKILL.md) 准备原生环境,[Precision Compare](skills/precision-compare/SKILL.md) 采集和对比,支持的路径运行失败或发现值得调查的数值差异时,进入 [Precision Repair](skills/precision-repair/SKILL.md);诊断发现算子超出 FP64 误差范围时,进入 [Operator Optimize](skills/operator-optimize/SKILL.md),给出每个方案的精度和速度;涉及离散不变量(掩码越界、UB 容量、流水线同步或控制流/代数等价性)时,可通过 [Operator Verify](skills/operator-verify/SKILL.md) 进行离线 Lean 4 形式化验证。每一步沿用已确认的需求和证据。

任务配方:[推理](skills/precision-compare/references/inference.md) · [SFT](skills/precision-compare/references/sft.md) · [RL](skills/precision-compare/references/rl.md)。

Expand Down
2 changes: 1 addition & 1 deletion docs/project-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Agent 从 [NumericBridge Skill](../skills/numericbridge/SKILL.md) 进入。[流
| 本地私有 projects/、runs/ | 原生案例、资源配置、原始数组、完整日志与过程记录 |

这些目录按用途分工,不是用户必须理解或依次启动的架构层。
安装包包含 numericbridge、framework-adapt、precision-compare、precision-repair、operator-optimize。operator-optimize 接在诊断之后,对照 FP64 测量配置、后端和 kernel 方案的精度与速度。
安装包包含 numericbridge、framework-adapt、precision-compare、precision-repair、operator-optimize、operator-verify。operator-optimize 接在诊断之后,对照 FP64 测量配置、后端和 kernel 方案的精度与速度;operator-verify 提供面向离散算子不变量的离线 Lean 4 形式化验证。

## 工具放置与安装

Expand Down
4 changes: 2 additions & 2 deletions scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil

ROOT = Path(__file__).resolve().parents[1]
INSTALLABLE_SKILLS = ('framework-adapt', 'numericbridge', 'operator-optimize', 'precision-compare', 'precision-repair')
INSTALLABLE_SKILLS = ('framework-adapt', 'numericbridge', 'operator-optimize', 'operator-verify', 'precision-compare', 'precision-repair')
COMMUNITY_DATA_NAMES = {'community-search.json', 'search-index.json', 'evaluations.json',
'repairs.json', 'relations.json'}

Expand Down Expand Up @@ -55,7 +55,7 @@ def install_skills(source, destination):
raise FileExistsError(destination / folder.name)
for folder in folders:
shutil.copytree(folder, destination / folder.name,
ignore=shutil.ignore_patterns('__pycache__', '*.pyc'),
ignore=shutil.ignore_patterns('__pycache__', '*.pyc', '.lake'),
copy_function=_copy_workflow_file)
if folder.name == 'precision-compare':
shutil.copytree(ROOT / 'tools',
Expand Down
45 changes: 45 additions & 0 deletions skills/operator-verify/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: operator-verify
description: Formally verify accelerator operators (Triton-Ascend, Ascend C, Triton, CUDA) without target hardware using Lean 4 to prove index/mask safety, on-chip resource bounds, pipeline sync safety, and discrete semantic equivalence, or produce machine-checked counterexamples.
---

# Operator verification

Run tools from this skill directory. Each tool's `--help` gives its interface.

| Step | Tool | Output |
|---|---|---|
| Classify verification scope and build a request | [triage](scripts/triage.py) | `verify-request.json` with category, eligibility, route, and model modules |
| Type-check Lean 4 proofs and audit `sorry` / axioms | [lean_check](scripts/lean_check.py) | `verify-report.json` with toolchain, hashes, theorem list, audit status, and verdict |

Read [taxonomy](references/taxonomy.md) for the discrete-verification vs floating-point boundary, [handoff](references/handoff.md) for the input/output JSON contracts, and [TCB](references/tcb.md) for hardware modeling assumptions.

`operator-verify` pairs with [operator-optimize](../operator-optimize/SKILL.md): `operator-verify` proves discrete structural, memory, synchronization, and algebraic/bit-level properties offline for a localized operator without an accelerator; pure floating-point rounding accuracy and runtime timing remain in [precision-compare](../precision-compare/SKILL.md) and [operator-optimize](../operator-optimize/SKILL.md).

## Entry

1. **Standalone mode.** Start from a single kernel source file, PR diff, or Lean 4 target. Run `triage.py` to classify the issue into one of the discrete categories (`index_and_mask`, `resource_capacity`, `pipeline_sync`, `semantic_equivalence`) or route `numeric_rounding` back to dynamic precision tools.
2. **NumericBridge companion / pre-gate mode.** Accept an operator handoff (`result/optimize/<operator>/handoff.json`) or a `diagnosis.json` hypothesis, verify discrete invariants offline, and write `result/verify/<operator>/verify-report.json` as evidence alongside dynamic checks.

## Verify

1. **Classify scope.** Run `triage.py` on the operator target or handoff. Stop and route `numeric_rounding` (quantitative FP rounding error) to `precision-compare` or `operator-optimize`; keep qualitative `±inf` / `NaN` propagation and poisoning in `semantic_equivalence`.
2. **Bind to a Lean target.** Map the kernel property to a reusable semantics module in `lean_lib/` (see [lean_lib/README.md](lean_lib/README.md)). Distinguish **refutation** (concrete counterexample proving a buggy kernel fails) from **universal proof** (invariant proved for all symbolic shapes/inputs). `lean_lib/` targets pure Lean 4 core with **no Mathlib** — use core tactics (`let`, `omega`, `decide`, `simp`, `by_cases`, `induction`) rather than Mathlib-only tactics (`set`, `linarith`, `ring`, `by_contra`).
3. **Run machine check.** Run `lean_check.py` against the target `.lean` file and Lake project, e.g. `python3 scripts/lean_check.py TARGET.lean --project lean_lib --source KERNEL.py --claim-kind refutation --output verify-report.json`. It records Lean/Lake versions, source SHA-256 digests, public theorems, `sorry`/`admit`/custom-`axiom` audit counts, compiler status, and verdict.
4. **Disclose TCB, preconditions, and deliver.** Record explicit modeling assumptions per [TCB](references/tcb.md) and any required or discovered `preconditions` in `result/verify/<operator>/verify-report.json` (or the standalone output directory).

```xml
<rules>
A verdict of `proved` or `refuted` requires zero compiler errors, zero `sorry`
or `admit` tokens, and zero unapproved custom axioms.
Never claim floating-point rounding error bounds from a discrete Lean model;
quantitative precision belongs to `precision-compare` and `kernel_check.py`
(discrete `±inf`/`NaN` abstract-domain propagation is in scope under `semantic_equivalence`).
Always preserve source SHA-256 digests, Lean toolchain identity, discovered
`preconditions`, and explicit TCB assumptions in `verify-report.json`.
When `lake` or `lean` is unavailable on the host, report `toolchain_missing`
and `verdict: "not_run"` rather than fabricating or skipping verification.
Keep experimental corpora, raw benchmarks, and `.lake/` build caches outside
the tracked skill directory.
</rules>
```
3 changes: 3 additions & 0 deletions skills/operator-verify/lean_lib/AscendLean.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AscendLean.PipeModel
import AscendLean.UBModel
import AscendLean.TritonModel
Loading