Skip to content

🔨 feat(model): add BailingMoeV3 (Ling 3.0) support - #63

Merged
worthant merged 4 commits into
masterfrom
feat/bailingmoe3
Aug 5, 2026
Merged

worthant merged 4 commits into
masterfrom
feat/bailingmoe3

Conversation

@worthant

@worthant worthant commented Aug 4, 2026

Copy link
Copy Markdown

Adds support for inclusionAI/Ling-3.0-flash (BailingMoeV3ForCausalLM, model_type: bailing_hybrid) as a new bailingmoe3 architecture.

Model

124B total / 5.1B active. 42 decoder blocks:

  • 35 KDA (linear attention) layers, 7 gated MLA layers, interleaved 5:1 (layer_group_size = 6)
  • MoE with 512 routed experts (top-8, group-limited routing over 8 groups, 4 used), sigmoid router with expert bias, 1 shared expert
  • dense FFN on the first 2 blocks
  • one MTP block, dropped during conversion

Implementation

The KDA + MLA layout is shared with KIMI_LINEAR, so the linear path reuses the existing gated delta net operator. A separate arch was needed for four differences:

Kimi Linear Ling 3.0
KDA forget/output gates low-rank f_a/f_b, g_a/g_b full-rank f_proj/g_proj (no_kda_lora)
KDA log-decay unclamped clamped from below (kda_safe_gate, kda_lower_bound = -5.0)
MLA positional encoding NoPE partial RoPE, 64 of 192 dims, rope_theta = 6e6
MLA output plain head-wise sigmoid gate before the output projection

On RoPE: the reference implementation rotates de-interleaved pairs (view(d/2, 2).transpose() followed by rotate_half), which is equivalent to the NORM rope type on the original layout. The permutation stays inside the rope slice and cancels in q * k, so no weight reordering is needed in the converter.

The tokenizer is byte-identical to Ling 2.0, so the existing bailingmoe2 pre-tokenizer applies unchanged.

Status

  • conversion covers every tensor of the checkpoint (checked against model.safetensors.index.json)
  • BF16 GGUF loads and generates coherent output on CPU
  • numerical validation against the HF reference (per-layer diff, then KL divergence on logits) is in progress; quantized builds should wait for it

Test

python convert_hf_to_gguf.py /path/to/Ling-3.0-flash --outtype bf16 --outfile Ling-3.0-flash-BF16.gguf
llama-cli -m Ling-3.0-flash-BF16.gguf -ngl 0 -c 512 -n 32 --temp 0 -no-cnv -p "The capital of France is"

Ling-3.0-flash is a 124B total / 5.1B active hybrid-linear MoE: 35 KDA
(linear attention) layers interleaved 5:1 with 7 gated MLA layers, on top
of a bailing MoE with 512 routed experts (group-limited sigmoid routing,
8 groups / 4 used) and 1 shared expert. Dense FFN on the first 2 blocks.

The layout is shared with KIMI_LINEAR, so the KDA path reuses the existing
gated delta net operator. Differences that required a separate arch:

- full-rank KDA forget/output gate projections (config: no_kda_lora),
  new ssm_f / ssm_g tensors instead of the low-rank a/b pairs
- the KDA log-decay is clamped from below (config: kda_safe_gate,
  kda_lower_bound = -5.0)
- MLA layers apply partial RoPE. HF rotates de-interleaved pairs, which is
  equivalent to the NORM rope type here, as the permutation cancels in q*k
- MLA layers carry a head-wise sigmoid output gate applied to the attention
  output before the output projection

The MTP block is dropped during conversion. The tokenizer is identical to
Ling 2.0, so the existing bailingmoe2 pre-tokenizer is reused.

Converts and runs: BF16 GGUF loads and generates coherent output on CPU.
Numerical validation against the HF reference is still in progress.
The KDA kernel switches the whole gate activation when a lower bound is
configured, it does not clamp the softplus form (fla/ops/kda, both the
chunked and the recurrent kernel):

    lower_bound * sigmoid(exp(A_log) * (g + dt_bias))    if lower_bound
    -exp(A_log) * softplus(g + dt_bias)                  otherwise

Ling 3.0 sets kda_safe_gate with kda_lower_bound = -5.0, so it takes the
first branch. The conversion script now stores exp(A_log) rather than
-exp(A_log), and the bound is carried in a new kda.lower_bound key.

Measured against a layer-by-layer HF reference forward (32 tokens, bf16),
mean KL over the vocabulary drops from 2.98e-2 to 4.8e-4, and the cosine
similarity of the first block output rises from 0.9959 to 0.99999.
The arch declared its own LLM_KV_KDA_LOWER_BOUND but never registered a
name for it, so llama_model_load threw map::at before reading the file.
Kimi K3 already carries the same safe gate with kda.gate_lower_bound,
hparams.kda_gate_lower_bound and add_kda_gate_lower_bound, so drop the
duplicate key, hparam and writer helper and use the existing ones.

Both models compute the same decay, so sharing the key keeps a single
spelling for it in the GGUF:

    g = gate_lower_bound * sigmoid(exp(A_log) * (g_raw + dt_bias))
test-llama-archs builds a tiny model per architecture from a generic set of
hyperparameters. bailingmoe3 cannot be described that way: the layer types come
from a per-layer head_kv array and the loader needs the MLA and KDA keys, so the
generated dense fixture fails to load and takes test-generate-models and the
recurrent-state-rollback fixture down with it.

Kimi K3 is skipped for the same reason.
@worthant
worthant merged commit 889e9d0 into master Aug 5, 2026
17 checks passed
NighmareGit added a commit to NighmareGit/atomic-llama-cpp-turboquant that referenced this pull request Aug 13, 2026
Brings E-1 (generation-salted RPC uid, BUG-002a fix) + stable-uid default ON
(da02606 flip) into the fabric branch so the E3 re-run is un-confounded
(the original E3 coherence-gate KILL ran on the default-uid path corrupted by
BUG-013/002a - LEDGER AtomicBot-ai#61 vs AtomicBot-ai#63/AtomicBot-ai#65).

Conflict resolution (ggml-backend.cpp, both hunks resolved to good-prototype):
- ggml_sched_rpc_stable_uid: default ON (unset -> ON, =0 opt-out)
- split_graph uid: E-1 salted uid = topo_hash ^ (uid_generation * golden_ratio)

Fabric E3 wiring (3c56bb0: layer assignment, inner-sched, FABH hop, logits
routing, --rpc-fabric) preserved intact via auto-merge.
NighmareGit added a commit to NighmareGit/atomic-llama-cpp-turboquant that referenced this pull request Aug 13, 2026
The server-side s_copy probe (added in E-1 d0fff25) logged cached-graph I32
leaf tensors on every recompute (~30+ lines/token spam). Purpose served: the
E-1 verification's server RPC_DEBUG command stream already discriminated M1
(stale binding) vs M2 (verify write-back); LEDGER AtomicBot-ai#63 recommends the revert.
No behavior change on the compute path - removes only the fprintf block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant