Repository navigation
Conversation
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.
Move #4125's float64 attention reference from zig/tests/cuda into core.contract.inkling2_attn_ref so the HIP contract can hold its kernels to the same rounding points. A Call now names its query heads, key heads and fp32 chains (Chain.cuda by default, Chain.hip for scalar IEEE sums), and tauAt takes the model's n_floor (Mini's is 8,192). CUDA's defaults are unchanged: the CUDA tests only change their import, and a pinned test holds row() at CUDA's defaults to the bits the old reference gave (checked bit for bit against it on sliding and global rows before the move). Checks: zig test of core.contract (17 pass); zig build test-inkling2-cuda-host (10/10) and compile-cuda-tests on the tree.
A new inkling2 kernel group (strict IEEE build) with #4125's rounding points on HIP: tf_ink2_prep (q/k L2 clips, tau on global layers, the gamma-free v norm, k and v into each segment's ring), tf_ink2_rel_table, chunked attention for sliding (tf_ink2_attn) and global layers (tf_ink2_attn_fold, a split form a block a 1,024-key sub-chunk, and tf_ink2_attn_prompt), and the ordered merge that takes the sink and the gate raw. One wave holds a (row, head) pair over 64-key K/V tiles in LDS with scalar fp32 sums; every path runs the same per-pair steps, so split and prompt are bit-equal to the fold. The prompt kernel shares each tile among 8 pairs in one 37 KiB LDS stage while the next tile loads into registers. The kernels build for gfx1030, gfx1100, gfx1151 and gfx1201 (no scratch; records in hip_records_inkling2.zig). The launcher (families/inkling2/hip_attention.zig) keeps heads, key heads, floor and clips as runtime arguments and per-segment cache offsets, as #4125's; whole-stream rings versus 64-position pages for global KV stays open with the maintainer. The contract entry (tf-hip-kernel-contract image inkling2) holds them at Mini's 24/8 heads and n_floor 8,192 to core.contract's FP64 reference with HIP's chains, at served shapes to 1M keys on a ring that wraps; three streams in one launch are bit-equal to each stream alone (prep, sliding, fold, split). Eight controls go red at shapes, among them a window one key long, the sink and gate given after their sigmoid (#4387's glue) and a prep writing one stream's keys into another's. Checks on gfx1151 with ROCm 10.1's hipcc: image inkling2 smoke and full, 11 kernels pass gates 1-4, 8 controls red, 0 limit problems; hip-kernel-contract-limits passes all 24 inkling2 records (its 11 remaining problems are other groups' records); test-inkling2-hip-host, check-hip-kernel-contract-host; lean 165 on base and head, 0 new.
The verifier's pins for core.contract.inkling2_attn_ref at CUDA's defaults: keys past the bias extent, a full sliding window, the exact (gate 4) branch, a NaN q and a +inf sink, gate 4's replay in fp32 and bf16, and tau at Small's floor. The bits come from the base file (5c1fea6:zig/tests/cuda/contract_inkling2_attn_ref.zig). Checks: zig test of core.contract, 18 pass.
The verifier's edge cases for the HIP contract: global (fold) rows at positions 0 to 1,024 held to float64 rather than only bit-compared, a lone sliding row at 0, prep at pos + 1 = 8,193 and 8,194 just past Mini's floor, and a NaN sink and a NaN gate planted beside gate 1's infinities.
attend() now refuses a layer whose ring is not whole 64-key tiles (error.Inkling2RingTiles: a tile's load never wraps), or is shorter than its window plus the call's rows less one (error.Inkling2RingShort: the rows' new keys would overwrite keys an earlier row still reads), before any launch. The contract's rings (3,072 sliding, 4,096 global) and Layer.sliding/global already meet both. Checks: test-inkling2-hip-host 8/8 (two new tests, red before the check), check-hip-kernel-contract-host.
The float64 bound allows P's bf16 rounding either way, so a kernel that kept P unrounded stayed green. Two registrations (sliding, fold) now make every output exact: rows below position 64 (one tile), q 0, no sink, a gate whose sigmoid is 1, integer values in [-16, 16], bias 2 at distance 0 and the rest drawn so each bf16(exp2f) sits over 2^-21 from a tie. Every P is then at least 2^-5, both of its sums are exact in fp32, and each output must equal bf16(fp32(sum P v / sum P)) bit for bit. A host test shows an unrounded P moves 19,232 of 49,152 outputs. docs/kernel-contract.md states the cases and the ring refusals, and gives the prompt kernel's LDS as 37,120 bytes (36.25 KiB). Checks on gfx1151: image inkling2 full, 13 kernels pass gates 1-4, 8 controls red, 0 limit problems. With the verifier's m1_p_unrounded mutation, smoke goes red on exactly these two cases (11 of 13 pass). test-inkling2-hip-host, check-hip-kernel-contract-host, test-inkling2-cuda-host, compile-cuda-tests; lean 165, 0 new.
… stated Rows.streams has no default any more: a caller states how many segments `segs` holds, so a multi-stream call that forgets it no longer compiles into the one-stream prompt kernel, which reads only segs[0] and ignores the tiles. A call with no streams is refused (error.Inkling2Streams). `slots` is now the partials the buffers hold, and attend() refuses fewer than rows x heads x stride before any launch (error.Inkling2PartialRoom); a split still needs 16 times that. The contract's calls pass their real room, so their paths are unchanged. A global position past the ring is not refused: the contract's 4,096-slot ring over 1M keys wraps on purpose. Layer.global and the contract docs say the engine glue keeps a global layer's positions inside its ring. Checks: test-inkling2-hip-host 11/11 (two new tests, red before the change); test-inkling2-cuda-host and compile-cuda-tests; on gfx1151, image inkling2 full: 13 kernels pass gates 1-4, 8 controls red, 0 limit problems. Lean 165 on base and head, 0 new.
Owner
Author
|
Stopped at #4266. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI for a landing train: #4266 #4633 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.