Image-Text-to-Text
Transformers
Safetensors
minimax_m3_vl
multimodal
Mixture of Experts
agent
coding
video
conversational
custom_code
Run this model with HF Jobs
Run CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 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 and TRL to fine-tune https://huggingface.co/CharyZeng/MiniMax-M3.1-Flash-4layer-bf16. 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/CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 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/CharyZeng/MiniMax-M3.1-Flash-4layer-bf16. 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/CharyZeng/MiniMax-M3.1-Flash-4layer-bf16. 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 CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="CharyZeng/MiniMax-M3.1-Flash-4layer-bf16", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("CharyZeng/MiniMax-M3.1-Flash-4layer-bf16", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("CharyZeng/MiniMax-M3.1-Flash-4layer-bf16", trust_remote_code=True, device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CharyZeng/MiniMax-M3.1-Flash-4layer-bf16" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CharyZeng/MiniMax-M3.1-Flash-4layer-bf16", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/CharyZeng/MiniMax-M3.1-Flash-4layer-bf16
- SGLang
How to use CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "CharyZeng/MiniMax-M3.1-Flash-4layer-bf16" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CharyZeng/MiniMax-M3.1-Flash-4layer-bf16", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "CharyZeng/MiniMax-M3.1-Flash-4layer-bf16" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CharyZeng/MiniMax-M3.1-Flash-4layer-bf16", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use CharyZeng/MiniMax-M3.1-Flash-4layer-bf16 with Docker Model Runner:
docker model run hf.co/CharyZeng/MiniMax-M3.1-Flash-4layer-bf16
Add MiniMax-M3.1-Flash-4layer-bf16
Browse filesFiles changed (26)
- .gitattributes+1
- LICENSEAdded+17
- README.mdAdded+289
- README_zh.mdAdded+287
- added_tokens.jsonAdded+63
- chat_template.jinjaAdded+248
- config.jsonAdded+114
- configuration_minimax_m3_vl.pyAdded+111
- generation_config.jsonAdded+8
- image_processor.pyAdded+223
- merges.txtAdded
- model-00001.safetensorsAdded+3
- model-00002.safetensorsAdded+3
- model-00003.safetensorsAdded+3
- model-00004.safetensorsAdded+3
- model-00005.safetensorsAdded+3
- model-00006.safetensorsAdded+3
- model-00007.safetensorsAdded+3
- model.safetensors.index.jsonAdded
- preprocessor_config.jsonAdded+32
- processing_minimax.pyAdded+254
- special_tokens_map.jsonAdded+16
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+501
- video_processor.pyAdded+208
- vocab.jsonAdded
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text/model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
1234567891011121314151617MINIMAX COMMUNITY LICENSECopyright (c) 2026 MiniMaxPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software for non-commercial purposes, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or provide copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.2. If the Software (or any derivative works thereof) is used for any Commercial Use for your products or services: 1. you shall prominently display “Built with MiniMax M3.1-Flash” on a related website, user interface, blogpost, about page or product documentation. 2. you shall obtain a separate, prior written authorization from MiniMax by contacting api@minimax.io with the subject line “M3.1-Flash licensing - authorization request”, if such products and services generate more than 20 million US dollars (or equivalent in other currencies) in yearly revenue; otherwise, you only need to send a one-time notice to api@minimax.io with the subject “M3.1-Flash licensing — notice”.3. “Commercial Use” means any use of the Software or any derivative work thereof that is primarily intended for commercial advantage or monetary compensation, which includes, without limitation: (i) offering products or services to third parties for a fee, which utilize, incorporate, or rely on the Software or its derivatives, (ii) the commercial use of APIs provided by or for the Software or its derivatives, including to support or enable commercial products, services, or operations, whether in a cloud-based, hosted, or other similar environment, and (iii) the deployment or provision of the Software or its derivatives that have been subjected to post-training, fine-tuning, instruction-tuning, or any other form of modification, for any commercial purpose.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Appendix: Prohibited Uses You agree you will not use, or allow others to use, the Software or any derivatives of the Software to:1. Generate or disseminate content prohibited by applicable laws or regulations.2. Assist with, engage in or otherwise support any military purpose.3. Exploit, harm, or attempt to exploit or harm minors.4. Generate or disseminate false or misleading information with the intent to cause harm.5. Promote discrimination, hate speech, or harmful behavior against individuals or groups based on race or ethnic origin, religion, disability, age, nationality and national origin, veteran status, sexual orientation, gender or gender identity, caste, immigration status, or any other characteristic that is associated with systemic discrimination or marginalization.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289---pipeline_tag: image-text-to-textlicense: otherlicense_name: minimax-communitylicense_link: LICENSElibrary_name: transformerstags: - multimodal - moe - agent - coding - video---
<div align="center"> <img width="60%" src="figures/logo.svg" alt="MiniMax"></div><hr>
<p align="center"> <a href="https://agent.minimax.io/" target="_blank"><img src="https://img.shields.io/badge/MiniMax%20Code-FF6C37?logo=minimax&logoColor=white" alt="MiniMax Code"></a> <a href="https://platform.minimax.io/docs/guides/text-generation" target="_blank"><img src="https://img.shields.io/badge/API-FF6C37?logo=minimax&logoColor=white" alt="API"></a> <a href="https://www.minimax.io" target="_blank"><img src="https://img.shields.io/badge/MiniMax%20Website-FF6C37?logo=minimax&logoColor=white" alt="MiniMax Website"></a> <br> <a href="https://modelscope.cn/organization/minimax" target="_blank" rel="noopener noreferrer"><img alt="ModelScope MiniMax AI" src="https://img.shields.io/badge/ModelScope-MiniMax%20AI-white?labelColor=%23EF3D5D"></a> <a href="https://platform.minimaxi.com/docs/faq/contact-us" target="_blank"><img src="https://img.shields.io/badge/WeChat-07C160?logo=wechat&logoColor=white" alt="WeChat"></a> <a href="https://discord.com/invite/DPC4AHFCBw" target="_blank"><img src="https://img.shields.io/badge/Discord-5865F2?logo=discord&logoColor=white" alt="Discord"></a> <a href="https://huggingface.co/MiniMaxAI" target="_blank"><img src="https://img.shields.io/badge/Hugging%20Face-FFD21E?logo=huggingface&logoColor=black" alt="Hugging Face"></a> <a href="https://github.com/MiniMax-AI" target="_blank"><img src="https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white" alt="GitHub"></a> <a href="https://arxiv.org/abs/2606.13392" target="_blank"><img src="https://img.shields.io/badge/arXiv-2606.13392-B31B1B?logo=arxiv&logoColor=white" alt="arXiv Paper"></a></p>
**MiniMax-M3.1-Flash** is a native multimodal mixture-of-experts model for coding, agentic workflows, computer use, and cybersecurity. It supports text, image, and video inputs with a context window of up to **1M tokens**.
Building on MiniMax-M3, M3.1-Flash improves task performance and inference efficiency with sparse attention throughout the model, quantization-aware training, and DSpark speculative decoding.
**Highlights:**- **Agentic performance:** A generational leap in agentic tasks, coding, and cybersecurity — 76.2 on BankerToolBench, 73.7% on DeepSWE v1.1, 61.7 on OSWorld V2, 29.6 on Agents' Last Exam, and 82.2 on CyberGym.- **Efficient by design:** Sparse attention throughout, quantization-aware training, and DSpark speculative decoding improve inference efficiency.
## Model at a Glance
- **Architecture:** Native multimodal mixture-of-experts (MoE)- **Parameters:** Approximately 428B total; 23B activated per token- **Inputs / output:** Text, image, and video inputs; text output- **Context window:** Up to 1,000,000 tokens- **Attention:** [MiniMax Sparse Attention](https://arxiv.org/abs/2606.13392) (MSA) throughout the model- **Speculative decoding:** DSpark draft head included
## Benchmarks
<div style="overflow-x:auto;margin:16px 0"><table style="width:100%;border-collapse:collapse;font-size:14px"><thead><tr><th style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">Benchmark</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:rgba(242,95,92,0.08);">MiniMax M3.1 Flash</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">DeepSeek V4.1 Flash-1017</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">DeepSeek V4.1 Flash</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">Kimi K3</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">GLM-5.3</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">GPT-5.6 Sol</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">Opus 5</th></tr></thead><tbody><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><div>Automation-Bench v1.0.6</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);"><strong>62.8</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">60.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">54.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">46.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">48.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">45.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">50.3</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">BankerToolBench</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);"><strong>76.2</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">73.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">69.1</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>76.2</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">GDP.pdf AA</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">20.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">12.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">22.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">11.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>27.2</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">21.6</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">Terminal Bench 4.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">38.1</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">42.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">31.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">12.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">37.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">39.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>51.8</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">LOCA-Bench 256K</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);"><strong>60.3</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">49.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">50.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">60.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">53.7</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>Agents’ Last Exam</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">29.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">28.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">30.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>32.2</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">OSWorld 2.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">61.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">54.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">58.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">65.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>70.6</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>PostTrain Bench v1.1</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">39.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">30.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">36.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">37.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">36.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>40.4</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">DeepSWE v1.1</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">73.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>77.0</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">67.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">66.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">73.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.0</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">NL2Repo-Bench</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">61.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">68.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">65.4</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">58.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">58.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">56.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>75.3</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">SWE Refactor Bench</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">23.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">11.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">19.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">10.4</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">28.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>31.0</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>CyberGym</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">82.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">80.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>84.5</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">83.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>BabyVision (with tools)</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">91.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">92.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">89.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">85.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">88.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>94.1</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">HLE (without tools)</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">43.4</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">42.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">39.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">43.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">42.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">49.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>55.6</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">CharXiv RQ</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">82.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">69.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">84.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>85.2</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">83.7</td></tr></tbody></table></div>
<details><summary><strong>Evaluation Notes</strong></summary>
- **Automation-Bench v1.0.6:** 600 publicly released tasks.- **BankerToolBench:** OpenCode 1.17.18; MiniMax-M2.7 judge.- **GDP.pdf AA:** Taken directly from Artificial Analysis.- **Terminal Bench 4.0:** Codex 0.149.1.- **LOCA-Bench 256K:** Official implementation.- **Agents’ Last Exam:** Official Overall setting; full-set results from the official ALE leaderboard only. Blank = no official result (CLI-only excluded), not zero.- **OSWorld 2.0:** 0808 Full release; highest reported per model at release, except DeepSeek V4.1 (in-house reproduction).- **PostTrain Bench v1.1:** Claude Code 2.1.251, 512K context; otherwise official setup.- **DeepSWE v1.1:** mini-SWE-agent 2.4.5, 512K context.- **NL2Repo-Bench:** Claude Code 2.1.233, 512K context; reward hacking = 0; two inconsistent tasks corrected (scores use the corrected set).- **SWE Refactor Bench:** Claude Code 2.1.220, 200K context; otherwise official setup.- **CyberGym:** Claude Code 2.1.263, 1M context.- **BabyVision (with tools):** Claude Code 2.1.285; min image side 1,500 px.- **HLE (without tools):** Text-only subset (2,158 questions).- **CharXiv RQ:** GPT-5.5 judge.
</details>
Results are for the official weights; third-party quantizations may differ.
## What’s New in M3.1-Flash
M3.1-Flash retains M3’s core mixture-of-experts architecture, with three main changes:
- **Sparse attention throughout:** the first three full-attention layers are replaced with sparse attention.- **Quantization-aware training:** the routed MoE experts and the attention paths are quantized during training, reducing memory footprint and improving serving efficiency.- **DSpark speculative decoding:** DSpark replaces the earlier EAGLE-like MTP approach. The release includes the draft head for use with compatible serving implementations.
## How to Use
- [MiniMax Code](https://agent.minimax.io/)- [MiniMax API](https://platform.minimax.io/)
### Local Deployment
Download the model:
```bashhf download MiniMaxAI/MiniMax-M3.1-Flash --local-dir MiniMax-M3.1-Flash```
We recommend the following inference frameworks to serve the model:
- [SGLang](https://docs.sglang.io/) — see [SGLang cookbook](https://docs.sglang.io/cookbook/autoregressive/MiniMax/MiniMax-M3.1).- [vLLM](https://github.com/vllm-project/vllm) — see [vLLM recipe](https://recipes.vllm.ai/MiniMaxAI/MiniMax-M3.1-Flash).- [TokenSpeed](https://github.com/lightseekorg/tokenspeed) — see [TokenSpeed recipe](https://lightseek.org/tokenspeed/recipes/models#minimax-m3-1).
Additional integrations in progress: Transformers, KTransformers, unsloth, and ATOM.
### Multi-Chip Deployment
[FlagOS](https://github.com/flagos-ai) — see [Multi-Chip Support and Downloads](https://huggingface.co/MiniMaxAI/MiniMax-M3.1-Flash/blob/main/docs/FlagOS-Multi-Chip-Support-and-Downloads.md).
## Inference Settings
Recommended sampling settings: `temperature=1.0` and `top_p=0.95`.
For reasoning, set `reasoning_effort` in the chat template: `low`, `medium`, `high`, `xhigh`, or `max`.
The model supports a context window of up to 1M tokens. Usable context length and throughput depend on GPU memory and the serving configuration.
## Contact Us
Contact us at [model@minimax.io](mailto:model@minimax.io).123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287---pipeline_tag: image-text-to-textlicense: otherlicense_name: minimax-communitylicense_link: LICENSElibrary_name: transformerstags: - multimodal - moe - agent - coding - video---
<p align="right"><a href="README.md">English</a></p>
# MiniMax-M3.1-Flash
<div align="center"> <img width="60%" src="figures/logo.svg" alt="MiniMax"></div><hr>
<p align="center"> <a href="https://agent.minimax.io/" target="_blank"><img src="https://img.shields.io/badge/MiniMax%20Agent-FF6C37?logo=minimax&logoColor=white" alt="MiniMax Agent"></a> <a href="https://platform.minimax.io/docs/guides/text-generation" target="_blank"><img src="https://img.shields.io/badge/API-FF6C37?logo=minimax&logoColor=white" alt="API"></a> <a href="https://www.minimax.io" target="_blank"><img src="https://img.shields.io/badge/MiniMax%20Website-FF6C37?logo=minimax&logoColor=white" alt="MiniMax Website"></a> <br> <a href="https://modelscope.cn/organization/minimax" target="_blank" rel="noopener noreferrer"><img alt="ModelScope MiniMax AI" src="https://img.shields.io/badge/ModelScope-MiniMax%20AI-white?labelColor=%23EF3D5D"></a> <a href="https://platform.minimaxi.com/docs/faq/contact-us" target="_blank"><img src="https://img.shields.io/badge/WeChat-07C160?logo=wechat&logoColor=white" alt="WeChat"></a> <a href="https://discord.com/invite/DPC4AHFCBw" target="_blank"><img src="https://img.shields.io/badge/Discord-5865F2?logo=discord&logoColor=white" alt="Discord"></a> <a href="https://huggingface.co/MiniMaxAI" target="_blank"><img src="https://img.shields.io/badge/Hugging%20Face-FFD21E?logo=huggingface&logoColor=black" alt="Hugging Face"></a> <a href="https://github.com/MiniMax-AI" target="_blank"><img src="https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white" alt="GitHub"></a> <a href="https://arxiv.org/abs/2606.13392" target="_blank"><img src="https://img.shields.io/badge/arXiv-2606.13392-B31B1B?logo=arxiv&logoColor=white" alt="arXiv Paper"></a></p>
**MiniMax-M3.1-Flash** 是一款原生多模态混合专家(MoE)模型,面向编程、智能体工作流、计算机使用和网络安全等场景。它支持文本、图像和视频输入,上下文窗口最高可达 **100 万 tokens**。
在 MiniMax-M3 的基础上,M3.1-Flash 通过全模型稀疏注意力、量化感知训练和 DSpark 投机解码,进一步提升了任务表现与推理效率。
**亮点:**- **智能体能力:** 在智能体任务、编程和网络安全方面实现代际跃升——BankerToolBench 76.2、DeepSWE v1.1 73.7%、OSWorld V2 61.7、Agents' Last Exam 29.6、CyberGym 82.2。- **高效设计:** 全模型稀疏注意力、量化感知训练和 DSpark 投机解码共同提升推理效率。
## 模型概览
- **架构:** 原生多模态混合专家(MoE)- **参数:** 总参数约 428B;每 token 激活约 23B- **输入 / 输出:** 文本、图像和视频输入;文本输出- **上下文窗口:** 最高 1,000,000 tokens- **注意力:** 全模型采用 [MiniMax Sparse Attention](https://arxiv.org/abs/2606.13392)(MSA)- **投机解码:** 包含 DSpark draft head
## 基准测试
<div style="overflow-x:auto;margin:16px 0"><table style="width:100%;border-collapse:collapse;font-size:14px"><thead><tr><th style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">基准测试</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:rgba(242,95,92,0.08);">MiniMax M3.1 Flash</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">DeepSeek V4.1 Flash-1017</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">DeepSeek V4.1 Flash</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">Kimi K3</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">GLM-5.3</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">GPT-5.6 Sol</th><th style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;font-weight:600;border-bottom:2px solid #f25f5c;background:#f7f7f8;">Opus 5</th></tr></thead><tbody><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><div>Automation-Bench v1.0.6</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);"><strong>62.8</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">60.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">54.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">46.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">48.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">45.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">50.3</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">BankerToolBench</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);"><strong>76.2</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">73.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">69.1</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>76.2</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">GDP.pdf AA</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">20.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">12.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">22.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">11.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>27.2</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">21.6</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">Terminal Bench 4.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">38.1</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">42.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">31.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">12.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">37.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">39.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>51.8</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">LOCA-Bench 256K</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);"><strong>60.3</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">49.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">50.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">60.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">53.7</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>Agents’ Last Exam</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">29.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">28.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">30.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>32.2</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">OSWorld 2.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">61.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">54.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">58.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">65.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>70.6</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>PostTrain Bench v1.1</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">39.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">30.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">36.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">37.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">36.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>40.4</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">DeepSWE v1.1</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">73.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>77.0</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">67.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">66.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">73.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">74.0</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">NL2Repo-Bench</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">61.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">68.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">65.4</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">58.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">58.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">56.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>75.3</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">SWE Refactor Bench</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">23.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">11.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">19.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">10.4</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">28.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>31.0</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>CyberGym</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">82.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">80.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>84.5</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">83.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><div>BabyVision (with tools)</div></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;background:rgba(242,95,92,0.08);">91.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">92.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">89.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">85.7</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;">88.9</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;border-top:2px solid #f1d6d3;"><strong>94.1</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">HLE (without tools)</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">43.4</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">42.6</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">39.2</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">43.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">42.3</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">49.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>55.6</strong></td></tr><tr><td style="padding:10px 12px;text-align:left;vertical-align:middle;border-bottom:1px solid #e5e7eb;">CharXiv RQ</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;background:rgba(242,95,92,0.08);">82.5</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">69.0</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">84.8</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">—</td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;"><strong>85.2</strong></td><td style="padding:10px 12px;text-align:center;vertical-align:middle;border-bottom:1px solid #e5e7eb;">83.7</td></tr></tbody></table></div>
<details><summary><strong>评测说明</strong></summary>
- **Automation-Bench v1.0.6:** 600 个公开任务。- **BankerToolBench:** OpenCode 1.17.18;MiniMax-M2.7 作为 judge。- **GDP.pdf AA:** 直接取自 Artificial Analysis。- **Terminal Bench 4.0:** Codex 0.149.1。- **LOCA-Bench 256K:** 官方实现。- **Agents’ Last Exam:** 采用官方 Overall 设置;仅收录官方 ALE 榜单的完整测试集结果。空白表示没有官方结果(仅 CLI 结果不计入),并非零分。- **OSWorld 2.0:** 采用 0808 Full 版本;各模型取其发布时报告的最高分,DeepSeek V4.1 除外(内部复现)。- **PostTrain Bench v1.1:** Claude Code 2.1.251,512K 上下文;其余设置遵循官方评测。- **DeepSWE v1.1:** mini-SWE-agent 2.4.5,512K 上下文。- **NL2Repo-Bench:** Claude Code 2.1.233,512K 上下文;reward hacking 计 0 分;修正了两个规格与测试不一致的任务(分数基于修正后的测试集)。- **SWE Refactor Bench:** Claude Code 2.1.220,200K 上下文;其余设置遵循官方评测。- **CyberGym:** Claude Code 2.1.263,1M 上下文。- **BabyVision(带工具):** Claude Code 2.1.285;图像最短边 1,500 px。- **HLE(不带工具):** 纯文本子集(2,158 题)。- **CharXiv RQ:** GPT-5.5 作为 judge。
</details>
以上结果基于官方权重;第三方量化版本可能有所不同。
## M3.1-Flash 的新特性
M3.1-Flash 延续 M3 的核心混合专家架构,主要有三项变化:
- **全模型稀疏注意力:** 前三个全注意力层替换为稀疏注意力。- **量化感知训练:** 路由 MoE 专家与注意力路径在训练阶段完成量化,降低显存占用并提升推理效率。- **DSpark 投机解码:** DSpark 取代此前的类 EAGLE MTP 方案。本次发布包含 draft head,可与兼容的 serving 实现配合使用。
## 如何使用
- [MiniMax Agent](https://agent.minimax.io/)- [MiniMax API](https://platform.minimax.io/)
### 本地部署
下载模型:
```bashhf download MiniMaxAI/MiniMax-M3.1-Flash --local-dir MiniMax-M3.1-Flash```
推荐使用以下推理框架部署模型:
- [SGLang](https://docs.sglang.io/) — 参见 [SGLang cookbook](https://docs.sglang.io/cookbook/autoregressive/MiniMax/MiniMax-M3.1)。- [vLLM](https://github.com/vllm-project/vllm) — 参见 [vLLM recipe](https://recipes.vllm.ai/MiniMaxAI/MiniMax-M3.1-Flash)。
更多集成正在推进中:Transformers、TokenSpeed、KTransformers、unsloth 和 ATOM。
## 推理设置
推荐采样设置:`temperature=1.0` 和 `top_p=0.95`。
推理时,在 chat template 中设置 `reasoning_effort`:`low`、`medium`、`high`、`xhigh` 或 `max`。
模型支持最高 100 万 tokens 的上下文窗口。可用上下文长度和吞吐量取决于 GPU 显存和 serving 配置。
## 联系我们
请联系 [model@minimax.io](mailto:model@minimax.io)。123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263{ "]!p~[": 200000, "<fim_prefix>": 200001, "<fim_middle>": 200002, "<fim_suffix>": 200003, "<fim_pad>": 200004, "<reponame>": 200005, "<filename>": 200006, "<gh_stars>": 200007, "<issue_start>": 200008, "<issue_comment>": 200009, "<issue_closed>": 200010, "<jupyter_start>": 200011, "<jupyter_text>": 200012, "<jupyter_code>": 200013, "<jupyter_output>": 200014, "<empty_output>": 200015, "<commit_before>": 200016, "<commit_msg>": 200017, "<commit_after>": 200018, "]~b]": 200019, "[e~[": 200020, "]!d~[": 200021, "<function_call>": 200022, "<code_interpreter>": 200023, "]<]speech[>[": 200024, "]<]image[>[": 200025, "]<]video[>[": 200026, "]<]start of speech[>[": 200027, "]<]end of speech[>[": 200028, "]<]start of image[>[": 200029, "]<]end of image[>[": 200030, "]<]start of video[>[": 200031, "]<]end of video[>[": 200032, "]<]vision pad[>[": 200033, "]~!b[": 200034, "<jupyter_error>": 200035, "<add_file>": 200036, "<delete_file>": 200037, "<rename_file>": 200038, "<edit_file>": 200039, "<commit_message>": 200040, "<empty_source_file>": 200041, "<repo_struct>": 200042, "<code_context>": 200043, "<file_content>": 200044, "<source_files>": 200045, "<pr_start>": 200046, "<review_comment>": 200047, "<filepath>": 200048, "<file_sep>": 200049, "<think>": 200050, "</think>": 200051, "<tool_call>": 200052, "</tool_call>": 200053, "]<]frame[>[": 200054, "]<]start of frame[>[": 200055, "]<]end of frame[>[": 200056, "<|content_altered_placeholder|>": 200057, "]<]minimax[>[": 200058, "<mm:think>": 200059, "</mm:think>": 200060}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248{# ---------- special token variables ---------- #}{%- set ns_token = ']<]minimax[>[' -%}{%- set bod_token = ']~!b[' -%}{%- set bos_token = ']~b]' -%}{%- set eos_token = '[e~[' -%}{%- set toolcall_begin_token = ns_token ~ '<tool_call>' -%}{%- set toolcall_end_token = ns_token ~ '</tool_call>' -%}{%- set think_begin_token = '<mm:think>' -%}{%- set think_end_token = '</mm:think>' -%}{%- set image_token = ']<]image[>[' -%}{%- set video_token = ']<]video[>[' -%}{#- Recursive XML renderer for tool_call arguments ======================== -#}{#- None values are intentionally skipped in mapping iteration so that `<key>null</key>` (which would round-trip to the literal string "null") never appears in the rendered tool_call. The convention is: omit the field entirely. The top-level `_args` loop applies the same rule. The `val is none` branch below is a safety net only — upstream cleaning (drop_none_in_tool_arguments) should ensure no None ever reaches here. -#}{%- macro to_xml(val, ns) -%}{%- if val is mapping -%}{%- for k, v in val.items() if v is not none -%}{{ ns }}<{{ k }}>{{ to_xml(v, ns) }}{{ ns }}</{{ k }}>{%- endfor -%}{%- elif val is iterable and val is not string -%}{%- for item in val -%}{{ ns }}<item>{{ to_xml(item, ns) }}{{ ns }}</item>{%- endfor -%}{%- elif val is none -%}{#- Should be unreachable when upstream cleaning is applied. -#}{%- elif val is boolean -%}{{ val | tojson }}{%- else -%}{{ val }}{%- endif -%}{%- endmacro -%}{#- Tool Rendering Functions ============================================== -#}{%- macro render_tool_namespace(namespace_name, tool_list) -%}{%- for tool in tool_list -%}<tool>{{ tool.function | tojson(ensure_ascii=False) }}</tool>{% endfor -%}{%- endmacro -%}{%- macro visible_text(content) -%} {%- if content is string -%} {{ content }} {%- elif content is iterable and content is not mapping -%} {%- for item in content -%} {%- if item is mapping and item.type == 'text' -%} {{- item.text }} {%- elif item is mapping and item.type == 'image' -%} {{- image_token }} {%- elif item is mapping and item.type == 'video' -%} {{- video_token }} {%- elif item is string -%} {{- item }} {%- endif -%} {%- endfor -%} {%- elif content is none -%} {{- '' }} {%- else -%} {{- content }} {%- endif -%}{%- endmacro -%}{#- System Message Construction ============================================ -#}{%- macro build_system_message(system_message) -%} {%- if system_message and system_message.content -%} {{- visible_text(system_message.content) }} {#- Handle current_date -#} {%- if system_message.current_date -%} {{- '\n' ~ 'Current date: ' + system_message.current_date }} {%- endif -%} {#- Handle current_location -#} {%- if system_message.current_location -%} {{- '\n' ~ 'Current location: ' + system_message.current_location }} {%- endif -%} {%- else -%} {{- 'Your model version is MiniMax-M3.1, developed by MiniMax. Knowledge cutoff: January 2026. Founded in early 2022, MiniMax is a global AI foundation model company committed to advancing the frontiers of AI towards AGI.' }} {%- endif -%}
{#- Thinking mode instructions -#} {{- '\n\n<thinking_instructions>\n' }} {{- 'You have a thinking capability that allows you to reason step by step before responding. When thinking is enabled, wrap your reasoning in ' ~ think_begin_token ~ think_end_token ~ ' tags before your response. When thinking is disabled, begin your response directly after the ' ~ think_end_token ~ ' prefix. When thinking is adaptive, decide on your own whether to think for the current turn.\n' }} {{- 'Current thinking mode: adaptive. You are encouraged to think for complex decision-making, multi-step reasoning, or when analyzing function/tool results.\n' }} {{- '</thinking_instructions>' }} {{- '\n\n<model_id>8bb8149fe</model_id>' }} {%- if reasoning_effort is defined and reasoning_effort is not none -%} {{- '\n\n<effort>' ~ reasoning_effort ~ '</effort>' }} {%- elif effort is defined and effort is not none -%} {{- '\n\n<effort>' ~ effort ~ '</effort>' }} {%- endif -%}{%- endmacro -%}{%- macro build_developer_message(developer_message) -%} {%- if developer_message and developer_message.content -%} {{- visible_text(developer_message.content) }} {%- else -%} {%- if model_identity is not defined -%} {%- set model_identity = "You are a helpful assistant." -%} {%- endif -%} {{- model_identity }} {%- endif -%}{%- endmacro -%}{#- Main Template Logic ================================================= -#}{#- Role mapping: root -> system sp (high priority), system/developer -> developer sp (low priority) -#}{%- set system_message = none -%}{%- set developer_message = none -%}{%- set conversation_messages = messages -%}{%- if messages and messages[0].role == "root" -%} {%- set system_message = messages[0] -%} {%- set conversation_messages = messages[1:] -%} {%- if conversation_messages and conversation_messages[0].role in ["system", "developer"] -%} {%- set developer_message = conversation_messages[0] -%} {%- set conversation_messages = conversation_messages[1:] -%} {%- endif -%}{%- elif messages and messages[0].role in ["system", "developer"] -%} {%- set developer_message = messages[0] -%} {%- set conversation_messages = messages[1:] -%}{%- endif -%}{#- Render system sp (higher priority, root role only) -#}{{- bod_token ~ bos_token ~ 'system' ~ '\n' }}{{- build_system_message(system_message) }}{{- eos_token ~ '\n' }}
{#- Render developer sp (lower priority: system/developer role + tools) -#}{{- bos_token ~ 'developer' ~ '\n' }}{{- build_developer_message(developer_message) }}{%- if tools -%} {{- '\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' }} {{- '\n' ~ '<tools>' ~ '\n' }} {{- render_tool_namespace("functions", tools) }} {{- '</tools>' ~ '\n\n' }} {{- 'To call tools, wrap all invocations in a single ' ~ toolcall_begin_token ~ toolcall_end_token ~ ' block. Parameter values containing nested objects or arrays are recursively expanded into XML elements. Example:\n' }} {{- '\n' ~ toolcall_begin_token ~ '\n' }} {{- ns_token + '<invoke name="tool-name-1">' }} {{- ns_token + '<param-1>value-1' + ns_token + '</param-1>' }} {{- ns_token + '<param-2>' }} {{- ns_token + '<item>' }} {{- ns_token + '<key-a>val-a' + ns_token + '</key-a>' }} {{- ns_token + '<key-b>val-b' + ns_token + '</key-b>' }} {{- ns_token + '</item>' }} {{- ns_token + '</param-2>' }} {{- ns_token + '</invoke>\n' }} {{- ns_token + '<invoke name="tool-name-2">' }} {{- ns_token + '<param-1>value-1' + ns_token + '</param-1>' }} {{- ns_token + '</invoke>\n' }} {{- toolcall_end_token }}{%- endif -%}{{- eos_token ~ '\n' }}
{#- Render messages -#}{%- set last_tool_call = namespace(name=none) -%}{%- for message in conversation_messages -%} {%- if message.role == 'assistant' -%} {{- bos_token ~ 'ai' ~ '\n' }}
{%- set reasoning_content = '' %} {%- set content = visible_text(message.content) %} {%- if message.reasoning_content is string %} {%- set reasoning_content = message.reasoning_content %} {%- else %} {%- if think_end_token in content %} {%- set reasoning_content = content.split(think_end_token)[0].strip('\n').split(think_begin_token)[-1].strip('\n') %} {%- set content = content.split(think_end_token)[-1].strip('\n') %} {%- endif %} {%- endif %}
{%- if reasoning_content -%} {#- Render thinking for every assistant turn (all-turn visible) -#} {{- think_begin_token ~ reasoning_content ~ think_end_token }} {%- else -%} {#- No thinking rendered → prefix with think_end_token -#} {{- think_end_token }} {%- endif -%}
{%- if content -%} {{- content }} {%- endif -%} {%- if message.tool_calls -%} {{- toolcall_begin_token ~ '\n' }}
{%- for tool_call in message.tool_calls -%} {%- if tool_call.function -%} {%- set tool_call = tool_call.function -%} {%- endif -%}{{- ns_token + '<invoke name="' + tool_call.name + '">' }}{%- set _args = tool_call.arguments -%}{%- for k, v in _args.items() if v is not none %}{{- ns_token + '<' + k + '>' -}}{{- to_xml(v, ns_token) -}}{{- ns_token + '</' + k + '>' }}{%- endfor -%}{{- ns_token + '</invoke>' ~ '\n' }} {%- endfor -%}
{{- toolcall_end_token }} {%- if message.tool_calls[-1].function -%} {%- set last_tool_call.name = message.tool_calls[-1].function.name -%} {%- else -%} {%- set last_tool_call.name = message.tool_calls[-1].name -%} {%- endif -%} {%- else -%} {%- set last_tool_call.name = none -%} {%- endif -%} {{- eos_token ~ '\n' }}
{%- elif message.role == 'tool' -%} {%- if last_tool_call.name is none -%} {{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }} {%- endif -%} {%- if loop.first or (conversation_messages[loop.index0 - 1].role != 'tool') -%} {{- bos_token ~ 'tool' }} {%- endif -%} {{- '\n<response>' }} {%- if message.content is string -%} {{- message.content }} {%- else -%} {%- for tr in message.content -%} {%- if tr is mapping and tr.type is defined and tr.type == 'image' -%} {{- image_token }} {%- elif tr is mapping and tr.type is defined and tr.type == 'video' -%} {{- video_token }} {%- else -%} {{- tr.output if tr.output is defined else (tr.text if tr.type == 'text' and tr.text is defined else tr) }} {%- endif -%} {%- endfor -%} {%- endif -%} {{- '</response>' }} {%- if loop.last or (conversation_messages[loop.index0 + 1].role != 'tool') -%} {{- eos_token ~ '\n' -}} {%- endif -%}
{%- elif message.role in ['system', 'developer'] -%} {#- Mid-conversation system/developer messages keep their position and map to the lower-priority M3 developer role. -#} {{- bos_token ~ 'developer' ~ '\n' }} {{- build_developer_message(message) }} {{- eos_token ~ '\n' }}
{%- elif message.role == 'user' -%} {{- bos_token ~ 'user' ~ '\n' }} {{- visible_text(message.content) }} {{- eos_token ~ '\n' }} {%- endif -%}{%- endfor -%}
{#- Generation prompt -#}{%- if add_generation_prompt -%}{{- bos_token ~ 'ai' ~ '\n' }}{#- adaptive: no prefix, let model decide -#}{%- endif -%}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114{ "architectures": [ "MiniMaxM3SparseForConditionalGeneration" ], "auto_map": { "AutoConfig": "configuration_minimax_m3_vl.MiniMaxM3VLConfig" }, "model_type": "minimax_m3_vl", "text_config": { "hidden_size": 6144, "intermediate_size": 3072, "num_hidden_layers": 4, "num_attention_heads": 64, "num_key_value_heads": 4, "head_dim": 128, "vocab_size": 200064, "max_position_embeddings": 1048576, "rms_norm_eps": 1e-06, "use_gemma_norm": true, "attention_output_gate": false, "rope_theta": 10000000, "rotary_dim": 64, "partial_rotary_factor": 0.5, "hidden_act": "swigluoai", "use_qk_norm": true, "tie_word_embeddings": false, "dense_intermediate_size": 12288, "shared_intermediate_size": 3072, "num_local_experts": 128, "num_experts_per_tok": 4, "n_shared_experts": 1, "scoring_func": "sigmoid", "use_routing_bias": true, "moe_layer_freq": [ 0, 0, 1, 1 ], "qk_norm_type": "per_head", "swiglu_alpha": 1.702, "swiglu_limit": 7.0, "routed_scaling_factor": 2.0, "sparse_attention_config": { "use_sparse_attention": true, "sparse_index_dim": 128, "sparse_num_index_heads": 4, "sparse_topk_blocks": 16, "sparse_block_size": 128, "sparse_score_type": "max", "sparse_init_block": 0, "sparse_local_block": 1, "sparse_attention_freq": [ 1, 1, 1, 1 ], "sparse_disable_index_value": [ 1, 1, 1, 1 ] }, "architectures": [ "MiniMaxM3SparseForCausalLM" ] }, "vision_config": { "hidden_size": 1280, "num_attention_heads": 16, "num_hidden_layers": 32, "intermediate_size": 5120, "patch_size": 14, "image_size": 672, "projection_dim": 6144, "position_embedding_type": "rope", "rope_mode": "3d", "rope_theta": 10000.0, "attention_dropout": 0.0, "hidden_act": "gelu", "initializer_factor": 1.0, "initializer_range": 0.02, "layer_norm_eps": 1e-05, "model_type": "clip_vision_model", "num_channels": 3, "vocab_size": 32000, "img_token_compression_config": { "image_token_compression_method": "patch_merge", "spatial_merge_size": 2, "temporal_patch_size": 2 }, "vision_segment_max_frames": 4 }, "img_token_compression_config": { "image_token_compression_method": "patch_merge", "spatial_merge_size": 2, "temporal_patch_size": 2 }, "image_grid_pinpoints": "[(336, 336), (336, 672), (336, 1008), (336, 1344), (336, 1680), (336, 2016), (672, 336), (672, 672), (672, 1008), (672, 1344), (672, 1680), (672, 2016), (1008, 336), (1008, 672), (1008, 1008), (1008, 1344), (1008, 1680), (1008, 2016), (1344, 336), (1344, 672), (1344, 1008), (1344, 1344), (1344, 1680), (1344, 2016), (1680, 336), (1680, 672), (1680, 1008), (1680, 1344), (1680, 1680), (1680, 2016), (2016, 336), (2016, 672), (2016, 1008), (2016, 1344), (2016, 1680), (2016, 2016)]", "image_seq_length": 576, "image_token_index": 200025, "video_token_index": 200026, "multimodal_projector_bias": true, "num_reward_heads": 0, "process_image_mode": "dynamic_res", "projector_hidden_act": "gelu", "vision_feature_layer": -1, "vision_feature_select_strategy": "full", "torch_dtype": "bfloat16", "transformers_version": "4.52.4", "projector_hidden_size": 6144}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111"""HuggingFace configs for the MiniMax VL family (M2 VL / M3 VL).
This file is bundled into every converted HF checkpoint so that loading via``AutoConfig.from_pretrained(..., trust_remote_code=True)`` works without anyruntime dependency on sglang or other internal packages — only stock``transformers`` is required.
The class definitions intentionally mirror``sglang.srt.configs.minimax_vl``; if either side changes, keep them in sync.
The file is named ``configuration_minimax_m3_vl.py`` (matching the legacy``model_type="minimax_m3_vl"`` and the converter's ``auto_map`` entry) sothat ckpts produced by this converter remain loadable by older sglang versionsthat only know the ``MiniMaxM3VL*`` names. The canonical class is``MiniMaxM3VLConfig``; ``MiniMaxM3VLConfig`` is a thin BC alias whose onlypurpose is to be referenced from ``auto_map``."""
from typing import Optional
from transformers.configuration_utils import PretrainedConfigfrom transformers.models.auto import CONFIG_MAPPING
def _coerce_sub_config( sub_config: Optional[dict], default_model_type: str) -> Optional[PretrainedConfig]: """Convert a config dict to a ``PretrainedConfig`` instance.
If ``model_type`` is registered in HF ``CONFIG_MAPPING`` the corresponding config class is used; otherwise we fall back to a generic ``PretrainedConfig`` so all dict keys still become real attributes (M3's text backbone uses ``model_type="minimax_m2"`` which is not in ``CONFIG_MAPPING``). """ if not isinstance(sub_config, dict): return sub_config model_type = sub_config.get("model_type", default_model_type) cls = CONFIG_MAPPING.get(model_type, PretrainedConfig) return cls(**sub_config)
class MiniMaxVLBaseConfig(PretrainedConfig): """Base config shared by every MiniMax VL variant.
Handles vision/text sub-config coercion. Concrete subclasses only need to declare a unique ``model_type`` string. """
def __init__( self, vision_config: Optional[dict] = None, text_config: Optional[dict] = None, image_token_index: int = 200025, video_token_index: int = 200026, image_seq_length: int = 576, process_image_mode: str = "dynamic_res", projector_hidden_act: str = "gelu", multimodal_projector_bias: bool = True, vision_feature_layer: int = -1, vision_feature_select_strategy: str = "full", img_token_compression_config: Optional[dict] = None, image_grid_pinpoints: Optional[str] = None, **kwargs, ): self.vision_config = _coerce_sub_config(vision_config, "clip_vision_model") self.text_config = _coerce_sub_config(text_config, "mixtral")
self.image_token_index = image_token_index self.video_token_index = video_token_index self.image_seq_length = image_seq_length self.process_image_mode = process_image_mode self.projector_hidden_act = projector_hidden_act self.multimodal_projector_bias = multimodal_projector_bias self.vision_feature_layer = vision_feature_layer self.vision_feature_select_strategy = vision_feature_select_strategy self.img_token_compression_config = img_token_compression_config or {} self.image_grid_pinpoints = image_grid_pinpoints
super().__init__(**kwargs)
def __post_init__(self, **kwargs): super().__post_init__(**kwargs) if hasattr(self, "vision_config"): self.vision_config = _coerce_sub_config(self.vision_config, "clip_vision_model") if hasattr(self, "text_config"): self.text_config = _coerce_sub_config(self.text_config, "mixtral")
class MiniMaxM2VLConfig(MiniMaxVLBaseConfig): """MiniMax M2 VL: vision tower + M2 (Mixtral-style MoE) text backbone."""
model_type = "minimax_m2_vl"
class MiniMaxM3VLConfig(MiniMaxVLBaseConfig): """MiniMax M3 VL: vision tower + M3 (mixed sparse/dense MoE) text backbone."""
model_type = "minimax_m3_vl"
class MiniMaxM2MiniVLConfig(MiniMaxM2VLConfig): """Legacy alias kept so old ``model_type="minimax_m2_mini_vl"`` ckpts load."""
model_type = "minimax_m2_mini_vl"
class MiniMaxM3VLConfig(MiniMaxM3VLConfig): """Legacy alias kept so old ``model_type="minimax_m3_vl"`` ckpts load."""
model_type = "minimax_m3_vl"12345678{ "bos_token_id": 200019, "do_sample": true, "eos_token_id": 200020, "temperature": 1.0, "top_p": 0.95, "transformers_version": "4.46.1"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223# Copyright 2023-2024 SGLang Team# Licensed under the Apache License, Version 2.0 (the "License");"""MiniMax VL family HuggingFace-compatible Processor, ImageProcessor, VideoProcessor."""import mathfrom typing import List, Tuple
import torchfrom torchvision.transforms import InterpolationModefrom transformers import BatchFeaturefrom transformers.image_processing_utils_fast import ( BaseImageProcessorFast, group_images_by_shape, reorder_images,)from transformers.image_utils import PILImageResampling, SizeDictfrom transformers.processing_utils import ( ImagesKwargs, Unpack,)from transformers.utils import TensorType
MAX_RATIO = 200
def round_by_factor(number: int, factor: int) -> int: return round(number / factor) * factor
def ceil_by_factor(number: int, factor: int) -> int: return math.ceil(number / factor) * factor
def floor_by_factor(number: int, factor: int) -> int: return math.floor(number / factor) * factor
def smart_resize( height: int, width: int, factor: int = 28, min_pixels: int = 4 * 28 * 28, max_pixels: int = 451584,) -> tuple[int, int]: if max(height, width) / min(height, width) > MAX_RATIO: raise ValueError( f"absolute aspect ratio must be smaller than {MAX_RATIO}, " f"got {max(height, width) / min(height, width)}" ) h_bar = max(factor, round_by_factor(height, factor)) w_bar = max(factor, round_by_factor(width, factor)) if h_bar * w_bar > max_pixels: beta = math.sqrt((height * width) / max_pixels) h_bar = floor_by_factor(height / beta, factor) w_bar = floor_by_factor(width / beta, factor) elif h_bar * w_bar < min_pixels: beta = math.sqrt(min_pixels / (height * width)) h_bar = ceil_by_factor(height * beta, factor) w_bar = ceil_by_factor(width * beta, factor) return h_bar, w_bar
# ==============================================================================# MiniMax M3 VL Image Processor Fast (Fast Mode - Torch based)# ==============================================================================
class MiniMaxM3VLImageProcessorKwargs(ImagesKwargs, total=False): patch_size: int temporal_patch_size: int merge_size: int max_pixels: int
class MiniMaxM3VLImageProcessor(BaseImageProcessorFast): do_resize = True resample = PILImageResampling.BICUBIC size = {"height": 672, "width": 672} # required by base class validation, not used as resize bound default_to_square = False do_rescale = True rescale_factor = 1 / 255 do_normalize = True image_mean = [0.48145466, 0.4578275, 0.40821073] image_std = [0.26862954, 0.26130258, 0.27577711] do_convert_rgb = True patch_size = 14 temporal_patch_size = 2 merge_size = 2 max_pixels = 451584 # 672*672 valid_kwargs = MiniMaxM3VLImageProcessorKwargs model_input_names = ["pixel_values", "image_grid_thw"]
def __init__(self, **kwargs: Unpack[MiniMaxM3VLImageProcessorKwargs]): super().__init__(**kwargs)
def preprocess( self, images, **kwargs: Unpack[MiniMaxM3VLImageProcessorKwargs] ) -> BatchFeature: return super().preprocess(images, **kwargs)
def _preprocess( self, images: List[torch.Tensor], do_resize: bool, size: SizeDict, resample: PILImageResampling | InterpolationMode | int | None, do_rescale: bool, rescale_factor: float, do_normalize: bool, image_mean: float | List[float] | None, image_std: float | List[float] | None, patch_size: int, temporal_patch_size: int, merge_size: int, max_pixels: int, disable_grouping: bool | None, return_tensors: str | TensorType | None, **kwargs, ) -> BatchFeature: grouped_images, grouped_images_index = group_images_by_shape( images, disable_grouping=disable_grouping ) resized_images_grouped = {} factor = patch_size * merge_size for shape, stacked_images in grouped_images.items(): height, width = stacked_images.shape[-2:] if do_resize: resized_height, resized_width = smart_resize( height, width, factor=factor, max_pixels=max_pixels, ) stacked_images = self.resize( stacked_images, size=SizeDict(height=resized_height, width=resized_width), resample=resample, ) resized_images_grouped[shape] = stacked_images
resized_images = reorder_images(resized_images_grouped, grouped_images_index)
grouped_images, grouped_images_index = group_images_by_shape( resized_images, disable_grouping=disable_grouping ) processed_images_grouped = {} processed_grids = {}
for shape, stacked_images in grouped_images.items(): resized_height, resized_width = stacked_images.shape[-2:]
patches = self.rescale_and_normalize( stacked_images, do_rescale, rescale_factor, do_normalize, image_mean, image_std, ) if patches.ndim == 4: patches = patches.unsqueeze(1)
if patches.shape[1] % temporal_patch_size != 0: repeats = patches[:, -1:].repeat( 1, temporal_patch_size - (patches.shape[1] % temporal_patch_size), 1, 1, 1, ) patches = torch.cat([patches, repeats], dim=1)
batch_size, grid_t, channel = patches.shape[:3] grid_t = grid_t // temporal_patch_size grid_h, grid_w = resized_height // patch_size, resized_width // patch_size
patches = patches.view( batch_size, grid_t, temporal_patch_size, channel, grid_h // merge_size, merge_size, patch_size, grid_w // merge_size, merge_size, patch_size, ) patches = patches.permute(0, 1, 4, 7, 5, 8, 3, 2, 6, 9)
flatten_patches = patches.reshape( batch_size, grid_t * grid_h * grid_w, channel * temporal_patch_size * patch_size * patch_size, )
processed_images_grouped[shape] = flatten_patches processed_grids[shape] = [[grid_t, grid_h, grid_w]] * batch_size
processed_images = reorder_images( processed_images_grouped, grouped_images_index ) processed_grids = reorder_images(processed_grids, grouped_images_index)
pixel_values = torch.cat(processed_images, dim=0) image_grid_thw = torch.tensor(processed_grids, dtype=torch.long)
return BatchFeature( data={"pixel_values": pixel_values, "image_grid_thw": image_grid_thw}, tensor_type=return_tensors, )
def get_number_of_image_patches(self, height: int, width: int, images_kwargs=None): images_kwargs = images_kwargs or {} patch_size = images_kwargs.get("patch_size", self.patch_size) merge_size = images_kwargs.get("merge_size", self.merge_size) max_pixels = images_kwargs.get("max_pixels", self.max_pixels)
resized_height, resized_width = smart_resize( height, width, factor=patch_size * merge_size, max_pixels=max_pixels, ) grid_h, grid_w = resized_height // patch_size, resized_width // patch_size return grid_h * grid_w123version https://git-lfs.github.com/spec/v1oid sha256:4a2fba7be1b0b28870cae3316941c1c039ae00c9f9abfe27458b0800395d9831size 5369783160123version https://git-lfs.github.com/spec/v1oid sha256:3fa43bbb54d16d06e42c4d24dce5df84dbadbd307556c0b47153d0141b3cd304size 5388692432123version https://git-lfs.github.com/spec/v1oid sha256:b6cff4ceea248f3bc03acb9be1b4165decf467de91beb061e07722899b732622size 5398090088123version https://git-lfs.github.com/spec/v1oid sha256:877194fdeeb036798ad9d06c952cc55e5c36303725c74478a92fc15c16450fc9size 5396544336123version https://git-lfs.github.com/spec/v1oid sha256:b5e1cad3248815d9f7d7ae945e93d45efc2c8449c5c756c63b1cbb87dc751224size 5398090184123version https://git-lfs.github.com/spec/v1oid sha256:328c4c15df290aeaf00fe02c3f0a8c691caa965782d4ae1ba953f9eb640da910size 5398090088123version https://git-lfs.github.com/spec/v1oid sha256:442d1a2d4dd61060beed19b8c002c5c8ea8acd6d3a4c08b33a1b77fe0ca6cd94size 53188144481234567891011121314151617181920212223242526272829303132{ "processor_class": "MiniMaxVLProcessor", "auto_map": { "AutoImageProcessor": "image_processor.MiniMaxM3VLImageProcessor", "AutoProcessor": "processing_minimax.MiniMaxVLProcessor", "AutoVideoProcessor": "video_processor.MiniMaxM3VLVideoProcessor" }, "process_image_mode": "dynamic_res", "image_mean": [ 0.48145466, 0.4578275, 0.40821073 ], "image_std": [ 0.26862954, 0.26130258, 0.27577711 ], "size": [ 672, 672 ], "patch_size": 14, "img_token_compression_config": { "image_token_compression_threshold": 1.1, "image_token_compression_method": "patch_merge", "max_image_resolution": 1008, "spatial_merge_size": 2, "temporal_patch_size": 2 }, "add_start_end_special_tokens": true}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254# Copyright 2023-2024 SGLang Team# Licensed under the Apache License, Version 2.0 (the "License");"""MiniMax VL family HuggingFace-compatible Processor, ImageProcessor, VideoProcessor."""
import mathimport refrom typing import List, Optional, Tuple, Union
import torchimport torchvisionfrom torchvision.transforms import InterpolationModefrom transformers import BatchFeaturefrom transformers.image_processing_utils_fast import ( BaseImageProcessorFast, group_images_by_shape, reorder_images,)from transformers.image_utils import PILImageResampling, SizeDictfrom transformers.processing_utils import ( ImagesKwargs, ProcessingKwargs, ProcessorMixin, Unpack, VideosKwargs,)from transformers.utils import TensorTypefrom transformers.video_processing_utils import BaseVideoProcessorfrom transformers.video_utils import group_videos_by_shape, reorder_videos
class MiniMaxVLProcessorKwargs(ProcessingKwargs, total=False): _defaults = { "videos_kwargs": { "do_resize": False, "return_metadata": True, }, }
class MiniMaxVLProcessor(ProcessorMixin): IMAGE_TOKEN = "]<]image[>[" VIDEO_TOKEN = "]<]video[>[" VISION_START_TOKEN = "]<]start of image[>[" VISION_END_TOKEN = "]<]end of image[>["
def __init__( self, image_processor=None, tokenizer=None, video_processor=None, **kwargs ): self.image_token_id = tokenizer.convert_tokens_to_ids(self.IMAGE_TOKEN) self.video_token_id = tokenizer.convert_tokens_to_ids(self.VIDEO_TOKEN) super().__init__(image_processor, tokenizer, video_processor) # Video expansion also uses image start/end tokens. Separate video # start/end tokens exist in the tokenizer, but the original MiniMax # serving path did not use them; keep that behavior for compatibility. self.vision_start_token_id = tokenizer.convert_tokens_to_ids( self.VISION_START_TOKEN ) self.vision_end_token_id = tokenizer.convert_tokens_to_ids( self.VISION_END_TOKEN )
def _prune_video_tokens( self, input_text: str, video_segments: List[int], video_token: str, ) -> str: """ Prune video tokens by temporal_patch_size (e.g., 2:1).
Expects the prompt to carry exactly sum(video_segments) video tokens — i.e. one token per *sampled* frame. Then drops token.
Args: input_text: prompt with N video_tokens per segment video_segments: actual sampled frame count per video segment video_token: the video token string, e.g. ']<]video[>['
Returns: Pruned input_text with ~N/temporal_patch_size tokens per segment. """ # If no videos or temporal_patch_size <= 1, no pruning needed if not video_segments or self.video_processor.temporal_patch_size <= 1: return input_text
# Split while keeping delimiters special_tokens = [video_token] # , image_token] pattern = "|".join(map(re.escape, special_tokens)) parts = re.split(f"({pattern})", input_text)
def is_timestamp(text: str) -> bool: """Check if text ends with timestamp format like ']<]0.0 seconds[>['""" return ( text.endswith("seconds[>[") or text.endswith("seconds[>[ ") or text.endswith("seconds [>[") or text.endswith("seconds [>[ ") )
def extract_timestamp(text: str) -> str: """Extract timestamp text from the end, starting from ']<]'""" start_index = text.rfind("]<]") if start_index == -1: raise ValueError(f"Failed to extract timestamp: {text}") return text[start_index:]
# Build new text with pruned video tokens final_parts = [] current_seg_idx = 0 # Which video segment we're in frame_in_seg = 0 # Frame index within current segment last_timestamp_len = 0 # Length of timestamp to potentially remove
for part in parts: if part == video_token: if current_seg_idx < len(video_segments): if frame_in_seg % self.video_processor.temporal_patch_size == 0: # Keep this video token final_parts.append(part) frame_in_seg += 1 if frame_in_seg >= video_segments[current_seg_idx]: current_seg_idx += 1 frame_in_seg = 0 last_timestamp_len = 0 else: # Skip this video token frame_in_seg += 1 if frame_in_seg >= video_segments[current_seg_idx]: current_seg_idx += 1 frame_in_seg = 0 # Remove the timestamp that was already appended if last_timestamp_len > 0: # Truncate the last part to remove timestamp assert len(final_parts) > 0 final_parts[-1] = final_parts[-1][:-last_timestamp_len] last_timestamp_len = 0 else: # No more video segments, keep as is final_parts.append(part) last_timestamp_len = 0 else: # Text part final_parts.append(part) # Check if this text ends with a timestamp if is_timestamp(part): last_timestamp_len = len(extract_timestamp(part)) else: last_timestamp_len = 0
return "".join(final_parts)
def __call__( self, images=None, text=None, videos=None, **kwargs: Unpack[MiniMaxVLProcessorKwargs], ) -> BatchFeature: output_kwargs = self._merge_kwargs( MiniMaxVLProcessorKwargs, tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs, )
if images is not None: images_kwargs = output_kwargs["images_kwargs"] image_inputs = self.image_processor(images=images, **images_kwargs) image_grid_thw = image_inputs["image_grid_thw"]
else: image_inputs = {} image_grid_thw = None
if videos is not None: videos_kwargs = output_kwargs["videos_kwargs"] video_inputs = self.video_processor(videos=videos, **videos_kwargs) video_grid_thw = video_inputs["video_grid_thw"] if not kwargs.get("return_metadata"): video_metadata = video_inputs.pop("video_metadata") else: video_metadata = video_inputs["video_metadata"] else: video_inputs = {} video_grid_thw = None
if not isinstance(text, list): text = [text] text = text.copy()
# Expand image tokens if image_grid_thw is not None: merge_length = self.image_processor.merge_size**2 placeholder = "]<]placeholder[>[" index = 0 for i in range(len(text)): while self.IMAGE_TOKEN in text[i]: num_tokens = image_grid_thw[index].prod() // merge_length text[i] = text[i].replace( self.IMAGE_TOKEN, self.VISION_START_TOKEN + placeholder * num_tokens + self.VISION_END_TOKEN, 1, ) index += 1 text[i] = text[i].replace(placeholder, self.IMAGE_TOKEN)
# Expand video tokens if video_grid_thw is not None: merge_length = self.image_processor.merge_size**2 placeholder = "]<]placeholder[>[" index = 0 for i in range(len(text)): while self.VIDEO_TOKEN in text[i]: metadata = video_metadata[index] grid_t = video_grid_thw[index][0] frame_seqlen = video_grid_thw[index][1:].prod() // merge_length
video_placeholder = "" for frame_idx in range(grid_t): if ( metadata.fps is not None and metadata.frames_indices is not None ): ts = ( metadata.frames_indices[ min( frame_idx * self.video_processor.temporal_patch_size, len(metadata.frames_indices) - 1, ) ] / metadata.fps ) video_placeholder += f"]<]{ts:.1f} seconds[>[" video_placeholder += ( self.VISION_START_TOKEN + placeholder * frame_seqlen + self.VISION_END_TOKEN )
text[i] = text[i].replace(self.VIDEO_TOKEN, video_placeholder, 1) index += 1 text[i] = text[i].replace(placeholder, self.VIDEO_TOKEN)
# Tokenize return_tensors = output_kwargs["text_kwargs"].pop("return_tensors", None) text_inputs = self.tokenizer(text, **output_kwargs["text_kwargs"])
return BatchFeature( data={**text_inputs, **image_inputs, **video_inputs}, tensor_type=return_tensors, )12345678910111213141516{ "bos_token": { "content": "]~b]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "eos_token": { "content": "[e~[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501{ "add_prefix_space": false, "added_tokens_decoder": { "200000": { "content": "]!p~[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200001": { "content": "<fim_prefix>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200002": { "content": "<fim_middle>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200003": { "content": "<fim_suffix>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200004": { "content": "<fim_pad>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200005": { "content": "<reponame>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200006": { "content": "<filename>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200007": { "content": "<gh_stars>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200008": { "content": "<issue_start>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200009": { "content": "<issue_comment>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200010": { "content": "<issue_closed>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200011": { "content": "<jupyter_start>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200012": { "content": "<jupyter_text>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200013": { "content": "<jupyter_code>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200014": { "content": "<jupyter_output>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200015": { "content": "<empty_output>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200016": { "content": "<commit_before>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200017": { "content": "<commit_msg>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200018": { "content": "<commit_after>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200019": { "content": "]~b]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200020": { "content": "[e~[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200021": { "content": "]!d~[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200022": { "content": "<function_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200023": { "content": "<code_interpreter>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200024": { "content": "]<]speech[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200025": { "content": "]<]image[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200026": { "content": "]<]video[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200027": { "content": "]<]start of speech[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200028": { "content": "]<]end of speech[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200029": { "content": "]<]start of image[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200030": { "content": "]<]end of image[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200031": { "content": "]<]start of video[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200032": { "content": "]<]end of video[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200033": { "content": "]<]vision pad[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200034": { "content": "]~!b[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200035": { "content": "<jupyter_error>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200036": { "content": "<add_file>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200037": { "content": "<delete_file>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200038": { "content": "<rename_file>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200039": { "content": "<edit_file>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200040": { "content": "<commit_message>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200041": { "content": "<empty_source_file>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200042": { "content": "<repo_struct>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200043": { "content": "<code_context>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200044": { "content": "<file_content>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200045": { "content": "<source_files>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200046": { "content": "<pr_start>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200047": { "content": "<review_comment>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200048": { "content": "<filepath>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200049": { "content": "<file_sep>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200050": { "content": "<think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "200051": { "content": "</think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "200052": { "content": "<tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "200053": { "content": "</tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "200054": { "content": "]<]frame[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200055": { "content": "]<]start of frame[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200056": { "content": "]<]end of frame[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200057": { "content": "<|content_altered_placeholder|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "200058": { "content": "]<]minimax[>[", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "200059": { "content": "<mm:think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "200060": { "content": "</mm:think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false } }, "bos_token": "]~b]", "clean_up_tokenization_spaces": false, "eos_token": "[e~[", "pad_token": "]!p~[", "model_max_length": 40960000, "tokenizer_class": "PreTrainedTokenizerFast", "unk_token": "[e~["}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208# Copyright 2023-2024 SGLang Team# Licensed under the Apache License, Version 2.0 (the "License");"""MiniMax VL family HuggingFace-compatible VideoProcessor."""
import mathfrom typing import List, Optional, Tuple, Union
import torchimport torchvisionfrom torchvision.transforms import InterpolationModefrom transformers import BatchFeaturefrom transformers.image_utils import PILImageResampling, SizeDictfrom transformers.processing_utils import ( Unpack, VideosKwargs,)from transformers.utils import TensorTypefrom transformers.video_processing_utils import BaseVideoProcessorfrom transformers.video_utils import group_videos_by_shape, reorder_videos
MAX_RATIO = 200
def round_by_factor(number: int, factor: int) -> int: return round(number / factor) * factor
def ceil_by_factor(number: int, factor: int) -> int: return math.ceil(number / factor) * factor
def floor_by_factor(number: int, factor: int) -> int: return math.floor(number / factor) * factor
def smart_resize( height: int, width: int, factor: int = 28, min_pixels: int = 4 * 28 * 28, max_pixels: int = 451584,) -> tuple[int, int]: if max(height, width) / min(height, width) > MAX_RATIO: raise ValueError( f"absolute aspect ratio must be smaller than {MAX_RATIO}, " f"got {max(height, width) / min(height, width)}" ) h_bar = max(factor, round_by_factor(height, factor)) w_bar = max(factor, round_by_factor(width, factor)) if h_bar * w_bar > max_pixels: beta = math.sqrt((height * width) / max_pixels) h_bar = floor_by_factor(height / beta, factor) w_bar = floor_by_factor(width / beta, factor) elif h_bar * w_bar < min_pixels: beta = math.sqrt(min_pixels / (height * width)) h_bar = ceil_by_factor(height * beta, factor) w_bar = ceil_by_factor(width * beta, factor) return h_bar, w_bar
class MiniMaxM3VLVideoProcessorKwargs(VideosKwargs, total=False): patch_size: int temporal_patch_size: int merge_size: int min_pixels: int max_pixels: int total_pixels: int min_frames: int max_frames: int fps: float | int
class MiniMaxM3VLVideoProcessor(BaseVideoProcessor): do_resize = True resample = PILImageResampling.BICUBIC size = {"height": 672, "width": 672} default_to_square = False do_rescale = True rescale_factor = 1 / 255 do_normalize = True image_mean = [0.48145466, 0.4578275, 0.40821073] image_std = [0.26862954, 0.26130258, 0.27577711] do_convert_rgb = True do_sample_frames = False patch_size = 14 temporal_patch_size = 2 merge_size = 2 min_pixels = 4 * 28 * 28 max_pixels = 768 * 28 * 28 # 602,112 total_pixels = int(64000 * 28 * 28 * 0.9) # ~45M, ~64k tokens budget fps = 1.0 min_frames = 4 max_frames = 768 valid_kwargs = MiniMaxM3VLVideoProcessorKwargs model_input_names = ["pixel_values_videos", "video_grid_thw"]
def __init__(self, **kwargs: Unpack[MiniMaxM3VLVideoProcessorKwargs]): super().__init__(**kwargs)
def _preprocess( self, videos: List[torch.Tensor], do_convert_rgb: bool, do_resize: bool, size: SizeDict, resample: PILImageResampling | InterpolationMode | int | None, do_rescale: bool, rescale_factor: float, do_normalize: bool, image_mean: float | List[float] | None, image_std: float | List[float] | None, patch_size: int, temporal_patch_size: int, merge_size: int, min_pixels: int, max_pixels: int, return_tensors: str | TensorType | None = None, **kwargs, ) -> BatchFeature: grouped_videos, grouped_videos_index = group_videos_by_shape(videos) resized_videos_grouped = {} factor = patch_size * merge_size for shape, stacked_videos in grouped_videos.items(): batch_size, num_frames, channels, height, width = stacked_videos.shape resized_height, resized_width = height, width if do_resize: resized_height, resized_width = smart_resize( height, width, factor=factor, min_pixels=min_pixels, max_pixels=max_pixels, ) stacked_videos = stacked_videos.view( batch_size * num_frames, channels, height, width ) stacked_videos = self.resize( stacked_videos, size=SizeDict(height=resized_height, width=resized_width), resample=resample, ) stacked_videos = stacked_videos.view( batch_size, num_frames, channels, resized_height, resized_width, ) resized_videos_grouped[shape] = stacked_videos resized_videos = reorder_videos(resized_videos_grouped, grouped_videos_index)
grouped_videos, grouped_videos_index = group_videos_by_shape(resized_videos) processed_videos_grouped = {} processed_grids = {} for shape, stacked_videos in grouped_videos.items(): resized_height, resized_width = stacked_videos.shape[-2:] patches = self.rescale_and_normalize( stacked_videos, do_rescale, rescale_factor, do_normalize, image_mean, image_std, )
if pad := -patches.shape[1] % temporal_patch_size: repeats = patches[:, -1:].expand(-1, pad, -1, -1, -1) patches = torch.cat([patches, repeats], dim=1)
batch_size, grid_t, channels = patches.shape[:3] grid_t = grid_t // temporal_patch_size grid_h, grid_w = resized_height // patch_size, resized_width // patch_size
patches = patches.view( batch_size, grid_t, temporal_patch_size, channels, grid_h // merge_size, merge_size, patch_size, grid_w // merge_size, merge_size, patch_size, ) patches = patches.permute(0, 1, 4, 7, 5, 8, 3, 2, 6, 9) flatten_patches = patches.reshape( batch_size, grid_t * grid_h * grid_w, channels * temporal_patch_size * patch_size * patch_size, )
processed_videos_grouped[shape] = flatten_patches processed_grids[shape] = [[grid_t, grid_h, grid_w]] * batch_size
processed_videos = reorder_videos( processed_videos_grouped, grouped_videos_index ) processed_grids = reorder_videos(processed_grids, grouped_videos_index) pixel_values_videos = torch.cat(processed_videos, dim=0) video_grid_thw = torch.tensor(processed_grids, dtype=torch.long)
return BatchFeature( data={ "pixel_values_videos": pixel_values_videos, "video_grid_thw": video_grid_thw, }, tensor_type=return_tensors, ).gitattributes+1
LICENSEAdded+17
README.mdAdded+289
README_zh.mdAdded+287
added_tokens.jsonAdded+63
chat_template.jinjaAdded+248
config.jsonAdded+114
configuration_minimax_m3_vl.pyAdded+111
generation_config.jsonAdded+8
image_processor.pyAdded+223
merges.txtAdded
model-00001.safetensorsAdded+3
model-00002.safetensorsAdded+3
model-00003.safetensorsAdded+3
model-00004.safetensorsAdded+3
model-00005.safetensorsAdded+3
model-00006.safetensorsAdded+3
model-00007.safetensorsAdded+3
model.safetensors.index.jsonAdded
preprocessor_config.jsonAdded+32
processing_minimax.pyAdded+254
special_tokens_map.jsonAdded+16
tokenizer.jsonAdded
tokenizer_config.jsonAdded+501
video_processor.pyAdded+208
vocab.jsonAdded