Instructions to use soyrsoyr/granite-vision-4.1-0.2B-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use soyrsoyr/granite-vision-4.1-0.2B-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="soyrsoyr/granite-vision-4.1-0.2B-tiny", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("soyrsoyr/granite-vision-4.1-0.2B-tiny", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("soyrsoyr/granite-vision-4.1-0.2B-tiny", trust_remote_code=True, device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use soyrsoyr/granite-vision-4.1-0.2B-tiny with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "soyrsoyr/granite-vision-4.1-0.2B-tiny" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "soyrsoyr/granite-vision-4.1-0.2B-tiny", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/soyrsoyr/granite-vision-4.1-0.2B-tiny
- SGLang
How to use soyrsoyr/granite-vision-4.1-0.2B-tiny with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "soyrsoyr/granite-vision-4.1-0.2B-tiny" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "soyrsoyr/granite-vision-4.1-0.2B-tiny", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "soyrsoyr/granite-vision-4.1-0.2B-tiny" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "soyrsoyr/granite-vision-4.1-0.2B-tiny", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use soyrsoyr/granite-vision-4.1-0.2B-tiny with Docker Model Runner:
docker model run hf.co/soyrsoyr/granite-vision-4.1-0.2B-tiny
This is a tiny version of ibm-granite/granite-vision-4.1-4b created for testing and development.
Intended Use
A small, fast stand-in for the granite4_vision architecture, useful for:
- Inference / CI testing where a real 4B checkpoint is too large to download or run
- Quantization & compression pipeline smoke tests (llm-compressor, compressed-tensors)
- Offloaded / distributed loading tests (see below)
- Exercising the vLLM
Granite4VisionForConditionalGenerationmodel path, including the SigLIP vision tower + deepstack projectors
Weights are random (then briefly fine-tuned on a toy corpus), so generations are not meaningful — this model is for plumbing, not output quality.
Model Details
- Base Model: ibm-granite/granite-vision-4.1-4b
- Architecture: granite4_vision (Granite4VisionForConditionalGeneration)
- Total Parameters: 0.162B
- Activated Parameters: 0.162B
Configuration Changes
The following parameters were reduced from the original model:
| Parameter | Original | Tiny |
|---|---|---|
| text_config.num_hidden_layers | 40 | 4 |
| text_config.hidden_size | 2560 | 1024 |
| text_config.intermediate_size | 8192 | 2048 |
| text_config.num_attention_heads | 40 | 8 |
| text_config.num_key_value_heads | 8 | 2 |
| vision_config.num_hidden_layers | 27 | 4 |
| vision_config.hidden_size | 1152 | 384 |
| vision_config.intermediate_size | 4304 | 768 |
| vision_config.num_attention_heads | 16 | 4 |
| spatial_target_layers | [12, 15, 18, 21] | [0, 1, 2, 3] |
| deepstack_layer_map | [(-19,9),(-13,6),(-7,3),(-1,0)] | [(-4,3),(-3,2),(-2,1),(-1,0)] |
The full 100,352-token vocabulary is retained.
Checkpoint Structure
Single safetensors file (model.safetensors). Key naming matches the original
checkpoint format (model.language_model.*, model.vision_tower.vision_model.*
(SigLIP), model.layerwise_projectors.*, model.spatial_projectors.*,
model.image_newline). Module-path structure was verified equal to the base
checkpoint's safetensors header.
Usage
from transformers import AutoModelForImageTextToText, AutoProcessor
model = AutoModelForImageTextToText.from_pretrained(
"soyrsoyr/granite-vision-4.1-0.2B-tiny", device_map="auto"
)
processor = AutoProcessor.from_pretrained("soyrsoyr/granite-vision-4.1-0.2B-tiny")
input_ids = processor.tokenizer("According to all known laws", return_tensors="pt").input_ids.to(model.device)
output = model.generate(input_ids, max_new_tokens=20)
print(processor.tokenizer.decode(output[0]))
Offloaded / distributed loading (compressed-tensors)
This is a multimodal ...ForConditionalGeneration model, so AutoModelForCausalLM
does not resolve it. Pass AutoModelForImageTextToText to
load_offloaded_model — the class you pass must match the class you call, since
that is where device_map="auto_offload" support is injected:
from transformers import AutoModelForImageTextToText
from compressed_tensors.offload import load_offloaded_model
from compressed_tensors.distributed import init_dist
init_dist()
with load_offloaded_model(model_class=AutoModelForImageTextToText):
model = AutoModelForImageTextToText.from_pretrained(
"soyrsoyr/granite-vision-4.1-0.2B-tiny",
device_map="auto_offload", # weights on CPU/disk, GPU for activations
)
Creation Process
This model was created using the llm-compressor create-tiny-model claude skill.
- Config inspected via
inspect_config.py - Tiny model created via a modified
save_tiny_model.py, adapted for the multimodal class (AutoModelForImageTextToText.from_config); the text tower and SigLIP vision tower were shrunk and any all-zero / non-finite / extreme param was fixed afterinit_weights() - Fine-tuned on the copypasta dataset; reached training perplexity 1.36 (target: ≤3.0) at lr=5e-4 (CPU, Adafactor)
- Checkpoint structure validated against the original HuggingFace safetensors header (module-path match)
- Inference validated via
validate_tiny_model.py
Notes
- Layer-index-sensitive fields remapped.
spatial_target_layersanddeepstack_layer_mapreference specific vision/text layer indices; they were remapped to the reduced depths so they stay valid at 4 vision / 4 text layers. - Vision tower key nesting. Current transformers flattens
SiglipVisionModelon save (model.vision_tower.*), but the published checkpoint and vLLM's loader expect the nestedmodel.vision_tower.vision_model.*layout. A conversion step restores the nesting so the checkpoint loads cleanly in both transformers (viaSiglipVisionModel.base_model_prefix) and vLLM. tie_word_embeddings=True:lm_headsharesembed_tokensand is not stored as a separate tensor.
Validation output: Success: 1.3236008882522583 <= 10.0
- Downloads last month
- 16
Model tree for soyrsoyr/granite-vision-4.1-0.2B-tiny
Base model
ibm-granite/granite-vision-4.1-4b