laguna: load the public checkpoint layouts (original poolside + repacks) - #1704
Open
pierre427 wants to merge 1 commit into
Open
laguna: load the public checkpoint layouts (original poolside + repacks)#1704pierre427 wants to merge 1 commit into
pierre427 wants to merge 1 commit into
Conversation
The laguna module added in ml-explore#1334 loads checkpoints whose keys already match its module tree, but the public checkpoints on the Hub use two other layouts, and both fail load_weights(strict=True): - poolside/Laguna-S-2.1-bf16 (the original layout): experts stored individually (mlp.experts.N.{gate,up,down}_proj) rather than stacked for SwitchGLU, and the router correction bias under mlp.experts.e_score_correction_bias. - AtomicChat/Laguna-XS-2.1-MLX-8bit and mlx-community/Laguna-XS-2.1-bf16: every tensor wrapped in a VLM-style language_model. prefix, and the router stored as a Linear (mlp.gate.proj.weight) - quantized to weight/scales/biases in the 8-bit repack. This adds a sanitize() covering both layouts, and stores the router as an nn.Linear (gate.proj) so quantized routers load directly; the bare gate.weight layout (including conversions made with the current module) is mapped onto it by sanitize. Router math is unchanged. Verified on all three public checkpoints (strict lazy load), plus a full CPU materialization and greedy continuation on the 8-bit repack. New test_laguna_sanitize covers the three layouts on a tiny config. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
lagunamodule from #1334 loads checkpoints whose keys already match its module tree, but the public Laguna checkpoints on the Hub use two other layouts, and all of them currently failload_weights(strict=True):Original poolside layout (
poolside/Laguna-S-2.1-bf16): experts are stored individually rather than stacked forSwitchGLU, and the router correction bias lives underexperts.:Public repacks (
AtomicChat/Laguna-XS-2.1-MLX-8bit,mlx-community/Laguna-XS-2.1-bf16): every tensor is wrapped in a VLM-stylelanguage_model.prefix, and the router is stored as a Linear (mlp.gate.proj.weight) — quantized toweight/scales/biasesin the 8-bit repack:Changes
Model.sanitize(): strips thelanguage_model.prefix, stacks individually-stored experts into theSwitchGLUlayout, and remapsexperts.e_score_correction_bias→gate.e_score_correction_bias.MoEGatestores the router as annn.Linear(gate.proj) instead of a bare matrix, so quantized routers (the 8-bit repack ships one) load directly — a bare matrix can't hold aweight/scales/biasestriple, andnn.quantizecan't target it either, somlx_lm.convert -qon a Laguna checkpoint currently leaves the router unquantizable. The baregate.weightlayout (the original checkpoint, and any conversion made with the current module) is mapped ontogate.proj.weightbysanitize(), so existing conversions keep loading. Router math is unchanged.Verification
AtomicChat/Laguna-XS-2.1-MLX-8bit(33B, quantized router):def quicksort(arr):→"\n if len(arr) <=".test_laguna_sanitizeexercises the three layouts (native / prefixed / original per-expert) on a tiny config with strict loading and a forward pass;test_all_modelsstill passes.🤖 Generated with Claude Code