Skip to content

Commit 7ea38e0

Browse files
Merge pull request #307 from stochasticai/marcos/minimax_m2
Marcos/minimax m2
2 parents 5c23ae8 + 79b2292 commit 7ea38e0

File tree

12 files changed

+521
-0
lines changed

12 files changed

+521
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Below is a list of all the supported models via `BaseModel` class of `xTuring` a
268268
|GPT-2 | gpt2|
269269
|LLaMA | llama|
270270
|LLaMA2 | llama2|
271+
|MiniMaxM2 | minimax_m2|
271272
|OPT-1.3B | opt|
272273

273274
The above are the base variants. Use these templates for `LoRA`, `INT8`, and `INT8 + LoRA` versions:

docs/docs/overview/supported_models.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ description: Models Supported by xTuring
1717
| GPT-2 | gpt2 |||||
1818
| LLaMA 7B | llama |||||
1919
| LLaMA2 | llama2 |||||
20+
| MiniMaxM2 | minimax_m2 |||||
2021
| Qwen3 0.6B | qwen3_0_6b |||||
2122
| OPT 1.3B | opt |||||
2223

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# MiniMaxM2 Model Examples
2+
3+
This directory contains examples for using the MiniMaxM2 model from HuggingFace with xTuring.
4+
5+
## Model Information
6+
7+
- **Model**: MiniMaxAI/MiniMax-M2
8+
- **Source**: [HuggingFace Model Hub](https://huggingface.co/MiniMaxAI/MiniMax-M2)
9+
10+
## Available Variants
11+
12+
The MiniMaxM2 model is available in multiple configurations:
13+
14+
1. **minimax_m2** - Base model
15+
2. **minimax_m2_lora** - LoRA fine-tuning enabled
16+
3. **minimax_m2_int8** - 8-bit quantized version
17+
4. **minimax_m2_lora_int8** - LoRA with 8-bit quantization
18+
5. **minimax_m2_lora_kbit** - LoRA with 4-bit quantization
19+
20+
## Usage Examples
21+
22+
### Basic Inference
23+
24+
```python
25+
from xturing.models import BaseModel
26+
27+
# Create the model
28+
model = BaseModel.create("minimax_m2")
29+
30+
# Generate text
31+
output = model.generate(texts=["What is machine learning?"])
32+
print(output)
33+
```
34+
35+
### Fine-tuning with LoRA
36+
37+
```python
38+
from xturing.datasets.instruction_dataset import InstructionDataset
39+
from xturing.models import BaseModel
40+
41+
# Load dataset
42+
dataset = InstructionDataset("path/to/your/dataset")
43+
44+
# Create model with LoRA
45+
model = BaseModel.create("minimax_m2_lora")
46+
47+
# Fine-tune
48+
model.finetune(dataset=dataset)
49+
50+
# Save
51+
model.save("./minimax_m2_finetuned")
52+
```
53+
54+
### Memory-Efficient Inference
55+
56+
For machines with limited GPU memory, use quantized versions:
57+
58+
```python
59+
from xturing.models import BaseModel
60+
61+
# Use 8-bit quantization
62+
model = BaseModel.create("minimax_m2_int8")
63+
64+
# Or use 4-bit quantization with LoRA
65+
model = BaseModel.create("minimax_m2_lora_kbit")
66+
67+
output = model.generate(texts=["Your prompt here"])
68+
```
69+
70+
## Files
71+
72+
- `minimax_m2_example.py` - Basic usage example
73+
- `minimax_m2_finetune.py` - Fine-tuning example
74+
- `README.md` - This file
75+
76+
## Configuration
77+
78+
The model uses the following default settings:
79+
80+
### Generation Config
81+
- `max_new_tokens`: 512
82+
- `temperature`: 0.1
83+
- `penalty_alpha`: 0.6 (for contrastive search)
84+
- `top_k`: 4
85+
86+
### Fine-tuning Config
87+
- `learning_rate`: 2e-4 (LoRA variants)
88+
- `num_train_epochs`: 3
89+
- `max_length`: 2048
90+
- `batch_size`: Varies by variant
91+
92+
These can be customized through the configuration files or when creating the model.
93+
94+
## Requirements
95+
96+
Make sure you have xTuring installed with all dependencies:
97+
98+
```bash
99+
pip install xturing
100+
```
101+
102+
## Notes
103+
104+
- The model requires `trust_remote_code=True` to load properly
105+
- LoRA variants are recommended for fine-tuning as they are more parameter-efficient
106+
- Quantized versions (int8, kbit) require less memory but may have slightly reduced accuracy
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Example usage of MiniMaxM2 model with xTuring
3+
4+
This example demonstrates how to use the MiniMaxM2 model from HuggingFace
5+
with the xTuring library for inference and fine-tuning.
6+
7+
Model: MiniMaxAI/MiniMax-M2
8+
"""
9+
10+
from xturing.models import BaseModel
11+
12+
# Example 1: Create the base MiniMaxM2 model
13+
print("Loading MiniMaxM2 model...")
14+
model = BaseModel.create("minimax_m2")
15+
16+
# Generate text
17+
output = model.generate(texts=["What is machine learning?"])
18+
print("Base model output:")
19+
print(output)
20+
21+
# Example 2: Use LoRA version for efficient fine-tuning
22+
print("\nLoading MiniMaxM2 with LoRA...")
23+
model_lora = BaseModel.create("minimax_m2_lora")
24+
25+
# You can also use INT8 quantized versions for memory efficiency
26+
# model_int8 = BaseModel.create("minimax_m2_int8")
27+
# model_lora_int8 = BaseModel.create("minimax_m2_lora_int8")
28+
# model_lora_kbit = BaseModel.create("minimax_m2_lora_kbit")
29+
30+
print("MiniMaxM2 model loaded successfully!")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Fine-tuning MiniMaxM2 model with xTuring
3+
4+
This example shows how to fine-tune the MiniMaxM2 model using LoRA
5+
for parameter-efficient training.
6+
"""
7+
8+
from xturing.datasets.instruction_dataset import InstructionDataset
9+
from xturing.models import BaseModel
10+
11+
# Load your instruction dataset
12+
# You can use your own dataset or create one following the xTuring format
13+
instruction_dataset = InstructionDataset("path/to/your/dataset")
14+
15+
# Initialize the model with LoRA for efficient fine-tuning
16+
model = BaseModel.create("minimax_m2_lora")
17+
18+
# Fine-tune the model
19+
print("Starting fine-tuning...")
20+
model.finetune(dataset=instruction_dataset)
21+
22+
# Save the fine-tuned model
23+
model.save("./minimax_m2_finetuned")
24+
25+
# Load and use the fine-tuned model
26+
print("Loading fine-tuned model...")
27+
finetuned_model = BaseModel.load("./minimax_m2_finetuned")
28+
29+
# Generate with the fine-tuned model
30+
output = finetuned_model.generate(texts=["Your prompt here"])
31+
print(output)

src/xturing/config/finetuning_config.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,52 @@ mamba:
302302
learning_rate: 5e-5
303303
weight_decay: 0.01
304304

305+
# MiniMaxM2 model fine-tuning configurations
306+
minimax_m2:
307+
learning_rate: 1e-5
308+
weight_decay: 0.01
309+
num_train_epochs: 1
310+
batch_size: 1
311+
gradient_accumulation_steps: 8
312+
max_length: 2048
313+
warmup_steps: 100
314+
315+
minimax_m2_lora:
316+
learning_rate: 2e-4
317+
weight_decay: 0.01
318+
num_train_epochs: 3
319+
batch_size: 2
320+
gradient_accumulation_steps: 4
321+
max_length: 2048
322+
warmup_steps: 100
323+
324+
minimax_m2_int8:
325+
learning_rate: 1e-4
326+
weight_decay: 0.01
327+
num_train_epochs: 2
328+
batch_size: 2
329+
gradient_accumulation_steps: 4
330+
max_length: 2048
331+
warmup_steps: 100
332+
333+
minimax_m2_lora_int8:
334+
learning_rate: 2e-4
335+
weight_decay: 0.01
336+
num_train_epochs: 3
337+
batch_size: 4
338+
gradient_accumulation_steps: 2
339+
max_length: 2048
340+
warmup_steps: 100
341+
342+
minimax_m2_lora_kbit:
343+
learning_rate: 2e-4
344+
weight_decay: 0.01
345+
num_train_epochs: 3
346+
batch_size: 8
347+
gradient_accumulation_steps: 1
348+
max_length: 2048
349+
warmup_steps: 100
350+
305351
qwen3_0_6b:
306352
learning_rate: 5e-5
307353
weight_decay: 0.01

src/xturing/config/generation_config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,36 @@ llama2_lora_kbit:
316316
mamba:
317317
do_sample: false
318318

319+
# Contrastive search for MiniMaxM2
320+
minimax_m2:
321+
penalty_alpha: 0.6
322+
top_k: 4
323+
max_new_tokens: 512
324+
do_sample: false
325+
temperature: 0.1
326+
327+
minimax_m2_lora:
328+
penalty_alpha: 0.6
329+
top_k: 4
330+
max_new_tokens: 512
331+
do_sample: false
332+
temperature: 0.1
333+
334+
minimax_m2_int8:
335+
max_new_tokens: 512
336+
do_sample: false
337+
temperature: 0.1
338+
339+
minimax_m2_lora_int8:
340+
max_new_tokens: 512
341+
do_sample: false
342+
temperature: 0.1
343+
344+
minimax_m2_lora_kbit:
345+
max_new_tokens: 512
346+
do_sample: false
347+
temperature: 0.1
348+
319349
# Contrastive search
320350
qwen3_0_6b:
321351
penalty_alpha: 0.6

src/xturing/engines/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
LlamaLoraKbitEngine,
7272
)
7373
from xturing.engines.mamba_engine import MambaEngine
74+
from xturing.engines.minimax_m2_engine import (
75+
MiniMaxM2Engine,
76+
MiniMaxM2Int8Engine,
77+
MiniMaxM2LoraEngine,
78+
MiniMaxM2LoraInt8Engine,
79+
MiniMaxM2LoraKbitEngine,
80+
)
7481
from xturing.engines.opt_engine import (
7582
OPTEngine,
7683
OPTInt8Engine,
@@ -142,6 +149,11 @@
142149
BaseEngine.add_to_registry(LLama2LoraInt8Engine.config_name, LLama2LoraInt8Engine)
143150
BaseEngine.add_to_registry(LLama2LoraKbitEngine.config_name, LLama2LoraKbitEngine)
144151
BaseEngine.add_to_registry(MambaEngine.config_name, MambaEngine)
152+
BaseEngine.add_to_registry(MiniMaxM2Engine.config_name, MiniMaxM2Engine)
153+
BaseEngine.add_to_registry(MiniMaxM2Int8Engine.config_name, MiniMaxM2Int8Engine)
154+
BaseEngine.add_to_registry(MiniMaxM2LoraEngine.config_name, MiniMaxM2LoraEngine)
155+
BaseEngine.add_to_registry(MiniMaxM2LoraInt8Engine.config_name, MiniMaxM2LoraInt8Engine)
156+
BaseEngine.add_to_registry(MiniMaxM2LoraKbitEngine.config_name, MiniMaxM2LoraKbitEngine)
145157
BaseEngine.add_to_registry(Qwen3Engine.config_name, Qwen3Engine)
146158
BaseEngine.add_to_registry(Qwen3Int8Engine.config_name, Qwen3Int8Engine)
147159
BaseEngine.add_to_registry(Qwen3LoraEngine.config_name, Qwen3LoraEngine)

0 commit comments

Comments
 (0)