Instructions to use immanuelpeter/MiniMax-M3.1-Flash-Vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use immanuelpeter/MiniMax-M3.1-Flash-Vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="immanuelpeter/MiniMax-M3.1-Flash-Vision")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("immanuelpeter/MiniMax-M3.1-Flash-Vision") model = AutoModel.from_pretrained("immanuelpeter/MiniMax-M3.1-Flash-Vision", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Extract pinned MiniMax M3.1 Flash Tower and Projector with exact source tensors
Browse files- LICENSE +17 -0
- NOTICE +5 -0
- README.md +58 -0
- config.json +36 -0
- examples/inference.py +43 -0
- export_manifest.json +14 -0
- model.safetensors +3 -0
- preprocessor_config.json +32 -0
- projector.py +36 -0
- projector.safetensors +3 -0
- projector_config.json +6 -0
LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MINIMAX COMMUNITY LICENSE
|
| 2 |
+
Copyright (c) 2026 MiniMax
|
| 3 |
+
Permission 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:
|
| 4 |
+
1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 5 |
+
2. If the Software (or any derivative works thereof) is used for any Commercial Use for your products or services:
|
| 6 |
+
1. you shall prominently display “Built with MiniMax M3.1-Flash” on a related website, user interface, blogpost, about page or product documentation.
|
| 7 |
+
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”.
|
| 8 |
+
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.
|
| 9 |
+
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.
|
| 10 |
+
|
| 11 |
+
Appendix: Prohibited Uses
|
| 12 |
+
You agree you will not use, or allow others to use, the Software or any derivatives of the Software to:
|
| 13 |
+
1. Generate or disseminate content prohibited by applicable laws or regulations.
|
| 14 |
+
2. Assist with, engage in or otherwise support any military purpose.
|
| 15 |
+
3. Exploit, harm, or attempt to exploit or harm minors.
|
| 16 |
+
4. Generate or disseminate false or misleading information with the intent to cause harm.
|
| 17 |
+
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.
|
NOTICE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MiniMax-M3.1-Flash Vision
|
| 2 |
+
Extracted from MiniMaxAI/MiniMax-M3.1-Flash at 54e4e69dfc452b1e94a426c24a4fdeeaa8e3ad5e.
|
| 3 |
+
Copyright MiniMax. Distributed under the accompanying MiniMax Community License.
|
| 4 |
+
Tower and Projector tensors are preserved exactly. State-dictionary keys are adapted for native Transformers classes.
|
| 5 |
+
This is a standalone vision extraction, not the complete language model.
|
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: minimax-community
|
| 4 |
+
license_link: LICENSE
|
| 5 |
+
pipeline_tag: image-feature-extraction
|
| 6 |
+
library_name: transformers
|
| 7 |
+
base_model:
|
| 8 |
+
- MiniMaxAI/MiniMax-M3.1-Flash
|
| 9 |
+
tags:
|
| 10 |
+
- vision
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# MiniMax-M3.1-Flash Vision
|
| 14 |
+
|
| 15 |
+
Standalone Tower and Projector extracted from MiniMaxAI/MiniMax-M3.1-Flash,
|
| 16 |
+
revision `54e4e69dfc452b1e94a426c24a4fdeeaa8e3ad5e`. No language-model weights
|
| 17 |
+
are included. The accompanying MiniMax Community License applies to these weights.
|
| 18 |
+
|
| 19 |
+
The Tower has 32 layers, width 1280, 16 heads, MLP width 5120, patch size 14,
|
| 20 |
+
temporal patch size 2, and 3D RoPE. The nominal image size is 672.
|
| 21 |
+
At 448 pixels it produces 1024 Tower tokens of width 1280. The bench merges
|
| 22 |
+
2x2 spatial neighbors into 256 tokens of width 5120. The Projector outputs
|
| 23 |
+
256 tokens of width 6144.
|
| 24 |
+
|
| 25 |
+
The bundle contains 515 Tower tensors in `model.safetensors` and eight Projector
|
| 26 |
+
tensors in `projector.safetensors`. All tensors preserve their pinned source
|
| 27 |
+
values and dtypes. `export_manifest.json` records checkpoint identity and file hashes.
|
| 28 |
+
Shard selection comes from the pinned source index, rather than M3 shard numbers.
|
| 29 |
+
|
| 30 |
+
## Use
|
| 31 |
+
|
| 32 |
+
Requires Transformers 5.17.0, PyTorch and Pillow. See `examples/inference.py`.
|
| 33 |
+
Load the Tower with `MiniMaxM3VLVisionModel.from_pretrained`; use `projector.py`
|
| 34 |
+
to load the separate Projector. The native parent processor uses dynamic resizing.
|
| 35 |
+
The benchmark uses a bicubic short-side resize and center crop at 448, CLIP
|
| 36 |
+
normalization and two repeated frames.
|
| 37 |
+
|
| 38 |
+
## Validation
|
| 39 |
+
|
| 40 |
+
`scripts/validate_minimax_m3.py` in vision-tower-bench independently loads the
|
| 41 |
+
pinned source tensors into native HF parent classes. Every Tower and Projector
|
| 42 |
+
tensor matches exactly. On fixed synthetic images at 56 and 448 pixels, all
|
| 43 |
+
eight Tower depths, merged tokens and projected tokens match exactly in BF16.
|
| 44 |
+
Changing nominal image size between 672 and 2016 leaves those outputs unchanged.
|
| 45 |
+
The report records the Transformers source hash. The pinned HF parent repository
|
| 46 |
+
contains no separate modeling Python file; this check uses the native HF implementation.
|
| 47 |
+
|
| 48 |
+
MiniMax M3 and M3.1-Flash share this architecture and preprocessing, but their
|
| 49 |
+
weights differ. Benchmark results and the complete tensor drift report are maintained
|
| 50 |
+
in [vision-tower-bench](https://github.com/immanuel-peter/vision-tower-bench).
|
| 51 |
+
No benchmark score is implied by this release.
|
| 52 |
+
|
| 53 |
+
## Reproduce
|
| 54 |
+
|
| 55 |
+
`python scripts/export_minimax_m3_vision.py --checkpoint minimax_m31_flash`
|
| 56 |
+
|
| 57 |
+
MiniMax released the parent weights and native Transformers implementation.
|
| 58 |
+
See LICENSE and NOTICE.
|
config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MiniMaxM3VLVisionModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"dtype": "bfloat16",
|
| 7 |
+
"hidden_act": "gelu",
|
| 8 |
+
"hidden_size": 1280,
|
| 9 |
+
"image_size": 672,
|
| 10 |
+
"img_token_compression_config": {
|
| 11 |
+
"image_token_compression_method": "patch_merge",
|
| 12 |
+
"spatial_merge_size": 2,
|
| 13 |
+
"temporal_patch_size": 2
|
| 14 |
+
},
|
| 15 |
+
"initializer_factor": 1.0,
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 5120,
|
| 18 |
+
"layer_norm_eps": 1e-05,
|
| 19 |
+
"model_type": "minimax_m3_vl_vision",
|
| 20 |
+
"num_attention_heads": 16,
|
| 21 |
+
"num_channels": 3,
|
| 22 |
+
"num_hidden_layers": 32,
|
| 23 |
+
"patch_size": 14,
|
| 24 |
+
"position_embedding_type": "rope",
|
| 25 |
+
"projection_dim": 6144,
|
| 26 |
+
"rope_mode": "3d",
|
| 27 |
+
"rope_parameters": {
|
| 28 |
+
"rope_theta": 10000.0,
|
| 29 |
+
"rope_type": "axial"
|
| 30 |
+
},
|
| 31 |
+
"spatial_merge_size": 2,
|
| 32 |
+
"temporal_patch_size": 2,
|
| 33 |
+
"transformers_version": "5.17.0",
|
| 34 |
+
"vision_segment_max_frames": 4,
|
| 35 |
+
"vocab_size": 32000
|
| 36 |
+
}
|
examples/inference.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import torch
|
| 7 |
+
from transformers import MiniMaxM3VLImageProcessor, MiniMaxM3VLVisionModel
|
| 8 |
+
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
|
| 10 |
+
from projector import load_projector
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
MODEL_ID = "immanuelpeter/MiniMax-M3.1-Flash-Vision"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def main() -> None:
|
| 17 |
+
parser = argparse.ArgumentParser(description="Extract MiniMax-M3 visual features.")
|
| 18 |
+
parser.add_argument("image", type=Path)
|
| 19 |
+
parser.add_argument("--model", default=MODEL_ID)
|
| 20 |
+
args = parser.parse_args()
|
| 21 |
+
|
| 22 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
+
dtype = torch.bfloat16 if device.type == "cuda" else torch.float32
|
| 24 |
+
tower = MiniMaxM3VLVisionModel.from_pretrained(args.model, dtype=dtype).to(device).eval()
|
| 25 |
+
processor = MiniMaxM3VLImageProcessor.from_pretrained(args.model)
|
| 26 |
+
projector = load_projector(args.model)
|
| 27 |
+
projector.to(device=device, dtype=dtype).eval()
|
| 28 |
+
inputs = processor(images=Image.open(args.image).convert("RGB"), return_tensors="pt")
|
| 29 |
+
|
| 30 |
+
with torch.inference_mode():
|
| 31 |
+
merged = tower(
|
| 32 |
+
pixel_values=inputs["pixel_values"].to(device=device, dtype=dtype),
|
| 33 |
+
grid_thw=inputs["image_grid_thw"].to(device),
|
| 34 |
+
).last_hidden_state
|
| 35 |
+
tokens = merged.reshape(-1, merged.shape[-1])
|
| 36 |
+
projected = projector(tokens)
|
| 37 |
+
|
| 38 |
+
print("tower", merged.shape)
|
| 39 |
+
print("projected", projected.shape)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
main()
|
export_manifest.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source_repo": "MiniMaxAI/MiniMax-M3.1-Flash",
|
| 3 |
+
"source_revision": "54e4e69dfc452b1e94a426c24a4fdeeaa8e3ad5e",
|
| 4 |
+
"tower_tensors": 515,
|
| 5 |
+
"projector_tensors": 8,
|
| 6 |
+
"files": {
|
| 7 |
+
"model.safetensors": "95e3731e26887d066a0b2291a1574da40a36aba5ba43e476746b9c16a64bcf08",
|
| 8 |
+
"projector.safetensors": "81fe7c8be0a2e91b26040ab23523713d1b775eadcdee5ac0021593762d3e6332",
|
| 9 |
+
"config.json": "9c3a6dac0654055594fdde1f148400331f3e55cb72ffe1b7a6806db07ab93a79",
|
| 10 |
+
"projector_config.json": "672b312ca5fb10324a41936294814367fb371a3891cc6d8ee8df3d22fc0c559c",
|
| 11 |
+
"preprocessor_config.json": "c95c459d449a2dacd974bcfef8986b2734afd55e73eb05a7aaad30542cf78b6e",
|
| 12 |
+
"LICENSE": "8c4978e3e0fe0349ff929cc8450463cba3039c4c9fc144d8bd5382ab00df247a"
|
| 13 |
+
}
|
| 14 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:95e3731e26887d066a0b2291a1574da40a36aba5ba43e476746b9c16a64bcf08
|
| 3 |
+
size 1265435224
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"processor_class": "AutoImageProcessor",
|
| 3 |
+
"auto_map": {
|
| 4 |
+
"AutoImageProcessor": "image_processor.MiniMaxM3VLImageProcessor",
|
| 5 |
+
"AutoProcessor": "processing_minimax.MiniMaxVLProcessor",
|
| 6 |
+
"AutoVideoProcessor": "video_processor.MiniMaxM3VLVideoProcessor"
|
| 7 |
+
},
|
| 8 |
+
"process_image_mode": "dynamic_res",
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.48145466,
|
| 11 |
+
0.4578275,
|
| 12 |
+
0.40821073
|
| 13 |
+
],
|
| 14 |
+
"image_std": [
|
| 15 |
+
0.26862954,
|
| 16 |
+
0.26130258,
|
| 17 |
+
0.27577711
|
| 18 |
+
],
|
| 19 |
+
"size": [
|
| 20 |
+
672,
|
| 21 |
+
672
|
| 22 |
+
],
|
| 23 |
+
"patch_size": 14,
|
| 24 |
+
"img_token_compression_config": {
|
| 25 |
+
"image_token_compression_threshold": 1.1,
|
| 26 |
+
"image_token_compression_method": "patch_merge",
|
| 27 |
+
"max_image_resolution": 1008,
|
| 28 |
+
"spatial_merge_size": 2,
|
| 29 |
+
"temporal_patch_size": 2
|
| 30 |
+
},
|
| 31 |
+
"add_start_end_special_tokens": true
|
| 32 |
+
}
|
projector.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
from safetensors.torch import load_file
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Projector(nn.Module):
|
| 11 |
+
def __init__(self, config: dict):
|
| 12 |
+
super().__init__()
|
| 13 |
+
self.spatial_merge_size = 2
|
| 14 |
+
self.linear_1 = nn.Linear(config["input_size"], config["hidden_size"], bias=True)
|
| 15 |
+
self.linear_2 = nn.Linear(config["hidden_size"], config["output_size"], bias=True)
|
| 16 |
+
self.merge_linear_1 = nn.Linear(config["merged_hidden_size"], config["hidden_size"], bias=True)
|
| 17 |
+
self.merge_linear_2 = nn.Linear(config["hidden_size"], config["output_size"], bias=True)
|
| 18 |
+
|
| 19 |
+
def forward(self, image_features: torch.Tensor) -> torch.Tensor:
|
| 20 |
+
hidden = torch.nn.functional.gelu(self.linear_1(image_features))
|
| 21 |
+
hidden = self.linear_2(hidden)
|
| 22 |
+
hidden = hidden.reshape(hidden.shape[0] // (self.spatial_merge_size ** 2), -1)
|
| 23 |
+
return self.merge_linear_2(torch.nn.functional.gelu(self.merge_linear_1(hidden)))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def load_projector(model: str | Path) -> Projector:
|
| 27 |
+
path = Path(model)
|
| 28 |
+
if path.is_dir():
|
| 29 |
+
config_path = path / "projector_config.json"
|
| 30 |
+
weights_path = path / "projector.safetensors"
|
| 31 |
+
else:
|
| 32 |
+
config_path = Path(hf_hub_download(str(model), "projector_config.json"))
|
| 33 |
+
weights_path = Path(hf_hub_download(str(model), "projector.safetensors"))
|
| 34 |
+
projector = Projector(json.loads(config_path.read_text()))
|
| 35 |
+
projector.load_state_dict(load_file(weights_path))
|
| 36 |
+
return projector
|
projector.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:81fe7c8be0a2e91b26040ab23523713d1b775eadcdee5ac0021593762d3e6332
|
| 3 |
+
size 468763376
|
projector_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"input_size": 1280,
|
| 3 |
+
"hidden_size": 6144,
|
| 4 |
+
"output_size": 6144,
|
| 5 |
+
"merged_hidden_size": 24576
|
| 6 |
+
}
|