Image Feature Extraction
Transformers
Safetensors
pixtral_large4_vision
feature-extraction
vision
custom_code
Instructions to use immanuelpeter/PixtralViT-Large-4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use immanuelpeter/PixtralViT-Large-4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="immanuelpeter/PixtralViT-Large-4", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("immanuelpeter/PixtralViT-Large-4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download projector.py from immanuelpeter/PixtralViT-Large-4: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/immanuelpeter/PixtralViT-Large-4/resolve/main/projector.py
- Command line
-
hf download hf://immanuelpeter/PixtralViT-Large-4/projector.py
-
curl -L -o projector.py https://huggingface.co/immanuelpeter/PixtralViT-Large-4/resolve/main/projector.py
1.28 kB
| import json | |
| from pathlib import Path | |
| import torch | |
| from huggingface_hub import hf_hub_download | |
| from safetensors.torch import load_file | |
| from transformers import Mistral3Config | |
| from transformers.models.mistral3.modeling_mistral3 import Mistral3MultiModalProjector | |
| def load_projector(model: str | Path) -> Mistral3MultiModalProjector: | |
| """RMSNorm, 2x2 patch merger and two-layer GELU adapter, as in Mistral Large 4.""" | |
| 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 = Mistral3MultiModalProjector(Mistral3Config(**json.loads(config_path.read_text()))) | |
| projector.load_state_dict(load_file(weights_path), strict=True) | |
| return projector | |
| def merged_and_projected(projector: Mistral3MultiModalProjector, tokens: torch.Tensor, image_sizes): | |
| """Return the patch-merger output (2048-d) and the Projector output (6144-d).""" | |
| merged = projector.patch_merger(projector.norm(tokens), image_sizes) | |
| return merged, projector.linear_2(projector.act(projector.linear_1(merged))) | |