|
| 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 |
0 commit comments