Instructions to use immanuelpeter/MiniMax-M3-Vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use immanuelpeter/MiniMax-M3-Vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="immanuelpeter/MiniMax-M3-Vision")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("immanuelpeter/MiniMax-M3-Vision") model = AutoModel.from_pretrained("immanuelpeter/MiniMax-M3-Vision", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download projector.py from immanuelpeter/MiniMax-M3-Vision: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/immanuelpeter/MiniMax-M3-Vision/resolve/main/projector.py
- Command line
-
hf download hf://immanuelpeter/MiniMax-M3-Vision/projector.py
-
curl -L -o projector.py https://huggingface.co/immanuelpeter/MiniMax-M3-Vision/resolve/main/projector.py
1.55 kB
| import json | |
| from pathlib import Path | |
| import torch | |
| from huggingface_hub import hf_hub_download | |
| from safetensors.torch import load_file | |
| from torch import nn | |
| class Projector(nn.Module): | |
| def __init__(self, config: dict): | |
| super().__init__() | |
| self.spatial_merge_size = 2 | |
| self.linear_1 = nn.Linear(config["input_size"], config["hidden_size"], bias=True) | |
| self.linear_2 = nn.Linear(config["hidden_size"], config["output_size"], bias=True) | |
| self.merge_linear_1 = nn.Linear(config["merged_hidden_size"], config["hidden_size"], bias=True) | |
| self.merge_linear_2 = nn.Linear(config["hidden_size"], config["output_size"], bias=True) | |
| def forward(self, image_features: torch.Tensor) -> torch.Tensor: | |
| hidden = torch.nn.functional.gelu(self.linear_1(image_features)) | |
| hidden = self.linear_2(hidden) | |
| hidden = hidden.reshape(hidden.shape[0] // (self.spatial_merge_size ** 2), -1) | |
| return self.merge_linear_2(torch.nn.functional.gelu(self.merge_linear_1(hidden))) | |
| def load_projector(model: str | Path) -> Projector: | |
| path = Path(model) | |
| if path.is_dir(): | |
| config_path = path / "projector_config.json" | |
| weights_path = path / "projector.safetensors" | |
| else: | |
| config_path = Path(hf_hub_download(str(model), "projector_config.json")) | |
| weights_path = Path(hf_hub_download(str(model), "projector.safetensors")) | |
| projector = Projector(json.loads(config_path.read_text())) | |
| projector.load_state_dict(load_file(weights_path)) | |
| return projector | |