Update README.md
Browse files
README.md
CHANGED
|
@@ -16,7 +16,7 @@ Leanstral consists of the following architectural choices:
|
|
| 16 |
|
| 17 |
- MoE: 128 experts and 4 active.
|
| 18 |
- 119B with 6.5B activated parameters per token.
|
| 19 |
-
-
|
| 20 |
- Multimodal Input: Accepts both text and image input, with text output.
|
| 21 |
|
| 22 |
Leanstral offers the following capabilities:
|
|
@@ -27,7 +27,15 @@ Leanstral offers the following capabilities:
|
|
| 27 |
- **System Prompt**: Maintains strong adherence and support for system prompts.
|
| 28 |
- **Speed-Optimized**: Delivers best-in-class performance and speed.
|
| 29 |
- **Apache 2.0 License**: Open-source license allowing usage and modification for both commercial and non-commercial purposes.
|
| 30 |
-
- **Large Context Window**: Supports a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
## Usage
|
| 33 |
|
|
@@ -45,9 +53,6 @@ The model can also be deployed with the following libraries, we advise everyone
|
|
| 45 |
|
| 46 |
#### vLLM (recommended)
|
| 47 |
|
| 48 |
-
<details>
|
| 49 |
-
<summary>Expand</summary
|
| 50 |
-
|
| 51 |
We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)
|
| 52 |
to implement production-ready inference pipelines.
|
| 53 |
|
|
@@ -144,284 +149,54 @@ data = {"model": model, "messages": messages, "temperature": 1.0, "reasoning_eff
|
|
| 144 |
# data = {"model": model, "messages": messages, "temperature": 0.15, "tools": tools} # Pass tools to payload.
|
| 145 |
|
| 146 |
response = requests.post(url, headers=headers, data=json.dumps(data))
|
| 147 |
-
|
| 148 |
-
print(response.json()["choices"][0]["message"]["content"])
|
| 149 |
-
```
|
| 150 |
-
</details>
|
| 151 |
-
|
| 152 |
-
#### SGLang
|
| 153 |
-
|
| 154 |
-
<details>
|
| 155 |
-
<summary>Expand</summary>
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
Install SGLang from source (track latest `main` locally):
|
| 163 |
-
|
| 164 |
-
```
|
| 165 |
-
git clone https://github.com/sgl-project/sglang.git
|
| 166 |
-
cd sglang
|
| 167 |
-
uv pip install -e python
|
| 168 |
-
uv pip install transformers==5.0.0rc # required
|
| 169 |
```
|
| 170 |
|
| 171 |
-
**
|
| 172 |
-
|
| 173 |
-
We recommend that you use Devstral in a server/client setting.
|
| 174 |
-
|
| 175 |
-
1. Spin up a server:
|
| 176 |
-
|
| 177 |
-
```
|
| 178 |
-
python -m sglang.launch_server --model-path mistralai/Devstral-2-123B-Instruct-2512 --host 0.0.0.0 --port 30000 --tp 8 --tool-call-parser mistral
|
| 179 |
```
|
|
|
|
| 180 |
|
|
|
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
url = "http://<your-server-url>:30000/v1/chat/completions"
|
| 191 |
-
headers = {"Content-Type": "application/json", "Authorization": "Bearer token"}
|
| 192 |
-
|
| 193 |
-
model = "mistralai/Devstral-2-123B-Instruct-2512"
|
| 194 |
-
|
| 195 |
-
def load_system_prompt(repo_id: str, filename: str) -> str:
|
| 196 |
-
file_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 197 |
-
with open(file_path, "r") as file:
|
| 198 |
-
system_prompt = file.read()
|
| 199 |
-
return system_prompt
|
| 200 |
-
|
| 201 |
-
SYSTEM_PROMPT = load_system_prompt(model, "CHAT_SYSTEM_PROMPT.txt")
|
| 202 |
-
|
| 203 |
-
messages = [
|
| 204 |
-
{"role": "system", "content": SYSTEM_PROMPT},
|
| 205 |
-
{
|
| 206 |
-
"role": "user",
|
| 207 |
-
"content": [
|
| 208 |
-
{
|
| 209 |
-
"type": "text",
|
| 210 |
-
"text": "<your-command>",
|
| 211 |
-
},
|
| 212 |
-
],
|
| 213 |
-
},
|
| 214 |
-
]
|
| 215 |
-
|
| 216 |
-
data = {"model": model, "messages": messages, "temperature": 0.15}
|
| 217 |
-
|
| 218 |
-
# Devstral 2 supports tool calling. If you want to use tools, follow this:
|
| 219 |
-
# tools = [ # Define tools (OpenAI-compatible)
|
| 220 |
-
# {
|
| 221 |
-
# "type": "function",
|
| 222 |
-
# "function": {
|
| 223 |
-
# "name": "git_clone",
|
| 224 |
-
# "description": "Clone a git repository",
|
| 225 |
-
# "parameters": {
|
| 226 |
-
# "type": "object",
|
| 227 |
-
# "properties": {
|
| 228 |
-
# "url": {
|
| 229 |
-
# "type": "string",
|
| 230 |
-
# "description": "The url of the git repository",
|
| 231 |
-
# },
|
| 232 |
-
# },
|
| 233 |
-
# "required": ["url"],
|
| 234 |
-
# },
|
| 235 |
-
# },
|
| 236 |
-
# }
|
| 237 |
-
# ]
|
| 238 |
-
# data = {"model": model, "messages": messages, "temperature": 0.15, "tools": tools} # Pass tools to payload.
|
| 239 |
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
```
|
| 243 |
-
</details>
|
| 244 |
|
| 245 |
-
|
| 246 |
|
| 247 |
-
|
| 248 |
-
<summary>Expand</summary
|
| 249 |
|
| 250 |
-
|
| 251 |
|
| 252 |
-
```
|
| 253 |
-
|
| 254 |
-
|
|
|
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
```python
|
| 259 |
-
from transformers import (
|
| 260 |
-
MistralForCausalLM,
|
| 261 |
-
MistralCommonBackend,
|
| 262 |
-
)
|
| 263 |
-
|
| 264 |
-
model_id = "mistralai/Devstral-2-123B-Instruct-2512"
|
| 265 |
-
|
| 266 |
-
tokenizer = MistralCommonBackend.from_pretrained(model_id)
|
| 267 |
-
model = MistralForCausalLM.from_pretrained(model_id, device_map="auto")
|
| 268 |
-
|
| 269 |
-
SP = """You are operating as and within Mistral Vibe, a CLI coding-agent built by Mistral AI and powered by default by the Devstral family of models. It wraps Mistral's Devstral models to enable natural language interaction with a local codebase. Use the available tools when helpful.
|
| 270 |
-
|
| 271 |
-
You can:
|
| 272 |
-
|
| 273 |
-
- Receive user prompts, project context, and files.
|
| 274 |
-
- Send responses and emit function calls (e.g., shell commands, code edits).
|
| 275 |
-
- Apply patches, run commands, based on user approvals.
|
| 276 |
-
|
| 277 |
-
Answer the user's request using the relevant tool(s), if they are available. Check that all the required parameters for each tool call are provided or can reasonably be inferred from context. IF there are no relevant tools or there are missing values for required parameters, ask the user to supply these values; otherwise proceed with the tool calls. If the user provides a specific value for a parameter (for example provided in quotes), make sure to use that value EXACTLY. DO NOT make up values for or ask about optional parameters. Carefully analyze descriptive terms in the request as they may indicate required parameter values that should be included even if not explicitly quoted.
|
| 278 |
-
|
| 279 |
-
Always try your hardest to use the tools to answer the user's request. If you can't use the tools, explain why and ask the user for more information.
|
| 280 |
-
|
| 281 |
-
Act as an agentic assistant, if a user asks for a long task, break it down and do it step by step.
|
| 282 |
-
|
| 283 |
-
When you want to commit changes, you will always use the 'git commit' bash command. It will always be suffixed with a line telling it was generated by Mistral Vibe with the appropriate co-authoring information. The format you will always use is the following heredoc.
|
| 284 |
-
|
| 285 |
-
```bash
|
| 286 |
-
git commit -m "<Commit message here>
|
| 287 |
-
|
| 288 |
-
Generated by Mistral Vibe.
|
| 289 |
-
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>"
|
| 290 |
-
```"""
|
| 291 |
-
|
| 292 |
-
input = {
|
| 293 |
-
"messages": [
|
| 294 |
-
{
|
| 295 |
-
"role": "system",
|
| 296 |
-
"content": SP,
|
| 297 |
-
},
|
| 298 |
-
{
|
| 299 |
-
"role": "user",
|
| 300 |
-
"content": [
|
| 301 |
-
{
|
| 302 |
-
"type": "text",
|
| 303 |
-
"text": "Can you implement in Python a method to compute the fibonnaci sequence at the `n`th element with `n` a parameter passed to the function ? You should start the sequence from 1, previous values are invalid.\nThen run the Python code for the function for n=5 and give the answer.",
|
| 304 |
-
}
|
| 305 |
-
],
|
| 306 |
-
},
|
| 307 |
-
],
|
| 308 |
-
"tools": [
|
| 309 |
-
{
|
| 310 |
-
"type": "function",
|
| 311 |
-
"function": {
|
| 312 |
-
"name": "add_number",
|
| 313 |
-
"description": "Add two numbers.",
|
| 314 |
-
"parameters": {
|
| 315 |
-
"type": "object",
|
| 316 |
-
"properties": {
|
| 317 |
-
"a": {"type": "string", "description": "The first number."},
|
| 318 |
-
"b": {"type": "string", "description": "The second number."},
|
| 319 |
-
},
|
| 320 |
-
"required": ["a", "b"],
|
| 321 |
-
},
|
| 322 |
-
},
|
| 323 |
-
},
|
| 324 |
-
{
|
| 325 |
-
"type": "function",
|
| 326 |
-
"function": {
|
| 327 |
-
"name": "multiply_number",
|
| 328 |
-
"description": "Multiply two numbers.",
|
| 329 |
-
"parameters": {
|
| 330 |
-
"type": "object",
|
| 331 |
-
"properties": {
|
| 332 |
-
"a": {"type": "string", "description": "The first number."},
|
| 333 |
-
"b": {"type": "string", "description": "The second number."},
|
| 334 |
-
},
|
| 335 |
-
"required": ["a", "b"],
|
| 336 |
-
},
|
| 337 |
-
},
|
| 338 |
-
},
|
| 339 |
-
{
|
| 340 |
-
"type": "function",
|
| 341 |
-
"function": {
|
| 342 |
-
"name": "substract_number",
|
| 343 |
-
"description": "Substract two numbers.",
|
| 344 |
-
"parameters": {
|
| 345 |
-
"type": "object",
|
| 346 |
-
"properties": {
|
| 347 |
-
"a": {"type": "string", "description": "The first number."},
|
| 348 |
-
"b": {"type": "string", "description": "The second number."},
|
| 349 |
-
},
|
| 350 |
-
"required": ["a", "b"],
|
| 351 |
-
},
|
| 352 |
-
},
|
| 353 |
-
},
|
| 354 |
-
{
|
| 355 |
-
"type": "function",
|
| 356 |
-
"function": {
|
| 357 |
-
"name": "write_a_story",
|
| 358 |
-
"description": "Write a story about science fiction and people with badass laser sabers.",
|
| 359 |
-
"parameters": {},
|
| 360 |
-
},
|
| 361 |
-
},
|
| 362 |
-
{
|
| 363 |
-
"type": "function",
|
| 364 |
-
"function": {
|
| 365 |
-
"name": "terminal",
|
| 366 |
-
"description": "Perform operations from the terminal.",
|
| 367 |
-
"parameters": {
|
| 368 |
-
"type": "object",
|
| 369 |
-
"properties": {
|
| 370 |
-
"command": {
|
| 371 |
-
"type": "string",
|
| 372 |
-
"description": "The command you wish to launch, e.g `ls`, `rm`, ...",
|
| 373 |
-
},
|
| 374 |
-
"args": {
|
| 375 |
-
"type": "string",
|
| 376 |
-
"description": "The arguments to pass to the command.",
|
| 377 |
-
},
|
| 378 |
-
},
|
| 379 |
-
"required": ["command"],
|
| 380 |
-
},
|
| 381 |
-
},
|
| 382 |
-
},
|
| 383 |
-
{
|
| 384 |
-
"type": "function",
|
| 385 |
-
"function": {
|
| 386 |
-
"name": "python",
|
| 387 |
-
"description": "Call a Python interpreter with some Python code that will be ran.",
|
| 388 |
-
"parameters": {
|
| 389 |
-
"type": "object",
|
| 390 |
-
"properties": {
|
| 391 |
-
"code": {
|
| 392 |
-
"type": "string",
|
| 393 |
-
"description": "The Python code to run",
|
| 394 |
-
},
|
| 395 |
-
"result_variable": {
|
| 396 |
-
"type": "string",
|
| 397 |
-
"description": "Variable containing the result you'd like to retrieve from the execution.",
|
| 398 |
-
},
|
| 399 |
-
},
|
| 400 |
-
"required": ["code", "result_variable"],
|
| 401 |
-
},
|
| 402 |
-
},
|
| 403 |
-
},
|
| 404 |
-
],
|
| 405 |
-
}
|
| 406 |
-
|
| 407 |
-
tokenized = tokenizer.apply_chat_template(
|
| 408 |
-
conversation=input["messages"],
|
| 409 |
-
tools=input["tools"],
|
| 410 |
-
return_tensors="pt",
|
| 411 |
-
return_dict=True,
|
| 412 |
-
)
|
| 413 |
-
|
| 414 |
-
input_ids = tokenized["input_ids"].to(device="cuda")
|
| 415 |
-
|
| 416 |
-
output = model.generate(
|
| 417 |
-
input_ids,
|
| 418 |
-
max_new_tokens=200,
|
| 419 |
-
do_sample=True,
|
| 420 |
-
temperature=0.15,
|
| 421 |
-
)[0]
|
| 422 |
-
|
| 423 |
-
decoded_output = tokenizer.decode(output[len(tokenized["input_ids"][0]) :])
|
| 424 |
-
print(decoded_output)
|
| 425 |
```
|
| 426 |
|
| 427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
- MoE: 128 experts and 4 active.
|
| 18 |
- 119B with 6.5B activated parameters per token.
|
| 19 |
+
- 256k Context Length.
|
| 20 |
- Multimodal Input: Accepts both text and image input, with text output.
|
| 21 |
|
| 22 |
Leanstral offers the following capabilities:
|
|
|
|
| 27 |
- **System Prompt**: Maintains strong adherence and support for system prompts.
|
| 28 |
- **Speed-Optimized**: Delivers best-in-class performance and speed.
|
| 29 |
- **Apache 2.0 License**: Open-source license allowing usage and modification for both commercial and non-commercial purposes.
|
| 30 |
+
- **Large Context Window**: Supports a 200k context window.
|
| 31 |
+
|
| 32 |
+
## Recommended Settings
|
| 33 |
+
- **Temperature**: 1.0
|
| 34 |
+
- **Reasoning Effort**: Choose between:
|
| 35 |
+
- 'none' => Do not use reasoning
|
| 36 |
+
- 'high' => Use reasoning
|
| 37 |
+
We recommend reasoning_effort="high" for more complex prompts
|
| 38 |
+
- **Context Length**: We recommend staying <= 200k for optimal results
|
| 39 |
|
| 40 |
## Usage
|
| 41 |
|
|
|
|
| 53 |
|
| 54 |
#### vLLM (recommended)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)
|
| 57 |
to implement production-ready inference pipelines.
|
| 58 |
|
|
|
|
| 149 |
# data = {"model": model, "messages": messages, "temperature": 0.15, "tools": tools} # Pass tools to payload.
|
| 150 |
|
| 151 |
response = requests.post(url, headers=headers, data=json.dumps(data))
|
| 152 |
+
output = response.json()["choices"][0]["message"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
+
print("Answer:")
|
| 155 |
+
print(output['content'])
|
| 156 |
|
| 157 |
+
print("Thinking:")
|
| 158 |
+
print(output['reasoning'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
```
|
| 160 |
|
| 161 |
+
**Example Output**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
```
|
| 163 |
+
To define transaction rules as an inductive proposition in Lean, you can create an inductive type that captures the valid transitions between states. This approach is particularly useful for modeling state machines and proving properties about transitions, such as invariants.
|
| 164 |
|
| 165 |
+
Here is an example of how to define an inductive proposition for valid transitions in a simple counter machine:
|
| 166 |
|
| 167 |
+
```lean
|
| 168 |
+
-- Example: Counter that can only increment by 1 (no decrement, no shortcuts)
|
| 169 |
+
inductive ValidTransition : Nat → Nat → Prop
|
| 170 |
+
| step1 : ∀ s, ValidTransition s (s + 1) -- Core transition: s → s+1
|
| 171 |
+
| step2 : ∀ s, ValidTransition s (2 * s) -- Bonus: s → 2s (optional)
|
| 172 |
+
| zero_step : ValidTransition 0 0 -- Additional special case
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
+
lemma reach_any_positive : ∀ n > 0, ValidTransition 0 n := by
|
| 175 |
+
induction n with
|
| 176 |
+
| zero => contradiction
|
| 177 |
+
| succ n ih =>
|
| 178 |
+
cases' Nat.eq_zero_or_pos n with h h
|
| 179 |
+
· simp [h]
|
| 180 |
+
· have : ValidTransition 0 (n + 1) := by
|
| 181 |
+
cases' h with _ ih -- Wait, this is messy...
|
| 182 |
```
|
|
|
|
| 183 |
|
| 184 |
+
In this example, `ValidTransition` is defined as an inductive proposition with constructors `step1`, `step2`, and `zero_step`. The `step1` constructor allows for any state to transition to the next state by incrementing by 1, while `step2` allows for doubling the state. The `zero_step` constructor is a special case for the initial state 0.
|
| 185 |
|
| 186 |
+
The lemma `reach_any_positive` aims to prove that any positive natural number is reachable from the initial state 0 through valid transitions. The proof uses induction on `n`, but due to simplification issues, the current approach may not be the most effective.
|
|
|
|
| 187 |
|
| 188 |
+
A more concise and effective way to define and prove properties about transitions is to use a simpler model, such as the following:
|
| 189 |
|
| 190 |
+
```lean
|
| 191 |
+
-- Simpler model for counter transitions (suffices for proofs)
|
| 192 |
+
inductive CounterTrans : Nat → Nat → Prop
|
| 193 |
+
| valid : ∀ n, CounterTrans n (n + 1)
|
| 194 |
|
| 195 |
+
lemma reach_positive : ∀ n > 0, CounterTrans 0 n
|
| 196 |
+
-- Proof is now trivial (by induction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
```
|
| 198 |
|
| 199 |
+
In this simpler model, `CounterTrans` is defined with a single constructor `valid`, which allows for any state to transition to the next state by incrementing by 1. The lemma `reach_positive` is straightforward to prove by induction, leveraging the simplicity of the transition rules.
|
| 200 |
+
|
| 201 |
+
This approach ensures that the proof remains concise and effective, avoiding unnecessary complexity in the transition rules. By using inductive propositions, we can effectively reason about state transitions and prove properties about the system.
|
| 202 |
+
```
|