Commit Graph
922 Commits
Author SHA1 Message Date
Niko1221 716ebae14e engine: run on the graphics card's NUMA node on two-node machines
On a machine with two or more memory nodes the engine now restricts
itself, at start-up and before the CPU pool, the host thread and the
helper threads exist, to the CPUs of the node the graphics card is
attached to. A start with nothing pinned then ends with the same thread
masks, pool start-up line and worker count as the same engine started
under taskset on that node (checked on a rented two-socket host with an
RTX 4090; card_node_test checks the decision on made-up machines and the
restriction of a live process).

Measured value: decode with CPU experts on a two-socket host: a
32-worker pool on one node read 1.11-1.18 of the two-node default over
three rounds (UD 4-bit set, RTX 5090 host).

The process is left as it is unless all of these hold: Linux, two or
more nodes with CPUs, the process's CPUs span more than one node (a
taskset, numactl or cpuset restriction is kept), every card the run uses
reports the same known node (sysfs numa_node), the process may allocate
on that node and the node has free memory for the pinned K/V copy and
staging buffers, the threads were not placed by hand (--pool-cores,
STRATA_NUMA_SPLIT, an --aux-cpus list), the CPU is not hybrid, and the
pool keeps its worker count on that node alone (with --pool-workers N:
the node has N + 1 physical cores). A container CPU quota bounds both
counts alike, so the quota's worker count is kept.

STRATA_NUMA_CARD=0 turns it off. One-node machines read the sysfs node
folder and nothing else; there the output is identical to
STRATA_NUMA_CARD=0 (first-token logits, expert-stream counts and
tokens). With STRATA_TRACE set the engine prints one line,
"strata trace: card node: ...", with the inputs and the decision. The
expert arena itself is not placed by this change.
2026-11-14 05:51:17 +01:00
Niko1221 0cb1550665 tests: cover the Q8_0 hyper-connection default and the file check behind it
The rule that reads a UD file's own Q8_0 hyper-connection rows by default on CUDA lived inline in generate.cpp and had no test.
It moves into NativeDense::apply_hc_q8_default (same condition, same environment write) and generate.cpp calls it.

native_dense_hc_default_test builds synthetic GGUFs and checks gguf_carries_q8_hc (Q8_0 rows true, BF16 rows false, inject rows,
one-dimensional tensors, several shards, a missing file) and the rule: unset plus Q8_0 rows sets 1, a value the user set (0 or 1)
is kept, BF16 rows leave it unset.
2026-11-13 16:49:51 +01:00
Niko1221 aad676f43f Merge f-dc-learn-fix fc66df986 into the batch 16 candidate (draft-cost table learning fix) 2026-11-13 16:33:04 +01:00
Niko1221 d3206b1450 Merge f-gyro-floor 2c388837f into the batch 16 candidate (Gyro floor; contains f-i8-gfx11) 2026-11-13 16:33:01 +01:00
Niko1221 2c388837f0 generate: no Hadamard-fold warning on gfx1201
The start-up warning "Hadamard-folded experts are validated end to end on gfx1151 among AMD GPUs, not yet on <arch>" no longer prints on a gfx1201 card (R9700): a Gyro-S run there passed the speed gate and the forced-token KL against the FP16 path. Other AMD cards keep the sentence, which now names both validated architectures. The comment above it names gfx1201.
2026-11-13 16:16:37 +01:00
Niko1221 fc66df9866 spec: the table the learning stretch writes is used by the next start at once
A table made by the one-start stretch (STRATA_DRAFT_COSTS_LEARN=1) had no real-size marks, so the next start held it back for 100 requests (live costs decided meanwhile) and rewrote the file at every request, which also drops a read-only mode. The stretch measured every size of its table, so mark_learned_real() marks all of them real (cost rounded to the 3 decimals the file keeps, so the learning start and the next start run the same numbers) before the file is written. The next start then logs "this machine's table is used", applies the stored CPU prompt share and PCIe share at once, and never rewrites the file. The call sits inside the learning stretch's "ready" block only; the passive path (no STRATA_DRAFT_COSTS_LEARN) does not reach it.

Unit tests: the marks and costs survive the file, a marked table is neither held nor calibrated and asks for no rewrite, an unmarked table is still held.
2026-11-13 15:16:13 +01:00
Niko1221 23c02a7f71 spec: the learning stretch of STRATA_DRAFT_COSTS_LEARN=1 starts a new busy run at every request
A harness that sends its requests back to back is one busy run for the learner, so only the first 6 seconds of the whole run count as fresh rounds. With a load-time effect in the data the stretch then needs 200 fresh rounds, which a burst on a slower card never collects (batch 15: no table after 20, 48 and 144 requests on Boston and z440). While the learning stretch runs, every request now begins a new busy run (CostLearner::starts_busy_run, used where the request's arrival is read). Outside the stretch the rule is the same 0.5 s pause as before, so the passive path (no STRATA_DRAFT_COSTS_LEARN, what a Mac user gets) is unchanged.

Unit test: 40 requests back to back finish the stretch with a busy run per request and never finish it with one long run.
2026-11-13 15:16:02 +01:00
Niko1221 f9bc2d239f Merge f-draft-costs 1b11a76e8 into f-p4-int (the draft-cost table is on by default on Metal only)
CUDA and HIP keep live costs, so a start with no table runs as before; "draft_costs": true in a config turns the table on anywhere. The branch also brings the passive learner of the table and the lookup-window statistic. The only conflict is data/settings-register.json (both sides add entries); both are kept and docs/SETTINGS.md is regenerated from the register.
2026-11-13 12:36:13 +01:00
Niko1221 30c2b84f27 Merge f-switch-point3 216af487d into f-p4-int (the per-card prompt switch rule is on by default for NVIDIA sm_86 cards)
The branch contains f-tail-loan (dd404b382, the prompt loan sized for the tail) and f-switch-point2; the default itself is one commit. The conflicts are mechanical: a test block in CMakeLists.txt (both sides keep their tests) and the generated docs/SETTINGS.md, regenerated from data/settings-register.json.
2026-11-13 12:35:52 +01:00
Niko1221 216af487d7 Turn the per-card prompt switch rule on by default for NVIDIA sm_86 cards
The prompt path now picks, per card, the chunk size from which every expert
the card does not hold is streamed (the floor), and sets the CPU share's
limit to 1.6 times it. It is on with nothing set for one class of card: CUDA,
NVIDIA discrete on PCIe, a single GPU, the start-up link probe ran, compute
capability 8.6. Every other card keeps the fixed 1,024 floor and the fixed
share limit.

STRATA_SWITCH_POINT=0 turns it off; STRATA_SWITCH_POINT=1 asks for it on any
other CUDA card. An explicit STRATA_PREFILL_STREAM_MIN or
STRATA_PREFILL_CPU_SHARE_MAX still wins over the rule.

On an RTX A6000 (UD-Q4_K_XL) the floor is 3,584 and the limit 5,632 against
1,024 and 3,072. With the tail-sized loan in the same build the rule equals
the old default above its limit.

The start-up line no longer calls the rule an opt-in and is printed only when
the floor moved. The rule's unit test covers the class (and every compute
capability, multi-GPU, no probe, integrated and HIP outside it) and the
variable. The settings register entry becomes a rollback switch.
2026-11-13 10:35:14 +01:00
Niko1221 dbe76e32de Merge the per-card prompt switch rule into the tail-sized loan branch
The settings register is regenerated with settings_register.py so that the
entries of both branches are in it.
2026-11-13 10:30:44 +01:00
Niko1221 271eb25a61 Merge f-pool-idle 379e966a5 into f-p4-int (the park pools are refilled only while the engine is idle)
Two commits. The pools that make a conversation park cheap (the checkpoint pool and the segment pool) were topped up while a request was running. Now a permit rule (park_pool_permit) lets them fill only while nothing is in flight; the serve loop kicks the refill at the top, between requests; a park or a periodic checkpoint that finds a pool short takes fresh memory and never waits; the park synchronises the device before it gives pool memory back; one log line per request says how many checkpoints came ready from the pool and how many were allocated fresh. Switches and pool sizes are unchanged. Way back: STRATA_CKPT_POOL=0 (no refill thread) or STRATA_PARK_SEGPOOL_MIB=0.

On a Radeon 780M the engine hung in 6 of 16 starts of a conversation plan with evictions (the GPU stopped answering and the driver reset it); with this change 8 of 8 starts of the same plan are clean. A park costs about 50 ms in a back-to-back test, against 13 to 17 ms before and 92 to 95 ms with the pools off.
2026-11-13 09:37:50 +01:00
Niko1221 9448501635 spec: a real draft-cost price is the median of its 16 rounds, the monotone guard lowers an outlier; the window warm-up runs before READY
srv118 JSON lost 2.4 % (10 of 12 pairs) with the passive table. A/B with hand-edited copies of the table as taken over (par/dc/w5c): the cause was the real price of 2 rows, 20.08 ms instead of about 8.3. The old "more rows never cost less" pass only raised: that one price became the price of every size from 2 to 7 rows and the policy took 12-row windows. Setting 2 rows to 8.5 ms brought the window counts and the speed back (JSON +2.4 % against off), setting sizes 7-12 to the earlier values did not.

- A size's real price is now the median of its 16 collected rounds (CalAcc keeps the rounds, "cal b t n sum v1..vn" in the file; a line without them keeps the mean). A cold first-use round, a stall or another process no longer moves it.
- The guard in apply_table lowers from the trusted side: a guessed size, or a real size below another real size, is lowered to the price of the next larger size first; a real size above an unreached next size is kept and that guess is lifted to it. The Q2_0 4-row / 5-row and the IQ3_S 4-row / 5-row inversions of the taken-over files and the srv118 2-row outlier are fixtures of the unit test (179 of 179).
- The window warm-up (one dummy verify window per allowed width, then session_zero) now runs before the READY line, from the options (lookup_size_mask), single-stage serve without --batch.
2026-11-13 09:23:03 +01:00
Niko1221 84e11a7732 spec: warm every verify window width once before the first request; log text of a taken-over table
A window width builds its graph / pipeline on its first run. A width the policy first picks inside a long request paid that cost there: on the M5 Max with IQ3_S the first five-row lookup round cost 37 ms instead of 25 ms in 5 of 8 launches of the table arm, because the release and the live costs happen to run one five-row round in the first (untimed) request.

serve now runs one dummy window per allowed width 1..S before the first request is read, then session_zero() as a request that reuses nothing does; no checkpoint, conversation entry, RNG draw, policy sample or statistic is touched. Single-stage, non-batch, non-pipelined serve only. STRATA_WINDOW_WARM=0 turns it off (research switch, in the settings register). The engine prints the ms of every width and the total.

The load line of a table that is in use but still collects sizes no longer says "not used yet" (policy.table_held() picks the text).
2026-11-13 08:56:40 +01:00
Niko1221 dd404b382e Add a debug switch that reuses a lent loan by chunk alone
STRATA_DBG_TAIL_NOREUSE=1 turns off the tail half of the loan reuse test, so a
later short segment runs in a layout whose tail is too small. It exists to
show that the chunk check in the prompt path ends such a request with its
error rather than an overrun.
2026-11-13 07:14:03 +01:00
Niko1221 71f3c6db67 Size the lent prompt buffers' MMQ tail from the request's own last chunk
The loan of expert-cache slots laid out the fused MoE buffers for a tail of
stream floor - 1 tokens of MMQ rows, taken out of the expert cache, so every
chunk above the floor streamed more experts (+1.2 to +1.5% prompt time on an
RTX A6000 at a floor of 3,584; a smaller share under today's CPU-share
limit). The lend now sizes the tail from the segment: Prefill::relayout and
bytes_needed take a tail, the lend asks loan_rules for it (grow-only while the
layout's chunk stays), the reuse of a loan by a later segment also needs its
tail to fit, and a chunk below the floor that does not fit the tail ends with
a clear error instead of an overrun.

One GPU, no peer, no --batch above one slot, no head alias; a layer split
keeps the floor's tail. STRATA_PREFILL_TAIL_LOAN=0 restores today's sizing.
2026-11-13 07:07:03 +01:00
Niko1221 8b225dcb2e spec: a machine with no draft-cost table builds one from its normal requests, no learning stretch
A start with no table file (a new engine, driver, model or setting discards it) ran a learning
stretch: forced filler windows to time every window size, for about 1,000 rounds. On a short
JSON request that cost 43 % on an RTX PRO 6000 (chat 6 %), and it would hit every user after
every release. Now such a start is passive from the first request: live costs decide exactly
as without a table, nothing is forced, and the rounds the policy runs anyway are counted per
size (only the first seconds of a busy run, the rule the table was tuned on; no detection of a
load-time effect is needed). A size is real at 16 own rounds; the file keeps the sums across
restarts ("fresh" file, no table lines yet). When every size is real, or after 100 requests, the
table takes over: real costs, and for a size never reached the live cost at that moment (the
policy's own prior when none was measured); such a size keeps collecting. The CPU prompt share
is stored only when a short prompt has measured it.

The old one-start stretch stays behind STRATA_DRAFT_COSTS_LEARN=1 for test harnesses (register
entry: research, harness switch); the server and the launcher never set it.
2026-11-13 06:13:43 +01:00
Niko1221 638533e3fc Merge f-pr-split-n4534 cca88a011 into f-p4-int (each card keeps only its own layers' dense weights on a layer split; the last card's draft-head room)
#4522 (the trim of each card's dense weights to its own layers, now the default for explicit and auto layer splits) and #4549 (the last card's draft-head room), with fixes on top as separate commits: the PLE hash constants and their row-range check restored, STRATA_STAGE_TRIM=0 as the way back, the trim's freed bytes credited to the first card only, exact pricing of a later card's hyper-connection rows and PLE key, a quieter pricing check, one test-fixture fix. #4534 is not in.

One card: nothing changes (48 forced continuations byte-identical to the base). Two RTX A6000 that already hold every expert: decode 122.27 against 122.71 tok/s, prompts 5.6 to 10.0% faster at 2K, 8K and 20K tokens (the base streams experts for the prompt, this build none). Two cards held to 15.5 GB free each: decode 75.88 against 64.16 tok/s (+18.3%), 867 more expert slots on the first card. Way back: STRATA_STAGE_TRIM=0.
2026-11-13 05:26:46 +01:00
Niko1221 8c1fa57f6f Merge f-loan-walk 5bc07c47a into f-p4-int (the prompt loan is sized by the walk a piece takes)
Two commits on c5e4e5109. The prompt path borrows cache slots from the experts for its buffers; the size of that loan is now taken from the walk the piece really takes, not from the rounded chunk. Only a piece whose rounded chunk reaches the floor while its real size is under it changes; every prompt of 1,024 tokens or more with a first chunk at or above the floor is unchanged. Way back: STRATA_PREFILL_LOAN_WALK=0 (settings register entry and one generated row in docs/SETTINGS.md). The second commit is test-only.

Measured on an RTX A6000 (UD-Q4_K_XL, 13,580 of 24,576 slots resident, MTP, fixed draft-cost table): prompt time -14 to -15% at 770 to 1,024 tokens with the CPU share off, -10 to -12% at 2,818 to 3,072 tokens with it on; no change below or above those pieces. R9700: -2 to -4%. With the way-back switch the base numbers come back.
2026-11-13 05:26:29 +01:00
Niko1221 b325833309 serve: a held draft-cost table leaves the CPU prompt share and the PCIe share live too
A table that is held back (live costs decide) also stored a CPU prompt share and a PCIe share,
and the engine fixed both at load, so a first start after a fresh table still differed from a
start without a table. The stored shares are now fixed when the table takes over (the end of the
request in which the last size is calibrated, or the 100th held request), not before. A table
that is used at once (every size calibrated, or 100 requests run) fixes them at load as before.
The log line at take-over says which case it was.
2026-11-13 04:58:36 +01:00
Niko1221 379e966a59 Serve: refill the park pools between requests, not during one
The segment pool's filler and the checkpoint pool's refill (also kicked from
the periodic prompt checkpoints) no longer run while a request is in flight:
their page faults and madvise calls overlapped the prompt read that follows a
park. The serve loop tops both up at its top, when nothing is in flight; a
park or a checkpoint that finds a pool short takes fresh memory and never
waits. The park also synchronises the device before it gives pool memory back.
The request log gets one line with how many checkpoints came ready from the
pool and how many were allocated fresh.
2026-11-13 04:52:36 +01:00
Niko1221 669b34a324 spec: a held table is used after 100 requests even when a size is never reached
Holding the table back until every size is calibrated would hold it back for good on a machine
whose real requests never reach the long lookup sizes (the RTX PRO 6000 table has 12 sizes, the
rounds of the sizes 7 to 12 are rare). The number of requests that ran while the table was held
back is kept in the table file ("reqs"); after 100 of them the table is used, and a size that
real requests have not reached is priced at its learned cost times the mean ratio real / learned
of the real sizes of 2 or more rows (the step of the earlier calibration, restored for this
case only), a size of 1 row at its learned cost. Calibration of those sizes goes on in use.
A start from a file with 100 or more requests uses the table at once.
2026-11-13 04:48:58 +01:00
Niko1221 5938e506da spec: a table that is not fully calibrated yet is held back, live costs decide meanwhile
A learned draft-cost table was used from its first request on, with only part of its sizes
calibrated against real rounds. On a JSON request that costs 5 % against live costs (the 4-row
window is priced under a real round). Now the table is loaded but not used while any of its
sizes is not calibrated: the policy decides with live costs exactly as without a table, the
real rounds are collected meanwhile, and the table (the real costs) takes over for good at the
end of the request in which the last size is calibrated. A table file that already has every
size calibrated is used from the first round, as before.

The provisional pooled-scale step is removed: it only mattered for a table in use with sizes
not yet calibrated, which no longer happens. The unit test covers: a held table picks and prices
like a policy without a table, one calibrated size does not bring the table into use, the last
one does, a fully calibrated file is used at once.
2026-11-13 04:42:54 +01:00
Niko1221 d71da59b29 spec: sizes not yet calibrated follow the sizes that are
A size that real requests reach rarely (the 4-row lookup: about one round per
request) stayed at its learned price for 16 requests while the sizes next to
it were already calibrated, and a price that is only a little lower than its
neighbours' flips a close choice (JSON decode 6 % slower than live costs).

The table file now keeps the learned costs on its bucket lines and the cost
of each real size on rc lines. A size with 2 or more rows that is not real yet
is priced at its learned cost x the mean of (real cost / learned cost) over
the real sizes of 2 or more rows, until it has its own 16 rounds (all sizes
scaled alike would change no choice). Nothing is scaled while no such size is
real. Unit test draft_policy_test: 147 of 147.
2026-11-13 03:58:17 +01:00
Niko1221 c3a861156d spec: a fixed draft-cost table is calibrated against real rounds, size by size
The learned costs come from a learning stretch (forced windows with filler
rows, a burst of prose). On an M5 Max a real round of 2, 3 and 5 rows costs
about 2 % more, which flips a close choice between a 4 and a 5 row lookup
window: JSON decode 6 % slower than live costs.

After a table is fixed, every real round (never a forced one) of a size that
still has its learned cost is kept, clamped to 0.85-1.30 x the learned cost,
and only the first 6 s of a busy run when the learning stretch showed a
load-time effect. The rounds are kept in the table file across starts
(state, real, cal lines). At 16 rounds a size takes their mean, is marked
real in the file and never changes again; a mean outside 0.86-1.29 x the
learned cost drops the rounds and collects again. A size that real requests
never reach keeps its learned cost. The new cost applies from the next
request. Unit test draft_policy_test: 145 of 145.
2026-11-13 03:54:17 +01:00
Niko1221 5d26d6f4ba spec: a learning stretch can time a lookup-type window in a round that has no proposal
On the M5 Max the MTP window is at most 3 rows, so windows of 4 and 5 rows exist only as lookup windows, and a prose learning stretch has a
lookup proposal in about 2 % of its rounds: with forcing limited to the first 6 seconds of a busy run (the rounds that count), sizes 4 and 5 got
11 and 31 rounds in the burst (table 12.808, 14.397, 16.526, 18.810, 21.094).

- DraftPolicy::explore_lookup(cap): in a round with no lookup proposal, a learning stretch may run a lookup-type window of the smallest unmeasured
  size (2..cap rows); every row after the first is filler (the MTP's own first guess repeated, which the verifier rejects). Same limits as the other
  forced windows: from round 100, only while the rounds count, 40 per size, 300 per stretch, deterministic windows only, learning only.
- Unit test draft_policy_test: 117 of 117.
2026-11-13 02:41:31 +01:00
Niko1221 f3ebb13687 spec: restore the CLI loop's observe_probs line
The previous commit also changed the CLI loop's observe_probs condition, but that loop has no forced-window variable, so the Metal build
failed there. The line is back as it was; only the serve loop changes.
2026-11-13 02:34:44 +01:00
Niko1221 bcbaf72dd4 spec: a learning stretch times window sizes in the rounds where they count, on every round
On the M5 Max the learning burst is one busy run, so only its first 6 seconds (about 375 rounds) are fresh rounds, and the sizes the table is made
of must be measured there. The forced rounds of the previous commit started after 300 rounds (after the fresh seconds) and needed a lookup proposal:
sizes 4 and 5 reached 68 and 95 rounds in the whole burst but under 20 fresh ones, so the table still filled them (12.651, 14.315, 16.398, 18.481, 20.564).

- A round with no lookup and no chain may run its MTP / drafter window at another size (DraftPolicy::explore_window): the smallest size under 30
  usable samples, not the size the round already has, up to the widest window; rows past the real drafts are whatever the drafts array holds
  (valid ids, rejected by the verifier). Deterministic windows only (not a probabilistic MTP window, not a gated proposal), learning only.
- Forced rounds start after 100 rounds and happen only while they count: in the first 6 seconds of a busy run, or when the stretch has shown no
  state effect (size with 20 fresh and 20 late samples agreeing within 2 %); a stretch with only late rounds so far does not force.
- A forced round goes to the learner and the size's cost and to no MTP / lookup / probability statistic (observe_forced; observe_probs skipped).
- Usable samples = fresh ones with a state effect, fresh + late otherwise (CostLearner::usable, state_known).
- Budget 300 forced rounds per stretch, 40 per size.
- Unit test draft_policy_test: 116 of 116.
2026-11-13 02:33:20 +01:00
Niko1221 d877f150a0 prefill: scale the research switch-point rule per card
The floor from STRATA_SWITCH_POINT=1 now takes the cache mean blob, the
start-up link probe and the SM count (copy terms by blob / link, compute
terms by 1 / SM); the floor is the real crossing rounded down to the 256 grid,
and the CPU share limit of a card whose floor moved is floor x 1.6. An unknown
card (no probe) keeps 1,024. Research only, default off.
2026-11-13 02:29:07 +01:00
Niko1221 e84392acc0 prefill: research switch STRATA_SWITCH_POINT, the walk of a chunk by estimated cost
With STRATA_SWITCH_POINT=1 (CUDA builds, default off) the chunk size from
which a prompt chunk streams every expert the card does not hold is taken from
a cost estimate of the staged and the streamed walk, from the card's share of
non-resident experts, instead of the fixed 1,024. A card that holds every
expert keeps 1,024 exactly. STRATA_PREFILL_STREAM_MIN, the CPU share's limit
and the Windows gfx1151 floor keep precedence; the small-card walk is not
touched.

The rule is a pure header (switch_point_rule.hpp) with a unit test; the card's
counts reach it through Prefill::set_card_expert_share, called before the
first lend. Register entry: research.
2026-11-13 02:27:27 +01:00
Niko1221 c43347d094 spec: a learning stretch times window sizes past its proposals with filler rows
Sizes 5 and 6 of the Radeon 780M and 4 and 5 of the M5 Max were never reached by a lookup proposal in a prose learning stretch, so their
table entries were filled in (780M: 174.9 and 206.1 ms against 160 and 178 measured by live costs; the lookup of 5 rows was then priced
out and the frozen table lost 1.9-2.5 % on code and JSON to live costs).

- choose() takes pad_cap: during learning, when the caller allows it (a deterministic proposal, never a probabilistic window), the window of the
  smallest size with under 30 samples is run even when the proposal is shorter; the rows past the proposal repeat its last token, which the
  verifier rejects. Pick::pad says how many rows are filler.
- A window run this way goes to the learner and to the cost of its size (observe_forced) and to no lookup or MTP statistic.
- The forced-round budget is 200 per stretch (40 per size).
- Unit test draft_policy_test: 108 of 108 (5 new: padded window, filler count, forced round feeds no statistic, pad_cap of one draft).
2026-11-13 02:25:47 +01:00
Niko1221 e474c27bf8 Layer split: price a pipelined two-stage split as the sum of the stages again
Reverts the effect of the merge of PR 4534 (b1b8b8d3d): with --pipeline-windows 2 and two stages the
search priced a split by its slower stage (its layers, 12 layer-times for the last stage's head and draft
chain, its misses) instead of the sum of the stages.

On two RTX A6000 (UD-Q4_K_XL, MTP, 36 requests of 300 tokens, fixed draft-cost table, medians of three
interleaved rounds) the rule moved a pair that already holds every expert from K=24 to K=30 and
decoded 119.2 tok/s [118.5, 119.5] against 126.8 [126.7, 126.9] with the sum. With the split fixed
under --pipeline-windows 2 the measured decode falls as K grows: K=24 126.5, K=26 126.0, K=28 124.0,
K=30 120.3 tok/s. The overlap the rule assumes is 3.5% on this pair (126.8 against 122.7 serial), not
the 17% it predicted. The rule is not on by default on CUDA; it would change the default placement
of AMD gfx12 pairs, which have not been measured with it.
2026-11-13 02:16:01 +01:00
Niko1221 1e50a146ed spec: a learning stretch measures the window sizes it can pick
The draft-cost table was filled in for every size with fewer than 20 rounds. On the Radeon 780M two sizes had 2 and 6-12 rounds, the filled
values (134.6 / 129.7 ms against 143 measured for 4 rows) lay below the measured trend, and a frozen table of guessed sizes can lose to live costs.

- After 300 rounds of a learning stretch, a lookup proposal long enough for a size that has under 30 samples takes that size's window
  (smallest size first), at most 40 times per size and 150 times in a stretch. Nothing is forced when learning is off or the costs are fixed.
  A learning stretch was never repeatable: window sizes follow the live costs.
- A size with 5 to 19 rounds counts by its median when that median is not below the fill and at most 1.5 times it; a handful of stalled rounds does not.
- A size above the measured ones continues the steeper of the last segment's slope and the slope over all measured sizes, and the table is written up
  to the largest allowed window size (so no size is left to the prior shape).
- CostLearner::table gains an `upto` argument; DraftPolicy gains reset_learning(), top_size() and forced_rounds().
- Unit test draft_policy_test: 103 of 103 (15 new: table fill rules, forced-round budget, per-size cap, none when fixed or not learning,
  a size no proposal reaches).
2026-11-13 02:05:23 +01:00
Niko1221 3ffa59e2be Merge f-kq-line 0ce77eaf8 into f-p4-int (the K-quant start-up line prints only when the loaded model has K-quant experts)
Two commits on 7d7590f40. The line "a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on ..." was printed at option time, before the model is known, so an IQ3_S or IQ2_XS set that has no K-quant layer also showed it. The default is still set at that point; the line is now printed once the expert layout is loaded, and only when some layer has a gate/up or a down tensor of Q4_K, Q5_K, Q6_K or Q5_1 (the types the K-quant switches decide for). The wording is unchanged and so is every default. Unit tests on the two deciding functions; the second commit keeps the unit test from reading STRATA_DEFAULTS before the check that sets it. The same kind of line on gfx12 (HIP) is not changed.
2026-11-13 01:41:31 +01:00
Niko1221 15a4be9c7a spec: the draft-cost table learns from the first seconds of a busy run
The learned window costs came from one continuous learning stretch. On a GPU that
slows down under sustained load (measured on an M5 Max: 1 row 14 %, 3 rows 21 %,
5 rows 27 % slower after 75 s of continuous load) the stretch priced 5 rows at
1.38 times 3 rows against 1.30 for a request that arrives after a pause, so
the fixed table priced two profitable 5-row lookup windows per request out.

The learner now keeps each round with the busy age it ran at (seconds since the
last pause of 0.5 s or more between requests, measured at the request's arrival).
Rounds of the first 6 s are fresh, the rest late. The table uses the fresh rounds
when a size with 20 samples of both differs by more than 2 % between them, and
every round otherwise (the Radeon 780M shows no difference, so it keeps all its
rounds). A stretch that never pauses ends after three times the round quota when a
fifth of the quota is fresh. Sizes with fewer than 20 samples above the measured
ones continue the straight line through the two largest measured sizes; the table
never falls from one size to the next. The file header is version 2, so tables
already learned are learned again; a table is still written whole or not at all,
only when the stretch is ready, and is fixed from then on.
2026-11-13 01:17:13 +01:00
Niko1221 b637627a37 prefill: size the prompt loan from the walk a piece takes
A prompt piece below the stream floor walks staged, but its loan of cache
slots was sized from the chunk rounded up to the 256 grid: a 999-token piece
under a 1,024 floor was lent the streamed layout (512-slot ring, fused MoE
buffers). The loan now uses floor - 1 for such a piece. Default on;
STRATA_PREFILL_LOAN_WALK=0 keeps the rounded chunk. Pure rule with a unit test.
2026-11-13 00:52:55 +01:00
Niko1221 3e28250e84 Docs: the dense-weight trim is the default with a layer split
STRATA_STAGE_TRIM moves from the opt-in table of docs/MULTI_GPU.md to a new "Turning a default off"
table (STRATA_STAGE_TRIM=0 or --no-trim-stage-weights keeps every card's full copy). docs/BATCHING.md
and the --trim-stage-weights usage line say the trim applies to explicit and auto splits and is the
default. The settings register marks STRATA_STAGE_TRIM as a rollback setting.
2026-11-13 00:29:52 +01:00
Niko1221 4f84787d6e nvidia: the start-up line about K-quant experts prints only when the loaded model has them
The line "a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on ..." was printed at option time, before the model is known, so it also appeared for an IQ3_S or IQ2_XS set that has no K-quant layer. The default is still set at that point (before any engine code reads its switches); the line is now printed once the expert layout is loaded, and only when some layer has a gate/up or a down tensor of one of the four types STRATA_MMQ_KQ and STRATA_PF_FUSED_KQ decide for (Q4_K, Q5_K, Q6_K, Q5_1; the types prefill::mmq::supported() hands to the K-quant switch). A set whose only such tensor is a Q5_1 down still prints it, because the switch decides that product. The wording is unchanged, and so is every default.

nv_kq_expert_type and nv_kq_line_wanted are the deciding functions, with unit tests in nv_defaults_test (IQ3_S / IQ2_S / IQ2_XS sets: no line; Q8_0 down only: no line; UD-Q4_K_XL: line; one Q5_K layer among i-quant ones: line; Q5_1-only down: line). apply_nv_kq_default gets a say argument (true by default) so the engine can set the default early and print later.
2026-11-13 00:19:15 +01:00
Niko1221 210bf9410c Layer split: do not warn about under-pricing of a few MiB
The check after a later stage's load compared the search's price with what the card lost.
With the hyper-connection rows and the PLE key priced (previous commit) the two agree to
1-2 MiB (2677 against 2678 MiB, 2020 against 2022 MiB on a two-card UD-Q4_K_XL start), and
the card reports free memory in 2 MiB steps, so an exact "priced < took" test warned on
rounding. It now warns when the price is more than 8 MiB under what was taken, or more than
5% over, as before.
2026-11-13 00:16:40 +01:00
Niko1221 59211f98b1 Merge f-fused-staged e521524f3 into f-p4-int (Windows Strix Halo reads prompt pieces below 1,024 tokens on the fused kernels' staged group entry; --short-read defaults to 24 there)
Five commits on f33e9fa7b (the earlier short-piece rule). On Windows with one gfx1151 card and a layer set in which every layer has no MMQ tile and the fused kernels take it (UD-Q4_K_XL), a
prompt piece below 1,024 tokens (the batched ones, from 26 tokens) now takes the staged walk's fused group entry: only the routed experts stream and they run on the fused kernels, with FP32 down
rows, instead of a dequantize and two FP16 GEMMs per routed expert. The step-one floor of 64 applies only with the entry off. The serve loop's --short-read default is 24 instead of 64 on that
class (a --short-read on the command line wins). Pieces of 1,100 tokens and more, other cards, other systems and sets with an MMQ tile are unchanged. STRATA_PF_STAGED_FO=0 is the way back
(the earlier behaviour byte for byte); with STRATA_PREFILL_STREAM_MIN=1024 as well it is the old FP16 path; STRATA_PF_STAGED_FO=1 asks for the entry on any card (research).

Measured on a Strix Halo (UD-Q4_K_XL, three rounds, one start per arm): prompt ms with the old FP16 path / the earlier rule / this default 303 / 303 / 268 at 32 tokens, 595 / 595 / 317 at 64,
1,797 / 418 / 343 at 128, 2,305 / 514 / 449 at 256, 3,675 / 1,022 / 977 at 1,000; 1,100 and 2,048 tokens the same in every arm. Forced-token KL of the default against the long path with FP32 rows 0
at 256 and 768 tokens, the way back equals the earlier rule (KL 0, 36 of 36 request ids identical). Decode unchanged (65.8 ms a window).

The branch changes data/settings-register.json, docs/STRIX_HALO.md, prefill.cpp and generate.cpp; the register is regenerated by its tool on the merged tree with the branch's hand-kept entries
(the new STRATA_PF_STAGED_FO and the note of STRATA_PREFILL_STREAM_MIN).
2026-11-13 00:09:19 +01:00
Niko1221 0b3364d416 Layer split: price a later stage's Q8_0 hyper-connection rows and the PLE key
The split search prices a later stage's weights from the pack index and the GGUF headers
(carve_bytes, NativeDense::weight_bytes_for), and NativeDense::load then allocates them.
Two parts of the load were not in the price:

- With STRATA_HC_Q8=1 (set by default when the GGUF carries Q8_0 hyper-connection rows) load
  copies those rows of its layers, and the final mixer's, to the card: 0.32 GiB for the second
  card of a 48-layer UD-Q4_K_XL file on two cards. weight_bytes_for now adds them, one granule-rounded
  allocation each, with the same filters as load (stage-local unless STRATA_HC_Q8_ALL_STAGES=1,
  F32 inject rows only with STRATA_HC_Q8_INJECT=1, and the bf16 pack's down / up projections).
- load takes the PLE key (blk.1.ple_key.weight) on every stage; the price skipped it for a stage
  that does not run layer 1.

allocated_bytes() now counts the Q8_0 hyper-connection rows too. When the check after a later
stage's load still finds the price off by more than 5%, the log says which part drifted
(projections priced against loaded, the rest priced against what the card lost).

native_dense_price_test builds a small GGUF and checks, for three stage ranges, that the price
equals what load allocates (needs a CUDA device; skipped without one).
2026-11-12 23:51:22 +01:00
Niko1221 191202132c Layer split auto: credit the trim's freed VRAM to CUDA0 only, not to the later stages
The search adds what the trim frees to each stage's room for experts. That is right for CUDA0, whose arena holds the dense weights of all layers when the search runs and gives back everything outside its own layers when it reloads trimmed. A later stage has not loaded anything yet when the search runs (its weights load after the split is known) and the search already prices its trimmed weights, so crediting it the bytes a trim would free counted the same bytes twice and handed the card cache room it does not have.
split_rules::trim_credit(stage, freed) is the rule (stage 0 gets the freed bytes, the others 0) with a unit check in split_rules_test; generate.cpp calls it where it used trim_frees directly.
2026-11-12 23:39:34 +01:00
Niko1221 116cdf2a35 serve: --short-read defaults to 24 where the staged fused entry reads short pieces
With the staged group entry on (Windows gfx1151, a layer set with no MMQ tile that the fused kernels take, STRATA_PF_STAGED_FO not 0) a batched read of a short
piece is cheaper than the verify windows from about 28 tokens. Strix Halo, UD-Q4_K_XL, prompt ms, median of 3 (windows / batched): 24 tokens 231 / 261,
32 tokens 303 / 265-270, 48 tokens 453 / 293-299, 64 tokens 598 / 314-316. The class default of --short-read is therefore 24 (the largest size measured
where the windows win; 64 stays everywhere else). A --short-read on the command line wins; the setting is not part of the draft-cost table key
unless it is given.
2026-11-12 22:40:12 +01:00
Niko1221 2f1b77b262 Layer split: do not count the PLE weights as freed by the trim
The split search adds what the trim frees to each card's expert-cache room. It counted the six blk.1.ple_* weights of layer 1 as freed on every later card, but the loader keeps the PLE weights on every card (the same rule as add_foreign), so the search room was a little too big. The per-layer row list now leaves the PLE rows out, which also keeps them in the first card's reload.
2026-11-12 22:30:35 +01:00
Niko1221 7c76ce4f16 One GPU: do not print the "--trim-stage-weights needs a layer split" line unless the flag was given
With the trim on by default, the line "--trim-stage-weights needs a layer split across GPUs (ignored)" would have printed at every start on one card. It now prints only when --trim-stage-weights was given on the command line, as before. The engine log of a one-card start is unchanged.
2026-11-12 22:30:01 +01:00
Niko1221 4c39e8624e Layer split: STRATA_STAGE_TRIM=0 still turns the trim off, and the short-card spill walk keeps its rule
The trim of each card's dense weights to its own layers is on by default with a split now (PR 4522). Two documented things must not move because of that:
- STRATA_STAGE_TRIM=0 is the documented way back and must keep switching the trim off, next to --no-trim-stage-weights. A given --trim-stage-weights still wins over STRATA_STAGE_TRIM=0, as before.
- The spill walk of 0.2.10 / 0.2.11 (two 8 GB cards: the split is chosen before anything loads, every card trimmed) reads "the user asked for the trim" (the flag or STRATA_STAGE_TRIM=1), as it always did. With the trim on by default that condition was always false and the walk was never reached, so short cards would have loaded the full dense set on CUDA0 again. The walk's two conditions now test the request, not the default.
No change with one card, and none for cards with room.
2026-11-12 22:30:01 +01:00
Niko1221 7e9bf8c8f8 PLE: use the model file's hash constants again, and keep the row-range check
The engine reads the PLE hash constants out of the model file when it carries them (ple_consts_run), and refuses to start when a hash would reach past the PLE table's rows. A rebase of the trim change (PR 4522) lost both: the wiring step took the default constants (ple_artifact_consts) and the range check was gone. That change reaches a single card too, so a model whose file has its own constants would have been hashed with the wrong ones.
This puts back the two lines and the check as they were before the merge. No other change.
2026-11-12 22:29:34 +01:00
Niko1221 3f64aa6534 Merge PR 4549 (f9a09885c) into f-pr-split: a layer split keeps the draft head's room out of the last card's cache
One commit by cobra91 on dbb2d168c, merged as written: in the per-stage cache sizing the last stage subtracts the draft head and its logits (mtp.bind_bytes), as one GPU does (#199), so they no longer come out of that card's reserve.
1 file: src/program/generate.cpp, 7 lines added, 2 changed. Git merged it without a conflict.
2026-11-12 22:28:51 +01:00
Niko1221 d20c94caeb Merge PR 4534 (b1b8b8d3d) into f-pr-split: the split search prices a pipelined two-stage split by its slower stage
One commit by cobra91 on dbb2d168c, merged as written: with --pipeline-windows 2 and exactly two stages the search's predicted window time is the slower stage's (its layers, plus about 12 layer-times for the last stage's head and draft chain, plus that stage's misses on its own link) instead of the sum of the stages. Nothing changes without --pipeline-windows 2 (on CUDA it is not on by default).
1 file: src/program/generate.cpp, 16 lines added in the search's predict lambda. Git merged it without a conflict.
2026-11-12 22:28:51 +01:00
Niko1221 b4a0b5e227 Merge PR 4522 (935165402) into f-pr-split: every card trims its dense weights to its own layers on --layer-split auto too
Two commits by cobra91 on dbb2d168c, merged as written: per-card weight trimming on --layer-split auto (default on, --no-trim-stage-weights keeps the copies; the split search counts the freed VRAM towards each card's expert cache; CUDA0 reloads only its own layers' dense weights), and the reload resets the process-wide layer range before each stage.
3 files: include/strata/core/native_dense.hpp, src/core/native_dense.cpp, src/program/generate.cpp. Git merged generate.cpp without a conflict.
2026-11-12 22:28:38 +01:00