Skip to content

Add a tiny Laguna model - #8589

Open
albertvillanova wants to merge 1 commit into
mainfrom
tiny-laguna
Open

albertvillanova wants to merge 1 commit into
mainfrom
tiny-laguna

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

This PR adds a generation script for trl-internal-testing/tiny-LagunaForCausalLM, based on poolside/Laguna-XS.2.

Part of #7943.

Motivation

Laguna is only covered by the parsing tests, which borrow another tokenizer (#8511 (review)). A tiny Laguna model lets it join the model parametrizations (SFT, GRPO with tools, the training template suite) like the other families. The stacked PR above it, #8511, uses this model.

Changes

  • Add laguna_for_causal_lm.py, which generates tiny-LagunaForCausalLM with the tokenizer and generation config of poolside/Laguna-XS.2. Laguna was added in transformers 5.7.0, but before 5.16.0 the order in which its rotary embedding registers the per-layer-type buffers comes from a set, so building the model fails at random (fixed in deterministic layer_types buffer registration in multiple models transformers#48162). The script pins 5.16.0.

Alignment with the reference

Dry run at transformers 5.16.0, with the real save and only the Hub calls stubbed. The config diff against poolside/Laguna-XS.2 has 16 keys:

  • size reductions: hidden_size 2048 → 8, intermediate_size 8192 → 32, num_attention_heads 48 → 4, num_key_value_heads 8 → 2, head_dim 128 → 8, num_experts 256 → 4, num_experts_per_tok 8 → 2, moe_intermediate_size 512 → 32, shared_expert_intermediate_size 512 → 32
  • 2 layers, the first two of the reference: num_hidden_layers 40 → 2, layer_types [full_attention, sliding_attention], mlp_layer_types [dense, sparse], num_attention_heads_per_layer [4, 8] (the sliding attention layers keep more heads than the full attention ones)
  • auto_map: dropped, the model is the transformers LagunaForCausalLM
  • top-level partial_rotary_factor (0.5): dropped. LagunaConfig writes it over the per-layer-type value of the sliding attention layers (1.0), while the model only reads the per-layer-type values in rope_parameters, which match the reference.

Every other key is the same as the reference, and all tensors have the reference dtype. The reloaded saved files run a forward pass and generate at transformers 5.16.0 and 5.22.0.


Note

Low Risk
Adds an isolated generation script with no changes to training, inference, or library runtime code.

Overview
Adds laguna_for_causal_lm.py to the tiny-model generator suite, producing tiny-LagunaForCausalLM with tokenizer and generation config from poolside/Laguna-XS.2.

The script shrinks the reference architecture to two layers (full attention + dense MLP, then sliding attention + sparse MoE), applies the usual _common checks (smoke_test, dtype pattern, config diff, Hub push), and pins transformers 5.16.0 because earlier versions can fail nondeterministically when building Laguna’s per-layer rotary buffers.

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

@github-actions github-actions Bot added the 🔧 maintenance CI, tooling, tests, or repo upkeep label Nov 25, 2026
@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.

This branch has not been deployed

No deployments
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.

1 participant