tiny ramdom models
Collection
198 items โข Updated โข 12
How to use tiny-random/granite-docling-v2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="tiny-random/granite-docling-v2")
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) # pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("tiny-random/granite-docling-v2")
model = AutoModelForMultimodalLM.from_pretrained("tiny-random/granite-docling-v2", 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=256)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use tiny-random/granite-docling-v2 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "tiny-random/granite-docling-v2"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "tiny-random/granite-docling-v2",
"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 run hf.co/tiny-random/granite-docling-v2
How to use tiny-random/granite-docling-v2 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "tiny-random/granite-docling-v2" \
--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": "tiny-random/granite-docling-v2",
"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 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 "tiny-random/granite-docling-v2" \
--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": "tiny-random/granite-docling-v2",
"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"
}
}
]
}
]
}'How to use tiny-random/granite-docling-v2 with Docker Model Runner:
docker model run hf.co/tiny-random/granite-docling-v2
This is a randomly initialized tiny model based on ibm-granite/granite-docling-v2-2b for testing and debugging.
| Feature | Source | This repo |
|---|---|---|
| Checkpoint tensor elements | 2.68B BF16 | 9.15M BF16 |
| Safetensors weight files | 5.37 GB (model.safetensors) | 18.32 MB (model.safetensors) |
| Vocabulary rows | 133,800 | Same |
| Text layers | 24 | 4 |
| Text width / heads / KV heads / head dim | 2,048 / 16 / 4 / 128 | 64 / 4 / 1 / 16 |
| Text intermediate width | 8,192 | 256 |
| Positional context / RoPE theta | 131,072 / 1e7 | Same |
| Granite multipliers (embed / residual / attention / logits) | 12 / 0.22 / 1/128 / 8 | Same |
| Vision layers / width / heads | 27 / 1,152 / 16 | 3 / 64 / 2 |
| Vision intermediate width | 4,304 | 256 |
| Tile size / patch size / pixel shuffle | 512 / 16 / 2 | Same |
| Image tokens per tile (coarse path) | 256 | Same |
| DeepStack taps | [8, 16, 24] (3 x 9-layer stacks) | [0, 1, 2] (3 x 1-layer stacks) |
| Fine connector path / density router | absent / absent | Same |
| MTP heads | 3 mtp.* layers, ignored by Transformers |
Not serialized |
| Serialized precision | BF16 | Same |
| File path | Size |
|---|---|
| model.safetensors | 18.3MB |
Requires transformers>=5.23. The snippet feeds one 512x512 page tile; the processor expands <image> to 256 image tokens per tile and the connector adds three DeepStack feature taps to the decoder. The model is random-initialized, so the generated markup is not meaningful.
def run_model(model_id: str) -> None:
import torch
from PIL import Image, ImageDraw
from transformers import AutoModelForImageTextToText, AutoProcessor
model_id = str(model_id)
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(model_id, dtype=torch.bfloat16).to("cuda").eval()
image = Image.new("RGB", (512, 512), "white")
draw = ImageDraw.Draw(image)
draw.rectangle((40, 40, 472, 90), outline="black", width=3)
for row in range(5):
draw.rectangle((40, 130 + row * 60, 432, 142 + row * 60), fill="black")
messages = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "<doclang>"}]}]
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
print("prompt tokens:", tuple(inputs["input_ids"].shape))
print(
"tiles:",
tuple(inputs["pixel_values"].shape),
"image tokens:",
int((inputs["input_ids"] == model.config.image_token_id).sum()),
)
with torch.inference_mode():
logits = model(**inputs).logits
generated = model.generate(**inputs, max_new_tokens=64, do_sample=False)
print("logits:", tuple(logits.shape), logits.dtype, float(logits.float().abs().max()))
print(processor.decode(generated[0, inputs["input_ids"].shape[1] :], skip_special_tokens=False))
text_ids = processor(text="<doclang>", return_tensors="pt").to(model.device)
with torch.inference_mode():
text_logits = model(**text_ids).logits
print("text-only logits:", tuple(text_logits.shape), float(text_logits.float().abs().max()))
if __name__ == "__main__":
run_model(model_id="tiny-random/granite-docling-v2")
This repo is generated by DeepSeek-V4.1-Flash.
Base model
ibm-granite/granite-4.0-1b-base