model: add Nanbeige4.2 (Looped Transformer) support#100
Open
Andgihat wants to merge 1 commit into
Open
Conversation
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 support for the Nanbeige4.2 architecture (Nanbeige/Nanbeige4.2-3B, Apache-2.0) — a Looped Transformer: the physical decoder layers are reused
num_loopstimes, so effective depth grows without adding parameters (22 physical layers ×num_loops=2→ 44 effective).Rebased onto current
main, so the diff is a single clean commit.What's included
LLM_ARCH_NANBEIGE+ KV keysnanbeige.num_loops/nanbeige.skip_loop_final_norm.src/models/nanbeige.cpp: standard RMSNorm + GQA + SwiGLU decoder with the loop unrolled over the logical (n_layer_all) layers. Physical weights are shared across loops via pointer copies (layers[i + j*n_phys] = layers[i]); each logical slot keeps its own KV index. An optional loop-boundaryoutput_normis applied between passes unlessskip_loop_final_normis set.gguf-pyconstants + writer keys and aconversion/nanbeige.pyconverter.load_arch_hparamsexpands the logical layer count via the existingn_layer(physical) /n_layer_all(logical) fields and replicates the per-layer arrays (n_head,n_head_kv,n_ff,is_swa_impl,is_recr_impl) across the loop copies, so the graph loop, KV cache and out-ids all size correctly with no changes to the base hparams API.Verification
Built for Windows/CUDA 12.8 (
sm_120) on top of currentmainand compared token-for-token against the authors' reference branchNanbeige/llama.cpp@nanbeige42on the same BF16 GGUF with greedy decoding — outputs are identical. Runs correctly with KVarN KV-cache (e.g.-ctk kvarn3 -ctv kvarn3) and long context.GGUF quants (imatrix + KLD-guided mixed precision) are available at Andgihat/Nanbeige4.2-3B-GGUF.