Skip to content
Merged
Show file tree
Hide file tree
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
init draft version
  • Loading branch information
guarin committed Nov 17, 2026
commit 0bab3c2a7c6bd17034a60ae2d24f8a98a2ffd44d
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,8 @@
title: Inkling
- local: model_doc/inkling2
title: Inkling2
- local: model_doc/inkling2_loop
title: Inkling2Loop
- local: model_doc/instructblip
title: InstructBLIP
- local: model_doc/instructblipvideo
Expand Down
103 changes: 103 additions & 0 deletions docs/source/en/model_doc/inkling2_loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!--Copyright 2026 the HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


⚠️ Note that this file is in Markdown but contains specific syntax for our doc-builder (similar to MDX) that may not be rendered properly in your Markdown viewer.

-->
*This model was contributed to Hugging Face Transformers on 2026-11-17.*

# Looped Inkling 2

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 core, runs 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 layers before the core, 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 core 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.

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

```python
import torch

from transformers import AutoModelForMultimodalLM, AutoProcessor

model_id = "thinkingmachines/inkling-1116-share"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForMultimodalLM.from_pretrained(model_id, 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?"},
],
},
]

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

</hfoption>
</hfoptions>

## Notes

- Attention runs in eager mode only, because every layer adds a relative position bias and a sink.
- Every pass through the core 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.
- `output_hidden_states` and `output_attentions` return one entry per layer visit.

## Inkling2LoopConfig

[[autodoc]] Inkling2LoopConfig

## Inkling2LoopTextConfig

[[autodoc]] Inkling2LoopTextConfig

## Inkling2LoopPreTrainedModel

[[autodoc]] Inkling2LoopPreTrainedModel
- forward

## Inkling2LoopTextModel

[[autodoc]] Inkling2LoopTextModel
- forward

## Inkling2LoopForCausalLM

[[autodoc]] Inkling2LoopForCausalLM
- forward

## Inkling2LoopModel

[[autodoc]] Inkling2LoopModel
- forward

## Inkling2LoopForConditionalGeneration

[[autodoc]] Inkling2LoopForConditionalGeneration
- forward
21 changes: 21 additions & 0 deletions src/transformers/conversion_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,27 @@ def _build_checkpoint_conversion_mapping():
),
]

# Looped Inkling2: the Inkling2 layout plus the loop core's message controllers and message queries. Renamed
# first, before Inkling2's `.attn.` -> `.self_attn.` would also catch `controllers.attn.`
mapping["inkling2_loop"] = mapping["inkling2"].copy()
mapping["inkling2_loop_text"] = [
WeightRenaming(source_patterns=r"controllers\.attn\.", target_patterns=r"q_controller."),
WeightRenaming(source_patterns=r"controllers\.k\.", target_patterns=r"k_controller."),
WeightRenaming(source_patterns=r"controllers\.v\.", target_patterns=r"v_controller."),
WeightRenaming(source_patterns=r"controllers\.mlp\.", target_patterns=r"mlp_controller."),
WeightRenaming(source_patterns=r"_controller\.down_weight", target_patterns=r"_controller.down_proj.weight"),
WeightRenaming(source_patterns=r"_controller\.gain_weight", target_patterns=r"_controller.gain_proj.weight"),
WeightRenaming(
source_patterns=r"_controller\.forget_weight", target_patterns=r"_controller.forget_proj.weight"
),
WeightRenaming(
source_patterns=r"middle_cycle_cross_pass_queries", target_patterns=r"cross_pass_messages.queries"
),
WeightRenaming(
source_patterns=r"middle_cycle_cross_pass_kv_queries", target_patterns=r"cross_pass_messages.kv_queries"
),
] + mapping["inkling2_text"].copy()

for model_type, base_pattern in _MODEL_TO_CONVERSION_PATTERN.items():
if model_type in mapping:
continue
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
from .informer import *
from .inkling import *
from .inkling2 import *
from .inkling2_loop import *
from .instructblip import *
from .instructblipvideo import *
from .internlm3 import *
Expand Down
3 changes: 3 additions & 0 deletions src/transformers/models/auto/auto_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@
("imagegpt", "ImageGPTConfig"),
("informer", "InformerConfig"),
("inkling2", "Inkling2Config"),
("inkling2_loop", "Inkling2LoopConfig"),
("inkling2_loop_text", "Inkling2LoopTextConfig"),
("inkling2_text", "Inkling2TextConfig"),
("inkling2_vision", "Inkling2VisionConfig"),
("inkling_audio", "InklingAudioConfig"),
Expand Down Expand Up @@ -952,6 +954,7 @@
("idefics3_vision", "idefics3"),
("idefics_perciever", "idefics"),
("idefics_vision", "idefics"),
("inkling2_loop_text", "inkling2_loop"),
("inkling2_text", "inkling2"),
("inkling2_vision", "inkling2"),
("inkling_audio", "inkling"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/image_processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
{"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"},
),
("ijepa", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
("inkling2_loop", {"torchvision": "Inkling2ImageProcessor"}),
("inkling_mm_model", {"torchvision": "InklingImageProcessor"}),
("instructblip", {"torchvision": "BlipImageProcessor", "pil": "BlipImageProcessorPil"}),
("internvl", {"torchvision": "GotOcr2ImageProcessor", "pil": "GotOcr2ImageProcessorPil"}),
Expand Down
5 changes: 5 additions & 0 deletions src/transformers/models/auto/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("imagegpt", "ImageGPTModel"),
("informer", "InformerModel"),
("inkling2", "Inkling2Model"),
("inkling2_loop", "Inkling2LoopModel"),
("inkling2_loop_text", "Inkling2LoopTextModel"),
("inkling2_text", "Inkling2TextModel"),
("inkling2_vision", "Inkling2VisionModel"),
("inkling_mm_model", "InklingModel"),
Expand Down Expand Up @@ -704,6 +706,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("idefics2", "Idefics2ForConditionalGeneration"),
("idefics3", "Idefics3ForConditionalGeneration"),
("inkling2", "Inkling2ForConditionalGeneration"),
("inkling2_loop", "Inkling2LoopForConditionalGeneration"),
("inkling_mm_model", "InklingForConditionalGeneration"),
("janus", "JanusForConditionalGeneration"),
("layoutlm", "LayoutLMForMaskedLM"),
Expand Down Expand Up @@ -865,6 +868,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("hy_v3", "HYV3ForCausalLM"),
("hy_v4", "HYV4ForCausalLM"),
("hyperclovax", "HyperCLOVAXForCausalLM"),
("inkling2_loop_text", "Inkling2LoopForCausalLM"),
("inkling2_text", "Inkling2ForCausalLM"),
("inkling_text", "InklingForCausalLM"),
("internlm3", "LlamaForCausalLM"),
Expand Down Expand Up @@ -1215,6 +1219,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("idefics2", "Idefics2ForConditionalGeneration"),
("idefics3", "Idefics3ForConditionalGeneration"),
("inkling2", "Inkling2ForConditionalGeneration"),
("inkling2_loop", "Inkling2LoopForConditionalGeneration"),
("inkling_mm_model", "InklingForConditionalGeneration"),
("instructblip", "InstructBlipForConditionalGeneration"),
("instructblipvideo", "InstructBlipVideoForConditionalGeneration"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
("granite_speech_plus", "GraniteSpeechProcessor"),
("groupvit", "CLIPProcessor"),
("hubert", "Wav2Vec2Processor"),
("inkling2_loop", "Inkling2Processor"),
("inkling_mm_model", "InklingProcessor"),
("lasr_ctc", "LasrProcessor"),
("lasr_encoder", "LasrProcessor"),
Expand Down
33 changes: 33 additions & 0 deletions src/transformers/models/inkling2_loop/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# This file was automatically generated from the modules in `src/transformers/models/inkling2_loop`.
# Do NOT edit this file manually as any edits will be overwritten by auto-generation of the file.
# A module is picked up once it exports a name through `__all__`.
# Regenerate the file with: `python utils/check_inits.py --fix_and_overwrite`
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# Copyright 2026 the HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_inkling2_loop import *
from .modeling_inkling2_loop import *
else:
import sys

_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
Loading