Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
78762b2
add initial tests
guarin Nov 17, 2026
0bab3c2
init draft version
guarin Nov 17, 2026
01147ff
Merge branch 'main' into add-inkling2-loop
guarin Nov 17, 2026
a69e017
update tests
guarin Nov 18, 2026
02ee726
more todo
guarin Nov 18, 2026
39b88b8
update cache layer handling
guarin Nov 18, 2026
aa0cc26
cleanup
guarin Nov 18, 2026
ef5f4bb
split layers
guarin Nov 18, 2026
3f2a85f
cleanup message passing
guarin Nov 18, 2026
f848297
update gates
guarin Nov 18, 2026
aea1583
refactor message passing
guarin Nov 18, 2026
7434736
cleanup
guarin Nov 18, 2026
1c79cce
update
guarin Nov 19, 2026
9354250
cleanup
guarin Nov 19, 2026
abe7127
remove defensive checks
guarin Nov 19, 2026
e2abf0f
move to correct place
guarin Nov 19, 2026
29b216e
dequant step 1
guarin Nov 19, 2026
737f980
flatten loop config
guarin Nov 19, 2026
6fa0050
merge message queries
guarin Nov 19, 2026
6f3482c
fix
guarin Nov 19, 2026
1aa26ba
norm
guarin Nov 19, 2026
5a3dab4
update init weights
guarin Nov 19, 2026
a6a4af2
split layer loop
guarin Nov 19, 2026
2983e57
more splitting
guarin Nov 19, 2026
c1846e6
fix tests
guarin Nov 19, 2026
ff6dc64
rename
guarin Nov 19, 2026
d03e8d3
update inkling2 attentions
guarin Nov 19, 2026
9507570
remove unneeded layers
guarin Nov 19, 2026
06661c0
more cleanup
guarin Nov 19, 2026
ef20ef1
cleanup
guarin Nov 19, 2026
e23ef0f
refactor relative logits
guarin Nov 19, 2026
908b61b
merge k/v proj
guarin Nov 19, 2026
cb6894c
move things
guarin Nov 19, 2026
1a8cad7
fix packed sequences
guarin Nov 20, 2026
cc4f307
add Inkling2GatedOutputProjection
guarin Nov 20, 2026
d425f55
drop sdpa
guarin Nov 20, 2026
6427d4f
refactor scales
guarin Nov 20, 2026
6620ca6
refactor rel pos bias
guarin Nov 20, 2026
eb892bf
minor
guarin Nov 20, 2026
32049ef
fix repo
guarin Nov 20, 2026
ed58c54
handle unpadded_vocab_size
guarin Nov 20, 2026
3add884
merge kv proj
guarin Nov 20, 2026
6e657c3
fix repo
guarin Nov 20, 2026
9a94031
fix head loading
guarin Nov 20, 2026
3b75972
fix mxfp8 loading
guarin Nov 20, 2026
b01cd5f
use attn interface
guarin Nov 20, 2026
48141e7
text_hidden_size is now in the config
guarin Nov 20, 2026
1a15086
use dory caching
guarin Nov 20, 2026
c9ccbdb
move norm to proj
guarin Nov 20, 2026
9aed9db
move test
guarin Nov 20, 2026
e843e8f
update docs
guarin Nov 20, 2026
9ed3671
add todo
guarin Nov 20, 2026
18c8ac8
update tests
guarin Nov 20, 2026
3ed39b6
update docs
guarin Nov 20, 2026
46c36e5
add blog link
guarin Nov 20, 2026
6b1044a
tiny checkpoint
guarin Nov 20, 2026
9a1ff82
Merge branch 'main' into add-inkling2-loop
guarin Nov 20, 2026
eb4b4a3
cleanup
guarin Nov 20, 2026
6819273
make linter happy
guarin Nov 20, 2026
8d628c7
cleanup
guarin Nov 20, 2026
09c356e
add a10 expectations
guarin Nov 20, 2026
f0fd853
skip export tests
guarin Nov 20, 2026
e916f57
Merge branch 'main' into add-inkling2-mini
guarin Nov 20, 2026
c5b376c
update links
guarin Nov 20, 2026
e18dccc
update links
guarin Nov 20, 2026
e3a65e2
Merge branch 'add-inkling2-mini' of https://github.com/huggingface/tr…
guarin Nov 20, 2026
6173a2f
update tests
guarin Nov 20, 2026
bc3f715
fix fp32 loading
guarin Nov 21, 2026
a10ebc3
add kernels note
guarin Nov 21, 2026
430050f
consistency
Cyrilvallez Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update docs
  • Loading branch information
guarin committed Nov 20, 2026
commit e843e8f1000a0a0cd49a498b71194ede5d230395
108 changes: 104 additions & 4 deletions docs/source/en/model_doc/inkling2_loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,52 @@ limitations under the License.
-->
*This model was contributed to Hugging Face Transformers on 2026-11-19.*

# Looped Inkling 2
# Inkling 2 Mini

Looped Inkling 2 is a multimodal model from [Thinking Machines Lab](https://huggingface.co/thinkingmachines) that accepts text and image inputs and generates text outputs. It is [Inkling 2](./inkling2) with one change to how the decoder runs: a contiguous middle section of layers, the loop layers, run several times for every token with the same weights. The released checkpoint has 24 decoder layers of which layers 6 to 17 run three times, so every token goes through 48 layers with the weights of 24. Every pass after the first starts again from the output of the pre loop layers, and reads the residual blocks of the previous pass through small learned messages that are mixed into the attention and mixture-of-experts inputs of each loop layer. The decoder has a hidden size of 2304 and routes each token to 8 of 128 experts. The image encoder, tokenizer and processor are the ones of Inkling 2.
Inkling 2 Mini is a multimodal model from [Thinking Machines Lab](https://huggingface.co/thinkingmachines) that accepts text and image inputs and generates text outputs. It is based on [Inkling 2 Small](./inkling2) but has only 24 decoder layers instead of 48. The lower layer count is compensated for by a looping mechanism in which layers 6 to 17 run three times. Information is shared between loop passes through a learned message-passing mechanism that mixes the residuals of the previous pass into the attention and mixture-of-experts inputs of each loop layer. The decoder has a hidden size of 2304 and routes each token to 8 of 128 experts. The image encoder, tokenizer and processor are identical to those of Inkling 2 Small.

Inkling 2 Mini comes with an additional [research checkpoint](https://huggingface.co/thinkingmachines/d24-varloop-research) that supports a variable number of loop passes. The architecture is identical to the main Inkling 2 Mini model. The number of loop passes can be adjusted to trade off speed against quality. Fewer passes are faster, while more passes improve quality.

Both checkpoints contain NVFP4 and MXFP8 quantized layers that Transformers dequantizes when loading the model.

<hfoptions id="usage">
<hfoption id="Pipeline">

```python
import torch

from transformers import pipeline

pipe = pipeline(
"image-text-to-text", model="thinkingmachines/inkling-1116-share", dtype=torch.bfloat16, device_map="auto"
)

messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg",
},
{"type": "text", "text": "What animal is in this image, and where is it?"},
],
},
]

output = pipe(messages, max_new_tokens=1024, return_full_text=False, skip_special_tokens=False)
print(output[0]["generated_text"])
# <|message_model|><|content_thinking|>The user is asking about an animal in an image. Let me
# analyze what I see: a small wild feline with thick, fluffy fur dusted with snow, short legs, a
# broad face, and black stripes/spots.
# ...
# <|end_message|><|message_model|><|content_text|>The animal appears to be a Pallas’s cat (manul) —
# a small, bear-like wild cat with thick speckled/striped fur. It’s standing on snow inside what
# looks like a zoo or wildlife enclosure, with snow-covered birch/log branches and a chain-link
# fence in the background.<|end_message|><|content_model_end_sampling|>
```

</hfoption>
<hfoption id="AutoModel">

```python
Expand Down Expand Up @@ -58,15 +99,74 @@ input_len = inputs["input_ids"].shape[-1]

outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0][input_len:], skip_special_tokens=False))
# <|message_model|><|content_thinking|>The user is asking what animal is in the image and where it
# is. Let me analyze the image.
# ...
# <|end_message|><|message_model|><|content_text|>The animal appears to be a Pallas’s cat (manul), a
# stocky small wild cat with thick, snow-dusted fur. It is standing on snow, likely inside a zoo or
# wildlife enclosure — you can see birch/aspen-like posts and chain-link fencing in the
# background.<|end_message|><|content_model_end_sampling|>
```

</hfoption>

<hfoption id="AutoModel Variable Loops">

```python
import torch

from transformers import AutoModelForMultimodalLM, AutoProcessor

model_id = "thinkingmachines/d24-varloop-research"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForMultimodalLM.from_pretrained(
model_id,
dtype=torch.bfloat16,
device_map="auto",
text_config={"loop_num_passes": 3}, # number of loop passes, must be at least 1
)

messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg",
},
{"type": "text", "text": "What animal is in this image, and where is it?"},
],
},
]

inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
input_len = inputs["input_ids"].shape[-1]

outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0][input_len:], skip_special_tokens=False))
# <|message_model|><|content_thinking|>We need answer image question. Need identify animal and where
# is it.
# ...
# <|end_message|><|message_model|><|content_text|>The animal is a Pallas’s cat (a.k.a. Manul), a
# stocky, densely furred small wild cat. It’s in the snow outdoors in a cold setting—likely a winter
# enclosure/habitat—standing/walking on snow at the center of the
# image.<|end_message|><|content_model_end_sampling|>
```

</hfoption>

</hfoptions>

## Notes

- Attention runs in eager mode only, because every layer adds a relative position bias and a sink.
- Every pass through the loop layers keeps its own keys, values and convolution states, so the cache has one layer per layer visit (48 for the released checkpoint). The cache layers of the passes after the first follow those of the 24 decoder layers.
- Attention runs in eager mode only because every layer adds a relative position bias and a sink.
- Every pass through the loop layers keeps its own keys, values and convolution states, so the cache has one layer per layer visit (48 for the released checkpoint).
- `output_hidden_states` and `output_attentions` return one entry per layer visit.

## Inkling2LoopConfig
Expand Down