Repository navigation
Laya router: the step-4 scorer in C++, routing each request to a device - #90
Conversation
…nd route requests per device
The non-autoregressive System 1 scorer (1bit-MONSTER src/laya_scorer.cpp on
backup/laya-and-results-2026-09-22) lands as laya/scorer.{h,cpp} +
laya/safetensors.{h,cpp} (Apache-2.0, zero Python at runtime): ModernBERT-large
encoder + RLCD head, weights via model.safetensors, tokens via npu::Tokenizer
(tokenizer.json). npu::Tokenizer gains token_id() and the Rust-tokenizers
ByteLevel regex so ModernBERT's tokenizer.json encodes digit runs correctly.
Gated against the Python reference on the pinned root and typed-decisions
checkpoints: tests/laya_gate.cpp compares raw logits (<= 1e-3), act logits
(<= 1e-3 rel), argmax (identical) and probabilities (<= 1e-4). Both pass.
Wired into the router: 1bit serve --laya-model routes each request by the
scorer (replacing the auto->vulkan hardcode) and lazily starts the chosen
device's backend; 1bit route prints the decision. tests/laya_route_e2e.sh
proves a request reaches the Laya-chosen backend.
… dirs, GPU backends for .gguf) route_device now takes a candidate device list. A .gguf routes among vulkan, hrx and zinc (NPU is never offered for a .gguf, so a request can no longer route to a device that cannot run it), and an NPU model directory routes to npu through the same path. 1bit route gains --devices. The e2e test now proves routing across more than one device (vulkan and zinc) plus the npu-only decision.
…ckend lines) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Docs7 for 1bit-monster/engine
Commit |
PR Reviewer Guide 🔍(Review updated until commit ad47f86)Here are some key observations to aid the review process:
|
… for bit) One routing decision took about 15 s on one core of Strix Halo's 32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Preparing review... |
|
Persistent review updated to latest commit 6fc774b |
|
Persistent review updated to latest commit ad47f86 |
Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…to our fork (Loom NaN backport) (#320) * Bump HRX: llama.cpp 522dab4789ce (long-prompt fix), hrx-system to our fork 98d05d94a9f9 third_party/llama.cpp e57beb9721af -> 522dab4789ce (fork #89 runtime overhead, #90: graph inputs never written back to host — every multi-ubatch prompt was wrong since #82 — and the non-replay upload race). third_party/hrx-system moves from ROCm/hrx-system 51b1739ae5fd to our fork 1bit-MONSTER/hrx-system 1bit/main 98d05d94a9f9 = the same AMD commit plus the GFX11 wave64 lane-mask drain backport (#313 NaN) and two libhrx device knobs. bump-hrx.yml now moves only the llama.cpp pin; hrx-system is rebased by hand. Co-Authored-By: Claude Fable 5.1 <[email protected]> * registry: regenerated at llama.cpp 522dab4789ce Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
… root-caused a NaN in the same family BUILT 05:52, compile caveat discharged: the patch applied to the real tree and the build exited 0 (graph-executor.cpp.o recompiled, libggml-hrx.so relinked), and the artefact was verified rather than inferred - bin/libggml-hrx.so.0.18.0 contains BOTH GGML_HRX_PRODUCER_PROBE and GGML_HRX_PRODUCER_DEVICE, object and library both timestamped 05:52, source backed up at /tmp/graph-executor.cpp.orig (sha256 cba0419f55e748ed...). Run 315dev launched behind the gate-aware wrapper that holds no lock and no GTT. Still NOT claimed: that it arms anything at run time - the armed/anomaly lines are that evidence and do not exist yet. THE SIBLING FIX: a fork pin-bump (fb24c1f, Oct 5) turned out to describe a root-caused NaN fix in exactly this family - llama.cpp e57beb9721af -> 522dab4789ce with fork #90: 'graph inputs never written back to host - every multi-ubatch prompt was wrong since #82 - and the non-replay upload race'; and hrx-system moved to our fork 98d05d94a9f9 carrying 'the GFX11 wave64 lane-mask drain backport (#313 NaN)'. The fork merge reads: '522dab478 Merge pull request #90 from 1bit-MONSTER/1bit/kv-nan-rootcause / ggml-hrx: graph inputs are never written back to host; non-replay programs wait for their input upload'. Two consequences: it is independent evidence that the family is real and reachable (a KV-NaN root cause was found in the host write-back path); and the engine pin's tree ALREADY contains a PendingHostWriteback path whose final step is memcpy(writeback.host_destination, writeback.mapped_source, size) - a DEVICE MAPPING copied into a HOST DESTINATION (runtime/command-program-executor.cpp) - i.e. the exact line where 'the device wrote these bytes' and 'the mapping still holds something else' are decided, in the pin this work runs on. NOT established, and it decides whether #90 is a fix or already shipped: 522dab4789ce versus the engine pin e44c9d01a. The local clone is SHALLOW - 522dab4789ce has no parents in it and e44c9d01a is absent - so merge-base cannot run. If 522dab4789ce is an ancestor of the pin, #90 is already shipped and #315's remaining faults are a different path; if it is a descendant, #90 is a forward-only fix candidate. Settling it needs a full fetch or the engine repo's submodule, and it is worth doing before any other run.
…INT=1 to BOTH conditions, making the run self-falsifying A design risk found while re-reading the publish path, and it would have made the run uninterpretable. THE RISK: the chain needs the staging path to be WARM, but the record already measured the deferred writeback route as COLD - '0 [hrx-wb-fp] records with the flag on over a complete 66/66 arm'. If it is cold in the disc-rig config too, add_host_writeback is never called, no graph input is ever published by this path, and A' and B' CANNOT DIFFER - a null that would say nothing about the mechanism while looking like evidence against it. THE AMENDMENT: both conditions now also carry GGML_HRX_WRITEBACK_FINGERPRINT=1 (the record's instrument; inert unless set). Added to BOTH arms so it stays a non-difference, and it converts the risk from an assumption into a measurement. Diagnostic added to the existing run; primary readout, arm counts and stopping rule unchanged. EXTRA READOUT, fixed in advance: [hrx-wb-fp] lines present -> the path WAS exercised and the A'/B' contrast is meaningful. NO [hrx-wb-fp] line in either condition -> the path is cold in this configuration, the chain has no first step here, the A'/B' null is STRUCTURALLY EXPECTED AND UNINFORMATIVE, and the candidate is dead FOR THE DISC RIG - needing a configuration that actually exercises host-staging downloads (the multi-ubatch/split path #90's message implicates) as a new pre-registration. That second row is the point: the run is now SELF-FALSIFYING, so a null cannot be mistaken for a refutation and cannot be mistaken for support either.
…wo faces never co-occur
From the existing archive plus the runtime source, no GPU. This is a reclassification of the record and it is
decision-relevant.
INSTRUMENT INVENTORY (first time enumerated): ids-fp 3,412,028; ids-sync 1,160,376; hrx-copy site= and
hrx-copy-LOGITS 164,552 each; tensor-fp 134,180; hrx-logits-fp 104,720 (HOST-side logits, not previously
accounted for); finite-fp 1,698; buf 351; dl-fp 146; sentinel 90; producer 24.
THE REAL MARKERS, AND THE ONES THAT DO NOT EXIST. Over every arm log: 'HTTP 500' 0 arms, 'Invalid UTF' 0
arms (consistent with 315-invalid-utf8-never-observed.md), HSA_STATUS_ERROR 12 arms (Face A), MEMORY_FAULT
3 arms (Face A subset), 'Content-only output' 77 arms (the operative Face-B marker). The marker line is
'common_chat_peg_parse: unparsed Content-only output: <text>' and reading <text> is what splits it.
FACE B IS TWO POPULATIONS OF ABOUT EQUAL SIZE: GARBAGE-text 39, prose-text 38. Prose is coherent English -
"We'll assume the reader has a basic understanding of", verbatim, in roughly twenty separate arms: a normal
model answer that the PEG parser rejected because the harness wanted structured JSON. That is a
FORMAT-COMPLIANCE FAILURE, not corruption - and it cannot be a memory fault, because the text is coherent.
GARBAGE is genuine corruption: token soup, repetition loops ('gaps gaps gaps gaps'), replacement characters,
and the telling COHERENT-THEN-DISSOLVE form ('We'll assume thet ( size(, ((A(A.,,//值*( (名 (。 de*。*') -
correct for a few tokens, then degrades.
THE TWO FACES ARE DISJOINT AND FACE B IS NEVER NaN: GARBAGE arms device-NaN 0, face-A 0; prose arms
device-NaN 0, face-A 0; device tensor-fp NaN present in 0 of 89; and every hrx-logits-fp record in a Face-B
arm reports nan=0 across all 104,720. Face A arms have EMPTY output - they crash before emitting text (all
six v315t-r* arms, 315probe3-p1c). No arm shows both faces. So 'both faces' are not two symptoms of one
intermittent event; they are two disjoint populations, and Face B is mostly not a hardware fault at all.
TWO RECORD ARTEFACTS RETIRED. (1) oor and dup_pairs in hrx-ids-fp are not corruption signals: the probe
checks each id against ne0 = node->ne[0], and for ffn_moe_argsort that is the top-k count (observed 4 or 64),
not the expert-table size, so VALID expert indices are flagged oor permanently. dup_pairs confirms it -
977,666,493 duplicate pairs in the 23 CLEAN arms versus 10,333,698 in the probed Face-B arms. A metric three
orders of magnitude worse in the clean population carries no information; any reading built on oor/dup_pairs
should be withdrawn, including the 'clean permutation' framing. (2) tensor-fp-on-result_output (8 arms) and
hrx-logits-fp (56 arms) have an EMPTY intersection, so the device-vs-host logits comparison is still not
possible on the record - the same disjoint-instrument defect as before.
WHAT THIS CHANGES: the objective's Face B, 'invalid-UTF-8 output surfacing as HTTP 500 parse failures',
describes a phenomenon with ZERO occurrences on the record. What exists is Content-only output and about half
of it is the model declining to emit JSON. A campaign counting all Content-only outcomes as faults counts
benign format failures as failures and can never reach 'zero faults'; one that excludes them silently narrows
the criterion. This needs /goal-tweak before a >=60-arm campaign can be built on it - the decision is the
user's. WHAT IT DOES NOT CHANGE: Face A is real and well-marked (12 arms HSA_STATUS_ERROR, 3 MEMORY_FAULT),
its arms have empty output, and it remains the thing to explain; the 256-byte measurements sit on hidden-state
tensors and are unaffected.
NEW LEAD for the genuine half: GARBAGE arms show finite logits and coherent-then-dissolve text, the signature
of corruption entering PARTWAY THROUGH GENERATION - a property of the decode-loop state (KV cache / hidden
state carried across steps), not of a single forward pass, and consistent with the record's own PR #90 finding
in the input direction. That is where the next mechanism hunt should look, not at the prefill path where the
256-byte readings were taken.
…ingle token
Reading the archive's SMALLEST NaN clusters - the least-propagated observations, therefore the closest to the
seed. No GPU.
THE MINIMAL OBSERVATIONS, RANKED: nan=4 ne0=1 of=4 (48 records, ffn_moe_weights-46 - a FOUR-element tensor,
ALL NaN); nan=40 ne0=1 of=40 (45, ffn_moe_weights-1); nan=64 ne0=64 of=64 (26, ffn_moe_probs-46 - softmax over
64 experts, ALL NaN); nan=8 ne0=1 of=40 (4); nan=192 ne0=2048 of=2048 (1, node_3305 - the ONLY sub-tensor
region found). Every one of the smallest NaN observations is an MoE routing tensor and every one is FULLY NaN,
down to a 4-element tensor. There is no smaller NaN region anywhere in the archive.
MECHANICALLY: ffn_moe_probs is the router softmax and ffn_moe_weights the top-k weight list; their inputs are
ffn_moe_gate (x @ W_gate) and ffn_moe_argsort. A softmax producing all-NaN over 64 experts means its input was
all -inf (the 0/0 case) or already contained NaN, and ffn_moe_gate-* is observed fully NaN at many layers. So:
hidden state x -> ffn_moe_gate -> softmax -> ffn_moe_probs (ALL NaN) -> top-k/weights -> ffn_moe_weights (ALL
NaN) -> MUL_MAT_ID over expert weights -> ffn_moe_weighted/out/down -> residual -> every downstream tensor. The
fault's most primitive observable manifestation is therefore: for a SINGLE TOKEN the MoE router output is
entirely NaN, which requires the hidden state fed to that router to already carry NaN.
THE ONE SUB-TENSOR REGION: node_3305 nan=192 of 2048 ne0=2048 first=1856, and 1856+192 = 2048 EXACTLY - so the
NaN is the last 192 elements of a single 2048-element row, granules 29-31 of 32, running to the end of the row.
node_3305 = 71x46+39, i.e. layer 46 (the final layer), just past the residual ADD. That is the only place on
the record where a NaN region is smaller than its whole tensor and measurable. Everywhere else the NaN has
already filled the tensor.
NOTHING UPSTREAM IS OBSERVED: the graph's input embeddings are never fingerprinted - across 567 distinct tensor
names the record contains no inp_*, no embedding, no token tensor; the earliest tensor ever observed is l_out-0
(layer 0's output).
THE NUMBERS DO NOT SUPPORT A SINGLE CLEAN UNIT. The archive-wide NaN-count histogram is dominated by
whole-tensor NaN (1048576 11.0%, 610304 11.0%, 1572928 3.5%) - the propagated end state. 2048 is third at
5.1% and is the most common value for ne0 in {768, 5120, 576}. 44% of NaN counts are multiples of 2048 and 56%
are not. The fbar arms' first eight buffers ARE all exactly nan=2048 across widths 64..5120, which is striking,
but IT DOES NOT GENERALISE and is recorded as a property of those four arms, not of the fault. So no single
unit - row, wave, granule, or 8192-byte region - is supported archive-wide, and the earlier claims of that
shape in this directory are superseded.
CORRECTED SHAPE OF THE PROBLEM: (1) the input path is unobserved; (2) the router is the seed's first observable
victim, per token, entirely; (3) per-node localization is structurally unavailable (aliasing), so the record
cannot walk the fault back from the router to its origin; (4) Face A = NaN logits (unambiguous, result_output
fully NaN on a unique buffer), Face B = finite logits, ~half benign prose, disjoint from Face A.
The record already contains a finding pointing at (1): PR #90, 'graph inputs are never written back to host',
shipped as an ancestor of the pin. Combined with an input path that is never instrumented, and a mechanism
chain the objective itself states as 'graph input published to host by deferred non-coherent staging writeback
-> re-uploaded to device -> device computes from stale input', the highest-value next instrument is the input
embedding tensor, which has never been observed. No mechanism is claimed.
…erified, and PRE-REGISTERED The record can no longer localize anything in the graph: the fingerprint reads tensors AFTER COMPUTE (its own code comment says so) and reads a BUFFER, so every name bound to a shared allocation reports one allocation's final content - measured node_2948 === ffn_shexp-41 (identical hash 65f4b97ca74c), l_out-42 === l_out-44, and 47 l_out-N names collapsing to 4 hashes. Two things remain unmeasured and both are now instrumented. THE INSTRUMENT (docs/315-campaign/tools/patch-input-f32-sync-twin.py), VERIFIED NOT ASSERTED: applies cleanly to ggml-hrx.cpp with exactly one occurrence per anchor (4 of 4), is idempotent on a second run, and the patched translation unit COMPILES with the exact build flags extracted from the real build directory (315fp-build/compile_commands.json, -fsyntax-only, exit 0). It adds, both inert unless their env var is set: (1) hrx-f32-sync - for every f32 tensor the fingerprint already reports, read the same bytes through hrx_synchronous_d2h and print nan, first, row, a FULL CONTENT HASH, and nan_agree / hashes_equal against the plain-memcpy line. The i32 branch has had this twin since the ids probe - and comparing its two reads produced the record's 'the two read paths agree' negative - but the f32 branch has NEVER had it, and f32 tensors are the ones that carry the fault. A content hash rather than a count, so a divergence confined to the tensor's interior is still visible (this was the blind spot in the earlier fp/sync comparison). (2) head:<N> - select the first N nodes, symmetric with the existing tail:<N>. The graph input (inp->embd = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_embd_inp, ubatch.n_tokens)) is created UNNAMED, so the name list cannot match it and tail never reaches it - it sits at the head of graph->nodes. Across 567 observed tensor names the record contains no inp_*, no embedding, no token tensor; the earliest thing ever observed is l_out-0. The input is the one tensor upstream of everything, the objective's own mechanism chain is 'graph input published to host by deferred non-coherent staging writeback -> re-uploaded to device -> device computes from stale input', and the record's own PR #90 was an INPUT-path defect. PRE-REGISTERED BEFORE ANY ARM RUNS (315-PREREGISTRATION-f32-readpath-and-graph-input.md), with the scored outcomes fixed and non-prunable: on the f32 twin, hashes_equal=0 on a faulting arm with a 256-byte-aligned differing region CONFIRMS read-path staleness for f32; hashes_equal=1 with nan>0 REFUTES it and leaves genuine device state; a divergence on a clean arm is a different finding and does not satisfy the criterion. On the graph input: input NaN while the first reader is clean means the seed is upstream of the graph; input clean with l_out-0 NaN means the seed is inside layer 0; both clean yet faulting means the forward path is not where it lives. An arm that does not fault is INVALID and will be reported as INVALID. STANDING CORRECTIONS THIS CARRIES: (a) the objective's premise that 'arena knobs and transient reuse are already falsified on the record' is CONTRADICTED by measurement - reuse is pervasive and is what made the read-pattern/onset result look meaningful, so any acceptance argument resting on that premise needs revisiting with the user; (b) Face B's stated definition has ZERO occurrences on the record (invalid UTF-8 0 arms, HTTP 500 0 arms) and needs /goal-tweak before a >=60-arm campaign can be scored against it. No mechanism is named and no fix is proposed.
agent-b72a1b's Laya scorer work, brought onto current
main.What it adds
laya/scorer.{h,cpp}andlaya/safetensors.{h,cpp}: the non-autoregressive step-4 scorer (ModernBERT-large encoder + RLCD head) in C++. Weights load frommodel.safetensors, tokens come fromnpu::Tokenizer, and nothing runs in Python.npu::Tokenizer: gainstoken_id()and the ByteLevel regex, so ModernBERT'stokenizer.jsonencodes digit runs correctly.laya/route.{h,cpp}:route_device(scorer, state, devices), which answers the fixed routing question among the candidate devices.1bit route --laya-model DIR --state TEXT [--devices ...]: prints the scorer's decision.1bit serve --laya-model DIR(with--device auto):.ggufon (vulkan, hrx, zinc)npuas its only candidate.Merge notes: the work was based on a pre-#69
main. Itsserve.cpprewrite (Backend/backend_for) is re-applied on today'sLaunch/launch_forstructure, andlaunch_foris unchanged frommain. Laya mode:Launchper candidate device, and starts it lazily under a lockdrop_model/set_model--adaptive,--embedding/--reranking,--prefill-deviceand--lean.Tested on Strix Halo:
ctest8/8:laya_gate_rootandlaya_gate_typed_decisions: raw logits ≤ 1e-3, act logits ≤ 1e-3 relative, argmax identical, probabilities ≤ 1e-4 against the Python reference, on the pinned checkpoints.laya_route_e2e: a request reaches the Laya-chosen backend, across vulkan and zinc, plus the npu-only decision.smoke_serve,think_split,npu_*.🤖 Generated with Claude Code