Add Nanbeige (Nanbeige4.2 looped transformer) model support - #1597
Open
MercuriusDream wants to merge 3 commits into
Open
Add Nanbeige (Nanbeige4.2 looped transformer) model support#1597MercuriusDream wants to merge 3 commits into
MercuriusDream wants to merge 3 commits into
Conversation
Author
|
Is anyone there? |
zcbenz
reviewed
Aug 21, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
Would mind rewriting the PR description following our new template?
https://github.com/ml-explore/mlx-lm/blob/main/.github/PULL_REQUEST_TEMPLATE/new_model.md?plain=1
It would help me verify the implementation much quicker.
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.
Adds the
nanbeigemodel type used by Nanbeige/Nanbeige4.2-3B.The architecture is a llama-style decoder executed
num_loopstimes with shared weights ("Looped Transformer"). Each loop gets its own KV cache entries and the final RMSNorm is applied at the end of each loop (or once at the end whenskip_loop_final_normis set).Correctness:
modeling_nanbeige.py(fp32, CPU) to a max abs diff of 9.5e-05 over the full 166k vocab.Config flags of the reference implementation not used by the released checkpoint (
enable_double_loop_split,loop_share_kv,enable_depth_attention) raiseNotImplementedErrorinstead of loading silently. Checkpoints using n-gram embeddings or mHC fail naturally on unexpected weight keys.Added a
test_nanbeigecase totests/test_models.py; the suite passes apart from the pre-existingtest_ssmfailure onmain.