8b95bffb0bf2bb7460f0a12e97e23cfa6c7ebbbf
4323
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
8b95bffb0b |
Decode: opt-in STRATA_MMVQ_IL_PF=1 hoisted-load, exact-integer interleaved GEMV kernels for Q6_K (#3779, #3712)
Problem: the interleaved small-batch matvec (native_mmvq_il) has one weight block in flight per warp: its four `if (kbx < bpr)` sections each sit behind their own branch, so on a GA100 (ncu: 432 GB/s on the qkv Q6_K matrix) the loads of a group are not issued together. Change, opt-in (every variant is bitwise native_mmvq): native_mmvq_il_pf_kernel issues every weight load of a group (4 virtual warps x R rows) before any of the group's dots, with the addresses clamped to the row's last block for a tail, and with the ring variants the next group's loads before this group's dots. The per-lane accumulation order is the plain kernel's. P2's forms replace conversions by exact ones where the value is a small integer: (float)p becomes p + 1.5 * 2^23 minus 1.5 * 2^23 for |p| < 2^22, and the saturating byte subtract of Q6_K's codes (0..63, so nothing saturates) becomes two instructions. Q4_K, Q5_K, IQ4_XS and Q6_K have the variants; Q3_K (the Q2_0 pack's type) keeps the plain kernel. - STRATA_MMVQ_IL_PF=1: the measured table (kIlPf_80 / kIlPf58_80: Q6_K only, read only when the card is sm_80; on every other card 1 does nothing); =2..6: one variant for every type and shape (A/B only, any CUDA card). - Unset or 0: the plain kernels through the same launch code (the variant argument is 0, and the added code is one cached environment read and a switch). - CUDA only; HIP has no interleaved path. Tests: mmvq_il_parity --pf a,b,.. bit-checks each listed variant against native_mmvq for every type and shape, T = 1..8 and rows 0/1/2/4, and with --bench times them interleaved (PFBENCH lines) and prints the joint (variant, rows) table in the source form of kIlPf_<cc>. New ctest entry mmvq_il_parity_pf runs it with --pf 0,2,3,4,5,6 on whatever card is present. Reporter's numbers (linxuhao, CMP 170HX): decode +1.4 % (two reference / on / reference / on sets) over the plain kernels; with STRATA_GRAPH_PRIO decode +1.3 % in their per-feature pair (4K prompts +3.9 %, 16K +1.2 %, 52K +0.2 % in the same pair, which the reporter reads as noise). Q4_K, Q5_K and IQ4_XS variants tie the plain kernels there. Theirs, not measured here. Original change by linxuhao (PR #3779, commit 116992ab). |
||
|
|
c2d3fe5000 |
mmvq_il_parity: the L2-residency arms (--hot / --gap / --persist / --ab), the clock warm-up and MMVQ_IL_TMIN (#3779, #3712)
Harness only; no engine code. The bench part of mmvq_il_parity times the interleaved matvec cold (24 copies of the weights rotated past the L2), hot (one copy), hot with other weights' reads in between (--gap MB, what a window's GEMVs do between a prefetch and its consumer), and with the timed weights in a persisting L2 set-aside (--persist); --ab runs the five arms per case in one process, because the clocks ramp over the first ~100 ms of a run. A 150 ms warm-up of launches runs before the first timed case, and MMVQ_IL_TMIN bounds T from below. The parity part is unchanged: without --bench the same checks run in the same order (every rows choice against native_mmvq, bitwise). The bench code is CUDA only (the test is built with STRATA_ENABLE_CUDA); the persisting-L2 calls are left out under STRATA_HIP_GFX906. Original change by linxuhao (PR #3779, commit 1f4b8139). |
||
|
|
0049fa73ff |
Decode window: opt-in STRATA_GRAPH_PRIO=1 gives the window graph's kernel nodes their stream's priority (#3779, #3712)
Problem: the decode window graph runs every kernel node at the launch stream's priority, so the one-block indexer kernels of the side branch wait behind the queued blocks of the big q GEMV, and the shared expert competes with the routed experts. Change, opt-in (bitwise by construction: no kernel changes, the same launches on the same inputs; only the dispatch order moves): with STRATA_GRAPH_PRIO=1 the side mixer's branch stream (GDN gates, QSA indexer chain) is created at the device's highest priority, cs_ and side2_ in the middle, the shared expert's stream at the lowest, and the window graph is instantiated with cudaGraphInstantiateFlagUseNodePriority. If a driver did not copy the stream priority into the nodes, the capture-time notes (the branch forks and the priority streams' tails) set the attribute per node. One log line per captured window prints the node priority histogram. A card whose priority range is 0..0 changes nothing. CUDA only: the members and the three methods sit under !STRATA_USE_HIP && !STRATA_HIP_GFX906 && !STRATA_GPU_METAL; graph_prio_on() is false there. Merged by hand with #3702 (the window-graph eviction): instantiate_evicting now takes both keep_t and the flags, and the retry after freeing other window sizes keeps the flags (the merged code would otherwise have dropped the node priorities on that retry). With the variable unset: every stream is created as before and the capture-time notes return at once. Tests: none of its own (a priority is a scheduling hint with no value to compare). The window graphs are exercised by the engine; see the checklist for the reporter's greedy-answer identity check. Reporter's numbers (linxuhao, CMP 170HX, IQ3_S, --spec 3, 3K context, interleaved in one session, each arm with STRATA_QIL=1): reference 125.3 / 126.6, GRAPH_PRIO 127.8 / 129.0, reference 125.0 / 126.8 tok/s, +1.8 %. Greedy 11 of 11 identical. In the later per-feature pair together with STRATA_MMVQ_IL_PF: decode +1.3 %. Theirs, not measured here. Original change by linxuhao (PR #3779, commit 68c487c3). |
||
|
|
0e63d59c01 |
docs: conversation cache copies on a slow host link, STRATA_CKPT_ASYNC and the park switches (#3779, #3712)
One section in DETAILS.md for the switches the four conversation-cache commits add: what each copies where, its VRAM and host memory cost, that they stay off on HIP, gfx906 and Metal, and the measured times. Rewritten from the PR's section: the times are labelled as the reporter's (linxuhao, one CMP 170HX on PCIe Gen2 x4; we have no sm_80 card and measured none of them), the independent RTX 3090 data of bitaccesscomau is added, and the pool row describes STRATA_CKPT_POOL_READY=N instead of the PR's change to the meaning of STRATA_CKPT_POOL=N (STRATA_CKPT_POOL=1 is unchanged). Original section by linxuhao (PR #3779, commit a04f4399). |
||
|
|
85e3dde522 |
Conversation cache: opt-in STRATA_PARK_VRAM_MIB=N keeps parked conversations' K/V in VRAM in front of the host copy (#3779, #3712)
Problem: restoring a parked conversation copies its K/V from the host over the link: 27-107 ms over a PCIe Gen2 x4 link. Change, opt-in and only with STRATA_PARK_ASYNC=1 (CUDA only): a park also keeps the whole K/V of its image in a VRAM slot of its own (64 MiB granules, up to N MiB in all, only while 1.5 GB of VRAM stays free beside it); the background copy to the host reads from the slot, and a restore of that image copies device to device from the slot (about 1 ms) without waiting for the background copy. Each K/V layer carries its own join-and-release token, so any order of destruction is safe (the layers outlive their image when they are retained for the next park). Under VRAM pressure the elastic K/V's growth releases every slot and the stage, then retries once (both growth sites in generate.cpp). With the variable unset the slot code is not reached: the budget is 0, a restore finds dev_tag 0 and takes the host path, and the growth sites see conversation_park_vram_release_all() return 0 and behave as before. Tests: none of its own (it needs a card with the VRAM for the slot and a parked conversation); see the checklist for the reporters' A/B/A conversation check with STRATA_PARK_VRAM_MIB set. Reporter's numbers (linxuhao, CMP 170HX): restore of a 3K conversation 28-47 -> 7-12 ms; outputs identical. The first restore of a run is slower (41.6 / 56.9 ms) than later ones (6.5-12.6 ms) and they have not found why. Theirs, not measured here. Original change by linxuhao (PR #3779, commit bafca410). |
||
|
|
ca378670b2 |
Conversation cache: opt-in ready checkpoint pool STRATA_CKPT_POOL_READY=N, gathered small checkpoint copies STRATA_CKPT_GATHER=1, park traces (#3779, #3712)
Problem (reporter, CMP 170HX, PCIe Gen2 x4): a conversation switch's park still paid 38-52 ms for the live state, because the STRATA_CKPT_POOL pool was empty at every park (a switch takes two checkpoints), so the 118 MB GDN vector was allocated fresh and page-faulted; and a checkpoint's 37 small synchronous device-to-host copies queue behind the 4 MiB DMA pieces of STRATA_CKPT_ASYNC. Change: - STRATA_CKPT_POOL_READY=N (opt-in, 1..16, with STRATA_CKPT_POOL on): the pool keeps N ready checkpoints, pre-sized to the session's state sizes with their pages in, topped up on a background thread after any take (not with a layer split). - STRATA_CKPT_GATHER=1 (CUDA, opt-in): the small running-state vectors (ple, and each layer's indexer tail, dead row and block position) are gathered device to device into one buffer and fetched with one copy into a pinned buffer. - The park stage is allocated rounded up to 64 MiB (a growing conversation does not cudaFree/cudaMalloc it every time) and a VRAM-resident K/V skips the pointer attribute query. - The background helpers (pool top-up, the checkpoint DMA, the park DMA) leave the host's pinned core (aux_cpus.hpp); no output depends on where a thread runs. - A parked image whose live GDN state is still being copied joins before its buffers are freed (SavedConversation::live_pending). - STRATA_PARK_TRACE prints the joins, the live-state vectors' readiness and the K/V sub-timers. Differs from the PR as submitted: the PR made STRATA_CKPT_POOL=1 allocate two ready checkpoints at startup (+236 MB of host RSS) and read STRATA_CKPT_POOL=N as a count. That changes what an existing switch does, so here STRATA_CKPT_POOL=1 keeps its meaning (the pool holds dropped checkpoints only, nothing is allocated ahead of time) and the ready pool has its own variable, STRATA_CKPT_POOL_READY. A user of the PR's STRATA_CKPT_POOL=2 sets STRATA_CKPT_POOL=1 STRATA_CKPT_POOL_READY=2. The PR's one-checkpoint refill after a park with STRATA_PARK_ASYNC is replaced by the top-up, as in the PR, and so is only active with the new variable. Merged by hand into #2526's park_source. With none of the new variables set: the stage size is rounded up only when the park stage is on, the extra code is trace output behind STRATA_PARK_TRACE and the join calls. Reporter's numbers (linxuhao, CMP 170HX): park at a 3K context 64-75 -> 21-40 ms (all park switches together, A/B/A conversation check identical, greedy 11 of 11 identical). Theirs, not measured here. Original change by linxuhao (PR #3779, commit 56088e71). |
||
|
|
f73b3c86a4 |
Conversation cache: opt-in STRATA_PARK_ASYNC=1 parks the K/V in the background and moves the dropped checkpoints (#3779, #3712)
Problem: parking the outgoing conversation copies its K/V device to host and deep-copies its checkpoints before the next prompt can start: 213 ms at a 3K context, 334 ms at 13K on a PCIe Gen2 x4 card (the reporter's CMP 170HX). Change, opt-in and CUDA only (off on HIP, gfx906 and Metal): - STRATA_PARK_ASYNC=1: conversation_kv_save copies the device K/V device to device into a VRAM stage (only while 1.5 GB stay free beside it; otherwise the save copies as before), and a background thread moves the stage into the host buffers in 4 MiB pieces through two pinned buffers. conversation_park_join waits for it: every reader of a parked image's K/V, the cache before it frees an entry, and the image itself (SavedConversation::pending) before its buffers go. ConversationBuffer::resize_for_overwrite leaves the added bytes unfilled for that copy; the buffer's segments use an allocator that value-initializes only when a fill value is given, and resize(n, value) is unchanged for every other caller. - With it, the checkpoints this request drops right after the park (all of them when another state comes in, else the ones off this prompt's path) move into the parked image instead of being copied, and a background allocation refills STRATA_CKPT_POOL for the next save. Only the main session's checkpoints move, not an idle batch slot's (the park_source of #2526 serves both). - conversation_snapshot_save takes dropped checkpoints' storage (the existing STRATA_CKPT_POOL) for its copies; with the pool off, nothing is taken. - Unset: park_drops is null, no storage is taken, the K/V copies are the synchronous ones; the added work is the K/V size sum for the stage request and a few join calls. Differs from the PR as submitted: the PR's join in conversation_file.cpp (put_payload) is not ported; the SAVE/RESTORE handler of generate.cpp joins the park first (see the previous commit, which carries the PR's 33a8146a fix). Hand-merged into the park_source / ParkSource refactor of #2526. Not covered: if the background copy fails after resize_for_overwrite, the parked image keeps unfilled bytes; the failure is logged. A restore of such an image would read them. No test of the park path with a failing copy. Tests: the PARK_ASYNC path has no unit test in this commit (it needs a card with 1.5 GB free for the stage); the reporter's A/B/A conversation check covers it, see the checklist. Reporter's numbers (linxuhao, CMP 170HX): park 213 -> 64-75 ms (3K), 334 -> 68 ms (13K); greedy answers identical on their 11 prompts and the A/B/A conversation check. Theirs, not measured here. Original change by linxuhao (PR #3779, commit 3e0c141c). |
||
|
|
0f7224d168 |
Conversation checkpoints: opt-in STRATA_CKPT_ASYNC (background device-to-host copy) and STRATA_CKPT_VRAM_SLOTS (#3779, #3712)
Problem: on a slow host link a turn checkpoint copies the whole GDN state to the host on the request path (118 MB at 1.64 GB/s on a PCIe Gen2 x4 card, 72 ms; an independent RTX 3090 on PCIe 3.0 x16 showed 73 ms to 62 ms with the switch). Restoring a parked conversation copies it back. Change, both opt-in and CUDA only (off on HIP, gfx906 and Metal): - STRATA_CKPT_ASYNC=1: the GDN state is copied device to device into a VRAM stage (one buffer the size of the state, allocated at the first checkpoint save, plus a pinned host buffer of the same size; if either allocation fails the save falls back to the synchronous copy), and a background thread moves it in 4 MiB pieces into the checkpoint's host vector. Every reader joins first and only for the copy it needs (restore, snapshot save and restore, the parked copies, the serve loop at each request start, the SAVE/RESTORE session handler). - STRATA_CKPT_VRAM_SLOTS=N (with ASYNC): the last N saved GDN states stay in VRAM, tag-checked, only allocated while 1.5 GB stays free; a restore of a checkpoint whose tag a slot holds copies device to device. - STRATA_TRACE lines carry a steady-clock timestamp; STRATA_PARK_TRACE prints the timing of the save steps. - Unset: the code adds a mutex-guarded no-op join per checkpoint save, restore and snapshot, a tag field that stays 0 and a few clock reads; the copies are the synchronous ones as before. Differs from the PR as submitted: the PR put a join into conversation_file.cpp (put_checkpoint), which broke the conversation_file_test and session_save_reclaim_test builds without CUDA and matched only the copied vector, not the one the copy in flight writes, so a SAVE within one checkpoint copy after a turn could write an incomplete GDN state (found by bitaccesscomau; fixed in the PR's last commit 33a8146a). This commit carries that fix: conversation_file.cpp stays as it is and the join runs first in the SAVE/RESTORE handler of generate.cpp. The commit 33a8146a is therefore not a separate commit here. One more join, found by running the new ctest entries: conversation_snapshot_sources (the SAVE path of a session file) saves the running state with the background copy and the caller writes it to the file at once, after the handler's join has already run. It now joins the copy of that checkpoint before it returns; without it a session file written with STRATA_CKPT_ASYNC=1 could hold an incomplete GDN state (conversation_snapshot_test failed at "both files read" before the join). Tests: conversation_snapshot_test now joins after each save and, with STRATA_TEST_BIG_GDN=1 (a GDN state over 1 MiB, so the async path is taken), runs as the new ctest entries conversation_snapshot_test_ckpt_async and conversation_snapshot_test_ckpt_vram_slots: every checkpoint, capture and restore must give the same bytes as the plain run. Not covered: no test destroys a checkpoint while its copy is in flight (readers join; the cache's eviction paths do not); the reporter saw 3 of about 35 engine starts stop answering after a park with evictions, on the paths with the switches off, and could not reproduce it in 15 reruns. The VRAM stage has no headroom check of its own (an RTX 3090 with 147 MiB minimum free showed no failure in 42 of 42 saves; the allocation failure falls back silently). Reporter's numbers (linxuhao, CMP 170HX): turn checkpoint 71.4 -> 0.9 ms, restore 114-126 -> 28-47 ms. Independent data (bitaccesscomau, RTX 3090 24 GB, PCIe 3.0 x16, release defaults, 4 pairs): checkpoint save 73.2 -> 62.4 ms, tiny-prompt time to first token median ratio 1.038, outputs byte-identical. Theirs, not measured here. Original change by linxuhao (PR #3779, commits 0d512925 and 33a8146a). |
||
|
|
8c2a846947 |
Prefill GDN: opt-in STRATA_GDN_TC=1 runs the DeltaNet recurrence as a chunked scan on the tensor cores, sm_80 (#3779, #3712)
Problem: the prompt path's DeltaNet recurrence is a large part of the prompt time of a GA100 card. Change, opt-in and rounding-level (the output is not the FP32 kernels' bits): src/prefill/gdn_tc.cuh holds the chunked WY-form recurrence with every product on the tensor cores (f16x3 splits with power-of-two scaling, one block per value head) and its prep kernel; kernels.cu dispatches it before the STRATA_GDN_CHUNKED branch for prompt chunks of 128+ tokens when STRATA_GDN_TC is set. Where it runs and where it does not: - gdn_rec_tc returns "not supported" and the existing kernels run unchanged on a card below sm_80, with fewer than 48 SMs, or with less than 122 KB of shared memory a block (the kernel needs 124,944 B). That excludes sm_86, sm_89 and sm_120 (99 KB opt-in): the code is compiled into those builds and never launched there. It runs on sm_80 and sm_90. A failed scratch allocation (60.3 MB a device) also falls back. - Device code for cards below sm_80 compiles to trapping stubs behind STRATA_GDN_TC_SM80; the whole header sits under !__HIPCC__. - Unset, the dispatch costs one cached flag test per call. Tests: gdn_rec_parity gains the tc variant (T = 1..4099, 8192, 32768, six stress inputs against gdn_rec_kh_kernel, gate 1e-4; "not on this card" where it cannot run), --selftest-frag (each tensor-core helper on one warp against a double reference) and --bench-tc. The new ctest entry gdn_rec_parity_selftest_frag runs the helper self-test, which any sm_80+ card can run (77 below sm_80). The full tc variant can only run on an sm_80 or sm_90 card. Reporter's numbers (linxuhao, CMP 170HX): recurrence 105 -> 34 ms at 3.3K tokens and 1,705 -> 547 ms at 52K; prompts +3.9 % (4K), +6.0 % (16K), +6.7 % (52K) over the same base; within 2.3e-6 of the FP32 kernel in gdn_rec_parity; teacher-forced KL against the bitwise base mean 0.0157, median 0.0011, max 0.098, top-1 100 %; 1 of 5 conversation checks identical and decode -2.6 % in their pair (they think draft acceptance moves with the rounding; not checked). Theirs, not measured here. Original change by linxuhao (PR #3779, commit f1cabc99). |
||
|
|
10c8cc629f |
Prefill fused IQ experts: opt-in f16 mma path STRATA_PF_FUSED_F16=1 and warp-specialized kernel STRATA_PF_FUSED_WS=1 (#3779, #3712)
Problem: the NT = 256 kernels still decode every 32 values to int8 and scale the int32 products in FP32. Change, both opt-in and both rounding-level (the output is not bit-identical to the int8 kernels; they are the PR's "rounding-level" switches): - STRATA_PF_FUSED_F16=1 (implies the NT = 256 set): the decoded weights times their block scales and the activations times theirs as F16, m16n8k16 F16 products into FP32 accumulators. The k order inside a 16-value group is permuted the same way for both operands. - STRATA_PF_FUSED_WS=1: native_ws_kernel, producer warps decode into an F16 ring in shared memory and consumer warps run the same F16 products (named barriers), so it has the F16 path's rounding. One block per multiprocessor; about 101 KB of shared memory at its defaults, so it is set up on sm_80 / sm_90 cards and says "not available" and keeps the 512-thread kernels on an sm_86 / sm_89 / sm_120 card (99 KB). Compile-time knobs STRATA_WS_PROD / _SLOTS / _NB / _KS / _HTAB. - Both take a WideBatch like the NT = 256 kernels, so STRATA_PF_BATCH above 128 reaches them. CUDA only (under !__HIPCC__); the Turing pass compiles the F16 instances against __trap() stubs and never runs them (dev_info stops before the NT = 256 setup on Turing). - With neither variable set the kernels, their launches and their shared-memory sizes are as before (the F16 template parameter defaults to false). Differs from the PR as submitted: when STRATA_PF_FUSED_Q2N=1 is on as well (#3809, after the PR was written) the WS setup also sets up the Q2_0 gate/up instance. Tests: prefill_fused_iq_test_f16 and prefill_fused_iq_test_ws (ctest) run the fused-experts test (double-precision reference and MMQ) with the switch set. The test now skips (77) when a requested NT / F16 / WS kernel set is not set up on the device, so a card that cannot run WS does not report a pass for the 512-thread kernels. Limits of the test for these two arms only: with STRATA_PF_FUSED_F16=1 or _WS=1 the test uses the limits it already has for STRATA_PF_F16 (F16 products): fused against the int8-rounded model rel RMS 5e-3 (2e-3 otherwise) and against MMQ 5e-3 (1e-3 otherwise). Measured with F16 on an RTX A4000 (sm_86, z440), over the 11 pairs: against the int8-rounded model rel RMS 2.85e-3 to 2.90e-3 and worst row 5.9e-3 to 8.1e-3; against MMQ the same; against the FP32 reference 1.438e-2 to 1.480e-2 with MMQ at 1.435e-2 to 1.478e-2 (the fused path stays within 1.003x of MMQ's rel RMS and 1.03x of its worst row). The rounding is the F16 rounding of the weights times their scales and of the activations times theirs (an 11-bit mantissa, about 2^-11 relative per operand), which the int8-rounded model does not have; it is not a different summation order. The same arm on an RTX PRO 5000 (sm_120): up to 2.90e-3 (rel RMS), worst row up to 8.1e-3. The default path and the NT=256 arm keep the old limits and their printed errors are unchanged: with no switch set the test prints identical output (52 lines) from the base tree and this tree, on an RTX A4000 (sm_86) and on an RTX PRO 5000 (sm_120). Reporter's numbers (linxuhao, CMP 170HX): one MoE layer of 3,256 tokens 8.27 ms (NT = 256) to 7.90 ms (F16) and 7.65 ms (WS); prompts +2..+6 % over the 256-thread kernels, 1 of 11 greedy answers changes. Teacher-forced KL against the bitwise base on their 20-prompt set: F16 / WS mean 0.0062, median 0.00006, max 0.076, top-1 100 %. Theirs, not measured here. Original change by linxuhao (PR #3779, commit 579cbfbb). |
||
|
|
dc390c3864 |
Prefill: opt-in STRATA_DEQUANT_SIDE=1 dequantizes the dense weights on a side stream into a double-buffered scratch (#3779, #3712)
Problem: Gemm::native dequantizes each dense weight to FP16 in front of its GEMM on the compute stream, so the dequant never overlaps the kernels queued ahead of it. Change, opt-in (CUDA only, always off on HIP): with STRATA_DEQUANT_SIDE=1 the prompt path takes a second GEMM scratch (64 MiB more of its region, counted in bytes_needed and carried through relayout) and Gemm::set_dequant_side hands it to the Gemm. native() then dequantizes the next weight on a non-blocking side stream into the scratch the compute stream read last but one. Four events order every write and read of each scratch (free -> dequant -> ready -> GEMM -> free), so each product sees the same bytes as in the serial form. The row-sliced path (a weight larger than the scratch) stays serial. Metal answers false and keeps the serial form. Differs from the PR as submitted: if the side stream, its events or the setup fail, the PR failed the prompt-path init. Here one line is printed and the dense weights are dequantized in front of their GEMMs as before. Unset, nothing changes (gemm_dequant_side() is one cached flag; the scratch, stream and events are not created). Test: new gemm_dequant_side_parity (ctest, GPU, synthetic, 77 without a device): eight Q4_K / Q5_K / Q6_K weights of the engine's shapes (one larger than the scratch, so it takes the sliced path) run three rounds through Gemm::native serially and with the side stream, with and without a spin kernel queued ahead of each GEMM; every output must be identical bit for bit. Not covered: dense weights read by the side stream are the resident ones; a weight that arrived by an upload on another stream would need its own event (the prompt path has none that do). Reporter's numbers (linxuhao, CMP 170HX): measured with STRATA_PLE_COPY_STREAM and STRATA_EMBED_VRAM, the four PLE / embedding / dequant switches together give +2.2..+2.6 % prompts. Theirs, not measured here. Original change by linxuhao (PR #3779, commit 741fc6ab). |
||
|
|
884e37dfdf |
Native head: opt-in STRATA_EMBED_VRAM=1 keeps the token-embedding table in VRAM (#3779, #3712)
Problem: the token-embedding table of a native pack lives in mapped pinned host
memory, so every prompt's scattered row gather crosses the PCIe link. On a Gen2
x4 link that costs more than the table's size in VRAM is worth.
Change, opt-in: with STRATA_EMBED_VRAM=1 the table is copied into the current
device's VRAM when the table plus 512 MiB stay free (322 MiB for an IQ4_XS
table). The gather kernels read the same bytes through dev_ as before. If the
VRAM is not there or the copy fails, the table stays in mapped host memory as
before and one line says so. The start-up line now says where the table is
("in VRAM" also for the two existing VRAM fallbacks, which it called mapped
host memory).
With the variable unset nothing changes (one getenv at load).
Not covered: a layer split across several devices places the table on the
device that is current when it loads, as the existing VRAM fallback does. No
unit test (it moves the same bytes to a different memory; the gather kernel is
unchanged).
Reporter's numbers (linxuhao, CMP 170HX): measured together with
STRATA_PLE_COPY_STREAM and STRATA_DEQUANT_SIDE on a 51.8K-token prompt, the
embedding step went from 191-201 to 70 ms. Theirs, not measured here.
Original change by linxuhao (PR #3779, commit 952dd784).
|
||
|
|
d6428bf291 |
Prefill: opt-in STRATA_PLE_COPY_STREAM=1 uploads the compact PLE rows on their own stream (#3779, #3712)
Problem: with STRATA_PLE_COMPACT the raw-row upload sat on the compute stream before layer 1, which idles for the DMA (4.7 MB per 3K-token chunk, 2.9 ms on a Gen2 x4 link). Change, opt-in, only with STRATA_PLE_COMPACT=1: the raw rows go up on a non-blocking stream of their own once the previous chunk's dequant has read the device buffer (ple_raw_free event); the compute stream waits for the upload (ple_copied) only at the dequant. Same bytes, same kernel. The stream is drained when a run ends so no upload is left in flight from a buffer the next run refills. Differs from the PR as submitted: if the stream or the event cannot be created, the PR failed Prefill::init. Here it prints one line and the rows go up on the compute stream as with STRATA_PLE_COMPACT alone. With the variable unset nothing changes (the stream and the events stay null). Reporter's numbers (linxuhao, CMP 170HX): PLE time of a 51.8K-token prompt 95-103 to 47 ms, measured together with STRATA_EMBED_VRAM and STRATA_DEQUANT_SIDE (+2.2..+2.6 % prompts for the four PLE/embedding/dequant switches together). Theirs, not measured here. Original change by linxuhao (PR #3779, commit 0ba47e61). |
||
|
|
17b08c9633 |
Prefill PLE: opt-in STRATA_PLE_COMPACT=1 uploads the raw IQ4_NL rows and dequantizes them on the device (#3779, #3712)
Problem: the prompt path reads 16 PLE rows a token, dequantizes them on the host and uploads 10,240 floats a token. On a slow host link (PCIe Gen2 x4) that upload is on the critical path of the first layer. Change, opt-in with STRATA_PLE_COMPACT=1: for an IQ4_NL table held in memory (--ple-io ram / mmap) the prompt path copies the raw 90-byte rows (1,440 bytes a token) into the same pinned buffer, uploads them and runs ple_iq4nl_dequant on the device (d times the code's value, one multiply, the split-half nibble order of iq4nl_dequant_row). Any other table (Direct I/O, pageable fallback, another format) and a failed allocation take the host path as before. With the variable unset nothing changes: the new code is behind one cached flag, and the extra members of the Prefill state stay null. Two things differ from the PR as submitted: - PleTable::gather_raw_iq4nl writes a row past the table as scale 0 and code 8 in every nibble. The PR wrote zero bytes, which the device decodes to -0.0f (0 times code 0's value -127), while the host path writes +0.0f for such a row. - New test ple_iq4nl_dequant_test (ctest, synthetic, no model, 77 without a device): the device decode against iq4nl_dequant_row, bit for bit, over every fp16 scale pattern with random codes, random rows, an odd row count and the out-of-table row. Reporter's numbers (linxuhao, CMP 170HX, PCIe Gen2 x4): prompts +1.0..+1.7 % (4K, 16K) with the switch on. Theirs, not measured here. On a Gen4 x16 card the gain will be smaller. Metal gets a stub (the Metal prompt runs through its window and never calls it). Original change by linxuhao (PR #3779, commit da818261). |
||
|
|
bdcc34dfa8 |
Prefill fused IQ experts: opt-in 256-thread kernels STRATA_PF_FUSED_NT=256 and whole-layer launches STRATA_PF_BATCH=N (#3779, #3712)
Problem: on a GA100 card (70 SMs) the 512-thread fused prompt-expert kernels leave the card idle at every barrier and at every grid tail. Change, all opt-in: - STRATA_PF_FUSED_NT=256 sets up a second set of native_kernel instances with 256 threads and two blocks a multiprocessor (WW 2 only), with two-pass weight loads (the loads of the next k step are issued before the current step's decode; load_unit_l gives the same words as load_unit). Every output is the same thread's sum in the same order. - STRATA_PF_BATCH=N launches up to N experts at once (WideBatch holds 512 blob pointers, 4 KB of kernel parameters: CUDA 12.1+, Volta and newer; HIP, gfx906 and the Pascal build keep kMaxBatch). Above 128 it needs the NT = 256 kernels. Below 128 it only changes the launch grouping. - With neither variable set the 512-thread kernels, their launches and their load sequence are unchanged: tile_rows(ww, 512) equals the old 256 / ww, the two-pass code is behind a constant-false TWO_PASS, and the one added test in experts_native is occ_nt > 0, which only STRATA_PF_FUSED_NT=256 sets. - If the 256-thread instances cannot be set up (shared memory, occupancy) the engine prints one line and keeps the 512-thread kernels. Cost: the NT = 256 instances are new device code in every CUDA build (the reporter measured 365,632 bytes for sm_80). Tests: new ctest entry prefill_fused_iq_test_nt256 runs prefill_fused_iq_test (the fused kernels against the double-precision reference and the MMQ path) with STRATA_PF_FUSED_NT=256; it exits 77 below sm_80. Reporter's numbers (linxuhao, CMP 170HX): one MoE layer of 3,256 tokens 8.27 ms with NT = 256; prompts +7.6 % (4K), +4.9 % (16K), +4.3 % (52K) for NT=256 with BATCH=512 on the PR's own build. Greedy answers identical on their 11 prompts. These are theirs. Original change by linxuhao (PR #3779, commit 056d36a9). Merged onto the Q2_0 fused path of #3809 (STRATA_PF_FUSED_Q2N=1) without textual conflicts; the PR predates it, so one line is mine: the NT = 256 setup also sets up the Q2_0 gate/up instance when Q2N is on (without it that instance would have launched without its shared-memory attribute). |
||
|
|
91aebae636 |
MMVQ-IL: sm_80 row tables, bitwise (#3779, #3712)
Problem: an sm_80 card took the shared interleaved-MMVQ row tables, which were measured on other cards (#3252 reports A100 slowdowns). Change: kIlRows_80 (2-4 columns), kIlRows58_80 (5-8 columns) and kIl1Rows_80 (one column), looked up under the key 80 only. They were read off mmvq_il_parity --bench --emit-table with the same 3 % rule as the other tables. STRATA_MMVQ_IL_SM80=0 maps an sm_80 card to the key 81, which has no table, so it gets the shared table again (and no one-column table, as before). A table only picks the rows a warp (0, 1, 2 or 4); 0 means native_mmvq's kernels. mmvq_il_parity already checks every rows choice against native_mmvq bitwise for every type and shape, T = 1..8, so any entry of the new tables is covered. Reporter's numbers (linxuhao, one CMP 170HX): decode +2.7..+3.2 % over the shared table, Qwen3.8-Flash-Next IQ3_S. The measured card is not an A100; the rows may want re-measuring there. Original change by linxuhao (PR #3779, commit eaedca84); the commit message here is rewritten. The sm_89 table of #3453 is a separate change in the same list. |
||
|
|
269c6d3e4a |
Dense dequant: the wide kernels by default on sm_80 too, bitwise (#3779, #3712)
Problem: sm_80 (GA100: A100, A30, CMP 170HX) ran the per-group dequant kernels that sm_61 and sm_86 had already left for the wide ones, because dequant_wide_on() had no sm_80 entry. Change: dequant_wide_on() answers yes for compute capability 8.0 as well. The test is the raw (major, minor) of the device, so it is false on every other card (sm_60, 70, 75, 86 keep their answer, sm_89, sm_90 and sm_120 stay off as before). STRATA_DEQUANT_WIDE=0 still turns the wide kernels off. Reporter's numbers (linxuhao, one CMP 170HX, GA100 sm_80 with 70 SMs): the GPU time of a 3,259-token prompt went from 857 to 792 ms, prompts +6.3..+7.2 % at 3.3K tokens and +3.9 % at 52K. We have no sm_80 card; these are theirs. Bit identity: the wide kernels are the ones sm_61 and sm_86 already run by default. dequant_wide_parity compares them with the per-group kernels byte for byte for FP16, BF16, FP32, the padded stride and a row slice. The kernels have no sm_80-only code, so the result does not depend on the card; what only an sm_80 card can show is that ptxas for sm_80 keeps the same arithmetic (see the checklist in phaseA-tests/gh027/gates/3779-sm80-checklist.md). Original change by linxuhao (PR #3779, commit 48dc535e); the commit message here is rewritten. |
||
|
|
40c9dae95b | Merge f-027-gh-eng-g (#3935 sm_89 in the DeepSeek CUDA package builds, #3796 collapsed tool-name alias and the rejected-calls marker) | ||
|
|
805ebe17be |
serve: a call returned as text for an undeclared name is named in the reply; the collapsed mcp__a__b spelling is the declared tool (#3796)
Problem: a request declares tools; the model writes a complete call for a name that is not among them (bash for shell, a dropped prefix, an MCP name with every "__" written as "_"). Since #3075 such a call stays text, which is the rule we keep, but the client saw an ordinary answer with finish_reason stop and nothing else, so the agent turn ended with raw XML and the model never learned of its mistake. Reporters on OpenCode, Pithagoras, OpenClaw, LibreChat, Open WebUI and Pi hit it. What changed (declared-only stays: nothing undeclared is ever returned as a call, finish_reason is unchanged): - serve/frontend.py OutputParser: a declared name that contains "__" is also read when written with every "__" as "_" (mcp_playwright_browser_navigate for mcp__playwright__browser_navigate); the call goes to the client under the declared name. Same rules as the other aliases: only when unambiguous, and a tool declared under that spelling wins. A reordered or renamed tool (server1_label_values for label_values_mcp_server1, bash for shell) is not guessed. - serve/server.py: when a block went back as text for an undeclared name, the reply carries "strata_rejected_tool_calls": [{"name": ..., "reason": "undeclared"}] (the names the parser already collected, up to five): at the top level of a Chat Completions reply and in its last streamed chunk, and in the message_delta event and the message of /v1/messages. It is absent when nothing was rejected, so every other reply is unchanged. The text itself is untouched. - The server window line says the response carries the names; the count goes to totals["tool_calls_unread"] and to /metrics/prometheus as strata:tool_calls_unread_total. - docs/DETAILS.md: the alias, the marker, the counter. Tests: serve/test_tool_name_alias.py (collapsed spelling at several chunk widths, a declared spelling and a plain tool unchanged, a tool declared in the collapsed spelling wins, two tools with one collapsed spelling are not guessed, reordered/renamed names stay text and are named), serve/test_server.py ForcedToolChoice (the field in Chat Completions whole and streamed and in /v1/messages, absent for an ordinary answer and a declared call, the collapsed name is a call; the counter). The whole serve/ suite: 1055 tests, two failures that also fail on the base tree (test_fatal_recovery on this PC, RestartWindow.test_not_alive_until_ready under load). Not covered: returning an undeclared call as a real tool call (the owner keeps declared-only); a block for a DECLARED name that came back as text because it was malformed (counted, no name to list); the /v1/messages field with a real client; a stderr or log-file copy of the warning. |
||
|
|
8486336f9b | Merge f-027-gh-eng-s (#3291 #3955 #3317 #4036 #2893 #3218 #3200: serve, tools and setup ports) | ||
|
|
675f7fc238 | Merge f-027-gh-eng-k2 (#2526 #1864 #1911 #4005 #3060 #4010 #3809: PR ports for the conversation cache, prefill events, expert source and batch groups) | ||
|
|
c47c699486 |
prefill: opt-in fused int8 prompt experts for the native Q2_0 pack on sm_80+, STRATA_PF_FUSED_Q2N=1 (#3809)
A PC whose CPU lacks the AVX-512 set that setup checks for gets the native Q2_0 pack. On a CUDA card of sm_80 or newer its
Q2_0 / Q2_0 prompt experts run through MMQ, although the fused int8 kernel for that format (#2145) is in the binary and set
up only on a Turing card (
|
||
|
|
4a759f82d4 |
DeepSeek engine packages: add sm_89 (RTX 40) to the CUDA builds (#3935)
Problem: the strata-dsv41 packages were built for sm_86 and sm_120 (+ PTX 120). An RTX 4090 user was stopped at setup on 0.2.4.1; since
|
||
|
|
9ea044962a |
OpenAI logprobs, top_logprobs and allowed_token_ids on /v1/chat/completions (#3200)
/v1/chat/completions on the CUDA and HIP engine accepted logprobs and returned an empty choices[0].logprobs.content. Now "logprobs": true with "top_logprobs" 0 to 20 (and the legacy "logprobs": N) returns one entry per token with its alternatives, streamed or not, and "allowed_token_ids" returns a distribution renormalised over exactly the ids the caller named. Engine (src/program/generate.cpp): the GEN line takes logprobs=K and allowed=a,b,c. After each "T id" the engine writes one "LP <logprob> [id:logprob ...]" line from the verify window's head logits before sampling, penalties and temperature. The SYCL engine already wrote LP lines for logprobs=K; it now reads allowed= as well, with the same line format. A request without logprobs reaches none of this: both call sites are behind "req_logprobs >= 0", a local int of the request, so the default path prints what it printed before and does no extra work per token. Changes from the PR: the call sites are guarded instead of calling the function for every token, the function is static, the token index is checked against the row, and the Chinese comment is in English. Server (serve/server.py): LP lines are read before the token is yielded and belong to the request that asked (tagged with its cancel Event), the entries spell the reply, json_schema replies return no logprobs rather than a mismatching set, an allowed id past the vocabulary is a 400, and logprobs on a --parallel server is answered for max_tokens 1 only (a slot's BT lines carry no LP line). serve/structured.py: _extract_json is now extract_json (the logprobs alignment uses it); the two uses added by the #2893 retry follow the rename. Left out: the PR's bench and result files (none in the diff). #3332 (/v1/completions) and #4056 (logprobs on it) build on this change; this one needs nothing from them. Tests: serve.test_logprobs and serve.test_logprobs_parallel (30 tests with the PR's), serve.test_structured, serve.test_responses: 94 tests OK. Not covered: no model ran here. The PR author reports 28 of 28 on an RTX 5080 with MTP and on a GTX 1080 Ti; the layer-split pipelined decode path (the first call site) was not run by anyone, and the LP values were not compared with a CPU softmax of dumped logits. Co-authored-by: Leonardo Murillo <4869242+leonardomurillo@users.noreply.github.com> |
||
|
|
a3bb38ec45 |
batch-groups: opt-in adaptive-tier rounds in the pipelined loop, STRATA_PIPE_ADAPT_EVERY (#4010)
With --batch-groups above 1 on a layer split the pipelined batch loop never starts a round of the adaptive VRAM tier (the serial batch windows start one every --adapt-every windows). While the slots are busy the tier only moves when they go back to the solo path, so a fresh engine keeps its start-up profile for minutes. STRATA_PIPE_ADAPT_EVERY=N (opt-in; unset, 0 or not a number is off): after N group windows pump starts no new group on the first stage, lets the groups in flight finish, then runs one round as batch_step does between serial windows, adapt() and apply_pending(true), so nothing in flight reads a cache slot while experts swap and the new experts have landed before the next launch. Not while a prompt is read beside the slots (in_prompt_read, its loan of cache slots), not with --adapt-async, not while the last round's copies are in flight, not with the tier off. The rule is two pure functions in include/strata/program/batch_groups.hpp (pipe_adapt_every, pipe_adapt_due) with 12 new cases in batch_groups_test. With the switch set the engine says so once at start and the "strata batch (pipelined ...)" line adds the rounds, the experts swapped in and the time spent. docs/BATCHING.md documents the switch with the author's table (2x RTX 5090, six streams, 309 to 410 rows/s over eight bursts after a fresh start, two engines per setting). Reviewed: unset costs one counter increment per group window and one false check where a group starts, and prints no new line. A due round cannot wait forever: no new group starts, the groups in flight finish, then the round runs. A prompt read sets in_prompt_read before the reader thread starts (including STRATA_PIPED_CONCURRENT) and clears it after the reader joined; the drain after the read runs the round if it is due. Tests: batch_groups_test (the new cases). Not covered and still the author's to show (the PR is a draft): a soak with prompts read beside the slots, a Linux run, another GPU pair, more than two stages, and exactness settings with the switch set. The model gate is written down. |
||
|
|
2b13a44933 |
expert source: STRATA_RAM_ADAPT copies the incoming expert out of its stage buffer when it is still there, and moves up to 4 pairs a layer (#3060)
STRATA_RAM_ADAPT (opt-in, --serve, one GPU, needs --adapt-every) lets the resident RAM copy follow the conversation: experts the windows keep routing to take the RAM places of unused experts of their layer. Each move re-read the incoming expert from the file and a layer moved one pair per window, although the incoming expert was usually read for the window before and its blob still sits in that read's stage buffer. What changed: - FileExpertSource::replace_resident_staged(layer, in, out): the same move as replace_resident, with the bytes copied out of the finished stage buffer of `in` (no file read). The copy runs under stage_mu_, so claim_stage cannot give the buffer to another blob meanwhile; it needs a non-busy buffer whose key is `in`, and returns false (nothing changed) otherwise, and the pair then goes the old way. The Foresight hold/unhold around the copy is the one install_resident uses. - generate.cpp: a layer pairs up to 4 of its most routed outside experts with up to 4 of its least routed ones in the copy (outgoing count below 0.5, incoming 2 or more), largest difference first. A pair whose incoming expert is staged moves by copy; `n` now caps only the pairs that need a file read. The log line counts the moves and how many came out of a stage buffer (ram_staged()). - docs/DETAILS.md: the RAM_ADAPT bullet in the low-RAM list in plain words and one row of the measured table (the author's numbers: RTX 3060, IQ2_XS and IQ3_XXS, 120 ShareGPT requests, 3 interleaved runs each). Unset (the default) nothing runs: the block is guarded by ram_adapt_n > 0 as before. The weights moved are byte copies of the same blob; which experts sit in RAM changes, as it already does with RAM_ADAPT, so greedy token ids may differ from run to run once it is on. Changed from the PR: the DETAILS.md hunk was rewritten against the current, shorter bullet. Tests: file_expert_source_test (new staged cases; the positive case needs unbuffered load and is skipped without it). Not covered: no model run. Model gate written down: RTX 3060 ShareGPT replay =8 against =1. |
||
|
|
c966d7ad89 |
setup: Maxwell gets a warning with the build recipe, not an env switch (#3218)
The first #3218 commit made setup.py admit a Maxwell (sm_52) card only when a tester set STRATA_EXPERIMENTAL_SM52=1, and then routed it to the CUDA 12 engine. That engine holds no sm_52 code, and users never set environment variables to get a fix. sm60_card() is back to Pascal and Volta (6.0 to 7.0). A PC whose only NVIDIA cards are Maxwell now gets a warning (maxwell_note) that says no ready-made engine holds code for it, gives the source-build recipe (-DSTRATA_EXPERIMENTAL_SM60=ON -DCMAKE_CUDA_ARCHITECTURES=52, CUDA 12.x) and the one reporter's result, and points to docs/OLDER_GPUS.md. The card table line says Maxwell runs only from a source build. A Maxwell card beside a newer card prints nothing new. Naming the card (--gpu, --cuda 12) or any env var does not admit it. The CMake floor from the first commit is unchanged (opt-in build only). Tests: tools.test_setup_older_gpus 23 tests OK (a Maxwell-only PC through setup.main() with and without the old switches installs nothing and prints the recipe; a Maxwell card beside an RTX prints no note). Not covered: no engine was built for sm_52 by this commit; the P1004 compile is recorded in the notes. |
||
|
|
f217b23bd3 |
prefill: the copy-wait dedupe skips a wait only when both slots were released in the current walk and the ring is longer than one group (#4005)
Review fix on the #4005 port. STRATA_PREFILL_COPY_WAIT_DEDUPE=1 skipped the copy stream's wait on a slot's release event when the previous entry had waited on the same event. Two cases break that: - At idx == ring the previous entry (ring - 1) is still in the first round, so its wait was on the event of an earlier walk. The same slot id can be this walk's first flush, which re-records the event after that wait; skipping the wait for slot 0 then lets the next copy overwrite a slot that the flush's gather has not finished reading. - With a ring of one MMQ group (16, the smallest ring) a flush of the whole ring re-records the event right after the previous slot's wait. The rule is now copy_wait_dedupe_ok() in include/strata/prefill/copy_events.hpp: idx > ring, ring > group, same event. copy_events_test models two to three walks with random group sizes and random issuer/consumer interleaving and checks that a refill always waits on a record at or after the flush that released its slot. The same model with the PR's original rule (idx >= ring) finds the stale-event case, so the test can fail. The default path is unchanged (dedupe off). Tests: copy_events_test passes (z440, g++ -std=c++20). Not covered: a GPU run. |
||
|
|
cea3ed40db |
serve: a slot's shorter checkpoints come along at a give-back only when they are prefixes of the tokens copied back (#2526)
Review fix on the #2526 port. At an admission from a slot the port copies every checkpoint of the slot that is not longer than the copied-back length into the main session's chain. Such a checkpoint is valid there only when its tokens are a prefix of what was copied back (its K/V cells are then the ones the main session holds) and it has no pictures (the main session's pictures are cleared at a give-back). The PR did not check either; a checkpoint left over from a branch the slot no longer holds would sit in the main chain with cells that are not its own. Both trees (CUDA/HIP and SYCL) now test the prefix and the empty picture list per checkpoint. The checkpoint the request continues from is copied as before. Nothing changes when every checkpoint is a prefix, which is the normal case. Tests: compiles on CUDA and SYCL (see the build lines of the branch). Not covered: no model run; the gate is written down. |
||
|
|
a8c1d4b7f8 |
verify: a window graph that does not fit frees the graphs of other window sizes instead of ending the engine (#3702)
On a layer split the later card is left with a few dozen MiB after loading, and each single-request window size is captured the first time it is used (68, 64, 58, 52 and then 10 MiB free in the report); when one capture's cudaGraphInstantiate ran out of memory, instantiate_evicting could only free graphs of batch slot layouts, a single-request run has none, and "verify: instantiate: out of memory" ended the engine. Now, after the batch layouts, a single-request window's capture frees the graph of the largest other window size (never the one being captured or a prelaunched one; pick_window_victim) and instantiates again, and says so once: the freed size is captured again when it is next used. capture_all keeps every size at once and is excluded. Only a failed instantiate does anything new; with enough VRAM nothing changes. window_evict_test (CPU, header-only) covers the choice. The real gate needs a model on a 2-GPU split with a thin later card (listed in the triage file); not changed here: the later-stage reserve of the split search (kWindowMib), which is a default placement change. |
||
|
|
a11f8b0aa5 |
prefill: opt-in sparse copied events and deduplicated slot waits in the streamed prompt walk (#4005)
Under WDDM every cudaEventRecord and cross-stream wait is a submission of its own (the author measured ~80 / ~45 us each on an RX 6900 XT under Windows 11), and the streamed walk paid one record and one wait per expert although a group gathers after one wait on its last copy. Two tester switches, threaded issuer only: - STRATA_PREFILL_COPY_EVENT_EVERY=N (2..64): the copied event is recorded every N-th entry, before the issuer waits and on the last; the compute stream waits on the first recorded entry at or after the one it needs (the copy stream is in order). - STRATA_PREFILL_COPY_WAIT_DEDUPE=1: the copy stream skips its wait on a slot's release event when the previous slot was released by the same event. The same copies into the same slots: the same bytes. Default path (both unset): read line by line. The issuer records copied[slot] and waits on used[used_of[slot]] exactly as before (the counters are bookkeeping, cover() is a no-op). Added to the PR so this holds by construction: wait_copied takes the slot the old code used and, without the sparse switch, waits on copied[slot] at all three consumer sites (the PR derived the slot from the entry number). The record/wait selection is now three pure functions in include/strata/prefill/copy_events.hpp, with a host test (copy_events_test, registered in CMakeLists.txt) that models the issuer and consumer with a full ring and checks that every wait names a live recorded entry at or after the one needed. Tests: copy_events_test passes (z440, g++ -std=c++20). Not yet: a CUDA build of prefill.cpp in this tree (queued), no GPU run. Not covered: the Windows HIP / WDDM speed claim and NVIDIA (the gate is written down). Needs the author's numbers repeated before any default talk. |
||
|
|
61ede87e1b |
Maxwell sm_52 floor for the opt-in old-card build (#3218)
A reporter built Strata for two Quadro M6000 (sm_52) by lowering two floors and saw about 22 tokens a second with Qwen3.8-Flash-Next IQ1. CMakeLists.txt: the experimental build (-DSTRATA_EXPERIMENTAL_SM60=ON) now accepts sm_52 and prints a warning for it (Maxwell, one reporter, no native half precision, CUDA 12.x). Without the flag the build still stops at sm_75 as before, and the architectures a build uses are not changed. setup.py: sm60_card() admits a 5.2 card only when the tester sets STRATA_EXPERIMENTAL_SM52=1, because the ready-made CUDA 12 engine holds no sm_52 code and a Maxwell card must not be routed to it by default. With the variable set, setup warns about the Maxwell card instead of refusing. Default: a Maxwell card is "not supported" exactly as before. docs/OLDER_GPUS.md: a Maxwell row and a short section, with the build command and a request for an answer-text check. Tests: tools/test_setup_older_gpus.py (20 tests, new Maxwell cases for default, opt-in and a newer card present). Not covered: no model run, and the answer text on a Maxwell card is unchecked. |
||
|
|
3100ca05ed |
expert cache: STRATA_VRAM_FREE=device reads the whole card's free VRAM through NVML, Windows + NVIDIA, opt-in (#1911)
Under WDDM cudaMemGetInfo answers for the calling process: memory another process holds on the card (the image encoder, a browser, another engine) is not in its free figure. The reporter measured, on an RTX 5090, 30,994 MiB free from CUDA where NVML read 24,348 with 6 GiB held elsewhere, so --expert-cache auto sized the cache too large and shrank it by guesses. device_free_bytes() now takes min(CUDA's figure, NVML's figure for the whole card) when STRATA_VRAM_FREE=device is set. nvml.dll is loaded from the system directory at first use (LoadLibraryExW with LOAD_LIBRARY_SEARCH_SYSTEM32), the card is matched by its PCI bus id, and a missing nvml.dll, a missing export or a failed nvmlInit leaves CUDA's figure with one line on stderr. The serve check of "VRAM free with everything loaded" uses the same function. The value can only get smaller, so the switch can only shrink the expert cache. Unset (the default), nothing changes: the NVML code is compiled only for _WIN32 and not for HIP, Metal or the no-VMM build, and the env variable is read once. The serve check's min() is the same value elsewhere (on a unified-memory system device_free_bytes() is never below cudaMemGetInfo's figure). Added to the PR: the NVML block is also left out of a SYCL build (SYCL_LANGUAGE_VERSION), whose CUDA names are a compatibility layer. docs/DETAILS.md: one row in the measured-and-left-off table instead of the PR's long paragraph. Tests: builds on Linux CUDA (the Windows-only block is skipped), SYCL (P1006) and on Windows MSVC (owner PC build of the final tree). Not covered: no run with a model; the Windows gate is written down. |
||
|
|
3a3f35c64a |
tests: cuda_spill_guard fails the CUDA test build when a Strata kernel spills or keeps a per-thread array in local memory (#2683, #2682)
tools/check_cuda_spills.py reads the resource usage the compiler wrote into the kernel libraries (cuobjdump --dump-resource-usage: STACK and LOCAL per entry function and per sm_) and fails on any Strata kernel outside its ALLOWED table, which carries the measured allowance of the kernels that hold such an array on purpose; ggml's vendored kernels (no namespace) are skipped and counted. ctest cuda_spill_guard runs it on eight libraries, skips (77) without cuobjdump or a demangler, CUDA builds only (HIP has no cuobjdump); check_cuda_spills_unit runs tools/test_check_cuda_spills.py (stand-in demanglers are sh scripts, so not on Windows). Changes against the PR: (1) a demangler that exits 0 but prints a blank name used to make the kernel's key empty, which reads as vendored, so a spilling Strata kernel was skipped; that is now "no verdict" (77) with a test. (2) The unit test is registered. (3) The ALLOWED table was re-measured on f-027-int: sm_120 with CUDA 13.0 on Windows (MSVC) and sm_86 with the CUDA 13.0 objects built on Linux (cuobjdump 12.9); allowances are only raised (new DFlash2 gemm8_kernel and rope_table_kernel, native_gu_swiglu_kernel on sm_86, dequant_kernel / expdec_gu_kernel / prompt_attn_i8v3_kernel / native_gu_swiglu_kernel on sm_120), none lowered or dropped. Result: 0 violations on both architectures; a test shows the same object fails once one allowance is lowered. Ported from PR #2683 (the tracking issue is #2682). |
||
|
|
2cc6ea169b |
serve: opt-in LaTeX-safe JSON recovery for structured output (#2893)
A json_object or json_schema answer that holds LaTeX such as \alpha is rejected (502) because \a, \g and the like are not JSON escapes. New opt-in: "repair_latex_escapes": true in response_format (and in text.format on /v1/responses). Only after the strict parse failed, the server doubles each backslash that does not start a valid JSON escape and parses once more with the same duplicate-key and NaN rules, then checks the schema as before, and prints one log line. Without the option, and for any answer that parses on the first try, nothing changes. Escapes that are valid JSON (\b \f \n \r \t \/ \" \ and a well-formed \uXXXX) are left alone, because they cannot be told from LaTeX: a \beta next to a \alpha comes back with a backspace. Truncated output, arrays, NaN and duplicate keys still fail. Tests: three new tests in serve/test_structured.py (default still 502, opt-in 200 and stream, failures stay failures, helper cases, Responses format passthrough). serve/test_structured.py 13 tests OK. |
||
|
|
2251053b42 |
serve: the serial decode timing line shows the adaptive waits in its sum (#1864)
With STRATA_DECODE_TIMING=1 the serial line listed `verify + commit/emit + draft` after `ms/window =`, while the adaptive wait before verify and the join after the draft were timed but printed after the sum, so the named parts did not add up to ms/window. The serial line now reads `adapt wait + verify + commit/emit + draft + adapt join + other`, where `other` is the decode time minus the named parts (not a timed step). The pipelined decode keeps its old line, byte for byte, and nothing is printed with the timing off or with no windows. Diagnostic only: no decode path changes. docs/DETAILS.md: a short paragraph on the new line (the hunk was rebased by hand onto the current file). Tests: compiles on CUDA (the format string was counted against its 22 arguments); no parser in the repo reads `ms/window = verify`. Not covered: no run of the line itself (it needs a decode). |
||
|
|
01e404c140 |
serve: an idle batch slot's decoded conversation is parked before an admission overwrites it (#2526)
A batch slot holds the reply it decoded. The main session was parked with the conversation's prompt only (the admission's copy), so when the next admission or a yielding read overwrote the slot, the reply lived nowhere: the conversation's next turn found its prompt-read state and read the whole reply again (the author measured 255 of a 256-token reply re-read on four 200K chats over two slots). What changed: - park_current is split into park_source (one budget / RAM-admission / snapshot path) and two callers: park_current (the main session, output line and byte accounting as before) and the new park_slot (an idle slot's ids, checkpoints, sessions and draft K/V). The ParkSource passes what a park captures; the main session's retained K/V (#1503 take_reuse_for) is taken only for the main session, never for a slot. - park_slot runs before copy_to_slot at a slot admission and before a BYIELD read overwrites a slot. It does nothing when the live main session or a parked conversation already holds that state (ConversationCache::holds / conversation_covers, new, with unit tests), for a slot with pictures, or without --batch-mtp when the drafter is on. - When a slot is admitted into the main session its checkpoints come along (the shorter ones too), so the chain keeps its branch points and the parked copies a turn back are superseded (#342) instead of taking an entry each. - Same refactor in sycl/src/program/generate.cpp. Changed from the PR: parking is an optimization like a checkpoint (#3350). The PR ended the request (ERR) or the batch (batch_fatal) when park_slot's snapshot failed; here a failed snapshot, a failed device sync and a host allocation that runs out are logged, the slot is overwritten as before and the request goes on. The slot's extra checkpoints that come along at an admission are copied under a bad_alloc guard (the one the request continues from is copied as before). Tests: conversation_cache_test (new holds() cases and the four-conversation replay at policy level) and conversation_split_failure_test. Not covered: no model run (the batch path itself needs one); the gate is written down. |
||
|
|
9c2d35d978 |
serve: /v1/responses accepts max_output_tokens of 0 and -1 (#4036)
The Responses validator still refused anything below 1 after the chat path made max_tokens of -1 and 0 mean no cap (documented in docs/DETAILS.md). It now accepts -1 and 0 as no cap; values below -1, floats, booleans and strings stay a 400. Nothing else changes: the server already passes max_output_tokens or 0 to prepare(), which gives the answer the room left in the context. Tests: OverHttp.test_max_output_tokens_zero_and_minus_one_mean_no_cap (stream and non-stream, status completed) and test_max_output_tokens_bad_values_are_400. The first fails without the change. serve/test_responses.py 43 tests OK. |
||
|
|
41188ec734 |
calibrate: an engine that dies mid-measurement drops only its candidate (#3317)
#1337 made a failed engine start in a later calibration step a candidate that loses. An engine that started and then exited during its own rate measurement still failed the whole run. measure_candidate() now treats both the same: the candidate is dropped and recorded in report["failed_starts"], the earlier results stay. It is used for the CPU worker step, the adaptive expert tier step and the AMD shared-expert fork. An operator cancel (CalibrationCancelled) is still raised. The first start (steps 1 to 3) still fails the run. src/core/verify.cpp: when adapt_gate_wait times out after 20 s, the message now says which layer was reached (atomic and copy signal), that the copy stream is not drained by the release, and dumps the STRATA_VERIFY_TRACE breadcrumbs when that is on. Diagnostics only, #2188 stays open. The watchdog label is set only once a wait actually starts, so a gate that is already open costs nothing extra (changed from the PR, which set it on every call). Tests: tools/test_calibrate.py 33 tests OK (3 new death tests). Not covered: engine compile of verify.cpp is checked in the build step. |
||
|
|
fb966cff37 |
pack_gguf: accept older DeepSeek GGUF metadata names (#3955)
Older converters write the Engram scalars as engram.key_length and engram.pad_id, and omit the sparse-attention geometry. The packer now reads the old names only when the canonical engram.head_dim and engram.pad_token_id are absent, and a new --config-json option fills the omitted geometry from the source model's config.json. A value that disagrees with metadata already in the GGUF stops the pack with a clear message. The weights are never rewritten and a set that already has the canonical names packs exactly as before. Tests: LegacyModelMetadata (2 new, 5 in the file) in tests/terminal/test_pack_gguf_engram.py. Not covered: the author reports the older Q2_K set still needs dense Q2/Q3 and Engram Q2_K tensor support in the engine; this does not add it. |
||
|
|
a0fc88abd6 |
serve: timings on /v1/responses (#3291)
The final response.completed / response.incomplete event and a non-streaming /v1/responses reply now carry the same top-level timings object that /v1/chat/completions has. The server already put timings in the done dict; the Responses assembler dropped them. Tests: UsageAndStatus.test_responses (stream and non-stream). Unset timings leave the event unchanged; response.failed has none. |
||
|
|
3478382eee |
conversation copies: the private copy streams and events are handed back to a pool when a thread ends (#3350, #3470)
conversation_detail::private_stream() and order_after_queued() kept one non-blocking stream and one event per device in thread_local storage and never destroyed them. The layer split's later stages run each prompt chunk on a fresh std::async thread (STRATA_HANDOFF_PIPE off, the default), and a checkpoint part is saved on that thread, so every periodic checkpoint of every long cold prompt left a stream and an event behind on each later card: a few MiB of VRAM per long prompt that never came back (#3470: the later card's free VRAM drops 2-6 MiB per long cold prompt, no plateau), until cudaStreamCreate failed with "out of memory" (#3350: "conversation snapshot running-state copy: out of memory", engine exit) on a card that was already nearly full. A thread now hands its handles to a process-wide pool when it ends and the next thread takes them, so the number of streams and events is the number of threads copying at once. Same stream, same flags, same contract; only the lifetime changed. copy_streams_created() / copy_events_created() count what the process made. conversation_copy_streams_test (CUDA, no model, skips without a device): 200 short-lived threads in a row create at most one stream and one event; ten rounds of six concurrent threads at most six more; the same on a second device. |
||
|
|
f62589fdbe |
serve: a checkpoint whose copy runs out of memory is skipped, it no longer ends the engine (#3350)
A conversation checkpoint is an optimization, like parking, but the writer treated a failed copy as fatal: "conversation snapshot running-state copy: out of memory" (cudaErrorMemoryAllocation from the snapshot copy: the private copy stream's first creation or the driver's staging on a nearly full card, not host RAM) made the prefill fail and the engine exit, 21 times in 4 h for one reporter and 16 in 34 h for another, each exit a reload and the in-flight requests lost. Now, after a failed save, checkpoint_failure_is_survivable() clears the non-sticky allocation error and synchronizes the device: when that is clean the checkpoint is skipped with a line on stderr and the request goes on (a layer split's stage part is left empty, which already means "no checkpoint at this length"; the message-boundary / turn / root checkpoints after a prompt chunk do the same). A device that is unwell (a sticky error, a GPU that stopped answering) still ends the request exactly as before. Same edits in sycl/src/program/generate.cpp. STRATA_TEST_COPY_FAIL_AT=N (tests only, like STRATA_TEST_SLOW_COPY_US): the N-th snapshot copy of the process fails with cudaErrorMemoryAllocation, so the case can be made without a full card. Unset, nothing changes. Not changed: "verify: instantiate: out of memory" (graph capture), which the reporter saw once. |
||
|
|
3cd33d504c |
cmake: a CUDA build with no architecture option is for sm_120, and native builds the W4A4 unit for sm_120a (#4029, #4023)
CMakeLists.txt tested "NOT DEFINED CMAKE_CUDA_ARCHITECTURES" after enable_language(CUDA). Since CMake 3.18 that call fills an unset variable with nvcc's default (sm_75 for CUDA 13), so the sm_120 default never applied: a hand build with no option was an sm_75 build. The default is now set before enable_language, unless the user gave -DCMAKE_CUDA_ARCHITECTURES or the CUDAARCHS environment variable, and the configure step prints a warning that says what to pass for another card (a recommendation, not a refusal). With -DCMAKE_CUDA_ARCHITECTURES=native, the one NVFP4 W4A4 unit (mmq_nvfp4_w4a4.cu) stayed on plain `native`, where ptxas refuses the FP4 MMA on an RTX 50. `native` is now replaced by CMAKE_CUDA_ARCHITECTURES_NATIVE (the detected architectures) before the 12x -> 12xa rewrite, as a list, so a mixed PC works too. docs/SOURCE_INSTALL.md says what `native` and the other values build. Release and setup builds pass their architectures explicitly and are unchanged. Configure matrix, CUDA 12.9 on Linux: none -> 120 (+ the warning), CUDAARCHS=86 -> 86, 89, "75;86;120" (w4a4 120a only for the 12x entry), native -> detected. Ported from PR #4029. |
||
|
|
4a7e373da3 |
engine: --adapt-decay outside 0..1 falls back to 0.7 with a line on stderr (#1284)
--adapt-decay took any number. Above 1 the adaptive tier's usage counts grow without end (inf after a few hundred adaptations) and the swap gains turn NaN, which breaks the sort that orders the swaps; a negative value flips the counts. The value is now checked where it is parsed (include/strata/program/adapt_decay.hpp, also in sycl/): a finite value in 0..1 is used exactly as before (0 and 1 included, the range the calibration profile already allows); anything else, NaN and inf too, runs with the default 0.7 and says so on stderr. A warning instead of the PR's exit 2: a risky pick is reported, the engine still starts. adapt_decay_test (25 checks) covers the range, the fallback and finite counts after 100000 adaptations. Ported from PR #1284 (the check; the refusal became a fallback). |
||
|
|
b3db5a1c83 |
serve: the lifeline identity is the child's start time, the sampler survives a bad source (#3590, #3407)
The portable lifeline watcher built a child's identity from `ps -o lstart=,stat=` and kept the whole line, so the token changed with the process state (R while it starts, S asleep). The watcher compared its own reading with the token taken at start, decided it was not the child it was told about and exited without ending it (test_lifeline "the child outlived a killed server (watcher)", #3407). The identity is now the start time alone: field 22 of /proc/<pid>/stat on Linux (a zombie has none), `ps -o lstart=` elsewhere; strata_control/procs.start_token drops the state column the same way. A launch that is not a real Popen is not watched. Telemetry._loop no longer ends on the first failing sample (a machine whose GPU or psutil source is unreadable): it prints one line and keeps sampling, and NoLeakedSampler checks the thread itself instead of counting threads. New test: the token is the same while the child runs (R) and sleeps (S); on the old code it fails on Linux ('...R' != '...S'). Ported from PR #3590. |
||
|
|
fd8d37e93d |
serve: accept Codex spellings of a namespace tool (#3972)
A declared namespace.member tool (Codex MCP: mcp__filesystem.write_file) was accepted only as namespace__member (#3556). Qwen3.8-Flash-Next also writes namespace=member (the <function= tag's equals sign ends up in the name), namespace_member (one underscore dropped) and the bare member. Each is now an alias of the declared tool when exactly one declared tool produces it and no declared name is the same; a name that matches nothing stays text (#3075), two namespaces that share a member are not guessed, and a declared flat tool always wins. Requests without namespaced tools are unchanged. serve/test_tool_name_alias.py (10 tests, 5 of the first 9 fail without the change; the tenth pins that a flat tool named like the underscore alias wins), docs/DETAILS.md names the spellings. Ported from PR #3972. |
||
|
|
f8ff3420d9 |
conversation cache: never park one conversation with another's retained K/V (#1503)
With --batch and conversation parking, a restore keeps the restored K/V (ConversationCache::retain) so the next park of the main session copies only what changed. The reuse tracked a token count (unchanged_tokens), not whose tokens, and copy_from_slot (a batch slot giving its conversation back to the main session) replaced the main session's K/V without dropping the retained image. The next park reused the earlier conversation's K/V for the new one's prefix: a restore of the new conversation then answered from the other one's history. retain() now records the ids of the conversation the K/V belongs to; a park calls take_reuse_for(live), which reuses only the prefix live shares with those ids (nothing when they share none or the ids are unknown), and one stderr line is printed whenever a reuse is cut. copy_from_slot drops the retained image before it replaces the main session's K/V. Same edits in sycl/src/program/generate.cpp. The guard only cuts reuse: at most one full copy of a parked conversation's K/V, the saved bytes are otherwise identical; no flag, no default change. Ported from PR #1503 onto the current tree (the first-stage ids sit after the stages field so the existing aggregate initialisers keep their meaning). conversation_cache_test gains the cross-conversation cases of the PR and the logged sequence (restore P, a slot hands Q to the main session, park Q): another conversation never gets the K/V, a diverging one only the shared prefix on every stage, a slot hand-back drops it, unknown identity is never reused. Removing the ids limit makes the first case fail. |
||
|
|
6c01f85add |
qwen35: a penalty for a history token outside the logit row no longer indexes past the row (#3911)
sample() applied the repeat / frequency / presence penalties to lg[id] for every token id of the last penalty_last_n tokens of the history. A row shorter than the vocabulary (the MTP draft head picks among the first N token ids, --draft-vocab N) made a history token with id >= N an out-of-bounds read and write on the host. A token that is not in the row takes no penalty; the loop skips ids < 0 or >= lg.size(). A full-vocabulary row is bit-identical. The loop and Sampling move to include/strata/qwen35/sampling.hpp (header-only) so a CPU unit test can run them: src/qwen35/sampling_test.cpp (qwen35_sampling_test) checks nothing is written past a short row, that in-row tokens take the penalty, and that a full row matches the unguarded loop bit for bit over 108 penalty/window mixes. Without the guard the test dies with an access violation. Co-authored-by: yehya <38882457+xyehya@users.noreply.github.com> |
||
|
|
3a604e0855 | Merge f-027-kva (docs/KVA.md: the shipped opt-in's numbers on the R9700 and the P100, and the decode trade on fast GPUs) |