Skip to content

[Engine] Ling 3.0 Flash and Tiny (bailingmoe3) - #201

Open
yudhanjaya wants to merge 2 commits into
simplexai-labs:mainfrom
yudhanjaya:ling3
Open

yudhanjaya wants to merge 2 commits into
simplexai-labs:mainfrom
yudhanjaya:ling3

Conversation

@yudhanjaya

@yudhanjaya yudhanjaya commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Title

Ling 3.0 flash and tiny (bailingmoe3) support; first asked for in #1

Summary

This is ling3.cpp, a strata-poly engine for llama.cpp's bailingmoe3 architecture which covers both Ling 3.0 Flash (124B, 5.1B active) and Ling 3.0 Tiny.

It works! Built from llama.cpp's graph (src/models/bailingmoe3.cpp) and tested on my PC (Linux, RTX 4080 SUPER 16 GB + RTX 3080 10 GB, Ryzen 7 5800X3D, 62 GB of RAM), Flash Q4_K_M at a 128K context on a layer split.

Comapred vs llama.cpp (PR #32517 build, --fit, 4,096-token batches) on the same file:

Writes new prompts Reads an 88K prompt Writes after it
PolyStrata (--prompt-batch 512 --no-draft) 30.9 / 35.5 tok/s 733 tok/s 20.0 tok/s
llama.cpp 22.7 tok/s (24.8 with its draft block) 463 tok/s 22.4 tok/s

On the 4080 SUPER alone on the polystrata benchmark (polystrata.py benchmark --prompt-tokens 24000, 32K): 835-1,048 tok/s reading the prompt, 6.6-13.0 writing after it.

Numbers on that first "writes new prompt" row are the lowest I saw and the highest I saw over several runs. Lowest was when I was while watching a GamersNexus video on Chrome with like 30 tabs open, so that's most of the variation right there; the cpu had other work to do.

includes a setup family for Flash.

Changes

  • src/poly/ling3.cpp, ling3.hpp: the engine.
    • MLA layers: the cache row is the RMS-normed 512-value latent plus the 64 rotary values, used as key and value;
      the query's non-rotary part goes through attn_k_b and the output's latent through attn_v_b, so the existing
      attend() / attend_batch() run it as one 576-wide key head. A per-head sigmoid output gate (attn_gate).
      Tiny's low-rank query (attn_q_a, attn_q_a_norm, attn_q_b).
    • KDA layers: GLM 5.3 Flash's kernels, with the full-rank decay (ssm_f_a + ssm_dt.bias) and output gate
      (ssm_g_a).
    • Routing on the host: sigmoid gates + exp_probs_b, the best 4 of 8 groups by their top-two sums, 8 experts,
      normalised and x2.5; one shared expert; dense lead layers.
    • Flash's blk.42.nextn runs as the engine's MTP block (nextn.shared_head_norm read from
      layer_output_norm).
  • src/poly/engine.cpp, CMakeLists.txt, metal/CMakeLists.txt: the engine named and built.
  • tools/strata_tokenizer.py: llama.cpp's bailingmoe pre-tokenizer pattern (the GGUFs say bailingmoe2).
  • serve/models.py, tools/strata_inspect.py: the architecture.
  • setup.py: family ling3, Ling 3.0 Flash from bloomer010's GGUFs (Q4_K_M, Q3_K_M, UD-Q2_K_XL), pinned to
    commit 3797301d and checked against their SHA-256; its configs pass --no-draft. A small no_draft family key adds
    that flag in poly_setup.
  • docs/models/ling3.md, docs/BACKENDS.md (what runs, the parity table, how it was checked), README.md
    (English only; I haven't touched the translations).
  • tools/test_setup_ling3.py, and tools/test_setup_menu.py's family order.

Extra Notes

Test proof (Linux, CUDA 13.0, sm_86 + sm_89, branch tip on main 3e16421):

  • Builds: strata-poly, poly_draft_race_test, poly_gdn_mma_state_test; no compiler warnings from ling3.cpp.

  • Parity against llama.cpp, five chat prompts of 35 to 8,036 tokens, 64 tokens each, top-5 probabilities:

    Same tokens (of 64) Largest probability difference
    Flash Q4_K_M 9, 18, 0, 33, 3 0.28
    Flash, draft block on 17, 51, 0, 33, 64 0.26
    Flash, every expert on the CPU 17, 64, 14, 33, 64 0.21
    Tiny Q4_K_M 14, 64, 64, 55, 14 0.19
    Tiny, every expert on the CPU 14, 10, 64, 10, 64 0.11

    Tiny's six departures and 8 of Flash's 12 are at a near tie. The other four are Flash's: the 4,034-token prompt at
    its 34th token in all three rows (llama.cpp 0.57 / 0.43, this engine 0.60-0.69 for the second), and the 8,036-token
    prompt at its 4th without the draft block. llama.cpp itself, with 512-token batches instead of 4,096, leaves its own
    tokens at that same 4th token. Details in BACKENDS.md.

  • A prompt read in one call and in two (4,096 tokens from the conversation cache, then 10,563) gives the same 64
    tokens with every expert on the CPU.

  • tools/test_setup_*.py: all 52 pass, plus the new test_setup_ling3.py.

Not done: HIP and Metal builds (I don't have the hardware); Windows; the Q3_K_M and UD-Q2_K_XL files (only Q4_K_M was
run, but the others should run without issue).

Two things I noticed that might be worth a future issue - or at least some more fixes:

  • On the 4080 SUPER alone, the staging buffer's growth during a long prompt (--stage-read-mib) took VRAM past
    --vram-reserve-mib: 0.2 GB free with a reserve of 1,100 MiB, 0.8 GB with 1,900. That card drives my display, so this was somehat annoying.
  • Setting --stage-mib to anything but its default also turns off that growth, which cut Ling's long-prompt reading
    from 704 to 110 tok/s on a layer split . . . which was an earlier problem I was having.

A new strata-poly engine, src/poly/ling3.cpp, from llama.cpp's bailingmoe3 graph. Some layers' attention is MLA over
cached latents (512 latent + 64 rotary values a row, a sigmoid gate on each head's output; Tiny's query is low rank)
on the existing attend()/attend_batch() kernels; the others are KDA with full-rank gates, on GLM 5.3 Flash's kernels.
Dense first layers, then routed experts picked from the best 4 of 8 groups (sigmoid gates + bias, normalised,
x2.5) and one shared expert. Flash's draft block (blk.42.nextn) runs as the engine's MTP block.

- setup: family "ling3", Ling 3.0 Flash from bloomer010's GGUFs (Q4_K_M, Q3_K_M, UD-Q2_K_XL), pinned and
  checksummed; its configs pass --no-draft (no faster here, slower deep in a long context). Tiny runs on the engine
  but is not offered: its experts fit in most cards' VRAM.
- tools/strata_tokenizer.py: llama.cpp's bailingmoe pre-tokenizer pattern; serve/models.py and
  tools/strata_inspect.py know the architecture; metal/CMakeLists.txt builds the engine (not compiled on a Mac).
- docs/models/ling3.md, docs/BACKENDS.md (what runs, the parity table and how it was checked), README.
- tools/test_setup_ling3.py; tools/test_setup_menu.py's family order.

Checked against llama.cpp on one Linux PC (RTX 4080 SUPER + RTX 3080), five chat prompts of 35 to 8,036 tokens,
64 tokens each: Flash Q4_K_M within 0.28 (8 of its 12 departures at a near tie, the other four explained in
BACKENDS.md), Tiny Q4_K_M within 0.19 (all six at a near tie). A prompt read in one call and in two gives the same
tokens with every expert on the CPU. CUDA only; HIP and Metal not built.
main split the repository into engine/ (the C++/CUDA/HIP/SYCL/Metal engines) and
terminal/ (setup.py, the server, the tools), and moved on 6,780 commits since this
branch was cut.  Everything Ling touches moved with it:

- src/poly/ling3.cpp and ling3.hpp -> engine/src/poly/; tools/test_setup_ling3.py ->
  terminal/tools/.
- The root CMakeLists.txt is gone: its poly targets now live in
  engine/cmake/strata_poly.cmake, and ling3.cpp goes into all five that link
  engine.cpp (poly_gdn_mma_state_test, strata-poly, poly_draft_race_test, and the
  two that did not exist when this branch was cut: poly_layer_split_picks_test and
  poly_logits_dump).
- setup.py -> terminal/setup.py, serve/models.py -> terminal/serve/models.py,
  tools/strata_inspect.py and tools/strata_tokenizer.py -> terminal/tools/.  The
  Ling and Inkling 2 entries sit side by side in each registry.
- docs/BACKENDS.md says ten architectures now that Ling is the tenth, and
  setup.py's two references to docs/LING.md point at docs/models/ling3.md.

strata-tokenizer keeps both pre-tokenizers: bailingmoe next to laguna and
inkling2, with inkling2 still in IGNORE_MERGES.

Checked: ling3.cpp compiles standalone against the merged headers (CUDA 13.0,
sm_86, no warnings); tools/test_setup_ling3.py's 5 tests and
tools/test_setup_menu.py's 26 pass, and the setup suite's 4 errors (test_setup_amd,
test_setup_rammode, test_setup_prompts, test_setup_dl_fix) are the same 4 on a
clean main checkout, from jinja2 not being installed here.
@yudhanjaya

yudhanjaya commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@VecSzn , I updated https://github.com/yudhanjaya/PolyStrata/tree/ling3 to account for the new changes to PS.

ling3.cpp compiles standalone against merged headers (CUDA 13.0, sm_86, no warnings); test_setup_ling3.py 5/5; test_setup_menu.py 26/26. ling3.cpp now links to poly_layer_split_picks_test and poly_logits_dump as well.

  • src/poly/ling3.cpp|hpp → engine/src/poly/; tools/test_setup_ling3.py → terminal/tools/
  • root CMakeLists.txt → engine/cmake/strata_poly.cmake
  • setup.py → terminal/setup.py, serve/models.py → terminal/serve/models.py,
    tools/strata_inspect.py and tools/strata_tokenizer.py → terminal/tools/
  • docs/BACKENDS.md now says ten architectures; two docs/LING.md references corrected
    to docs/models/ling3.md

@yudhanjaya yudhanjaya changed the title polystrata: Ling 3.0 Flash and Tiny (bailingmoe3) [Engine] Ling 3.0 Flash and Tiny (bailingmoe3) Nov 24, 2026
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