File size: 3,859 Bytes
83d4aa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
library_name: transformers
pipeline_tag: image-text-to-text
base_model:
- ibm-granite/granite-docling-v2-2b
---

This is a randomly initialized tiny model based on [ibm-granite/granite-docling-v2-2b](https://huggingface.co/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 |

### Example usage

#### Transformers (✅ verified)

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.

```python
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")
```

### Creating this repo

- Code: [.meta/create_model.py](.meta/create_model.py)
- Model structure: [.meta/model.log](.meta/model.log)
- Environment: [.meta/env.json](.meta/env.json)

### Change log

- 2026-12-01: Initial tiny Granite-Docling v2 checkpoint.

*This repo is generated by DeepSeek-V4.1-Flash.*