Instructions to use MiniMaxAI/MiniMax-M2.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MiniMaxAI/MiniMax-M2.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="MiniMaxAI/MiniMax-M2.1", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("MiniMaxAI/MiniMax-M2.1", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("MiniMaxAI/MiniMax-M2.1", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use MiniMaxAI/MiniMax-M2.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MiniMaxAI/MiniMax-M2.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MiniMaxAI/MiniMax-M2.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/MiniMaxAI/MiniMax-M2.1
- SGLang
How to use MiniMaxAI/MiniMax-M2.1 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 "MiniMaxAI/MiniMax-M2.1" \ --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": "MiniMaxAI/MiniMax-M2.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "MiniMaxAI/MiniMax-M2.1" \ --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": "MiniMaxAI/MiniMax-M2.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use MiniMaxAI/MiniMax-M2.1 with Docker Model Runner:
docker model run hf.co/MiniMaxAI/MiniMax-M2.1
add mlx
#8
by rogeryoungh - opened
- README.md +1 -0
- docs/mlx_deploy_guide.md +70 -0
README.md
CHANGED
|
@@ -171,6 +171,7 @@ We recommend using [Transformers](https://github.com/huggingface/transformers) t
|
|
| 171 |
|
| 172 |
### Other Inference Engines
|
| 173 |
|
|
|
|
| 174 |
- [KTransformers](https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/kt-kernel/MiniMax-M2.1-Tutorial.md)
|
| 175 |
|
| 176 |
### Inference Parameters
|
|
|
|
| 171 |
|
| 172 |
### Other Inference Engines
|
| 173 |
|
| 174 |
+
- [MLX-LM](./docs/mlx_deploy_guide.md)
|
| 175 |
- [KTransformers](https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/kt-kernel/MiniMax-M2.1-Tutorial.md)
|
| 176 |
|
| 177 |
### Inference Parameters
|
docs/mlx_deploy_guide.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## MLX deployment guide
|
| 2 |
+
|
| 3 |
+
Run, serve, and fine-tune [**MiniMax-M2.1**](https://huggingface.co/MiniMaxAI/MiniMax-M2.1) locally on your Mac using the **MLX** framework. This guide gets you up and running quickly.
|
| 4 |
+
|
| 5 |
+
> **Requirements**
|
| 6 |
+
> - Apple Silicon Mac (M3 Ultra or later)
|
| 7 |
+
> - **At least 256GB of unified memory (RAM)**
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
**Installation**
|
| 11 |
+
|
| 12 |
+
Install the `mlx-lm` package via pip:
|
| 13 |
+
|
| 14 |
+
```bash
|
| 15 |
+
pip install -U mlx-lm
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
**CLI**
|
| 19 |
+
|
| 20 |
+
Generate text directly from the terminal:
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
mlx_lm.generate \
|
| 24 |
+
--model mlx-community/MiniMax-M2.1-4bit \
|
| 25 |
+
--prompt "How tall is Mount Everest?"
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
> Add `--max-tokens 256` to control response length, or `--temp 0.7` for creativity.
|
| 29 |
+
|
| 30 |
+
**Python Script Example**
|
| 31 |
+
|
| 32 |
+
Use `mlx-lm` in your own Python scripts:
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
from mlx_lm import load, generate
|
| 36 |
+
|
| 37 |
+
# Load the quantized model
|
| 38 |
+
model, tokenizer = load("mlx-community/MiniMax-M2.1-4bit")
|
| 39 |
+
|
| 40 |
+
prompt = "Hello, how are you?"
|
| 41 |
+
|
| 42 |
+
# Apply chat template if available (recommended for chat models)
|
| 43 |
+
if tokenizer.chat_template is not None:
|
| 44 |
+
messages = [{"role": "user", "content": prompt}]
|
| 45 |
+
prompt = tokenizer.apply_chat_template(
|
| 46 |
+
messages,
|
| 47 |
+
tokenize=False,
|
| 48 |
+
add_generation_prompt=True
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Generate response
|
| 52 |
+
response = generate(
|
| 53 |
+
model,
|
| 54 |
+
tokenizer,
|
| 55 |
+
prompt=prompt,
|
| 56 |
+
max_tokens=256,
|
| 57 |
+
temp=0.7,
|
| 58 |
+
verbose=True
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
print(response)
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
**Tips**
|
| 65 |
+
- **Model variants**: Check this [MLX community collection on Hugging Face](https://huggingface.co/collections/mlx-community/minimax-m2.1) for `MiniMax-M2.1-4bit`, `6bit`, `8bit`, or `bfloat16` versions.
|
| 66 |
+
- **Fine-tuning**: Use `mlx-lm.lora` for efficient parameter-efficient fine-tuning (PEFT).
|
| 67 |
+
|
| 68 |
+
**Resources**
|
| 69 |
+
- GitHub: [https://github.com/ml-explore/mlx-lm](https://github.com/ml-explore/mlx-lm)
|
| 70 |
+
- Models: [https://huggingface.co/mlx-community](https://huggingface.co/mlx-community)
|