HuggingFace镜像/Leanstral-2603
模型介绍文件和版本分析
下载使用量0

Leanstral 119B A6B

Leanstral 是首个为 Lean 4 设计的开源代码智能体。Lean 4 是一款证明助手,能够表达复杂的数学对象(如 完美oid空间)以及软件规范(如 Rust 代码片段的属性)。

作为 Mistral Small 4 系列 的一部分,Leanstral 融合了多模态能力与高效架构,与现有的闭源替代方案相比,兼具高性能与成本效益。

有关该模型及其适用范围的更多详情,请阅读相关 博客文章。

主要特性

Leanstral 采用了以下架构设计:

  • MoE:128 个专家,每个 token 激活 4 个专家
  • 模型大小:1190 亿参数,每个 token 激活 65 亿参数
  • 上下文长度:256k tokens
  • 多模态输入:接受文本和图像输入,生成文本输出

Leanstral 具备以下功能:

  • 证明智能体:专为证明工程场景设计
  • 工具调用支持:针对 Mistral Vibe 优化
  • 视觉能力:能够分析图像并提供见解
  • 多语言支持:支持英语、法语、西班牙语、德语、意大利语、葡萄牙语、荷兰语、中文、日语、韩语和阿拉伯语
  • 系统提示遵从性:严格遵循系统提示
  • 速度优化:业界领先的性能
  • Apache 2.0 许可证:适用于商业和非商业用途的开源许可证
  • 大上下文窗口:支持高达 256k tokens

推荐设置

  • 温度(Temperature):1.0
  • 推理努力程度(Reasoning Effort):
    • 'none' → 不使用推理
    • 'high' → 使用推理(推荐用于复杂提示) 对于复杂任务,使用 reasoning_effort="high"
  • 上下文长度:建议 ≤ 200k tokens

使用方法

Mistral-Vibe

将 Leanstral 119B A6B 与 Mistral Vibe 配合使用。安装最新版本(2.5.0):

uv pip install mistral-vibe --upgrade

# make sure it's >= 2.5.0

Leanstral 可以通过启动 vibe 并直接运行以下命令来添加:

/leanstall

这将添加 leanstral 作为额外模型,添加系统提示(参见 LEAD.md),并确保 leanstral 可用作子智能体。

Screenshot 2026-03-16 at 18.03.39

然后只需按几次“tab+shift”,直到看到新的“lean”模式和 leanstral 模型。

Screenshot 2026-03-16 at 18.17.04

本地服务器

如果您不想调用 Mistral API,而是希望使用本地 vLLM 服务器,可以按以下步骤操作:

    1. 按照 Usage - vllm 中的说明启动 vllm 服务器
    1. 在 ~/.vibe/agents 目录中创建一个名为 lean.toml 的新智能体文件:
mkdir ~/.vibe/agents/ && touch ~/.vibe/agents/lean.toml

然后将以下配置复制粘贴到 ~/.vibe/agents/lean.toml 中

display_name = "Lean (local vLLM)"
description = "Lean 4 mode using local vLLM"
safety = "neutral"

system_prompt_id = "lean"
active_model = "leanstral"

[[providers]]
name = "vllm"
api_base = "http://<your-host-url>:8000/v1"
api_key_env_var = ""
backend = "generic"
reasoning_field_name = "reasoning_content"

[[models]]
name = "mistralai/Leanstral-2603"
provider = "vllm"
alias = "leanstral"
thinking = "high"
temperature = 1.0
auto_compact_threshold = 168000

[tools.bash]
default_timeout = 1200

注意:确保将 <your-host-url> 替换为您服务器的 URL。

然后重启 vibe 并通过“tab-shift”切换至“lean”模式。

您可以尝试使用一些“lean”代码进行测试,例如:PrimeNumberTheoremAnd

本地部署

该模型也可通过以下库进行部署。如果本地部署效果欠佳,建议大家使用 Mistral AI API:

  • vllm(推荐):详见此处。
  • transformers:开发中 ⏳ - 请关注此 PR 的更新。
  • SGLang:开发中 ⏳ - 请关注此 PR 的更新。

vLLM(推荐)

我们建议将此模型与 vLLM 库 配合使用,以实现生产级推理管道。

安装

[!提示] 我们建议从我们的自定义 Docker 镜像安装 vLLM,该镜像包含针对 vLLM 中工具调用和推理解析的修复,并使用最新版本的 Transformers。我们正与 vLLM 团队合作,以尽快将这些修复合并到主分支。

自定义 Docker

请确保使用以下 Docker 镜像 mistralllm/vllm-ms4:latest:

docker pull mistralllm/vllm-ms4:latest
docker run -it mistralllm/vllm-ms4:latest

手动安装

如果您愿意,也可以通过此 PR 手动安装 vllm:Add Mistral Guidance。

注意: 此 PR 可能会拆分为更小的 PR,并在未来 1-2 周内合并到 vllm 主分支(截至:2026 年 3 月 16 日)。 请直接在 PR 上查看最新进展。

  1. Git 克隆 vLLM:
git clone --branch fix_mistral_parsing https://github.com/juliendenize/vllm.git
  1. 使用预编译内核安装
VLLM_USE_PRECOMPILED=1 pip install --editable .
  1. 确保从 "main" 安装 transformers:
uv pip install git+https://github.com/huggingface/transformers.git

同时,请确保已安装 mistral_common >= 1.10.0。

检查方法:

python -c "import mistral_common; print(mistral_common.__version__)"

启动服务器

我们建议您在服务器/客户端环境中使用 Leanstral。

vllm serve mistralai/Leanstral-2603 \
  --max-model-len 200000 \
  --tensor-parallel-size 4 \
  --attention-backend FLASH_ATTN_MLA \
  --tool-call-parser mistral \
  --enable-auto-tool-choice \
  --reasoning-parser mistral

客户

from openai import OpenAI
from huggingface_hub import hf_hub_download

# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "<your-host-url>"

client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

TEMP = 1.0
MAX_TOK = 32000
REASONING = "high" # switch to 'none' for faster answers

models = client.models.list()
model = models.data[0].id


prompt = """Define the transition rules as an inductive proposition.

This choice provides better support for proving properties about valid transitions and is generally more natural for modeling state machines in Lean, where you want to express logical rules rather than just computing a yes/no vale for each possible transition."""
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": prompt,
            },
        ],
    },
]



response = client.chat.completions.create(
    model=model,
    messages=messages,
    temperature=TEMP,
    max_tokens=MAX_TOK,
    reasoning_effort=REASONING,
)

print("Content")
print(response.choices[0].message.content)

pritn("Reasoning")
print(response.choices[0].message.reasoning)

示例内容:

展开 要在 Lean 中将事务规则定义为归纳命题,您可以创建一个归纳类型来捕获状态之间的有效转换。这种方法对于建模状态机以及证明转换相关的属性(如不变量)特别有用。

以下是如何为简单计数器机器定义有效转换的归纳命题示例:

-- Example: Counter that can only increment by 1 (no decrement, no shortcuts)
inductive ValidTransition : Nat → Nat → Prop
  | step1 : ∀ s, ValidTransition s (s + 1)   -- Core transition: s → s+1
  | step2 : ∀ s, ValidTransition s (2 * s)    -- Bonus: s → 2s (optional)
  | zero_step : ValidTransition 0 0          -- Additional special case

lemma reach_any_positive : ∀ n > 0, ValidTransition 0 n := by
  induction n with
  | zero => contradiction
  | succ n ih =>
    cases' Nat.eq_zero_or_pos n with h h
    · simp [h]
    · have : ValidTransition 0 (n + 1) := by
        cases' h with _ ih    -- Wait, this is messy...

在本例中,ValidTransition 被定义为一个归纳命题,包含构造子 step1、step2 和 zero_step。构造子 step1 允许任意状态通过加 1 转换到下一个状态,而 step2 允许将状态加倍。zero_step 构造子是初始状态 0 的特殊情况。

引理 reach_any_positive 旨在证明任何正自然数都可以通过有效的转换从初始状态 0 到达。该证明对 n 使用了归纳法,但由于简化问题,当前方法可能并非最有效。

一种更简洁有效的定义和证明转换性质的方法是使用更简单的模型,如下所示:

-- Simpler model for counter transitions (suffices for proofs)
inductive CounterTrans : Nat → Nat → Prop
  | valid : ∀ n, CounterTrans n (n + 1)

lemma reach_positive : ∀ n > 0, CounterTrans 0 n
  -- Proof is now trivial (by induction)

在这个更简单的模型中,CounterTrans 通过单个构造函数 valid 定义,该构造函数允许任何状态通过加 1 转换到下一个状态。引理 reach_positive 可以通过归纳法直接证明,这得益于转换规则的简洁性。

这种方法确保证明保持简洁有效,避免了转换规则中不必要的复杂性。通过使用归纳命题,我们可以有效地对状态转换进行推理,并证明系统的相关属性。

Tool-Calling

你可以按以下方式将 tools 添加到聊天补全中:

prompt = """I have the following Lean 4 code snippet and want to check if it compiles and runs without errors. Can you run it for me and let me know the result?

```lean\ninductive State where\n  | idle\n  | busy\n  | error\n\ndef transition : State → State → Bool\n  | .idle, .busy => true\n  | .busy, .idle => true\n  | .busy, .error => true\n  | _, _ => false\n\n#eval transition .idle .busy\n```"""

tools = [{
    "type": "function",
    "function": {
        "name": "lean_run_code",
        "description": "Run or compile an independent Lean code snippet or file and return the result or error message.",
        "parameters": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "Lean code snippet to run or compile. Either this or file_path must be provided."
                },
                "file_path": {
                    "type": "string",
                    "description": "Path to the Lean file to run or compile. Either this or code must be provided."
                }
            },
        }
        }
}]

messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": prompt,
            },
        ],
    },
]

response = client.chat.completions.create(
    model=model,
    messages=messages,
    temperature=TEMP,
    max_tokens=MAX_TOK,
    reasoning_effort=REASONING,
    tools=tools,
)

print("Tool Calls")
print(response.choices[0].message.tool_calls)

print("Reasoning")
print(response.choices[0].message.reasoning)

示例工具调用:

展开

Function(arguments='{"code": "inductive State where\\n | idle\\n | busy\\n | error\\n\\ndef transition : State → State → Bool\\n | .idle, .busy => true\\n | .busy, .idle => true\\n | .busy, .error => true\\n | _, _ => false\\n\\n#eval transition .idle .busy"}', name='lean_run_code')

许可证

本模型采用 Apache 2.0 许可证 授权。

您不得将本模型用于侵犯、盗用或以其他方式违反任何第三方权利(包括知识产权)的行为。