Commit ·
e3b467b
0
Parent(s):
Initial commit
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +9 -0
- LICENSE +1 -0
- README.md +333 -0
- added_tokens.json +56 -0
- chat_template.jinja +159 -0
- config.json +120 -0
- configuration_minimax_m2.py +131 -0
- docs/MiniMax M2 Model SGLang Deployment Guide.md +106 -0
- docs/Progressive Expert Pruning with Teacher-Guided Distillation for MoE LLMs.pdf +3 -0
- docs/tool_calling_guide.md +484 -0
- generation_config.json +6 -0
- logo.png +0 -0
- merges.txt +0 -0
- model-00001-of-00070.safetensors +3 -0
- model-00002-of-00070.safetensors +3 -0
- model-00003-of-00070.safetensors +3 -0
- model-00004-of-00070.safetensors +3 -0
- model-00005-of-00070.safetensors +3 -0
- model-00006-of-00070.safetensors +3 -0
- model-00007-of-00070.safetensors +3 -0
- model-00008-of-00070.safetensors +3 -0
- model-00009-of-00070.safetensors +3 -0
- model-00010-of-00070.safetensors +3 -0
- model-00011-of-00070.safetensors +3 -0
- model-00012-of-00070.safetensors +3 -0
- model-00013-of-00070.safetensors +3 -0
- model-00014-of-00070.safetensors +3 -0
- model-00015-of-00070.safetensors +3 -0
- model-00016-of-00070.safetensors +3 -0
- model-00017-of-00070.safetensors +3 -0
- model-00018-of-00070.safetensors +3 -0
- model-00019-of-00070.safetensors +3 -0
- model-00020-of-00070.safetensors +3 -0
- model-00021-of-00070.safetensors +3 -0
- model-00022-of-00070.safetensors +3 -0
- model-00023-of-00070.safetensors +3 -0
- model-00024-of-00070.safetensors +3 -0
- model-00025-of-00070.safetensors +3 -0
- model-00026-of-00070.safetensors +3 -0
- model-00027-of-00070.safetensors +3 -0
- model-00028-of-00070.safetensors +3 -0
- model-00029-of-00070.safetensors +3 -0
- model-00030-of-00070.safetensors +3 -0
- model-00031-of-00070.safetensors +3 -0
- model-00032-of-00070.safetensors +3 -0
- model-00033-of-00070.safetensors +3 -0
- model-00034-of-00070.safetensors +3 -0
- model-00035-of-00070.safetensors +3 -0
- model-00036-of-00070.safetensors +3 -0
- model-00037-of-00070.safetensors +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
vibe_processed_by_imagy.png filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
docs/Thrift.pdf filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
docs/Progressive[[:space:]]Expert[[:space:]]Pruning[[:space:]]with[[:space:]]Teacher-Guided[[:space:]]Distillation[[:space:]]for[[:space:]]MoE[[:space:]]LLMs.pdf filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
preview.png filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Apache-2.0
|
README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- moe
|
| 4 |
+
- minimax
|
| 5 |
+
- bfloat16
|
| 6 |
+
- sglang
|
| 7 |
+
- gguf
|
| 8 |
+
license: mit
|
| 9 |
+
datasets:
|
| 10 |
+
- nick007x/github-code-2025
|
| 11 |
+
- tatsu-lab/alpaca
|
| 12 |
+
base_model:
|
| 13 |
+
- MiniMaxAI/MiniMax-M2
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
<p align="center">
|
| 17 |
+
<img src="logo.png" alt="Lemura Labs" width="110"/>
|
| 18 |
+
</p>
|
| 19 |
+
|
| 20 |
+
# lemuralabs/MiniMax-M2-Pruned-25 — Expert-Pruned for Inference and Fine-Tuning
|
| 21 |
+
|
| 22 |
+
  
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
A performance-optimized variant of the base model that delivers faster responses and lower memory usage while preserving quality for everyday tasks, developed by Lemura Labs.
|
| 26 |
+
|
| 27 |
+
## TLDR
|
| 28 |
+
|
| 29 |
+
We, over-caffinated researchers at Lemura Labs wanted to create a 50% pruned version of the SOTA MiniMax M2 that is best suited for local/air-gapped coding. This version we achieved ~25%. A 50% pruned version is under development while a not so sucky team of ours is working on a 50% pruned version of Kimi K2 Thinking.We’re writing the paper and expanding the evaluation set to substantiate the results. Check back later, cheers!
|
| 30 |
+
|
| 31 |
+
## Why it’s useful
|
| 32 |
+
|
| 33 |
+
* **Lower latency:** Snappier responses for interactive apps and chatbots.
|
| 34 |
+
* **Smaller memory footprint:** Runs on cheaper GPUs or with fewer resources per replica.
|
| 35 |
+
* **Higher throughput:** Serve more concurrent users at the same cost.
|
| 36 |
+
* **Deployment-friendly:** Drop-in replacement for the base model in most inference stacks.
|
| 37 |
+
* **Adaptable:** Supports light fine-tuning to match your domain and style guidelines.
|
| 38 |
+
|
| 39 |
+
## Intended use
|
| 40 |
+
|
| 41 |
+
* General chat and coding assistance
|
| 42 |
+
* Enterprise assistants with strict latency/VRAM budgets
|
| 43 |
+
* Batch or realtime serving in cloud and on-prem environments
|
| 44 |
+
* Edge or cost-sensitive deployments where efficiency matters
|
| 45 |
+
|
| 46 |
+
## When to use it
|
| 47 |
+
|
| 48 |
+
* You’re constrained by GPU memory or need shorter response times
|
| 49 |
+
* You want to increase QPS without scaling infrastructure
|
| 50 |
+
* You need a model that is “good enough” for most tasks at a better cost profile
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
# Model Comparison Report
|
| 55 |
+
|
| 56 |
+
**Models Under Evaluation**
|
| 57 |
+
|
| 58 |
+
| Model | Type |
|
| 59 |
+
| :--------------------------- | :------------------- |
|
| 60 |
+
| ModelCloud/MiniMax-M2-BF16 | Base Model |
|
| 61 |
+
| lemuralabs/MiniMax-M2-Pruned-25 | Compressed/Optimized |
|
| 62 |
+
|
| 63 |
+
**Evaluation Dates:** November 7–9, 2025
|
| 64 |
+
|
| 65 |
+
## Results Comparison
|
| 66 |
+
|
| 67 |
+
### 1) Multiple Choice Q&A (lm-eval)
|
| 68 |
+
|
| 69 |
+
**Overall MMLU Performance**
|
| 70 |
+
|
| 71 |
+
| Model | MMLU Overall | Humanities | STEM | Social Sciences | Other |
|
| 72 |
+
| :----------------- | -----------: | ---------: | -----: | --------------: | -----: |
|
| 73 |
+
| MiniMax-M2-BF16 | **83.16%** | 77.45% | 80.91% | **90.02%** | 87.29% |
|
| 74 |
+
| MiniMax-M2-Pruned-25 | **77.72%** | 70.14% | 77.61% | 86.84% | 80.27% |
|
| 75 |
+
| **Δ (Difference)** | **-5.44%** | -7.31% | -3.30% | -3.18% | -7.02% |
|
| 76 |
+
|
| 77 |
+
**Individual Task Performance**
|
| 78 |
+
|
| 79 |
+
| Task | BF16 (Base) | Pruned-25-BF16 | Difference |
|
| 80 |
+
| :----------------------- | ----------: | ----------: | ------------: |
|
| 81 |
+
| arc_challenge (acc_norm) | 73.21% | 61.01% | -12.20% |
|
| 82 |
+
| arc_easy | 88.30% | 83.08% | -5.22% |
|
| 83 |
+
| boolq | 87.95% | 84.95% | -3.00% |
|
| 84 |
+
| hellaswag (acc_norm) | 83.00% | 77.09% | -5.91% |
|
| 85 |
+
| mmlu | 83.16% | 77.72% | -5.44% |
|
| 86 |
+
| openbookqa (acc_norm) | 48.60% | 43.00% | -5.60% |
|
| 87 |
+
| rte | 75.45% | **80.14%** | **+4.69%** |
|
| 88 |
+
| winogrande | 76.48% | 74.90% | -1.58% |
|
| 89 |
+
|
| 90 |
+
**Average Accuracy Drop:** **-4.28%**
|
| 91 |
+
|
| 92 |
+
### 2) Code Generation (EvalPlus)
|
| 93 |
+
|
| 94 |
+
**MBPP Results (Python, 378 problems)**
|
| 95 |
+
|
| 96 |
+
| Model | MBPP (base) | MBPP+ (extended) | Average |
|
| 97 |
+
| :----------------- | ----------: | ---------------: | --------: |
|
| 98 |
+
| MiniMax-M2-BF16 | **73.8%** | **64.0%** | 68.9% |
|
| 99 |
+
| MiniMax-M2-Pruned-25 | **70.1%** | **60.1%** | 65.1% |
|
| 100 |
+
| **Δ (Difference)** | **-3.7%** | **-3.9%** | **-3.8%** |
|
| 101 |
+
|
| 102 |
+
**HumanEval Results (164 problems)**
|
| 103 |
+
|
| 104 |
+
| Model | HumanEval (base) | HumanEval+ (extended) | Average |
|
| 105 |
+
| :----------------- | ---------------: | --------------------: | --------: |
|
| 106 |
+
| MiniMax-M2-BF16 | **72.6%** | **71.3%** | 72.0% |
|
| 107 |
+
| MiniMax-M2-Pruned-25 | **65.2%** | **63.4%** | 64.3% |
|
| 108 |
+
| **Δ (Difference)** | **-7.4%** | **-7.9%** | **-7.7%** |
|
| 109 |
+
|
| 110 |
+
### 3) Math Benchmarks
|
| 111 |
+
|
| 112 |
+
**GSM8K Results**
|
| 113 |
+
|
| 114 |
+
| Model | Accuracy | Problems | Status |
|
| 115 |
+
| :----------------- | ------------: | -------: | :------------------- |
|
| 116 |
+
| MiniMax-M2-BF16 | **92.72%** | 1,319 | Yes — Complete |
|
| 117 |
+
| MiniMax-M2-Pruned-25 | **93.25%** | 1,319 | Yes — Complete |
|
| 118 |
+
| **Δ (Difference)** | **+0.53%** | - | **Pruned-25 Better!** |
|
| 119 |
+
|
| 120 |
+
| Benchmark | MiniMax-M2-BF16 | MiniMax-M2-Pruned-25 | Change |
|
| 121 |
+
|-----------|------|------------|--------|
|
| 122 |
+
| **GSM8K** | 92.72% | 93.25% | **+0.53%** |
|
| 123 |
+
| **MATH-500 (Levels 1-4)** | 91.25% | 90.75% | -0.5% (near-parity) |
|
| 124 |
+
|
| 125 |
+
### 4) LiveCodeBench (Live Coding Problems)
|
| 126 |
+
|
| 127 |
+
| Model | pass@1 | Problems | Status |
|
| 128 |
+
| :-------------------- | ------------: | -------: | :------------------- |
|
| 129 |
+
| **MiniMax-M2-BF16** | **35.71%** | 182 | Yes — Complete |
|
| 130 |
+
| **MiniMax-M2-Pruned-25** | **36.81%** | 182 | Yes — Complete |
|
| 131 |
+
| **Δ (Difference)** | **+1.10%** | - | **Pruned-25 Better!** |
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
## Analysis (Updated)
|
| 136 |
+
|
| 137 |
+
**Highlights**
|
| 138 |
+
|
| 139 |
+
* **Pruned-25 wins** on **GSM8K (+0.53%)** and **LiveCodeBench (+1.10%)**, and on **RTE (+4.69%)**.
|
| 140 |
+
* **BF16 leads** on broad **MMLU**, **HumanEval**, **MBPP**, and tasks like **arc_challenge**.
|
| 141 |
+
|
| 142 |
+
**Compression Trade-off**
|
| 143 |
+
|
| 144 |
+
* Average knowledge-task drop for Pruned-25 is ~**4–5%**, with **math preserved or slightly improved**.
|
| 145 |
+
|
| 146 |
+
**Subject Breakdown (MMLU)**
|
| 147 |
+
|
| 148 |
+
| Category | BF16 (Base) | Pruned-25-BF16 | Difference | Status |
|
| 149 |
+
| :--------------------- | ----------: | ----------: | ---------: | :---------------- |
|
| 150 |
+
| High School Government | 97.93% | 94.82% | -3.11% | Yes — Still Excellent |
|
| 151 |
+
| High School Psychology | 95.41% | 93.58% | -1.83% | Yes — Well Preserved |
|
| 152 |
+
| Marketing | 95.73% | 91.88% | -3.85% | Yes — Good |
|
| 153 |
+
| Professional Medicine | 92.28% | 79.78% | -12.50% | Notable Drop |
|
| 154 |
+
| Clinical Knowledge | 92.83% | 85.66% | -7.17% | Moderate Drop |
|
| 155 |
+
|
| 156 |
+
---
|
| 157 |
+
|
| 158 |
+
## **sglang Deployment with Python**
|
| 159 |
+
|
| 160 |
+
It is recommended to use a virtual environment (such as **venv**, **conda**, or **uv**) to avoid dependency conflicts.
|
| 161 |
+
|
| 162 |
+
We recommend installing SGLang in a fresh Python environment:
|
| 163 |
+
|
| 164 |
+
```shell
|
| 165 |
+
git clone -b v0.5.4.post1 https://github.com/sgl-project/sglang.git
|
| 166 |
+
cd sglang
|
| 167 |
+
|
| 168 |
+
# Install the python packages
|
| 169 |
+
pip install --upgrade pip
|
| 170 |
+
pip install -e "python"
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
Run the following command to start the SGLang server. SGLang will automatically download and cache the MiniMax-M2 model from Hugging Face.
|
| 174 |
+
|
| 175 |
+
**4-GPU deployment command:**
|
| 176 |
+
|
| 177 |
+
```shell
|
| 178 |
+
python -m sglang.launch_server \
|
| 179 |
+
--model-path MiniMaxAI/MiniMax-M2 \
|
| 180 |
+
--tp-size 4 \
|
| 181 |
+
--tool-call-parser minimax-m2 \
|
| 182 |
+
--reasoning-parser minimax-append-think \
|
| 183 |
+
--host 0.0.0.0 \
|
| 184 |
+
--trust-remote-code \
|
| 185 |
+
--port 8000 \
|
| 186 |
+
--mem-fraction-static 0.85
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
**8-GPU deployment command:**
|
| 190 |
+
|
| 191 |
+
```shell
|
| 192 |
+
python -m sglang.launch_server \
|
| 193 |
+
--model-path MiniMaxAI/MiniMax-M2 \
|
| 194 |
+
--tp-size 8 \
|
| 195 |
+
--ep-size 8 \
|
| 196 |
+
--tool-call-parser minimax-m2 \
|
| 197 |
+
--trust-remote-code \
|
| 198 |
+
--host 0.0.0.0 \
|
| 199 |
+
--reasoning-parser minimax-append-think \
|
| 200 |
+
--port 8000 \
|
| 201 |
+
--mem-fraction-static 0.85
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
## **Testing Deployment**
|
| 205 |
+
|
| 206 |
+
After startup, you can test the SGLang OpenAI-compatible API with the following command:
|
| 207 |
+
|
| 208 |
+
```shell
|
| 209 |
+
curl http://localhost:8000/v1/chat/completions \
|
| 210 |
+
-H "Content-Type: application/json" \
|
| 211 |
+
-d '{
|
| 212 |
+
"model": "MiniMaxAI/MiniMax-M2",
|
| 213 |
+
"messages": [
|
| 214 |
+
{"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
|
| 215 |
+
{"role": "user", "content": [{"type": "text", "text": "Who won the world series in 2020?"}]}
|
| 216 |
+
]
|
| 217 |
+
}'
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
## Benchmarks
|
| 221 |
+
|
| 222 |
+
See the tables above for the latest **MMLU**, **MBPP**, **HumanEval**, **GSM8K**, **MATH-500**, and **LiveCodeBench** results (updated **November 9, 2025**).
|
| 223 |
+
|
| 224 |
+
## Research paper
|
| 225 |
+
|
| 226 |
+
Coming soon.
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## License
|
| 231 |
+
|
| 232 |
+
This model is derived from MiniMax-M2 and distributed under the MIT License [http://github.com/MiniMax-AI/MiniMax-M2/blob/main/LICENSE](http://github.com/MiniMax-AI/MiniMax-M2/blob/main/LICENSE)
|
| 233 |
+
|
| 234 |
+
---
|
| 235 |
+
|
| 236 |
+
## Credits
|
| 237 |
+
|
| 238 |
+
Model conversion and HF Transformers code by @Qubitum at ModelCloud.
|
| 239 |
+
|
| 240 |
+
## **References (BibTeX)**
|
| 241 |
+
|
| 242 |
+
```
|
| 243 |
+
@article{cai2025thinking,
|
| 244 |
+
title = {Thinking with DistilQwen: A Tale of Four Distilled Reasoning and Reward Model Series},
|
| 245 |
+
author = {Cai, Wenrui and Wang, Chengyu and Yan, Junbing and Huang, Jun and Fang, Xiangzhong},
|
| 246 |
+
journal = {arXiv preprint arXiv:2511.01354},
|
| 247 |
+
year = {2025},
|
| 248 |
+
eprinttype = {arXiv},
|
| 249 |
+
eprint = {2511.01354},
|
| 250 |
+
primaryclass = {cs.CL},
|
| 251 |
+
institution = {Shanghai Jiao Tong University and Alibaba Cloud Computing},
|
| 252 |
+
note = {License: arXiv.org perpetual non-exclusive license}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
@misc{lasby-reap,
|
| 256 |
+
title = {{REAP the Experts: Why Pruning Prevails for One-Shot MoE compression}},
|
| 257 |
+
author = {Lasby, Mike and Lazarevich, Ivan and Sinnadurai, Nish and Lie, Sean and Ioannou, Yani and Thangarasa, Vithursan},
|
| 258 |
+
year = {2025},
|
| 259 |
+
publisher = {arXiv},
|
| 260 |
+
note = {arXiv:2510.13999v1 [cs]},
|
| 261 |
+
url = {https://arxiv.org/abs/2510.13999v1},
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
@article{yang2025wanda++,
|
| 265 |
+
title = {Wanda++: Pruning Large Language Models via Regional Gradients},
|
| 266 |
+
author = {Yang, Yifan and Zhen, Kai and Ganesh, Bhavana and Galstyan, Aram and Huybrechts, Goeric and Müller, Markus and Kübler, Jonas M. and Swaminathan, Rupak Vignesh and Mouchtaris, Athanasios and Bodapati, Sravan Babu and Susanj, Nathan and Zhang, Zheng and FitzGerald, Jack and Kumar, Abhishek},
|
| 267 |
+
journal = {arXiv preprint arXiv:2503.04992},
|
| 268 |
+
year = {2025},
|
| 269 |
+
eprinttype = {arXiv},
|
| 270 |
+
eprint = {2503.04992},
|
| 271 |
+
primaryclass = {cs.CL}
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
@article{li2025tyr,
|
| 275 |
+
title = {Týr-the-Pruner: Structural Pruning LLMs via Global Sparsity Distribution Optimization},
|
| 276 |
+
author = {Li, G. and Xu, Yixing and Li, Zeping and Liu, Ji and Yin, Xuanwu and Li, Dong and Barsoum, Emad},
|
| 277 |
+
journal = {arXiv preprint arXiv:2503.09657},
|
| 278 |
+
year = {2025},
|
| 279 |
+
eprinttype = {arXiv},
|
| 280 |
+
eprint = {2503.09657},
|
| 281 |
+
primaryclass = {cs.CL}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
@article{xia2023sheared,
|
| 285 |
+
title = {Sheared LLaMA: Accelerating Language Model Pre-training via Structured Pruning},
|
| 286 |
+
author = {Xia, Mengzhou and Gao, Tianyu and Zeng, Zhiyuan and Chen, Danqi},
|
| 287 |
+
journal = {arXiv preprint arXiv:2310.06694},
|
| 288 |
+
year = {2023},
|
| 289 |
+
eprinttype = {arXiv},
|
| 290 |
+
eprint = {2310.06694},
|
| 291 |
+
primaryclass = {cs.CL}
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
@article{ma2023llmpruner,
|
| 295 |
+
title = {LLM-Pruner: On the Structural Pruning of Large Language Models},
|
| 296 |
+
author = {Ma, Xinyin and Fang, Gongfan and Wang, Xinchao},
|
| 297 |
+
journal = {arXiv preprint arXiv:2305.11627},
|
| 298 |
+
year = {2023},
|
| 299 |
+
eprinttype = {arXiv},
|
| 300 |
+
eprint = {2305.11627},
|
| 301 |
+
primaryclass = {cs.CL}
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
@article{yang2023wanda,
|
| 305 |
+
title = {Wanda: Pruning by Weights and Activation-based Discriminant Analysis},
|
| 306 |
+
author = {Yang, Yifan and Ganesh, Bhavana and Galstyan, Aram and Huybrechts, Goeric and Müller, Markus and Kübler, Jonas M. and Swaminathan, Rupak Vignesh and Mouchtaris, Athanasios and Bodapati, Sravan Babu and Zhang, Zheng and FitzGerald, Jack and Kumar, Abhishek},
|
| 307 |
+
journal = {arXiv preprint arXiv:2306.11695},
|
| 308 |
+
year = {2023},
|
| 309 |
+
eprinttype = {arXiv},
|
| 310 |
+
eprint = {2306.11695},
|
| 311 |
+
primaryclass = {cs.CL}
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
@article{frantar2023sparsegpt,
|
| 315 |
+
title = {SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot},
|
| 316 |
+
author = {Frantar, Elias and Alistarh, Dan},
|
| 317 |
+
journal = {arXiv preprint arXiv:2301.00774},
|
| 318 |
+
year = {2023},
|
| 319 |
+
eprinttype = {arXiv},
|
| 320 |
+
eprint = {2301.00774},
|
| 321 |
+
primaryclass = {cs.CL}
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
@article{dettmers2023qlora,
|
| 325 |
+
title = {QLoRA: Efficient Finetuning of Quantized LLMs},
|
| 326 |
+
author = {Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},
|
| 327 |
+
journal = {arXiv preprint arXiv:2307.02973},
|
| 328 |
+
year = {2023},
|
| 329 |
+
eprinttype = {arXiv},
|
| 330 |
+
eprint = {2307.02973},
|
| 331 |
+
primaryclass = {cs.CL}
|
| 332 |
+
}
|
| 333 |
+
```
|
added_tokens.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"</minimax:tool_call>": 200053,
|
| 3 |
+
"</think>": 200051,
|
| 4 |
+
"<add_file>": 200036,
|
| 5 |
+
"<code_context>": 200043,
|
| 6 |
+
"<code_interpreter>": 200023,
|
| 7 |
+
"<commit_after>": 200018,
|
| 8 |
+
"<commit_before>": 200016,
|
| 9 |
+
"<commit_message>": 200040,
|
| 10 |
+
"<commit_msg>": 200017,
|
| 11 |
+
"<delete_file>": 200037,
|
| 12 |
+
"<edit_file>": 200039,
|
| 13 |
+
"<empty_output>": 200015,
|
| 14 |
+
"<empty_source_file>": 200041,
|
| 15 |
+
"<file_content>": 200044,
|
| 16 |
+
"<file_sep>": 200049,
|
| 17 |
+
"<filename>": 200006,
|
| 18 |
+
"<filepath>": 200048,
|
| 19 |
+
"<fim_middle>": 200002,
|
| 20 |
+
"<fim_pad>": 200004,
|
| 21 |
+
"<fim_prefix>": 200001,
|
| 22 |
+
"<fim_suffix>": 200003,
|
| 23 |
+
"<function_call>": 200022,
|
| 24 |
+
"<gh_stars>": 200007,
|
| 25 |
+
"<issue_closed>": 200010,
|
| 26 |
+
"<issue_comment>": 200009,
|
| 27 |
+
"<issue_start>": 200008,
|
| 28 |
+
"<jupyter_code>": 200013,
|
| 29 |
+
"<jupyter_error>": 200035,
|
| 30 |
+
"<jupyter_output>": 200014,
|
| 31 |
+
"<jupyter_start>": 200011,
|
| 32 |
+
"<jupyter_text>": 200012,
|
| 33 |
+
"<minimax:tool_call>": 200052,
|
| 34 |
+
"<pr_start>": 200046,
|
| 35 |
+
"<rename_file>": 200038,
|
| 36 |
+
"<repo_struct>": 200042,
|
| 37 |
+
"<reponame>": 200005,
|
| 38 |
+
"<review_comment>": 200047,
|
| 39 |
+
"<source_files>": 200045,
|
| 40 |
+
"<think>": 200050,
|
| 41 |
+
"[e~[": 200020,
|
| 42 |
+
"]!d~[": 200021,
|
| 43 |
+
"]!p~[": 200000,
|
| 44 |
+
"]<]end of image[>[": 200030,
|
| 45 |
+
"]<]end of speech[>[": 200028,
|
| 46 |
+
"]<]end of video[>[": 200032,
|
| 47 |
+
"]<]image[>[": 200025,
|
| 48 |
+
"]<]speech[>[": 200024,
|
| 49 |
+
"]<]start of image[>[": 200029,
|
| 50 |
+
"]<]start of speech[>[": 200027,
|
| 51 |
+
"]<]start of video[>[": 200031,
|
| 52 |
+
"]<]video[>[": 200026,
|
| 53 |
+
"]<]vision pad[>[": 200033,
|
| 54 |
+
"]~!b[": 200034,
|
| 55 |
+
"]~b]": 200019
|
| 56 |
+
}
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{# ----------‑‑‑ special token variables ‑‑‑---------- #}
|
| 2 |
+
{%- set toolcall_begin_token = '<minimax:tool_call>' -%}
|
| 3 |
+
{%- set toolcall_end_token = '</minimax:tool_call>' -%}
|
| 4 |
+
{#- Tool Rendering Functions ============================================== -#}
|
| 5 |
+
{%- macro render_tool_namespace(namespace_name, tool_list) -%}
|
| 6 |
+
{%- for tool in tool_list -%}
|
| 7 |
+
<tool>{{ tool.function | tojson(ensure_ascii=False) }}</tool>
|
| 8 |
+
{% endfor -%}
|
| 9 |
+
{%- endmacro -%}
|
| 10 |
+
{%- macro visible_text(content) -%}
|
| 11 |
+
{%- if content is string -%}
|
| 12 |
+
{{ content }}
|
| 13 |
+
{%- elif content is iterable and content is not mapping -%}
|
| 14 |
+
{%- for item in content -%}
|
| 15 |
+
{%- if item is mapping and item.type == 'text' -%}
|
| 16 |
+
{{- item.text }}
|
| 17 |
+
{%- elif item is string -%}
|
| 18 |
+
{{- item }}
|
| 19 |
+
{%- endif -%}
|
| 20 |
+
{%- endfor -%}
|
| 21 |
+
{%- else -%}
|
| 22 |
+
{{- content }}
|
| 23 |
+
{%- endif -%}
|
| 24 |
+
{%- endmacro -%}
|
| 25 |
+
{#- System Message Construction ============================================ -#}
|
| 26 |
+
{%- macro build_system_message(system_message) -%}
|
| 27 |
+
{%- if system_message and system_message.content -%}
|
| 28 |
+
{{- visible_text(system_message.content) }}
|
| 29 |
+
{%- else -%}
|
| 30 |
+
{%- if model_identity is not defined -%}
|
| 31 |
+
{%- set model_identity = "You are a helpful assistant." -%}
|
| 32 |
+
{%- endif -%}
|
| 33 |
+
{{- model_identity }}
|
| 34 |
+
{%- endif -%}
|
| 35 |
+
|
| 36 |
+
{#- Handle current_date -#}
|
| 37 |
+
{%- if system_message and system_message.current_date -%}
|
| 38 |
+
{{- '\n' ~ 'Current date: ' + system_message.current_date }}
|
| 39 |
+
{%- endif -%}
|
| 40 |
+
{#- Handle current_location -#}
|
| 41 |
+
{%- if system_message and system_message.current_location -%}
|
| 42 |
+
{{- '\n' ~ 'Current location: ' + system_message.current_location }}
|
| 43 |
+
{%- endif -%}
|
| 44 |
+
{%- endmacro -%}
|
| 45 |
+
{#- Main Template Logic ================================================= -#}
|
| 46 |
+
{#- Extract system message (only first message if it's system) -#}
|
| 47 |
+
{%- set system_message = none -%}
|
| 48 |
+
{%- set conversation_messages = messages -%}
|
| 49 |
+
{%- if messages and messages[0].role == "system" -%}
|
| 50 |
+
{%- set system_message = messages[0] -%}
|
| 51 |
+
{%- set conversation_messages = messages[1:] -%}
|
| 52 |
+
{%- endif -%}
|
| 53 |
+
{#- Get the last user message turn, for interleved thinking -#}
|
| 54 |
+
{%- set ns = namespace(last_user_index=-1) %}
|
| 55 |
+
{% for m in conversation_messages %}
|
| 56 |
+
{%- if m.role == 'user' %}
|
| 57 |
+
{% set ns.last_user_index = loop.index0 -%}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- endfor %}
|
| 60 |
+
{#- Render system message -#}
|
| 61 |
+
{{- ']~!b[' ~ ']~b]system' ~ '\n' }}
|
| 62 |
+
{{- build_system_message(system_message) }}
|
| 63 |
+
{#- Render tools if available -#}
|
| 64 |
+
{%- if tools -%}
|
| 65 |
+
{{- '\n\n' ~ '# Tools' ~ '\n' ~ 'You may call one or more tools to assist with the user query.\nHere are the tools available in JSONSchema format:' ~ '\n' }}
|
| 66 |
+
{{- '\n' ~ '<tools>' ~ '\n' }}
|
| 67 |
+
{{- render_tool_namespace("functions", tools) }}
|
| 68 |
+
{{- '</tools>' ~ '\n\n' }}
|
| 69 |
+
{{- 'When making tool calls, use XML format to invoke tools and pass parameters:' ~ '\n' }}
|
| 70 |
+
{{- '\n' ~ toolcall_begin_token }}
|
| 71 |
+
<invoke name="tool-name-1">
|
| 72 |
+
<parameter name="param-key-1">param-value-1</parameter>
|
| 73 |
+
<parameter name="param-key-2">param-value-2</parameter>
|
| 74 |
+
...
|
| 75 |
+
</invoke>
|
| 76 |
+
{{- '\n' ~ toolcall_end_token }}
|
| 77 |
+
{%- endif -%}
|
| 78 |
+
{{- '[e~[\n' }}
|
| 79 |
+
|
| 80 |
+
{#- Render messages -#}
|
| 81 |
+
{%- set last_tool_call = namespace(name=none) -%}
|
| 82 |
+
{%- for message in conversation_messages -%}
|
| 83 |
+
{%- if message.role == 'assistant' -%}
|
| 84 |
+
{#- Only render reasoning_content if no user message follows -#}
|
| 85 |
+
{{- ']~b]ai' ~ '\n' }}
|
| 86 |
+
|
| 87 |
+
{%- set reasoning_content = '' %}
|
| 88 |
+
{%- set content = visible_text(message.content) %}
|
| 89 |
+
{%- if message.reasoning_content is string %}
|
| 90 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 91 |
+
{%- else %}
|
| 92 |
+
{%- if '</think>' in content %}
|
| 93 |
+
{%- set reasoning_content = content.split('</think>')[0].strip('\n').split('<think>')[-1].strip('\n') %}
|
| 94 |
+
{%- set content = content.split('</think>')[-1].strip('\n') %}
|
| 95 |
+
{%- endif %}
|
| 96 |
+
{%- endif %}
|
| 97 |
+
{%- if reasoning_content and loop.index0 > ns.last_user_index -%}
|
| 98 |
+
{{- '<think>' ~ '\n' ~ reasoning_content ~ '\n' ~ '</think>' ~ '\n\n' }}
|
| 99 |
+
{%- endif -%}
|
| 100 |
+
{%- if content -%}
|
| 101 |
+
{{- content }}
|
| 102 |
+
{%- endif -%}
|
| 103 |
+
{%- if message.tool_calls -%}
|
| 104 |
+
{{- '\n' ~ toolcall_begin_token ~ '\n' }}
|
| 105 |
+
|
| 106 |
+
{%- for tool_call in message.tool_calls -%}
|
| 107 |
+
{%- if tool_call.function %}
|
| 108 |
+
{%- set tool_call = tool_call.function %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{{- '<invoke name="' + tool_call.name + '">' }}
|
| 111 |
+
{% set _args = tool_call.arguments %}
|
| 112 |
+
{%- for k, v in _args.items() %}
|
| 113 |
+
{{- '<parameter name="' + k + '">' }}
|
| 114 |
+
{{- v | tojson(ensure_ascii=False) if v is not string else v }}
|
| 115 |
+
{{- '</parameter>' }}
|
| 116 |
+
{% endfor %}
|
| 117 |
+
{{- '</invoke>' ~ '\n' }}
|
| 118 |
+
{%- endfor -%}
|
| 119 |
+
|
| 120 |
+
{{- toolcall_end_token}}
|
| 121 |
+
{%- set last_tool_call.name = message.tool_calls[-1].name -%}
|
| 122 |
+
{%- else -%}
|
| 123 |
+
{%- set last_tool_call.name = none -%}
|
| 124 |
+
{%- endif -%}
|
| 125 |
+
{{- '[e~[' ~ '\n' }}
|
| 126 |
+
|
| 127 |
+
{%- elif message.role == 'tool' -%}
|
| 128 |
+
{%- if last_tool_call.name is none -%}
|
| 129 |
+
{{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
|
| 130 |
+
{%- endif -%}
|
| 131 |
+
{%- if loop.first or (conversation_messages[loop.index0 - 1].role != 'tool') -%}
|
| 132 |
+
{{- ']~b]tool' }}
|
| 133 |
+
{%- endif -%}
|
| 134 |
+
{%- if message.content is string -%}
|
| 135 |
+
{{- '\n<response>' }}
|
| 136 |
+
{{- message.content }}
|
| 137 |
+
{{- '</response>' }}
|
| 138 |
+
{%- else -%}
|
| 139 |
+
{%- for tr in message.content -%}
|
| 140 |
+
{{- '\n<response>' }}
|
| 141 |
+
{{- tr.output if tr.output is defined else (tr.text if tr.type == 'text' and tr.text is defined else tr) }}
|
| 142 |
+
{{- '\n</response>' }}
|
| 143 |
+
{%- endfor -%}
|
| 144 |
+
{%- endif -%}
|
| 145 |
+
{%- if loop.last or (conversation_messages[loop.index0 + 1].role != 'tool') -%}
|
| 146 |
+
{{- '[e~[\n' -}}
|
| 147 |
+
{%- endif -%}
|
| 148 |
+
|
| 149 |
+
{%- elif message.role == 'user' -%}
|
| 150 |
+
{{- ']~b]user' ~ '\n' }}
|
| 151 |
+
{{- visible_text(message.content) }}
|
| 152 |
+
{{- '[e~[' ~ '\n' }}
|
| 153 |
+
{%- endif -%}
|
| 154 |
+
{%- endfor -%}
|
| 155 |
+
|
| 156 |
+
{#- Generation prompt -#}
|
| 157 |
+
{%- if add_generation_prompt -%}
|
| 158 |
+
{{- ']~b]ai' ~ '\n' ~ '<think>' ~ '\n' }}
|
| 159 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MiniMaxM2ForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"attn_type_list": [
|
| 7 |
+
1,
|
| 8 |
+
1,
|
| 9 |
+
1,
|
| 10 |
+
1,
|
| 11 |
+
1,
|
| 12 |
+
1,
|
| 13 |
+
1,
|
| 14 |
+
1,
|
| 15 |
+
1,
|
| 16 |
+
1,
|
| 17 |
+
1,
|
| 18 |
+
1,
|
| 19 |
+
1,
|
| 20 |
+
1,
|
| 21 |
+
1,
|
| 22 |
+
1,
|
| 23 |
+
1,
|
| 24 |
+
1,
|
| 25 |
+
1,
|
| 26 |
+
1,
|
| 27 |
+
1,
|
| 28 |
+
1,
|
| 29 |
+
1,
|
| 30 |
+
1,
|
| 31 |
+
1,
|
| 32 |
+
1,
|
| 33 |
+
1,
|
| 34 |
+
1,
|
| 35 |
+
1,
|
| 36 |
+
1,
|
| 37 |
+
1,
|
| 38 |
+
1,
|
| 39 |
+
1,
|
| 40 |
+
1,
|
| 41 |
+
1,
|
| 42 |
+
1,
|
| 43 |
+
1,
|
| 44 |
+
1,
|
| 45 |
+
1,
|
| 46 |
+
1,
|
| 47 |
+
1,
|
| 48 |
+
1,
|
| 49 |
+
1,
|
| 50 |
+
1,
|
| 51 |
+
1,
|
| 52 |
+
1,
|
| 53 |
+
1,
|
| 54 |
+
1,
|
| 55 |
+
1,
|
| 56 |
+
1,
|
| 57 |
+
1,
|
| 58 |
+
1,
|
| 59 |
+
1,
|
| 60 |
+
1,
|
| 61 |
+
1,
|
| 62 |
+
1,
|
| 63 |
+
1,
|
| 64 |
+
1,
|
| 65 |
+
1,
|
| 66 |
+
1,
|
| 67 |
+
1,
|
| 68 |
+
1
|
| 69 |
+
],
|
| 70 |
+
"attn_window_size": null,
|
| 71 |
+
"auto_map": {
|
| 72 |
+
"AutoConfig": "configuration_minimax_m2.MiniMaxM2Config",
|
| 73 |
+
"AutoModelForCausalLM": "modeling_minimax_m2.MiniMaxM2ForCausalLM"
|
| 74 |
+
},
|
| 75 |
+
"head_dim": 128,
|
| 76 |
+
"hidden_act": "silu",
|
| 77 |
+
"hidden_size": 3072,
|
| 78 |
+
"initializer_range": 0.02,
|
| 79 |
+
"intermediate_size": 1536,
|
| 80 |
+
"layernorm_full_attention_beta": 1.0,
|
| 81 |
+
"layernorm_linear_attention_beta": 1.0,
|
| 82 |
+
"layernorm_mlp_beta": 1.0,
|
| 83 |
+
"max_model_len": null,
|
| 84 |
+
"max_position_embeddings": 196608,
|
| 85 |
+
"mlp_intermediate_size": 8192,
|
| 86 |
+
"model_type": "minimax",
|
| 87 |
+
"mtp_transformer_layers": 1,
|
| 88 |
+
"num_attention_heads": 48,
|
| 89 |
+
"num_expert_group": null,
|
| 90 |
+
"num_experts_per_tok": 8,
|
| 91 |
+
"num_hidden_layers": 62,
|
| 92 |
+
"num_key_value_heads": 8,
|
| 93 |
+
"num_local_experts": 192,
|
| 94 |
+
"num_mtp_modules": 3,
|
| 95 |
+
"output_router_logits": false,
|
| 96 |
+
"partial_rotary_factor": 0.5,
|
| 97 |
+
"qk_norm_type": "per_layer",
|
| 98 |
+
"rms_norm_eps": 1e-06,
|
| 99 |
+
"rope_scaling": null,
|
| 100 |
+
"rope_theta": 5000000,
|
| 101 |
+
"rotary_dim": 64,
|
| 102 |
+
"routed_scaling_factor": 1.0,
|
| 103 |
+
"router_aux_loss_coef": 0.001,
|
| 104 |
+
"router_jitter_noise": 0.0,
|
| 105 |
+
"scoring_func": "sigmoid",
|
| 106 |
+
"shared_intermediate_size": 0,
|
| 107 |
+
"shared_moe_mode": "sigmoid",
|
| 108 |
+
"sliding_window": null,
|
| 109 |
+
"swa_rope_theta": -1.0,
|
| 110 |
+
"tie_word_embeddings": false,
|
| 111 |
+
"topk_group": null,
|
| 112 |
+
"torch_dtype": "bfloat16",
|
| 113 |
+
"transformers_version": "4.55.0",
|
| 114 |
+
"use_cache": false,
|
| 115 |
+
"use_grouped_topk": true,
|
| 116 |
+
"use_mtp": true,
|
| 117 |
+
"use_qk_norm": true,
|
| 118 |
+
"use_routing_bias": true,
|
| 119 |
+
"vocab_size": 200064
|
| 120 |
+
}
|
configuration_minimax_m2.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: 2024-2025 ModelCloud.ai
|
| 2 |
+
# SPDX-FileCopyrightText: 2024-2025 qubitium@modelcloud.ai
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
# Contact: qubitium@modelcloud.ai, x.com/qubitium
|
| 5 |
+
|
| 6 |
+
"""Configuration for the MiniMax M2 architecture."""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
from typing import List, Optional, Union
|
| 11 |
+
|
| 12 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class MiniMaxM2Config(PretrainedConfig):
|
| 16 |
+
model_type = "minimax"
|
| 17 |
+
|
| 18 |
+
def __init__(
|
| 19 |
+
self,
|
| 20 |
+
vocab_size: int = 200_064,
|
| 21 |
+
hidden_size: int = 3_072,
|
| 22 |
+
intermediate_size: int = 1_536,
|
| 23 |
+
mlp_intermediate_size: int = 8_192,
|
| 24 |
+
num_hidden_layers: int = 62,
|
| 25 |
+
num_attention_heads: int = 48,
|
| 26 |
+
num_key_value_heads: int = 8,
|
| 27 |
+
head_dim: Optional[int] = 128,
|
| 28 |
+
num_local_experts: int = 256,
|
| 29 |
+
num_experts_per_tok: int = 8,
|
| 30 |
+
attn_type_list: Optional[List[int]] = None,
|
| 31 |
+
attention_dropout: float = 0.0,
|
| 32 |
+
hidden_act: str = "silu",
|
| 33 |
+
rms_norm_eps: float = 1e-6,
|
| 34 |
+
max_position_embeddings: int = 196_608,
|
| 35 |
+
rope_theta: float = 5_000_000.0,
|
| 36 |
+
rotary_dim: int = 64,
|
| 37 |
+
rope_scaling: Optional[dict] = None,
|
| 38 |
+
use_qk_norm: bool = True,
|
| 39 |
+
qk_norm_type: str = "per_layer",
|
| 40 |
+
use_routing_bias: bool = True,
|
| 41 |
+
scoring_func: str = "sigmoid",
|
| 42 |
+
router_aux_loss_coef: float = 0.001,
|
| 43 |
+
router_jitter_noise: float = 0.0,
|
| 44 |
+
output_router_logits: bool = False,
|
| 45 |
+
use_grouped_topk: bool = True,
|
| 46 |
+
num_expert_group: Optional[int] = None,
|
| 47 |
+
topk_group: Optional[int] = None,
|
| 48 |
+
routed_scaling_factor: float = 1.0,
|
| 49 |
+
layernorm_full_attention_beta: float = 1.0,
|
| 50 |
+
layernorm_linear_attention_beta: float = 1.0,
|
| 51 |
+
layernorm_mlp_beta: float = 1.0,
|
| 52 |
+
shared_intermediate_size: int = 0,
|
| 53 |
+
shared_moe_mode: str = "sigmoid",
|
| 54 |
+
use_mtp: bool = True,
|
| 55 |
+
num_mtp_modules: int = 3,
|
| 56 |
+
mtp_transformer_layers: int = 1,
|
| 57 |
+
attn_window_size: Optional[Union[int, List[int]]] = None,
|
| 58 |
+
swa_rope_theta: float = -1.0,
|
| 59 |
+
sliding_window: Optional[int] = None,
|
| 60 |
+
initializer_range: float = 0.02,
|
| 61 |
+
tie_word_embeddings: bool = False,
|
| 62 |
+
max_model_len: Optional[int] = None,
|
| 63 |
+
bos_token_id: Optional[int] = None,
|
| 64 |
+
eos_token_id: Optional[int] = None,
|
| 65 |
+
pad_token_id: Optional[int] = None,
|
| 66 |
+
use_cache: bool = True,
|
| 67 |
+
**kwargs,
|
| 68 |
+
) -> None:
|
| 69 |
+
quantization_config = kwargs.pop("quantization_config", None)
|
| 70 |
+
transformers_version = kwargs.pop("transformers_version", None)
|
| 71 |
+
|
| 72 |
+
super().__init__(
|
| 73 |
+
bos_token_id=bos_token_id,
|
| 74 |
+
eos_token_id=eos_token_id,
|
| 75 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 76 |
+
pad_token_id=pad_token_id,
|
| 77 |
+
**kwargs,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
self.vocab_size = vocab_size
|
| 81 |
+
self.hidden_size = hidden_size
|
| 82 |
+
self.intermediate_size = intermediate_size
|
| 83 |
+
self.mlp_intermediate_size = mlp_intermediate_size
|
| 84 |
+
self.num_hidden_layers = num_hidden_layers
|
| 85 |
+
self.num_attention_heads = num_attention_heads
|
| 86 |
+
self.num_key_value_heads = num_key_value_heads
|
| 87 |
+
self.head_dim = head_dim or hidden_size // num_attention_heads
|
| 88 |
+
self.num_local_experts = num_local_experts
|
| 89 |
+
self.num_experts_per_tok = num_experts_per_tok
|
| 90 |
+
self.attn_type_list = attn_type_list or [1] * num_hidden_layers
|
| 91 |
+
self.attention_dropout = attention_dropout
|
| 92 |
+
self.hidden_act = hidden_act
|
| 93 |
+
self.rms_norm_eps = rms_norm_eps
|
| 94 |
+
self.max_position_embeddings = max_position_embeddings
|
| 95 |
+
self.rope_theta = rope_theta
|
| 96 |
+
self.rotary_dim = rotary_dim
|
| 97 |
+
self.rope_scaling = rope_scaling
|
| 98 |
+
self.use_qk_norm = use_qk_norm
|
| 99 |
+
self.qk_norm_type = qk_norm_type
|
| 100 |
+
self.use_routing_bias = use_routing_bias
|
| 101 |
+
self.scoring_func = scoring_func
|
| 102 |
+
self.router_aux_loss_coef = router_aux_loss_coef
|
| 103 |
+
self.router_jitter_noise = router_jitter_noise
|
| 104 |
+
self.output_router_logits = output_router_logits
|
| 105 |
+
self.use_grouped_topk = use_grouped_topk
|
| 106 |
+
self.num_expert_group = num_expert_group
|
| 107 |
+
self.topk_group = topk_group
|
| 108 |
+
self.routed_scaling_factor = routed_scaling_factor
|
| 109 |
+
self.layernorm_full_attention_beta = layernorm_full_attention_beta
|
| 110 |
+
self.layernorm_linear_attention_beta = layernorm_linear_attention_beta
|
| 111 |
+
self.layernorm_mlp_beta = layernorm_mlp_beta
|
| 112 |
+
self.shared_intermediate_size = shared_intermediate_size
|
| 113 |
+
self.shared_moe_mode = shared_moe_mode
|
| 114 |
+
self.use_mtp = use_mtp
|
| 115 |
+
self.num_mtp_modules = num_mtp_modules
|
| 116 |
+
self.mtp_transformer_layers = mtp_transformer_layers
|
| 117 |
+
self.attn_window_size = attn_window_size
|
| 118 |
+
self.swa_rope_theta = swa_rope_theta
|
| 119 |
+
self.sliding_window = sliding_window
|
| 120 |
+
self.initializer_range = initializer_range
|
| 121 |
+
self.max_model_len = max_model_len
|
| 122 |
+
self.use_cache = use_cache
|
| 123 |
+
|
| 124 |
+
# Convenient accessor used by rotary embedding helper
|
| 125 |
+
self.partial_rotary_factor = float(self.rotary_dim) / float(self.head_dim)
|
| 126 |
+
if quantization_config is not None:
|
| 127 |
+
self.quantization_config = quantization_config
|
| 128 |
+
self.transformers_version = transformers_version
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
__all__ = ["MiniMaxM2Config"]
|
docs/MiniMax M2 Model SGLang Deployment Guide.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MiniMax M2 Model SGLang Deployment Guide
|
| 2 |
+
|
| 3 |
+
We recommend using [SGLang](https://github.com/sgl-project/sglang) to deploy the [MiniMax-M2](https://huggingface.co/MiniMaxAI/MiniMax-M2) model. SGLang is a high-performance inference engine with excellent serving throughput, efficient and intelligent memory management, powerful batch request processing capabilities, and deeply optimized underlying performance. We recommend reviewing SGLang's official documentation to check hardware compatibility before deployment.
|
| 4 |
+
|
| 5 |
+
## Applicable Models
|
| 6 |
+
|
| 7 |
+
This document applies to the following models. You only need to change the model name during deployment.
|
| 8 |
+
|
| 9 |
+
- [MiniMaxAI/MiniMax-M2](https://huggingface.co/MiniMaxAI/MiniMax-M2)
|
| 10 |
+
|
| 11 |
+
The deployment process is illustrated below using MiniMax-M2 as an example.
|
| 12 |
+
|
| 13 |
+
## System Requirements
|
| 14 |
+
|
| 15 |
+
- OS: Linux
|
| 16 |
+
|
| 17 |
+
- Python: 3.9 \- 3.12
|
| 18 |
+
|
| 19 |
+
- GPU:
|
| 20 |
+
|
| 21 |
+
- compute capability 7.0 or higher
|
| 22 |
+
|
| 23 |
+
- Memory requirements: 220 GB for weights, 240 GB per 1M context tokens
|
| 24 |
+
|
| 25 |
+
The following are recommended configurations; actual requirements should be adjusted based on your use case:
|
| 26 |
+
|
| 27 |
+
- 4x 96GB GPUs: Supported context length of up to 400K tokens.
|
| 28 |
+
|
| 29 |
+
- 8x 144GB GPUs: Supported context length of up to 3M tokens.
|
| 30 |
+
|
| 31 |
+
## Deployment with Python
|
| 32 |
+
|
| 33 |
+
It is recommended to use a virtual environment (such as **venv**, **conda**, or **uv**) to avoid dependency conflicts.
|
| 34 |
+
|
| 35 |
+
We recommend installing SGLang in a fresh Python environment:
|
| 36 |
+
|
| 37 |
+
```shell
|
| 38 |
+
git clone -b v0.5.4.post1 https://github.com/sgl-project/sglang.git
|
| 39 |
+
cd sglang
|
| 40 |
+
|
| 41 |
+
# Install the python packages
|
| 42 |
+
pip install --upgrade pip
|
| 43 |
+
pip install -e "python"
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
Run the following command to start the SGLang server. SGLang will automatically download and cache the MiniMax-M2 model from Hugging Face.
|
| 47 |
+
|
| 48 |
+
4-GPU deployment command:
|
| 49 |
+
|
| 50 |
+
```shell
|
| 51 |
+
python -m sglang.launch_server \
|
| 52 |
+
--model-path MiniMaxAI/MiniMax-M2 \
|
| 53 |
+
--tp-size 4 \
|
| 54 |
+
--tool-call-parser minimax-m2 \
|
| 55 |
+
--reasoning-parser minimax-append-think \
|
| 56 |
+
--host 0.0.0.0 \
|
| 57 |
+
--trust-remote-code \
|
| 58 |
+
--port 8000 \
|
| 59 |
+
--mem-fraction-static 0.85
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
8-GPU deployment command:
|
| 63 |
+
|
| 64 |
+
```shell
|
| 65 |
+
python -m sglang.launch_server \
|
| 66 |
+
--model-path MiniMaxAI/MiniMax-M2 \
|
| 67 |
+
--tp-size 8 \
|
| 68 |
+
--ep-size 8 \
|
| 69 |
+
--tool-call-parser minimax-m2 \
|
| 70 |
+
--trust-remote-code \
|
| 71 |
+
--host 0.0.0.0 \
|
| 72 |
+
--reasoning-parser minimax-append-think \
|
| 73 |
+
--port 8000 \
|
| 74 |
+
--mem-fraction-static 0.85
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## Testing Deployment
|
| 78 |
+
|
| 79 |
+
After startup, you can test the SGLang OpenAI-compatible API with the following command:
|
| 80 |
+
|
| 81 |
+
```shell
|
| 82 |
+
curl http://localhost:8000/v1/chat/completions \
|
| 83 |
+
-H "Content-Type: application/json" \
|
| 84 |
+
-d '{
|
| 85 |
+
"model": "MiniMaxAI/MiniMax-M2",
|
| 86 |
+
"messages": [
|
| 87 |
+
{"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
|
| 88 |
+
{"role": "user", "content": [{"type": "text", "text": "Who won the world series in 2020?"}]}
|
| 89 |
+
]
|
| 90 |
+
}'
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
## Common Issues
|
| 94 |
+
|
| 95 |
+
### Hugging Face Network Issues
|
| 96 |
+
|
| 97 |
+
If you encounter network issues, you can set up a proxy before pulling the model.
|
| 98 |
+
|
| 99 |
+
```shell
|
| 100 |
+
export HF_ENDPOINT=https://hf-mirror.com
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### MiniMax-M2 model is not currently supported
|
| 104 |
+
|
| 105 |
+
Please upgrade to the latest stable version, \>= v0.5.4.post3.
|
| 106 |
+
|
docs/Progressive Expert Pruning with Teacher-Guided Distillation for MoE LLMs.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc929abde5d13d43bd9c7b894d52de6fc8c9f3fea20b13e9833c3a1bac1c3c0d
|
| 3 |
+
size 194014
|
docs/tool_calling_guide.md
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MiniMax-M2 Tool Calling Guide
|
| 2 |
+
|
| 3 |
+
## Introduction
|
| 4 |
+
|
| 5 |
+
The MiniMax-M2 model supports tool calling capabilities, enabling the model to identify when external tools need to be called and output tool call parameters in a structured format. This document provides detailed instructions on how to use the tool calling features of MiniMax-M2.
|
| 6 |
+
|
| 7 |
+
## Basic Example
|
| 8 |
+
|
| 9 |
+
The following Python script implements a weather query tool call example based on the OpenAI SDK:
|
| 10 |
+
|
| 11 |
+
```py
|
| 12 |
+
from openai import OpenAI
|
| 13 |
+
import json
|
| 14 |
+
|
| 15 |
+
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
|
| 16 |
+
|
| 17 |
+
def get_weather(location: str, unit: str):
|
| 18 |
+
return f"Getting the weather for {location} in {unit}..."
|
| 19 |
+
|
| 20 |
+
tool_functions = {"get_weather": get_weather}
|
| 21 |
+
|
| 22 |
+
tools = [{
|
| 23 |
+
"type": "function",
|
| 24 |
+
"function": {
|
| 25 |
+
"name": "get_weather",
|
| 26 |
+
"description": "Get the current weather in a given location",
|
| 27 |
+
"parameters": {
|
| 28 |
+
"type": "object",
|
| 29 |
+
"properties": {
|
| 30 |
+
"location": {"type": "string", "description": "City and state, e.g., 'San Francisco, CA'"},
|
| 31 |
+
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
| 32 |
+
},
|
| 33 |
+
"required": ["location", "unit"]
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
}]
|
| 37 |
+
|
| 38 |
+
response = client.chat.completions.create(
|
| 39 |
+
model=client.models.list().data[0].id,
|
| 40 |
+
messages=[{"role": "user", "content": "What's the weather like in San Francisco? use celsius."}],
|
| 41 |
+
tools=tools,
|
| 42 |
+
tool_choice="auto"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
print(response)
|
| 46 |
+
|
| 47 |
+
tool_call = response.choices[0].message.tool_calls[0].function
|
| 48 |
+
print(f"Function called: {tool_call.name}")
|
| 49 |
+
print(f"Arguments: {tool_call.arguments}")
|
| 50 |
+
print(f"Result: {get_weather(**json.loads(tool_call.arguments))}")
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
**Output Example:**
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
Function called: get_weather
|
| 57 |
+
Arguments: {"location": "San Francisco, CA", "unit": "celsius"}
|
| 58 |
+
Result: Getting the weather for San Francisco, CA in celsius...
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Manually Parsing Model Output
|
| 62 |
+
|
| 63 |
+
**We strongly recommend using vLLM or SGLang for parsing tool calls.** If you cannot use the built-in parser of inference engines (e.g., vLLM and SGLang) that support MiniMax-M2, or need to use other inference frameworks (such as transformers, TGI, etc.), you can manually parse the model's raw output using the following method. This approach requires you to parse the XML tag format of the model output yourself.
|
| 64 |
+
|
| 65 |
+
### Example Using Transformers
|
| 66 |
+
|
| 67 |
+
Here is a complete example using the transformers library:
|
| 68 |
+
|
| 69 |
+
```py
|
| 70 |
+
from transformers import AutoTokenizer
|
| 71 |
+
|
| 72 |
+
def get_default_tools():
|
| 73 |
+
return [
|
| 74 |
+
{
|
| 75 |
+
"name": "get_current_weather",
|
| 76 |
+
"description": "Get the latest weather for a location",
|
| 77 |
+
"parameters": {
|
| 78 |
+
"type": "object",
|
| 79 |
+
"properties": {
|
| 80 |
+
"location": {
|
| 81 |
+
"type": "string",
|
| 82 |
+
"description": "A certain city, such as Beijing, Shanghai"
|
| 83 |
+
}
|
| 84 |
+
},
|
| 85 |
+
}
|
| 86 |
+
"required": ["location"],
|
| 87 |
+
"type": "object"
|
| 88 |
+
}
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
# Load model and tokenizer
|
| 92 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 93 |
+
prompt = "What's the weather like in Shanghai today?"
|
| 94 |
+
messages = [
|
| 95 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 96 |
+
{"role": "user", "content": prompt},
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
# Enable function calling tools
|
| 100 |
+
tools = get_default_tools()
|
| 101 |
+
|
| 102 |
+
# Apply chat template and include tool definitions
|
| 103 |
+
text = tokenizer.apply_chat_template(
|
| 104 |
+
messages,
|
| 105 |
+
tokenize=False,
|
| 106 |
+
add_generation_prompt=True,
|
| 107 |
+
tools=tools
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
# Send request (using any inference service)
|
| 111 |
+
import requests
|
| 112 |
+
payload = {
|
| 113 |
+
"model": "MiniMaxAI/MiniMax-M2",
|
| 114 |
+
"prompt": text,
|
| 115 |
+
"max_tokens": 4096
|
| 116 |
+
}
|
| 117 |
+
response = requests.post(
|
| 118 |
+
"http://localhost:8000/v1/completions",
|
| 119 |
+
headers={"Content-Type": "application/json"},
|
| 120 |
+
json=payload,
|
| 121 |
+
stream=False,
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
# Model output needs manual parsing
|
| 125 |
+
raw_output = response.json()["choices"][0]["text"]
|
| 126 |
+
print("Raw output:", raw_output)
|
| 127 |
+
|
| 128 |
+
# Use the parsing function below to process the output
|
| 129 |
+
tool_calls = parse_tool_calls(raw_output, tools)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## 🛠️ Tool Call Definition
|
| 133 |
+
|
| 134 |
+
### Tool Structure
|
| 135 |
+
|
| 136 |
+
Tool calls need to define the `tools` field in the request body. Each tool consists of the following parts:
|
| 137 |
+
|
| 138 |
+
```json
|
| 139 |
+
{
|
| 140 |
+
"tools": [
|
| 141 |
+
{
|
| 142 |
+
"name": "search_web",
|
| 143 |
+
"description": "Search function.",
|
| 144 |
+
"parameters": {
|
| 145 |
+
"properties": {
|
| 146 |
+
"query_list": {
|
| 147 |
+
"description": "Keywords for search, list should contain 1 element.",
|
| 148 |
+
"items": { "type": "string" },
|
| 149 |
+
"type": "array"
|
| 150 |
+
},
|
| 151 |
+
"query_tag": {
|
| 152 |
+
"description": "Category of query",
|
| 153 |
+
"items": { "type": "string" },
|
| 154 |
+
"type": "array"
|
| 155 |
+
}
|
| 156 |
+
},
|
| 157 |
+
"required": [ "query_list", "query_tag" ],
|
| 158 |
+
"type": "object"
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
]
|
| 162 |
+
}
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
**Field Descriptions:**
|
| 166 |
+
|
| 167 |
+
- `name`: Function name
|
| 168 |
+
- `description`: Function description
|
| 169 |
+
- `parameters`: Function parameter definition
|
| 170 |
+
- `properties`: Parameter property definition, where key is the parameter name and value contains detailed parameter description
|
| 171 |
+
- `required`: List of required parameters
|
| 172 |
+
- `type`: Parameter type (usually "object")
|
| 173 |
+
|
| 174 |
+
### Internal Processing Format
|
| 175 |
+
|
| 176 |
+
When processing within the MiniMax-M2 model, tool definitions are converted to a special format and concatenated to the input text. Here is a complete example:
|
| 177 |
+
|
| 178 |
+
```
|
| 179 |
+
]~!b[]~b]system
|
| 180 |
+
You are a helpful assistant.
|
| 181 |
+
|
| 182 |
+
# Tools
|
| 183 |
+
You may call one or more tools to assist with the user query.
|
| 184 |
+
Here are the tools available in JSONSchema format:
|
| 185 |
+
|
| 186 |
+
<tools>
|
| 187 |
+
<tool>{"name": "search_web", "description": "Search function.", "parameters": {"type": "object", "properties": {"query_list": {"type": "array", "items": {"type": "string"}, "description": "Keywords for search, list should contain 1 element."}, "query_tag": {"type": "array", "items": {"type": "string"}, "description": "Category of query"}}, "required": ["query_list", "query_tag"]}}</tool>
|
| 188 |
+
</tools>
|
| 189 |
+
|
| 190 |
+
When making tool calls, use XML format to invoke tools and pass parameters:
|
| 191 |
+
|
| 192 |
+
<minimax:tool_call>
|
| 193 |
+
<invoke name="tool-name-1">
|
| 194 |
+
<parameter name="param-key-1">param-value-1</parameter>
|
| 195 |
+
<parameter name="param-key-2">param-value-2</parameter>
|
| 196 |
+
...
|
| 197 |
+
</invoke>
|
| 198 |
+
[e~[
|
| 199 |
+
]~b]user
|
| 200 |
+
When were the latest announcements from OpenAI and Gemini?[e~[
|
| 201 |
+
]~b]ai
|
| 202 |
+
<think>
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
**Format Description:**
|
| 206 |
+
|
| 207 |
+
- `]~!b[]~b]system`: System message start marker
|
| 208 |
+
- `[e~[`: Message end marker
|
| 209 |
+
- `]~b]user`: User message start marker
|
| 210 |
+
- `]~b]ai`: Assistant message start marker
|
| 211 |
+
- `]~b]tool`: Tool result message start marker
|
| 212 |
+
- `<tools>...</tools>`: Tool definition area, each tool is wrapped with `<tool>` tag, content is JSON Schema
|
| 213 |
+
- `<minimax:tool_call>...</minimax:tool_call>`: Tool call area
|
| 214 |
+
- `<think>...</think>`: Thinking process marker during generation
|
| 215 |
+
|
| 216 |
+
### Model Output Format
|
| 217 |
+
|
| 218 |
+
MiniMax-M2 uses structured XML tag format:
|
| 219 |
+
|
| 220 |
+
```xml
|
| 221 |
+
<minimax:tool_call>
|
| 222 |
+
<invoke name="search_web">
|
| 223 |
+
<parameter name="query_tag">["technology", "events"]</parameter>
|
| 224 |
+
<parameter name="query_list">["\"OpenAI\" \"latest\" \"release\""]</parameter>
|
| 225 |
+
</invoke>
|
| 226 |
+
<invoke name="search_web">
|
| 227 |
+
<parameter name="query_tag">["technology", "events"]</parameter>
|
| 228 |
+
<parameter name="query_list">["\"Gemini\" \"latest\" \"release\""]</parameter>
|
| 229 |
+
</invoke>
|
| 230 |
+
</minimax:tool_call>
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
Each tool call uses the `<invoke name="function_name">` tag, and parameters use the `<parameter name="parameter_name">` tag wrapper.
|
| 234 |
+
|
| 235 |
+
## Manually Parsing Tool Call Results
|
| 236 |
+
|
| 237 |
+
### Parsing Tool Calls
|
| 238 |
+
|
| 239 |
+
MiniMax-M2 uses structured XML tags, which require a different parsing approach. The core function is as follows:
|
| 240 |
+
|
| 241 |
+
```py
|
| 242 |
+
import re
|
| 243 |
+
import json
|
| 244 |
+
from typing import Any, Optional, List, Dict
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def extract_name(name_str: str) -> str:
|
| 248 |
+
"""Extract name from quoted string"""
|
| 249 |
+
name_str = name_str.strip()
|
| 250 |
+
if name_str.startswith('"') and name_str.endswith('"'):
|
| 251 |
+
return name_str[1:-1]
|
| 252 |
+
elif name_str.startswith("'") and name_str.endswith("'"):
|
| 253 |
+
return name_str[1:-1]
|
| 254 |
+
return name_str
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def convert_param_value(value: str, param_type: str) -> Any:
|
| 258 |
+
"""Convert parameter value based on parameter type"""
|
| 259 |
+
if value.lower() == "null":
|
| 260 |
+
return None
|
| 261 |
+
|
| 262 |
+
param_type = param_type.lower()
|
| 263 |
+
|
| 264 |
+
if param_type in ["string", "str", "text"]:
|
| 265 |
+
return value
|
| 266 |
+
elif param_type in ["integer", "int"]:
|
| 267 |
+
try:
|
| 268 |
+
return int(value)
|
| 269 |
+
except (ValueError, TypeError):
|
| 270 |
+
return value
|
| 271 |
+
elif param_type in ["number", "float"]:
|
| 272 |
+
try:
|
| 273 |
+
val = float(value)
|
| 274 |
+
return val if val != int(val) else int(val)
|
| 275 |
+
except (ValueError, TypeError):
|
| 276 |
+
return value
|
| 277 |
+
elif param_type in ["boolean", "bool"]:
|
| 278 |
+
return value.lower() in ["true", "1"]
|
| 279 |
+
elif param_type in ["object", "array"]:
|
| 280 |
+
try:
|
| 281 |
+
return json.loads(value)
|
| 282 |
+
except json.JSONDecodeError:
|
| 283 |
+
return value
|
| 284 |
+
else:
|
| 285 |
+
# Try JSON parsing, return string if failed
|
| 286 |
+
try:
|
| 287 |
+
return json.loads(value)
|
| 288 |
+
except json.JSONDecodeError:
|
| 289 |
+
return value
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def parse_tool_calls(model_output: str, tools: Optional[List[Dict]] = None) -> List[Dict]:
|
| 293 |
+
"""
|
| 294 |
+
Extract all tool calls from model output
|
| 295 |
+
|
| 296 |
+
Args:
|
| 297 |
+
model_output: Complete output text from the model
|
| 298 |
+
tools: Tool definition list for getting parameter type information, format can be:
|
| 299 |
+
- [{"name": "...", "parameters": {...}}]
|
| 300 |
+
- [{"type": "function", "function": {"name": "...", "parameters": {...}}}]
|
| 301 |
+
|
| 302 |
+
Returns:
|
| 303 |
+
Parsed tool call list, each element contains name and arguments fields
|
| 304 |
+
|
| 305 |
+
Example:
|
| 306 |
+
>>> tools = [{
|
| 307 |
+
... "name": "get_weather",
|
| 308 |
+
... "parameters": {
|
| 309 |
+
... "type": "object",
|
| 310 |
+
... "properties": {
|
| 311 |
+
... "location": {"type": "string"},
|
| 312 |
+
... "unit": {"type": "string"}
|
| 313 |
+
... }
|
| 314 |
+
... }
|
| 315 |
+
... }]
|
| 316 |
+
>>> output = '''<minimax:tool_call>
|
| 317 |
+
... <invoke name="get_weather">
|
| 318 |
+
... <parameter name="location">San Francisco</parameter>
|
| 319 |
+
... <parameter name="unit">celsius</parameter>
|
| 320 |
+
... </invoke>
|
| 321 |
+
... </minimax:tool_call>'''
|
| 322 |
+
>>> result = parse_tool_calls(output, tools)
|
| 323 |
+
>>> print(result)
|
| 324 |
+
[{'name': 'get_weather', 'arguments': {'location': 'San Francisco', 'unit': 'celsius'}}]
|
| 325 |
+
"""
|
| 326 |
+
# Quick check if tool call marker is present
|
| 327 |
+
if "<minimax:tool_call>" not in model_output:
|
| 328 |
+
return []
|
| 329 |
+
|
| 330 |
+
tool_calls = []
|
| 331 |
+
|
| 332 |
+
try:
|
| 333 |
+
# Match all <minimax:tool_call> blocks
|
| 334 |
+
tool_call_regex = re.compile(r"<minimax:tool_call>(.*?)</minimax:tool_call>", re.DOTALL)
|
| 335 |
+
invoke_regex = re.compile(r"<invoke name=(.*?)</invoke>", re.DOTALL)
|
| 336 |
+
parameter_regex = re.compile(r"<parameter name=(.*?)</parameter>", re.DOTALL)
|
| 337 |
+
|
| 338 |
+
# Iterate through all tool_call blocks
|
| 339 |
+
for tool_call_match in tool_call_regex.findall(model_output):
|
| 340 |
+
# Iterate through all invokes in this block
|
| 341 |
+
for invoke_match in invoke_regex.findall(tool_call_match):
|
| 342 |
+
# Extract function name
|
| 343 |
+
name_match = re.search(r'^([^>]+)', invoke_match)
|
| 344 |
+
if not name_match:
|
| 345 |
+
continue
|
| 346 |
+
|
| 347 |
+
function_name = extract_name(name_match.group(1))
|
| 348 |
+
|
| 349 |
+
# Get parameter configuration
|
| 350 |
+
param_config = {}
|
| 351 |
+
if tools:
|
| 352 |
+
for tool in tools:
|
| 353 |
+
tool_name = tool.get("name") or tool.get("function", {}).get("name")
|
| 354 |
+
if tool_name == function_name:
|
| 355 |
+
params = tool.get("parameters") or tool.get("function", {}).get("parameters")
|
| 356 |
+
if isinstance(params, dict) and "properties" in params:
|
| 357 |
+
param_config = params["properties"]
|
| 358 |
+
break
|
| 359 |
+
|
| 360 |
+
# Extract parameters
|
| 361 |
+
param_dict = {}
|
| 362 |
+
for match in parameter_regex.findall(invoke_match):
|
| 363 |
+
param_match = re.search(r'^([^>]+)>(.*)', match, re.DOTALL)
|
| 364 |
+
if param_match:
|
| 365 |
+
param_name = extract_name(param_match.group(1))
|
| 366 |
+
param_value = param_match.group(2).strip()
|
| 367 |
+
|
| 368 |
+
# Remove leading and trailing newlines
|
| 369 |
+
if param_value.startswith('\n'):
|
| 370 |
+
param_value = param_value[1:]
|
| 371 |
+
if param_value.endswith('\n'):
|
| 372 |
+
param_value = param_value[:-1]
|
| 373 |
+
|
| 374 |
+
# Get parameter type and convert
|
| 375 |
+
param_type = "string"
|
| 376 |
+
if param_name in param_config:
|
| 377 |
+
if isinstance(param_config[param_name], dict) and "type" in param_config[param_name]:
|
| 378 |
+
param_type = param_config[param_name]["type"]
|
| 379 |
+
|
| 380 |
+
param_dict[param_name] = convert_param_value(param_value, param_type)
|
| 381 |
+
|
| 382 |
+
tool_calls.append({
|
| 383 |
+
"name": function_name,
|
| 384 |
+
"arguments": param_dict
|
| 385 |
+
})
|
| 386 |
+
|
| 387 |
+
except Exception as e:
|
| 388 |
+
print(f"Failed to parse tool calls: {e}")
|
| 389 |
+
return []
|
| 390 |
+
|
| 391 |
+
return tool_calls
|
| 392 |
+
```
|
| 393 |
+
|
| 394 |
+
**Usage Example:**
|
| 395 |
+
|
| 396 |
+
```py
|
| 397 |
+
# Define tools
|
| 398 |
+
tools = [
|
| 399 |
+
{
|
| 400 |
+
"name": "get_weather",
|
| 401 |
+
"parameters": {
|
| 402 |
+
"type": "object",
|
| 403 |
+
"properties": {
|
| 404 |
+
"location": {"type": "string"},
|
| 405 |
+
"unit": {"type": "string"}
|
| 406 |
+
},
|
| 407 |
+
"required": ["location", "unit"]
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
]
|
| 411 |
+
|
| 412 |
+
# Model output
|
| 413 |
+
model_output = """Let me help you query the weather.
|
| 414 |
+
<minimax:tool_call>
|
| 415 |
+
<invoke name="get_weather">
|
| 416 |
+
<parameter name="location">San Francisco</parameter>
|
| 417 |
+
<parameter name="unit">celsius</parameter>
|
| 418 |
+
</invoke>
|
| 419 |
+
</minimax:tool_call>"""
|
| 420 |
+
|
| 421 |
+
# Parse tool calls
|
| 422 |
+
tool_calls = parse_tool_calls(model_output, tools)
|
| 423 |
+
|
| 424 |
+
# Output results
|
| 425 |
+
for call in tool_calls:
|
| 426 |
+
print(f"Function called: {call['name']}")
|
| 427 |
+
print(f"Arguments: {call['arguments']}")
|
| 428 |
+
# Output: Function called: get_weather
|
| 429 |
+
# Arguments: {'location': 'San Francisco', 'unit': 'celsius'}
|
| 430 |
+
```
|
| 431 |
+
|
| 432 |
+
### Executing Tool Calls
|
| 433 |
+
|
| 434 |
+
After parsing is complete, you can execute the corresponding tool and construct the return result:
|
| 435 |
+
|
| 436 |
+
```py
|
| 437 |
+
def execute_function_call(function_name: str, arguments: dict):
|
| 438 |
+
"""Execute function call and return result"""
|
| 439 |
+
if function_name == "get_weather":
|
| 440 |
+
location = arguments.get("location", "Unknown location")
|
| 441 |
+
unit = arguments.get("unit", "celsius")
|
| 442 |
+
# Build function execution result
|
| 443 |
+
return {
|
| 444 |
+
"role": "tool",
|
| 445 |
+
"content": [
|
| 446 |
+
{
|
| 447 |
+
"name": function_name,
|
| 448 |
+
"type": "text",
|
| 449 |
+
"text": json.dumps({
|
| 450 |
+
"location": location,
|
| 451 |
+
"temperature": "25",
|
| 452 |
+
"unit": unit,
|
| 453 |
+
"weather": "Sunny"
|
| 454 |
+
}, ensure_ascii=False)
|
| 455 |
+
}
|
| 456 |
+
]
|
| 457 |
+
}
|
| 458 |
+
elif function_name == "search_web":
|
| 459 |
+
query_list = arguments.get("query_list", [])
|
| 460 |
+
query_tag = arguments.get("query_tag", [])
|
| 461 |
+
# Simulate search results
|
| 462 |
+
return {
|
| 463 |
+
"role": "tool",
|
| 464 |
+
"content": [
|
| 465 |
+
{
|
| 466 |
+
"name": function_name,
|
| 467 |
+
"type": "text",
|
| 468 |
+
"text": f"Search keywords: {query_list}, Category: {query_tag}\nSearch results: Relevant information found"
|
| 469 |
+
}
|
| 470 |
+
]
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
return None
|
| 474 |
+
```
|
| 475 |
+
### Returning Tool Execution Results to the Model
|
| 476 |
+
|
| 477 |
+
After successfully parsing tool calls, you should add the tool execution results to the conversation history so that the model can access and utilize this information in subsequent interactions. Refer to [chat\_template.jinja](https://huggingface.co/MiniMaxAI/MiniMax-M2/blob/main/chat_template.jinja) for concatenation format.
|
| 478 |
+
|
| 479 |
+
## References
|
| 480 |
+
|
| 481 |
+
- [MiniMax-M2 Model Repository](https://github.com/MiniMax-AI/MiniMax-M2)
|
| 482 |
+
- [vLLM Project Homepage](https://github.com/vllm-project/vllm)
|
| 483 |
+
- [SGLang Project Homepage](https://github.com/sgl-project/sglang)
|
| 484 |
+
- [OpenAI Python SDK](https://github.com/openai/openai-python)
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_sample": true,
|
| 3 |
+
"top_k": 40,
|
| 4 |
+
"top_p": 0.95,
|
| 5 |
+
"transformers_version": "4.55.0"
|
| 6 |
+
}
|
logo.png
ADDED
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-00001-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92ce9d4dac7d33263ec980a594d86593272d3ab1907ae152775f355ee17602a1
|
| 3 |
+
size 4997842560
|
model-00002-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:22f4f1bc412143547a5cc5a9492cc31add89c9c26f88df33ace8a71c43b9e028
|
| 3 |
+
size 4996692376
|
model-00003-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:969ec2fe7af75411b511a8dab9dc380c201a0fd579808e43babf105b5edb8578
|
| 3 |
+
size 4996692392
|
model-00004-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4cbb2d048f6f177917de1a1ade7b000bb88d4ac03283b15faf7b157572f09f88
|
| 3 |
+
size 4996692432
|
model-00005-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:48d0da24d5a8f2486a2686c44f896e8d30c6c42888d7bdc629d7bdb24e9dc5cf
|
| 3 |
+
size 4996692432
|
model-00006-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:adb79dba9bb640bf26a39fcadee3c625a958e8b311dca95a4e429643001bb3a0
|
| 3 |
+
size 4996692432
|
model-00007-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14198f3595051135c45de69c2e6be6658db6a6e8b70f1aa804cfd37c080f471a
|
| 3 |
+
size 4996692432
|
model-00008-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d036567118e18a6796312aef53a8787b3f8e1c4f77aeedc50fc11c1b772ebedc
|
| 3 |
+
size 4977802792
|
model-00009-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:76d004002f3bcdc3f1ed018624712e9f49178fe7e849583722a85345ad514bb5
|
| 3 |
+
size 4992354664
|
model-00010-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:037abcefe796e54d0d811ae5e1f8896aa81207dfc9533e6370fc034fd4a0b3fe
|
| 3 |
+
size 4996692368
|
model-00011-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5eb8f27d65720a4d7e2502aedeb17ac34add567e278eb12c7193cd06d60768b7
|
| 3 |
+
size 4996692376
|
model-00012-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ca3734e67fdb4fdaa9eab3bce7b3f58d81b5185a8687275702e1f2c312444bcc
|
| 3 |
+
size 4996692736
|
model-00013-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d5fa2066ba143889e76f267a4483f097388b4422220589b4623af592988fda4f
|
| 3 |
+
size 4996692904
|
model-00014-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4f9ff75bf7e987a72e1457ed1480b220c0edd354b3775d7ee13979174226bec3
|
| 3 |
+
size 4996692960
|
model-00015-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fca8287025bb9bc461dae02ba76a0fb6920ce756ff4cc0eaab02ada55164135d
|
| 3 |
+
size 4996692960
|
model-00016-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:72fb56372bd4f2862bfe102d14eaf5ad2e378d4374b74e96fdf144e68cc4bc0b
|
| 3 |
+
size 4996692960
|
model-00017-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5427acfa913f92ae7c7ea986d96dbe729806ce4c731cfb9deaf1be2167a1718f
|
| 3 |
+
size 4996692960
|
model-00018-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99dd2779ddb568eec957580653923ec05879e05027a8d30a56070c1cfa4fa8f9
|
| 3 |
+
size 4996692968
|
model-00019-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab3d12ad435507ea42c97c63220acdb5471027e4646940145705fa0f7bbcb231
|
| 3 |
+
size 4992340208
|
model-00020-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb4c4f4b9a7739d48d521126da70f36d1411e683acf6ecec2a131bc208b9cbad
|
| 3 |
+
size 4996692896
|
model-00021-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:774792c0526a5315515556087ec8ee87c8861a41c1d28d175343e46bacecbed1
|
| 3 |
+
size 4996692896
|
model-00022-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:703b9887e755a866e68737620f67eb668eae3456bb1fe1439c5865a27a7ae988
|
| 3 |
+
size 4996692904
|
model-00023-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e6c70264fd3a71f44f9adb646470018c6f5b1a996947067310e084116e749c52
|
| 3 |
+
size 4996692904
|
model-00024-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf94a3627fb32d9505c95fcac7ff112ba65d10d4ff65479b802b6457b05974d1
|
| 3 |
+
size 4996692936
|
model-00025-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:95ef12862c60786dce34383a4ba0db2ab706a3c5117d70dd56f4eb2f4c65e6e6
|
| 3 |
+
size 4996692960
|
model-00026-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:740b8a48b514c4855d74c5262d11a8e8f890a3c0c26038ad7579a5b09dd13144
|
| 3 |
+
size 4996692960
|
model-00027-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91f105473920bc03907183f076b729fbdc2eb378a1bb23dfea23b62815545f97
|
| 3 |
+
size 4996692960
|
model-00028-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4bc19c9e7cb7c01625f2a8fca20b216900ee75582708e46e84d8aedb249143cf
|
| 3 |
+
size 4996692960
|
model-00029-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:251dfaca5c3b81362e54d4e4e5ace14d2837dd7e2b3958a7168246244e2279d9
|
| 3 |
+
size 4992340240
|
model-00030-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d98a6dc2c1ddd6eef7f24af38f2a2068c47a0b385fa23c5219ab4c8e062d1d34
|
| 3 |
+
size 4996692888
|
model-00031-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:671334330b78709a02a1b9dcc20be5ce575a0177cf46bc538539941c1c26f335
|
| 3 |
+
size 4996692896
|
model-00032-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7fc96ad8210ca4941622e7f9313d4d98683b4f1e66165629727025ffe7e36b1b
|
| 3 |
+
size 4996692904
|
model-00033-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:28c0e3c7a66485517126362209eaabc261128c24fcc26fd8c33e62aec4998b66
|
| 3 |
+
size 4996692904
|
model-00034-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1bdd65a4af8e04fa9ee17476523fa5e7eec493439cbbd8e2922b11eaf2a8c8a1
|
| 3 |
+
size 4996692912
|
model-00035-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c38159eb713042e382f6e7b39a96074a400d360d01926ef8a1fba9a567f9c63
|
| 3 |
+
size 4996692960
|
model-00036-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b1470e6b21485c800b5ca78ac2eb234a4fe68a48ad81a927061e8cdc267d55c
|
| 3 |
+
size 4996692960
|
model-00037-of-00070.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7ec6ee695578b68ab3e44a8e0b156ca30dbf9295b2a31843965b47c1b92d265b
|
| 3 |
+
size 4996692960
|