经 AI Skill Hub 精选评估,Lean4-MLIR 获评「推荐使用」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。
Lean4-MLIR是一款开源AI工具,用于LLM-assisted Lean规范化神经网络架构,并且可以生成验证过的IREE代码。它提供了一个强大的框架,帮助开发者快速构建和验证AI模型。
Lean4-MLIR 是一款基于 Lean 开发的开源工具,专注于 Lean、AI、MLIR 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
Lean4-MLIR是一款开源AI工具,用于LLM-assisted Lean规范化神经网络架构,并且可以生成验证过的IREE代码。它提供了一个强大的框架,帮助开发者快速构建和验证AI模型。
Lean4-MLIR 是一款基于 Lean 开发的开源工具,专注于 Lean、AI、MLIR 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/brettkoonce/lean4-mlir cd lean4-mlir # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 lean4-mlir --help # 基本运行 lean4-mlir [options] <input> # 详细使用说明请查阅文档 # https://github.com/brettkoonce/lean4-mlir
# lean4-mlir 配置说明 # 查看配置选项 lean4-mlir --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export LEAN4_MLIR_CONFIG="/path/to/config.yml"
Interactive proof blueprint: brettkoonce.github.io/lean4-mlir/blueprint/ (or PDF) — clickable dependency DAG for the full VJP proof suite (no sorrys, zero project axioms), from pdiv primitives up to the whole-network VJPs (ViT, ResNet, MobileNetV2, ConvNeXt, EfficientNet).
Lean 4 as a specification language for neural networks. Declare architecture in Lean, generate StableHLO MLIR (forward + loss + backward + optimizer all in one fused function), compile to GPU via IREE, train end-to-end. No Python runtime, no autograd library — the gradients are computed at codegen time in Lean.
Companion code for the upcoming book Verified Deep Learning with Lean 4 (follow-up to Convolutional Neural Networks with Swift for TensorFlow, Apress).
Current version: v0.6.0 — Object detection joins the framework. A YOLOv1 person detector on Pascal VOC, bootstrapped from Chapter 6's ResNet-34 backbone with a 1×1 convolutional detection head — the FC head can't learn localization on a small dataset (diagnosed end to end in planning/yolo_v5.md); the focal-loss objectness term is the remaining piece, flagged in the bestiary's new detection intro. The IREE/Lean training path gains global-norm gradient clipping, env-var checkpoint resume (LEAN_MLIR_INIT_LOAD / LEAN_MLIR_START_STEP), and per-step LR warmup. Blueprint adds demo-anchored intros for object detection (§11.2.2) and diffusion (§11.2.7), redraws the MNIST/CIFAR training curves as native pgfplots (vector, regenerable from logs/), and adds a BatchNorm "why normalizing helps" intuition.
The v0.5.7 headline still holds: two parallel-agent audits closed. The "canonical correct := rfl" pattern at non-smooth operators (ReLU, the composed MLP, MaxPool2) now has machine-checked smooth-point bridges: relu_codegen_matches_canonical and maxPool2_codegen_matches_canonical prove the canonical-witness backward equals the codegen formula wherever every coordinate avoids the kink. A HasVJPAt pointwise framework provides smooth-input variants of the three kinked-operator instances whose correct field is a real chain-rule proof rather than rfl. The comparator suite extends from 38 → 41 theorems independently kernel-rechecked against `[propext, Quot.sound, Classical.choice]`. Blueprint gets a half-dozen flow improvements (GAP defined at first material use in Ch 6, Diffusion split into its own Bestiary subsection, ResNet entry expanded to the full standard family including R-18, Tomáš Skřivan's Scientific Computing in Lean credited at the top of the acknowledgments). Android bottom-cutoff bug fixed (issue #2); Umami cookieless analytics replaces planned GA. First Zenodo deposit lands with this release.
The v0.5.6 headline still holds: Chapter 9 lands its ConvNeXt-T worked example (84.94% val on Imagenette, paper-faithful recipe); Chapter 10 gets a Data Augmentation section with a 9-row ViT recipe ablation table — CutMix is the load-bearing knob at 9.5K images, and stacking RandAugment + Random Erasing on top of it hurts val accuracy. Bestiary gets paper-exact entries for VGG, ResNet-50/101/152, WRN, and DenseNet, plus the "N new primitives" claim reframed around the Ch 2-10 reader's toolbox (what's free) rather than the codebase (what's already in Types.lean). Found and fixed a long-standing eval-pipeline bug along the way: centerCrop was running on already-224 val data, reading past per-image bounds and making heavy-aug runs appear to collapse. New LEAN_MLIR_EVAL_ONLY=1 mode re-evals saved checkpoints in ~5 sec each.
The v0.5.5 headline still holds: Swish/SiLU as a first-class activation (forward + backward + proved swish_has_vjp_correct) plus the independent-kernel comparator re-check covering 38 theorems via public *_has_vjp_correct wrappers, and Ch 2's "Why VJPs, not Jacobians?" bridge + canonical-pdiv witness explainer + three-pillar TikZ spine diagram.
On top of that, a differential-test suite in tests/vjp_oracle/ uses JAX's value_and_grad as an oracle for the hand-derived VJPs in LeanMlir/Proofs/. Nine test cases cover every axiom family — dense, conv, BN, maxPool, residual (biPath), depthwise, SE (elementwise product), attention, and the transformer block — each verified to 1–2 ULP of JAX autodiff. The ULP-floor cross-backend agreement (Lean→IREE→GPU vs Lean→JAX→XLA on both NVIDIA and AMD) established in v0.5.4 still holds; see traces/CROSS_BACKEND_RESULTS.md for the four-corner verification tables.
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh
You need the IREE runtime built for your GPU (CUDA or ROCm). The FFI shim in ffi/ links against libiree_runtime_unified.a from the IREE build tree. See IREE_BUILD.md for build instructions.
lake build resnet34-train
This compiles the Lean trainer (which generates MLIR + drives IREE + runs the training loop). Other targets, in roughly book order: mnist-mlp-train, mnist-cnn-train, cifar-cnn-train, cifar-bn-train, resnet50-train, mobilenet-v2-train, mobilenet-v3-train, mobilenet-v4-train, efficientnet-train, efficientnet-v2-train, vgg-train, vit-tiny-train.
bash run.sh resnet34 # GPU 0, ROCm (defaults) bash run.sh efficientnet-v2 1 cuda # GPU 1, CUDA ```
For CUDA, set IREE_BACKEND=cuda (the default) and use CUDA_VISIBLE_DEVICES.
Lean NetSpec (~15 lines)
│
│ MlirCodegen.generateTrainStep
▼
StableHLO MLIR (500 KB - 2 MB of text, forward+loss+backward+Adam fused)
│
│ iree-compile (~10-15 min for ROCm gfx1100)
▼
VMFB flatbuffer (1.8-3 MB)
│
│ IREE runtime via libiree_ffi.so
▼
GPU execution (HIP/ROCm or CUDA)
The same Lean → MLIR pipeline handles every architecture. Adding a new architecture means extending LeanMlir/MlirCodegen.lean with: - forward emission for the new layer types - VJP / backward emission - FwdRec recording for backward intermediates
The training executable, FFI, and IREE runtime are unchanged.
Lean4-MLIR是一款非常有前景的AI工具,提供了一个强大的框架,帮助开发者快速构建和验证AI模型。它的Lean语言支持使得它成为一个非常有用的工具,特别是在需要快速构建和验证AI模型的场景下。然而,它的文档和社区支持还需要进一步改善。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ BSD 3-Clause — 宽松协议,可商用修改分发,禁止使用原作者名称进行背书宣传。
AI Skill Hub 点评:Lean4-MLIR 的核心功能完整,质量良好。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | lean4-mlir |
| 原始描述 | 开源AI工具:LLM-assisted Lean specification of neural architectures with verified IREE codeg。⭐21 · Lean |
| Topics | LeanAIMLIR |
| GitHub | https://github.com/brettkoonce/lean4-mlir |
| License | BSD-3-Clause |
| 语言 | Lean |
收录时间:2026-06-10 · 更新时间:2026-06-10 · License:BSD-3-Clause · AI Skill Hub 不对第三方内容的准确性作法律背书。