Skip to content

Add a tiny Inkling model - #8512

Merged
albertvillanova merged 3 commits into
mainfrom
tiny-inkling
Nov 24, 2026
Merged

albertvillanova merged 3 commits into
mainfrom
tiny-inkling

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

This PR adds a generation script for trl-internal-testing/tiny-InklingForConditionalGeneration, based on thinkingmachines/Inkling.

Part of #7962.

Motivation

The stacked PR above it adds Inkling chat template support and tests it on this tiny model. Inkling's markers (<|message_model|>, <|content_model_end_sampling|>, ...) are single special tokens of its own tokenizer, so the tests need it: with another tiny tokenizer they are split into plain text and the mask boundaries move.

Changes

  • Add inkling_for_conditional_generation.py, which generates tiny-InklingForConditionalGeneration at transformers 5.14.0 (where Inkling was introduced), with the reference processor and tokenizer.
  • 4 text layers, so that each per-layer pattern of the reference appears: sliding-window layers then a global one, and dense MLP layers then sparse ones.
  • The router bias and global scale stay in float32, as in the reference.

Alignment with the reference

Dry run at transformers 5.14.0, with the real save and only the Hub calls stubbed. Of the 59 keys of the reference config, 40 are the same, 5 are stored under their transformers name (model_max_length, sconv_kernel_size, dense_mlp_idx, dense_intermediate_size, torch_dtype, converted the same way when the reference loads), and the rest are size reductions and the fields derived from them:

  • hidden_size 6144 → 16, num_hidden_layers 66 → 4, local_layer_ids → [0, 1, 2]
  • num_attention_heads 64 → 4, num_key_value_heads 8 → 2, head_dim 128 → 8
  • swa_num_attention_heads 64 → 4, swa_num_key_value_heads 16 → 2, swa_head_dim 128 → 8
  • n_routed_experts 256 → 4, num_experts_per_tok 6 → 2, expert and dense MLP sizes → 32
  • audio and vision decoder_dmodel 6144 → 16 (the text width)

All tensors have the reference dtype. The reloaded saved files run a forward pass at transformers 5.14.0 and 5.22.0.

Notes

  • The vision tower holds 25M of the 31M parameters: its widths follow from patch_size 40, which the image processor's 40x40 size shares, so both stay as in the reference.
  • The reference tokenizer has no pad token; the smoke test sets one on a copy of the processor, so the pushed tokenizer stays as the reference's.
  • The smoke test runs before the cast to bfloat16: the Inkling vision tower does not cast the float32 pixel_values to the model dtype.
  • Building the vision tower needs scipy.

The model does not exist on the Hub yet: it will be generated with this script once the script is approved.


Note

Low Risk
Only adds a Hub generation script and a test fixture revision pin; no changes to training, auth, or core library runtime paths.

Overview
Adds a tiny-model generation script for InklingForConditionalGeneration that builds trl-internal-testing/tiny-InklingForConditionalGeneration from thinkingmachines/Inkling, reusing the reference processor/tokenizer while shrinking text, audio, vision, and MoE settings so reference layer patterns (sliding-window vs global, dense vs sparse MLP) still appear in four layers.

The script follows the usual tiny-model flow: init weights, smoke test (with a copied processor that adds a pad token only for batching), cast to bfloat16, keep MoE router bias/global scale in float32, then validate dtypes, print config diff, and push to the Hub.

Tests pin the new Hub artifact in MODEL_REVISIONS so CI loads a fixed commit for Inkling chat-template and related coverage.

Reviewed by Cursor Bugbot for commit 4ce7c3d. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c7f9c93. Configure here.

# The reference tokenizer has no pad token, which smoke_test needs to batch its two conversations: set one on a copy, so
# the pushed tokenizer stays as the reference's. The test runs before the cast to bfloat16 because the vision tower does
# not cast the float32 `pixel_values` to the model dtype.
smoke_processor = copy.deepcopy(processor)

@AmineDiro AmineDiro Nov 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to change, if we support a custom template for the model?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: the tiny model keeps the reference tokenizer and chat template as they are, because TRL replaces the template with its training version only when it matches the Hub one exactly (#8513), so the tiny model must ship the original. The copy only adds a pad token for the smoke test's batching; the pushed tokenizer is unchanged.

@AmineDiro AmineDiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts with : #8498

@albertvillanova

albertvillanova commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

Thanks, @AmineDiro! These are two different models, so I don't think they conflict:

  • This PR: Inkling (thinkingmachines/Inkling, InklingForConditionalGeneration, models/inkling, transformers 5.14.0): text + audio + vision towers
  • Add a tiny Inkling 2 model and run it in the VLM tests #8498: Inkling 2 (thinkingmachines/Inkling-2-Small-MXFP8, Inkling2ForConditionalGeneration, models/inkling2, transformers 5.23.0)

They have different configs, weights and chat templates, and each tiny model goes to its own repo. The PRs also share no files: this one only adds inkling_for_conditional_generation.py, and both this PR and #8513 merge cleanly on top of #8498.

@AmineDiro

Copy link
Copy Markdown
Member

Oh my bad ! sorry

@albertvillanova

Copy link
Copy Markdown
Member Author

The model has been generated with this PR's script: https://huggingface.co/trl-internal-testing/tiny-InklingForConditionalGeneration

#8513 runs the Inkling training template tests on it.

@albertvillanova
albertvillanova merged commit f0f778d into main Nov 24, 2026
12 checks passed
@albertvillanova
albertvillanova deleted the tiny-inkling branch November 24, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔧 maintenance CI, tooling, tests, or repo upkeep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants