Repository navigation
Ling-3.0-tiny on ARM CPUs: exact GGUF decoder (#1247) - #4266
Conversation
|
On public head
The exact head merges cleanly with Igor Lessio - AIFLOW LABS |
|
I verified the Windows guard with Zig 0.17.0 using the same command on both heads: zig build tf-ling-cpu-decode -Dtarget=x86_64-windows-gnu -Dfixed-cpu -Doptimize=ReleaseSafe -j2 --summary all
A merge-tree check of After the rebase to On the new prefill head Igor Lessio - AIFLOW LABS |
baa0377 to
c65732d
Compare
|
Thank you @AIFlowML for running both hosts and for listing the skips. That covers the x86 execution gap the description named, on the checked in fixtures. Agreed on the receipt. The next board numbers will keep the two modes in separate cells: exact mode against our scalar reference, and fast mode's differences from exact mode, each with the GGUF file's SHA-256 and repository revision, the prompt token IDs, the commit and the launch line. The description's current figures have the prompt length and commit but not the file hash or the IDs; I will add those with the next run. Thank you also for checking the Windows guard on both heads, and for the note on the changelog conflict; the branch is rebased onto current main. |
c65732d to
23dc855
Compare
|
Thanks for keeping exact mode as the default and documenting the fast-mode differences; that separation looks sound. A few things before this can land:
You don't need to add a CHANGELOG line; we file it at landing.
|
|
Thank you @ashhart for the review! All five points are addressed at the new head
Exact: Fast: Fast mode first differs from exact mode at the 20th generated token (698 against 341), as before this round. Both match our earlier receipts from this round. Decode speeds for each run are in the recipe. One question this raised. The full check in point 2 reads the GGUF and the cache in full, about 9 GB, so a warm Checks at Cheers |
|
I verified revised head This includes the revised host coverage for matching cache hits, changed source with unchanged stat identity, malformed tables, corrupted payload recovery, and GGUF metadata refusals. I did not rerun the author’s board token measurements or the reported warm-start cost. Igor Lessio - AIFLOW LABS |
ab0e788 to
425a44a
Compare
|
I verified On M5 Max with Zig 0.17.0:
These runs cover the checked-in host fixtures and compilation. The Qualcomm checkpoint token IDs, cold/warm cache timing, and throughput are from the author's board run. I did not run the Windows executable. Igor Lessio - AIFLOW LABS |
|
Thank you @ashhart for the answer on #1247 and for correcting the rule so quickly! Round 3 takes
Checks at Cheers |
d966088 to
2e05353
Compare
The affine reader's block validator becomes public so a family can check a tensor's scales once before projecting it. cpu_weights.zig exposes only the mapped formats and the FP64 GGUF source reference, without an engine or a graphics backend, for host-only CPU modules and their tests.
gguf_names.zig lists the 526 source tensors of the tiny bailingmoe3 GGUF with their native names, shapes and roles; transformed roles (split MLA key and value, stacked experts, exp-decay rates) are explicit rather than passed off as native tensors. cpu_gguf_views.zig resolves a native name to a borrowed source view and slices one expert or one row without copying quantized bytes. The new test-ling-cpu-host step runs these under zig build test.
cpu_gguf_rows.zig decodes a block through the shared affine reader and projects rows with one eight-lane FMA order per dot. The Q4_K kernel and the Q6_K and Q5_0 kernels vectorise the same order, so each output equals the scalar block-decode reference bit for bit; threads split output rows only, so 1 to 8 threads give the same bytes. F32 tensors go through the dense rows in cpu_rows.zig. Bad scales are refused before any output is written. The tests check decoded values against the independent FP64 source definition (signed zeros included), projections against expanded weights with and without BF16 rounding, a selected embedding row, and 1 to 8 thread results against one thread.
cpu_gguf.File opens a bailingmoe3 GGUF only when its metadata matches the tiny geometry exactly (24 blocks, 128 experts, MLA every fourth layer, no SwiGLU clamps) and every one of the 526 tensors has the planned shape and an admitted kind: F32 for vectors and convolutions, F32, Q4_K, Q6_K or Q5_0 for matrices. It returns small tensors as F32, rebuilds each MLA layer's joined key-value matrix from the split source once, embeds selected rows, and projects a named matrix through the exact kernels after validating its scales once. cpu_gguf_config.zig derives the family Config from the same metadata.
…red decay rates mixState carries the three preceding projections beside the recurrent matrix, so a prompt fed in chunks or one row at a time convolves exactly as it would whole. Shape.stored_rate takes the per-head rate as stored, the positive exp(A_log) the published GGUF holds, instead of recomputing exp; the oracle test checks that both give the same bytes.
cpu_forward.Forward(Source) runs Ling-3.0-tiny's 24 layers on the CPU: RMS norms, KDA with its recurrent matrix and convolution history, MLA with a per-stream latent cache and RoPE, the dense SwiGLU layer, grouped sigmoid routing to 8 of 128 experts plus the shared expert, and the output head. Every projection goes through the source's exact kernels; activations round to BF16 where the reference model does. A Session holds one stream's state, refuses tokens past the vocabulary or its capacity before touching it, and poisons the state if a layer fails. cpu.Gguf is the forward over the GGUF reader, whose small tensors are now decoded once and kept. The tests run the forward on a small synthetic F32 model: a whole prompt, the same prompt in chunks of 1, 2 and 4 rows, at 1 and 3 threads, after a reset, and without a state give the same logits bit for bit.
zig build tf-ling-cpu-decode builds ling-cpu-decode (ReleaseSafe) for the selected target, natively or cross-built for aarch64 Linux. It opens the published Q4_K_M GGUF, prefills the prompt token IDs 8 rows a call, decodes greedily, and prints the generated IDs with prefill and decode tokens a second. The recipe gives the weights, the build and run commands and the output shape.
With more than one thread, each projection used to spawn and join its threads, so threads were slower than one. cpu_gguf_pool.Pool keeps threads - 1 workers for the life of the GGUF file. A projection's output rows are claimed in chunks from a shared counter, and a token's routed experts run one per claim, each a whole gate, up, SwiGLU and down for its row. Workers spin between jobs and park on a condition when idle. Matrices under 65,536 weights stay on the calling thread. Each output row is still one dot in the single-thread order, and the forward mixes expert results in pick order as before, so the bytes do not change. The new tests compare the workers' Q4_K, Q6_K, Q5_0 and F32 rows and whole experts with the one-thread results at 1, 2, 3, 4 and 8 threads, and the synthetic forward now runs through the workers at the same thread counts. The recipe gives thread advice.
…hread oversubscription
TensorFold takes no mode that changes output tokens, even opt-in, so the SDOT kernels, eight-row repack and its cache, the fast KDA/MLA attention and the --fast flag go. The exact path is unchanged: the pool, the GGUF reader, the forward and the decode tool return to their exact-only forms, and the affinity-mask test moves to the exact pool tests.
Drop the fast-mode run, its repack cache, the +sha2 note, the fast accuracy bullet and the fast measured figures. The dot-product build stays as an optional exact build, since the measured table has both.
2e05353 to
d0c4f84
Compare
|
Thank you @ThinkOffApp. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Thank you @ashhart for 1.3.0, and for the steer to start with the part that already runs! This is Ling-3.0-tiny on ARM CPUs: an exact decoder you can build and launch on an aarch64 Linux board from the recipe in this PR.
What it adds
ling-cpu-decode, that takes prompt token ids and prints the generated ids and tokens per second.docs/recipes/ling-3.0-tiny-cpu.md, with the download, the build lines and the launch command.There is one mode, exact: every projection equals a scalar block-decode reference bit for bit, at every thread count and in both builds.
Try it
-Dcpu=baseline+dotprodis optional; without it the build runs on any aarch64 CPU.Measured from the recipe
On an 8 core Qualcomm board (four fast cores, dot product, no i8mm), each run under
taskset -c 0,3,5,7on an otherwise idle board, a 37 token prompt and 32 generated tokens, on the code of this head (only the recipe changed after the run):+dotprodGenerated ids:
56890 7912 1352 259 6559 23323 1829 14547 268 2599 10448 11 14348 1352 81910 301 48216 13 5177 698 259 3212 15503 23323 16219 25 198 198 16 13 5321 25791, the same as round 2's exact runs.One run each, decode rate as printed by the tool; model opening and prefill are not in these rates. Eight threads on four cores is slow because the workers spin.
Ling-3.0-tiny-Q4_K_M.gguffrominclusionAI/Ling-3.0-tiny-GGUFat revision01b850e29ed5b44e2b810160ff980a9bb353296f, SHA-256246d67d45f5b0c7447ca0ce0bdb8b46b8a47b593c5068635dc16422c051d7be9.taskset -c 0,3,5,7 ling-cpu-decode Ling-3.0-tiny-Q4_K_M.gguf "$PROMPT_IDS" 32 4Prompt token ids
157151,90827,157152,14136,5381,6350,928,156895,157151,39,116171,157152,102141,1099,11028,7912,11,3212,527,3212,11,296,482,3390,810,8025,4614,13,156895,157151,8469,7342,5468,157152,198,156903,156904Accuracy
Decoded values are bit equal to an independent float64 reference and projections are bit equal to the expanded weights; 1 to 8 threads give the same bytes. On the board the 32 generated ids equal our scalar reference.
Checks
d21617008. Head commit:d9660886b, 26 files, +3354 -6. Merges cleanly with current main.zig fmt --check build.zig zig: cleantest-ling-cpu-host: 50 passed.test-ling-host: 64 passed, 2 skipped.test-gguf-host: 50 passed.aarch64-linux-gnu(baseline and+dotprod),aarch64-linux-musl, and the decoder forx86_64-windows-gnuzig build test, x86 execution, CUDA and HIP.Questions for you
Cheers