Skip to content

model: add Beam (Reflection) - #281

Open
danielhanchen wants to merge 23 commits into
base/upstream-620d2225cfrom
pin-model-arch-fixes
Open

danielhanchen wants to merge 23 commits into
base/upstream-620d2225cfrom
pin-model-arch-fixes

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Adds support for Reflection's Beam-1.0-501B-A23B (HF BeamForCausalLM): converter, model graph and a chat parser for its tool-call format.

Architecture

subsystem how it is handled
MoE, 256 experts, top-8, sigmoid routing with grouped selection build_moe_ffn; correction bias used for selection only, routed scale and normalised weights required in the GGUF
3 leading dense SwiGLU layers standard FFN path
Interleaved sliding-window (512) and NoPE full-attention layers iSWA cache; RoPE (NeoX) on the sliding layers only
Power-law query scale on the NoPE layers optional form of llm_graph_input_attn_temp, off by default
q/k RMSNorm, per-head sigmoid output gate, scaled residuals, final logit softcap in src/models/beam.cpp
Tool calls (<|channel|> + <|constrain|>xml + rfl:parameter) new harmony-xml chat parser, detected only when all three markers are present

No new ggml op.

Correctness

  • Reference parity on a tiny random checkpoint with the real layer pattern, tokenizer and routing constants, against the transformers implementation in fp32: top-1 agreement and selected-expert Jaccard 1.0 on 64, 600 and 2000 token prompts; max logit difference 6.8e-5 / 5.2e-4 / 2.0e-3.
  • test-llama-archs -a beam: OK on CPU, CUDA and Meta. test-chat, test-jinja pass.
  • Real weights: the 501B checkpoint converts, and quantized GGUFs load and generate on CUDA. Chat template renders byte-identical to apply_chat_template; multi-turn tool-call sessions (parallel calls, typed and nested arguments, long logs) pass end to end through llama-server.
  • Malformed GGUFs (missing routing keys, no sliding layer, zero temperature scale) fail at load instead of at the first decode.

Effect on other architectures

  • llama-graph.cpp: the power-law temperature is a separate branch; existing users take the old path. llm_graph_input_attn_temp gains a shape-only can_reuse, since set_input recomputes the scale every ubatch.
  • llama-vocab.cpp: Beam's </s> stays a normal token (it is plain text in its tokenizer), using the existing gemma4/plamo exception keyed on a Beam-only token. Token ids, EOG sets and attributes are unchanged on 19 upstream test vocabs and 224 local GGUFs.
  • common/jinja: the list filter accepts objects (returns the keys).
  • common/chat.cpp: the new parser is only selected for templates containing all three markers.

AI Usage

Used Claude and Local Models for testing, iteration and code design - manual verification of model / PR usage

@danielhanchen
danielhanchen requested a review from CISC as a code owner October 16, 2026 05:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T05:59:40.002556Z cfb9f2c PR opened
🔒 Security Review ✅ Completed 2026-10-16T05:52:35.300608Z cfb9f2c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfb9f2cecb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread conversion/beam.py Resolved
Comment thread src/models/beam.cpp Resolved
Comment thread src/models/beam.cpp Resolved
Comment thread src/models/beam.cpp Resolved
Harmony templates whose tool calls carry <|constrain|>xml bodies with
rfl:parameter arguments were detected as gpt-oss, whose parser expects
JSON arguments behind to=functions.NAME. Every tool call failed to parse
and the lazy grammar pushed the model towards the wrong call format.

Add a dedicated handler, detected ahead of the gpt-oss check:
- reasoning and final channels parse as before
- one or more calls (<|end|> between parallel calls), arguments typed
  from the tool schema, a missing closing tag tolerated
- lazy grammar triggered on the call header, eager for tool_choice=required
- end-of-generation tokens are preserved so the parser sees where the
  last call ends; output cut off mid-call keeps the call open

Tests cover the reference parser corpus plus streaming, typed arguments,
parallel calls and structured output.
When rope_parameters is absent, take the sliding-attention rope params from
the values TextModel already normalized instead of replacing them with empty
dicts, so rope.freq_base is still written.
Without them the generic defaults silently skip the routed scaling and the
top-k renormalization; the converter always writes both keys.
The beam graph always builds the iSWA cache, which asserts is_swa_any() at
context creation; fail at load time and in the converter instead.
The attn temp input asserts a nonzero scale on the first decode, so a file
that sets it to zero now fails to load instead of aborting later.
@danielhanchen danielhanchen changed the title Model arch fixes model: add Beam (Reflection) Oct 16, 2026
danielhanchen added a commit that referenced this pull request Oct 16, 2026
ggml-org#30670 is the upstream PR for the same change (one squashed commit, identical changed lines).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant