Text Generation
PEFT
Safetensors
English
lora
qlora
mixture-of-experts
function-calling
code
math
ministral
Run this model with HF Jobs
Run SharpAir/Levante on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/SharpAir/Levante. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/SharpAir/Levante on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/SharpAir/Levante. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/SharpAir/Levante. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use SharpAir/Levante with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use SharpAir/Levante with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
File size: 6,479 Bytes
4e28659 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | ---
license: apache-2.0
base_model: mistralai/Ministral-3-8B-Instruct-2512
library_name: peft
pipeline_tag: text-generation
language:
- en
tags:
- lora
- qlora
- peft
- mixture-of-experts
- function-calling
- code
- math
- ministral
datasets:
- hiyouga/glaive-function-calling-v2-sharegpt
- NousResearch/hermes-function-calling-v1
- nvidia/When2Call
- google-research-datasets/mbpp
- nvidia/OpenCodeInstruct
- openai/gsm8k
---
<p align="center"><img src="assets/levante-wordmark-light.png" alt="Levante" width="420"></p>
# Levante
Levante is a mixture-of-experts style assistant built on **Ministral 3 8B Instruct**. A lightweight
router reads each request and hands it to one of three small LoRA experts that share the same base model:
| Expert | Folder | Good at |
|---|---|---|
| Tools | `tools/` | Calling functions, and knowing when *not* to call one. Default for chat and agent steps |
| Coding | `coding/` | Writing code that passes its tests |
| Math | `math/` | Word problems, step by step, ending in a final answer |
Each expert is a QLoRA adapter of about 90 MB, so one copy of the base model serves all three.
Levante is an independent student project by Extra, trained entirely on free Kaggle T4 GPUs, and it is
still in development. It is not affiliated with Mistral AI.
## Results
Correct answers on 200 held-out prompts per expert, against the base model on the same prompts
(greedy decoding, base model in 4-bit).
| Expert | Ministral 3 8B | Levante expert |
|---|---|---|
| Tools | 129 / 200 | **152 / 200** |
| Coding | 163 / 200 | **168 / 200** |
| Math | 184 / 200 | **188 / 200** |
- **Tools:** 200 prompts from Glaive, Hermes function calling and When2Call, none seen in training.
A pass is the exact function call (name and arguments), or correctly answering without a call.
This is a clear gain over the base model, mostly from knowing when not to call a tool.
- **Coding:** 100 MBPP (sanitized test split) and 100 HumanEval problems, scored by running their unit tests.
- **Math:** 200 GSM8K test problems, scored on the exact final number.
The coding and math gains are small, within what 200 prompts can tell apart, so read them as
"keeps the base model's strength" rather than a big jump.
## Use it
### With Transformers and PEFT
```python
from transformers import AutoModelForImageTextToText, AutoTokenizer
from peft import PeftModel
base_id = "unsloth/Ministral-3-8B-Instruct-2512-unsloth-bnb-4bit" # 4-bit, fits a 16 GB GPU
tok = AutoTokenizer.from_pretrained("mistralai/Ministral-3-8B-Instruct-2512")
base = AutoModelForImageTextToText.from_pretrained(base_id, device_map="auto")
model = PeftModel.from_pretrained(base, "SharpAir/Levante", subfolder="math", adapter_name="math")
model.load_adapter("SharpAir/Levante", subfolder="coding", adapter_name="coding")
model.load_adapter("SharpAir/Levante", subfolder="tools", adapter_name="tools")
model.set_adapter("math")
messages = [
{"role": "system", "content": "You are Levante, a helpful assistant that is very good at math. "
"Solve problems step by step and end with the final answer."},
{"role": "user", "content": "A shirt costs 25 dollars and is 20% off. How much do I pay?"},
]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True,
return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
print(tok.decode(out[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
```
Each expert was trained with its own system prompt. Use the same one for best results; all three are in
`router/router.json`.
### The router
`router/levante_router.py` picks the expert for a message with no extra model and no dependencies:
```python
from levante_router import Router
r = Router.load("router/router.json")
expert = r.route("Why does my Python loop never end?") # -> "coding"
system_prompt = r.system_prompt(expert)
```
Messages that are clearly about code go to `coding`, clearly about math go to `math`, and everything else
goes to `tools`, which is also the best expert for general chat and agent steps.
## Training
- **Base:** Ministral 3 8B Instruct (2512), trained on Unsloth's 4-bit copy of it.
- **Method:** QLoRA, rank 16, alpha 16, no dropout, on the attention and MLP layers of the language model
(the vision encoder is untouched). Up to 4,096 tokens per example, 1 epoch, learning rate 2e-4 with
cosine decay, 8-bit AdamW. Loss only on the assistant's own words.
- **Tools:** about 1,500 conversations from Glaive function calling v2, Hermes function calling v1 and
When2Call, including chats where the right answer is not to call a tool.
- **Coding:** 509 problems from MBPP (train, validation and prompt splits) and OpenCodeInstruct, each
answered by the base model itself and kept only if the answer passed the problem's unit tests.
- **Math:** 952 GSM8K training problems, each solved step by step by the base model itself and kept only
if the final answer matched the reference.
- **Hardware:** free Kaggle T4 GPUs.
None of the test prompts above appear in the training data.
## Limits
- The base model is multimodal, but the experts were trained and tested on text only.
- Trained with up to 4,096 tokens per example; long conversations past that are untested.
- Coding answers sometimes run long and get cut off at the token limit; give them room
(`max_new_tokens` of 1,024 or more).
- Like any small model, Levante can be confidently wrong. Check code and numbers that matter.
## License and credits
The adapters and router are released under the Apache 2.0 license, the same as the base model.
Training used these datasets, under their own licenses:
- [Glaive function calling v2 (ShareGPT format)](https://huggingface.co/datasets/hiyouga/glaive-function-calling-v2-sharegpt), Apache 2.0
- [Hermes function calling v1](https://huggingface.co/datasets/NousResearch/hermes-function-calling-v1), Apache 2.0
- [When2Call](https://huggingface.co/datasets/nvidia/When2Call), CC BY 4.0
- [MBPP](https://huggingface.co/datasets/google-research-datasets/mbpp), CC BY 4.0
- [OpenCodeInstruct](https://huggingface.co/datasets/nvidia/OpenCodeInstruct), CC BY 4.0
- [GSM8K](https://huggingface.co/datasets/openai/gsm8k), MIT
HumanEval (MIT) was used for testing only. Built on
[Ministral 3 8B Instruct](https://huggingface.co/mistralai/Ministral-3-8B-Instruct-2512) by Mistral AI.
|