Repository navigation
Conversation
…m its logprob row An opt-in `kept_probs: true` on chat (with logprobs) and completions (with a logprobs count) adds, for each reply token, the probabilities over the tokens the sampler keeps after temperature, top_k, top_p and min_p, renormalized. The server computes them on the host with the sampler's own cut (`sampling.kept`, moved out of `chooseOrdered` unchanged) and asks the engine for all 20 alternatives, while `top_logprobs` still prints the count asked for. A sampled request needs top_k from 1 to 20 so the kept set fits the row; other top_k values and nonzero penalties are refused with HTTP 400. Tokens and every other field are unchanged with the option on or off. Fixes #3182
…rted preservation
… -Dcontract-root option The contract runner built only the Q4 projection's shaders. Each later operator registers in the same runner, so it now imports the stage 1 to 5 shader modules (norm, rope, attention, GDN, greedy and the data-movement kernels) that the operator probes already build, and the stage modules are hoisted out of their probe blocks so both can share them. -Dcontract-root points the runner at another root file, so one operator group can be built and run on its own.
…nel contract The stage 4 GatedDeltaNet images (conv_dw1d, gdn_conv_decode, gdn_split, gated_delta_prefill_ash and gated_delta_decode in its ASH_QWEN35 raw-gates mode) register as eight kernels through the production Gdn wrapper, so the wrapper's binding tables — the read-only g slot and the single-chunk snapshot dummy among them — are the ones under test. f32 state flows in and out of place, the interior chunk snapshot is bound exactly when chunks exceed one, and the decode loop chains the carried state. References are the stage 4 fixture's f64 walkers made parametric in tokens; every depth a spec states is a function of the token count (one ~130-deep state update per token, the fixture's stated derivation). The f32 state parts prove fp32 sums with an engineered stress fill whose kv partials overflow fp16; the bf16 parts declare bf16=0 with the reason the output's own rounding hides the sum error, as HIP's mamba and CUDA's gdn_prep do. The host suite cross-checks the walker against the fixture's bit for bit and proves the generated fills against the references without a GPU. contract_gdn_main.zig runs the group alone via -Dcontract-root and prints the same LIMITS lines, records audit and runAll tally as contract_main, plus live local-size and shared-memory evidence for all seven pipelines. Proven: zig build vulkan-host-test (20 gdn contract tests, walker parity with fx.RecurWalk/fx.Decode, stress fp16 margins >= 100x); both contract runners build; the runner refuses the software Vulkan device fail-closed. GPU gates 1-4 pending on the M1/M2 devices (none reachable from this host: llvmpipe only).
…e run Three fixture bugs the M1 Max's first run surfaced, none of them shader bugs: the split parts uploaded one combined output buffer where the wrapper binds soa, g and beta separately (OutOfRange on every gate); the decode conv's unchanged-check listed the host chain scratch as an input while indexing one device buffer fewer, so input_now's tail was never filled (a false 'a run changed its inputs'); and the prefill recurrence's random fill used the stage 4 fixture's ranges, which only ever ran at 8 tokens - at 130 the walk outgrew f32. The random fill now decays (g, beta and the whole soa at 2^-3 scale or less), so any token count stays bounded. Also the sums replay the gates ran: every dot re-summed in the requested accumulator and order, the conv chains replayed from the uploaded initial state, exactly as computeWant walks them. Proven: vulkan-host-test green; runAll on Apple M1 Max (G13C C0) Honeykrisp - prefill conv, decode conv and decode state pass gates 1-4 fully; prefill y, hf+snap and split classes settle with the fill fix pending the next device run.
…the soa sums proof The M1 Max run showed the split g shapes gate failing where a random a_log above ~2.4 drove g into f32 subnormals the device flushes - the exact case the stage 4 fixture's census deferred to Main. The served random fill now draws a_log in [-6, 0] (g >= e^-4.5, normal), with the census case named in the fill; the subnormal-flush decision stays with Main. The split soa sums gate moves to f16=0 with the measured reason: the fixture budget's magnitude term at the output's scale is wider than any fp16 miss the stress can engineer, and gate 3's shapes already bound the norm's sum to f32 quality (a bf16-summed ss misses ~2^-8 relative against an observed worst of 0.037 of bound). Proven: vulkan-host-test green.
…tes 1-4 cast_f32_bf16, cast_bf16_f32, copy_u32, copy_u16, gather_u32, gather_u16 and dequant_bf16 register with the kernel contract, bit for bit (a NaN keeps its class; a non-finite dequant scale or bias is checked by class; every gather run includes an out-of-range id whose stated rule is the documented zero row). tf-stage1-datamove runs the group on a real GPU (zig build stage1-datamove) and refuses CPU devices; the stage 1 imports hoist so the probe and this runner share them. Ported from w7p/native-vulkan's a3f040c onto the engine-pr2 tree: the files needed no source change; the wiring reuses this tree's hoisted stage1_shaders module. Proven: zig build -Dvulkan=true stage1-gpu-build and vulkan-host-test pass on this box (llvmpipe only); tf-stage1-datamove --help exits 0 and the runner fails closed (exit 1) with only the software device present.
rope_bf16 and sdpa_rows_bf16 against stage3_fixture's f64 references generalized past the fixture's 8-key score buffer to the served shapes (decode rows 1, prefill rows <= 32, visible keys 1..7168 on the 16-key tile, 256-lane scan and 1024-thread stride edges and the kStreamKeys bound). The sdpa bound is derived from the shader text -- denominator depth ceil(n/256)+8, the 256-lane strided chains plus the 8-level tree, NOT the plain n-term sum -- and pinned to the source by a host test. Single-key rows carry the V bits exactly; multi-row prefill rows decode alone bit-identical. Ported from w7p/native-vulkan-model's 60a22e7 onto the engine-pr2 tree: the files needed no source change; the wiring reuses this tree's hoisted stage1/stage3 shader modules. Proven: zig build -Dvulkan=true stage3-gpu-build, stage3-host-test and vulkan-host-test pass on this box; tf-attention-contract --help exits 0 and honestly refuses this box's software llvmpipe (exit 1). Real-GPU run needs the Apple Vulkan rig.
The greedy draw — finite_logits, argreduce_chunk and argreduce_combine behind one submission, three launches inside the run hook — registers through gates 1-4, plus the planted control contract_controls_greedy.comp (the mirror of HIP's tf_ctl_fmax_max: a row max that drops a NaN), registered with control = .nonfinite and required to go red. The acceptance is exact: the token equals the host greedyRef (max wins, ties to the lowest index, +0/-0 equal), a planted non-finite row refuses naming its first offender, repeats are byte-identical, inputs and guards untouched. Ported from the greedy agent's files on w7p/native-vulkan-model onto the engine-pr2 tree: the files needed no source change; the wiring compiles the control beside the stage 5 variants and reuses this tree's hoisted stage5_shaders module. Proven: zig build -Dvulkan=true stage5-gpu-build, stage5-host-test and vulkan-host-test pass on this box; tf-vulkan-greedy-contract --help exits 0 and the runner fails closed (exit 1) with only the software llvmpipe present.
…ion shapes contract_pointwise.zig states and checks the six pointwise closures of stages 2-4 on the host: the stage 2 trio reuses stage2_fixture, the f32-preserving residual add claims the exact f32 sum bit for bit (a flush-to-zero device fails HONESTLY), the attention output gate uses boundExact with ops 4 mids 1 and demands signed-exact zeros, and the gated RMSNorm uses the rows family bound plus ops 10 mids 12 with nan/inf/±0/zero-row/nan-row controls class-checked. Every checker also refuses a corrupted output, a sign-flipped zero and a planted nonfinite. contract_pointwise_main.zig drives all six on a real GPU through the wrappers' exact dispatch shapes (NormMlp for stage 2; the preserve add, gate and gated norm at attention.gatePlan's and gdn.gatedNormPlan's geometry), three byte-identical repeats per case. Ported from w7p/native-vulkan-stage2 (c0ee7bf + eb72415) onto the engine-pr2 tree. One source adaptation: this tree's NormMlp.Shaders gained the add_preserve_bf16 field, so the runner now serves it (the image this tree's stage 2 closure already compiles); the shader sources themselves landed with this tree's stage 3/4 closures. Proven: zig build -Dvulkan=true contract-pointwise-build, vulkan-host-test pass on this box, and zig-out/stage{2,3,4} carries the six images; tf-contract-pointwise --help exits 0 and the runner fails closed (exit 1) with only the software llvmpipe present.
… cross target The datamove test module was built for -Dtarget, so a cross build (aarch64 on the x86 build host) failed with 'unable to spawn foreign binary' in vulkan-host-test. It now gets its own host-target module like every other host suite. Proved by: vulkan-host-test and all stage and runner build steps pass with -Dtarget=aarch64-linux-gnu (224/224 steps).
… and u16 copy On a real device (Apple M2 Max, Honeykrisp) the shapes gate failed three kernels with the Zig error Misaligned: the gate's edge shapes include odd element counts, and a 16-bit range of an odd count is not bindable (dispatch.bind needs whole 32-bit words; View.init refuses the same ragged tail), so the fixture's view call raised an error that the gate scored as FAIL. The kernel refuses that edge, so prepare now returns false for it (an edge refused by the kernel, as the gates count them); served shapes (146x1, 3x700, 300x1, 2x520) are all even. Proved by: vulkan-host-test and stage1-gpu-build pass for aarch64 (81/81 steps, 210/212 tests, 2 skipped). Not proved: no device rerun yet.
…hat prepare sized The M2 Max's run of the gdn group died in gate 1 of the prefill_y kernel: "index out of bounds: index 524288, len 10248" at contract_gdn.zig's uploadBuffers, called from the nonfinite gate's prepare. 524288 is 2 * state_elems and 10248 is 5 * linear_dim + the guard words, so the sliced region belonged to a different kernel: the prefill arm uploaded the same buffers for prefill_y and prefill_state, and the state's region (prefill_y's out holds y only) was sliced out of a much shorter out. The upload path now lives in one place, uploadWords, which hands each device buffer the words it takes: a checked output its own region of out, an output no fetch reads fresh poison scratch, and every region bounded by what prepare sized, so a mismatch is an error the gate reports instead of a panic that kills the runner. The prefill_y and decode_state outputs that no fetch downloads take scratch, the checked ones keep out's region, and every other arm keeps the bytes it had. Proof: a new host test drives the gates' own shape sequence (gate 1 and 2's small() shape, gate 3's served and edge shapes, gate 4's stress shape) through prepare and the upload path with no device, and holds every upload inside the region prepare sized and the buffer count at what run() binds. It fails on the old sourcing with the same out-of-range region the device hit (outWords: OutputRegionOutOfRange) and passes on the fix; the whole host suite is 21/21 and the arm64 runner builds clean (100/100 steps). The split g gate's class finding (1 of 128 outputs: nan where float64 gives finite) is untouched: it is a device finding for the maintainer to decide on, not a fixture bug.
…assuming it Why: the repeat gate failed on the PR-B device run with 'a run wrote outside its outputs' (gates.zig intact check). The rig's input() uploaded only the data window at offset guard, so the shell's guard bytes never held the 0xa5 pattern intact() demands — fresh device memory reads as zeros, and the gate was false on every run of every shape. The draw itself never writes the shell (its outputs are the internal partials and results buffers, the same shape HIP's argmax contract declares via rig.scratch/rig.output), so the guard finding was a runner bug, not an overrun. What: Rig.input builds the full shell through a new shellFor (pattern, data, pattern) and uploads it at offset 0, the way the datamove rig's slot() already did. New host test pins the layout: guards patterned on both sides, data between, exact length — the invariant the old code never stated anywhere. Proof: zig build vulkan-host-test stage5-gpu-build contract-pointwise-build contract-pointwise-host-test (shared cache) green: 103/103 steps, 22/22 tests, including the new shell test. The gate's strictness is unchanged; a real overrun still fails intact(). The gate line's device-side pass still needs its device run, which is out of scope for this offline fix. Build log: scratch/atc-vulkan-native-20261026/prb-fix-gp-build.log
…ally built Why: the PR-B device run failed all three preserve-add cases and the plain add's classes case. The preserve fixture modeled a pipeline nobody builds: it filled f32 buffers and demanded exact f32 sums, but add_preserve_bf16 is binary_vec.comp with -DPRESERVE_F32 over the default bf16 storage — the -DUSE_BF16 the build passed alongside it matches no ifdef in the shader (storage variant is USE_FP16/default), so the device ran the bf16 add reading u16 halves of f32 bits. Every reported got matches that model bit for bit: cancel element 0 is widen(0x293a)+widen(0x293a) stored bf16 0x29ba (read back as u32 0x000029ba), random element 0 is 0xbed4fbc2, classes element 6 is the j=12 NaN 0x7fc0 beside the j=13 overflow +inf 0x7f80 = 0x7f807fc0. The plain add's classes failure was a runner gap: stage2's measured-property policy (allow_subnormal_flush from shaderDenormPreserveFloat32, as stage2_probe wires it) was never applied, so the subnormal rows were checked strictly regardless of the device's reported float controls. What: PreserveAdd and PreserveCase become aliases of stage2.Add/AddCase — one model of the pipeline (f32 add, one RNE bf16 store), two pipelines — and the preserve gate checks strictly (no flush qualification ever): a device that flushes fp32 denormals fails the subnormal classes rows as an honest finding, printed by a NOTE, never fitted away. addGate now wires the stage 2 policy from the device property and the device line prints preserve32/flush32 so the next run is decidable. The inert -DUSE_BF16 is dropped from both binary_vec build entries and the stale 'compiled without -DUSE_BF16 stores exact f32' comments are gone. A host test scans the embedded SPIR-V: add_preserve_bf16 declares OpCapability DenormPreserve (4464), add_bf16 does not — a define that matches no ifdef can never silently produce the plain add again. Proof: shared-cache build green, 103/103 steps, 22/22 tests, including the rewritten preserve tests (subnormal want 0x0002 must stay refused when a device flushes) and the capability scan; the generated images were verified directly (4464 present only in add_preserve_bf16). Build log: scratch/atc-vulkan-native-20261026/prb-fix-gp-build.log
zig/tests/vulkan/qwen35_model_probe.zig was 646 lines, past the 600-line lean limit. The receipt shape (the result.json fields, the repeat and oracle echoes), its JSON writer, the execution-mode labels and the receipt's round-trip test move to zig/tests/vulkan/qwen35_model_receipt.zig. The probe keeps every name reachable under the same name, so the result.json bytes it writes are unchanged. qwen35_model_probe.zig is 558 lines and qwen35_model_receipt.zig is 98, which leaves room for the three lines the next change adds. The moved code is byte-identical apart from the pub markers the cross-file use needs, and the probe keeps its nine tests: model-host-test succeeds with the same 6/6 steps and vulkan-model-probe-build with the same 31/31 steps. The branch's lean checker now reports 463 problems against the 466 baseline, with none in the touched or the new files.
zig/build/vulkan.zig held every stage's build steps in one function and had grown past the house's 600-line lean limit. The per-stage and per-contract steps now live in zig/build/vulkan_stages.zig, one function per stage (hostAdmission, probeSteps, stage1 to stage5, contracts, kernelContract), called from vulkan.zig in the order the steps are created. The shader lists, the server's modules and the backend module stay in vulkan.zig, which the new file reads, the way vulkan_model.zig already reads it. Every step name, option and install path is unchanged: `zig build --help -Dvulkan=true` lists the same Steps and the same -D options before and after, and the 472 moved lines are verbatim apart from the context fields they now read. vulkan-host-test, stage1-gpu-build, stage3-gpu-build, stage5-gpu-build, tf-vulkan-kernel-contract and vulkan-model-probe-build build and pass, installing the same artifacts under zig-out.
zig/kernels/vulkan/omarchy_trig.h carried 29 multi-line comments: one run of 27 lines over the header and one of 4 over the tan wrapper. Each is now one line of at most 120 columns, the form the house's lean rule takes, and the code lines are untouched. The shader that includes it compiles to byte-identical SPIR-V (fast_rope.comp, -DUSE_BF16 -DASH_QWEN35). The facts the one-line comments keep: - the attribution: copied from the mlx-omarchy overlay's omarchy_trig.h, MIT, full text in LICENSES/mlx-omarchy-MIT.txt. - why: the built-in sin/cos/tan lose upstream accuracy above ~1e3 and collapse past ~1e6 (llvmpipe past ~1e7, measured), so every trigonometric argument not bounded by construction goes through these wrappers. - what: accurate to OMARCHY_TRIG_LIMIT, NaN above it, never a wrong finite value, and the raw built-in stays bit-identical below OMARCHY_TRIG_BUILTIN_MAX. - how: Cody-Waite with C1 = 6.28125 = 201 * 2^-5 (8 significant bits), exact for |k| <= 83601 and so for every argument up to 525371.9; the rest is a dyadic 2^-9 (exact for all k) plus two f32 correction terms; the three-subtract chain is marked precise so a driver may not reassociate it (Honeykrisp has a documented inexact-constant-reassociation defect); above the limit the argument leaves the exact-product zone and the wrappers return NaN. - tan reduces through the 2*pi-periodic sin/cos forms, which are exact period shifts, so the reduced argument serves; the relative error grows near the poles as at the built-in.
The stage 4 fixture (1035 lines) and probe (950 lines) each broke the 600-line lean rule, and the fixture's two-line header was a multi-line comment. The fixture is now four files (the shared core, the split fixtures, the state fixtures, and the root that keeps the public surface and the host tests) and the probe three (the shared helpers, the gates, and the root), all under 580 lines. Each file reaches the others through @import inside the same module, so zig/build/vulkan.zig is unchanged: the stage 4 host test still runs stage4_fixture.zig as its root, and the probe executable still roots at stage4_probe.zig. Every line of code is the original line, moved. The only new tokens are the import aliases, the pub on the helpers the parts share (violated, poisonedShell, f32Of, the gate and buffer helpers), and the one-line file headers. The fixture root re-exports the whole public surface (fx.Split, fx.SplitOne, fx.Conv, fx.RecurWalk, fx.Recur, fx.Decode, fx.Norm, fx.Model, fx.c, fx.budget, fx.gateRefAsh, fx.sampleDyadic, fx.tokens), so the probe and contract_gdn.zig are untouched; the probe root calls the gates through the gates module. Proven: tools/zig/lean_check.py reports no problem for any stage4_*.zig (the repo total falls from 466 to 463). `zig build stage4-host-test -Dvulkan=true` passes with the same 60 + 9 tests, `zig build stage4-gpu-build -Dvulkan=true` compiles tf-stage4-gpu, and `zig build test -Dvulkan=true` gives the identical summary before and after (543/549 steps, 2273/2313 tests; the 37 failures are the pre-existing originals_test ones, the same at the base commit). zig fmt --check is clean.
contract_gdn.zig was 1611 lines, over the 600-line lean limit, so no case could be added without splitting it. The served shapes, the specs and the f64 references move unchanged into contract_gdn_ref.zig, the fixture's buffers and launches into contract_gdn_ops.zig, and the host fills, references and upload order into contract_gdn_host.zig; the root re-exports them, so every caller keeps the same API. The tests stay in the root file, so every artifact that imports the fixture still runs them and the test counts do not move.
weights.zig: remove the .full_every = 4 admission pin and its drift-test field. The Spec field was removed in 89dff3d, so the pin no longer compiles on this branch. backend.zig: prefillStepFn takes the lanes contract argument max_rows (zig/src/core/lanes/backend.zig) and caps the prompt chunk when it is nonzero. Zero means uncapped. The host test passes zero. Proof, all with -Dvulkan=true on this branch: - zig build qwen35-model-host-test: 38/38 steps, 7/8 tests passed (1 skipped). - zig build: 31/31 steps succeeded. - zig build test: the only failing tests are core originals_test (12) and server slide_forget_test (1). The same tests fail on the base commit a24b24f on this filesystem, which refuses reflink clones (cp --reflink=always: Operation not permitted), so originals clone fails with CloneFailed. Those failures are environmental and predate this commit. (cherry picked from commit 845030f)
…es for the oracle Each shader taken from omarchy-mlx now opens with its source path and commit, what changed, and the copyright line; THIRD_PARTY_NOTICES.md lists every such file. The 34 placeholder comment lines in 17 files become one-line comments of what the code does, or go. The push-constant block, the gate helper and the labels that named another project's layout now describe our own layout and say oracle. No code changes. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The port serves "vulkan" as a --backend choice (cli.zig line 136), so the
config-file case that expected the invalid-choice refusal for 'vulkan'
stopped testing the choice check: on builds without -Dvulkan it passed
the choice check and hit the not-served refusal instead. Use an unlisted
backend name ('vbogus') so the case tests the invalid-choice refusal on
every build. Step test-serve-flags-host green locally.
…dy shaders for #1544 Rewrites the omarchy-derived Vulkan compute shaders from the behavior spec, from cast/copy through the gated-delta state machines to the argreduce pair. omarchy_trig.h becomes vulkan_trig.h (single inv_freq helper, Synthena #6), gated_delta_prefill_ash becomes gated_delta_prefill_oracle, accepting both -DASH_QWEN35 and -DORACLE_QWEN35. PRESERVE_F32 requests OpExecutionMode DenormPreserve (f32) via spirv_execution_mode; sdpa_decode_native pins the single-key bit-exact V transport (Synthena #7) and the 7168-key shared bound. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…x SDPA & composed baseline
…ows_f32q contract (#1990)
…gine turn The test thread's send after an idle end raced the rest of the engine's turn: it landed inside the prompt visit that ended the last request or a turn later, and that visit's burst then set whether a step or a round ran first, so a seed's second run could take another schedule (#5367). The test counts the engine's turns through the host's activity scope; a finished event stores the turn it came in before its box shows it, and the test thread sends the next request only once a whole turn has run after that one. With nothing in flight that turn is empty and ends under the host's lock as the engine goes idle, so the send meets no prompt visit and is admitted at a later turn's head. The finished callback only records, and idle reads the boxes and the next index under the explorer's lock.
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: #3207 #5193 #5386 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.