Skip to content

model: add Nanbeige4.2 (Looped Transformer) support#99

Open
Andgihat wants to merge 1 commit into
Anbeeld:mainfrom
Andgihat:nanbeige-v0.4.0
Open

model: add Nanbeige4.2 (Looped Transformer) support#99
Andgihat wants to merge 1 commit into
Anbeeld:mainfrom
Andgihat:nanbeige-v0.4.0

Conversation

@Andgihat

Copy link
Copy Markdown

Adds support for the Nanbeige4.2 architecture (Nanbeige/Nanbeige4.2-3B, Apache-2.0) — a Looped Transformer: the physical decoder layers are reused num_loops times, so effective depth grows without adding parameters (22 physical layers × num_loops=2 → 44 effective).

What's included

  • New arch LLM_ARCH_NANBEIGE + KV keys nanbeige.num_loops / nanbeige.skip_loop_final_norm.
  • Graph builder src/models/nanbeige.cpp: standard RMSNorm + GQA + SwiGLU decoder, with the loop unrolled over logical layers. Physical weights are shared across loops via pointer copies (layers[i + j*n_phys] = layers[i]), while each logical slot keeps its own KV index. An optional loop-boundary output_norm is applied between passes unless skip_loop_final_norm is set.
  • gguf-py constants + writer keys and a conversion/nanbeige.py converter.

Integration with this fork's hparams

This fork carries a single n_layer field (rather than a separate physical/logical pair). load_arch_hparams expands n_layer to the logical count (n_layer_phys * num_loops) before tensors/KV are allocated, and replicates the per-layer arrays (n_head, n_head_kv, n_ff, swa/recurrent flags) across the loop copies. This keeps the graph loop, KV cache, and out-ids handling correct without touching the base hparams API. Pure graph/arch code — no new ggml kernels.

Verification

Built for Windows/CUDA 12.8 (sm_120) and compared token-for-token against the authors' reference branch Nanbeige/llama.cpp@nanbeige42 on the same BF16 GGUF with greedy decoding: outputs are identical (48/48 tokens). Q8_0 / Q4_K_M / imatrix quants run and produce coherent output with the embedded chat template.

GGUF quants (incl. an imatrix + mixed-precision Q4) and a prebuilt Windows CUDA release are available at Andgihat/Nanbeige4.2-3B-GGUF.

Port the Nanbeige4.2 architecture from Nanbeige/llama.cpp (branch
nanbeige42, commit 26cfdc4) onto BeeLlama v4.0. Looped transformer
reuses layers via num_loops; no new ggml ops (pure graph/arch level).

Adds: nanbeige arch enum + KV keys (num_loops, skip_loop_final_norm),
model class + graph builder (src/models/nanbeige.cpp), GGUF conversion
(conversion/nanbeige.py), and the larger graph-node budget in
graph_max_nodes for the expanded looped layer stack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant