kva-batch2
699
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
ec8e405909 |
batch groups: two NVIDIA cards pipeline by default; the serial group is opt-in (STRATA_BATCH_GROUPS_NV_SERIAL=1, STRATA_DEFAULTS=026)
0.2.1 made a layer split over exactly two NVIDIA cards with --batch and no --batch-groups run one serial group (measured then on 2x RTX A4000, IQ3_XXS: +12..16%). With the 0.2.7 code the pipelined groups are faster at 2 and 4 streams on every box and quant measured, so the default goes back to the pipeline. Measured (tools/serve_load.py, --batch 4, 256 tokens per request, interleaved pairs, total tok/s, pipelined / serial): - 2x RTX A6000, IQ3_S, all experts in VRAM: 1 stream 101.7 / 101.7; 2 streams 125.7 / 107.4 (+17%); 4 streams 171.4 / 141.0 (+22%). The v0.2.6 binary on the same box: serial default 104.9 and 137.2, --batch-groups auto 124.6 and 169.6. - 2x RTX A4000, Q2_0 pack (17037 of 24576 pairs cached, 4 clean pairs): 2 streams 80.2-82.5 / 75.0-75.5 (+7..9%, 4 of 4); 4 streams 110.8-111.5 / 94.8-95.3 (+17%, 4 of 4); 1 stream 63.6-68.7 / 68.2-70.3. - 2x RTX A4000, IQ3_XXS (13056 of 24576 pairs cached, 3 pairs): 2 streams 73.2-73.7 / 65.8-66.5 (+12%, 3 of 3); 4 streams 100.5-100.7 / 82.9-83.6 (+20%, 3 of 3); 1 stream 58.4-60.5 / 60.7-62.6 (serial about 4% faster, 3 of 3). The single stream runs on the solo path in both; only the A4000s show the 4%. What changed: batch_groups.hpp has a pure rule nv_serial_wanted(env value, STRATA_DEFAULTS=026). STRATA_BATCH_GROUPS_NV_SERIAL set to anything but 0 asks for the serial group, an explicit 0 wins over STRATA_DEFAULTS=026, and with the variable unset or empty STRATA_DEFAULTS=026 gives v0.2.6's serial group. An explicit --batch-groups (a number or auto) still wins. Three or more cards, AMD builds and --batch-mtp/--adapt-async handling are unchanged. The serial message names the opt-in. Tests: batch_groups_test (the rule over the env values and 026, two cards pipeline, the existing serial cases). Real engine on 2x A6000 (IQ3_S), no --batch-groups: the engine says "2 groups of 2 slots" / "2 groups of 1 slot"; with 4 and 2 slots, greedy, greedy+seeded sampled, slots finishing at different lengths and a cancel in the middle of a draft, every slot's tokens equal its solo decode and the pipelined build's. A long-prompt slot differs from the pre-merge base build in the same way with the flag and without it (it is the parent's prompt path, not this change). Not covered: no run on AMD or on three cards; the 4% single-stream cost on the A4000s is measured on one box. |
||
|
|
5cfa395476 | Merge f-027-gh-eng-pm (#4121 MTP drafts in pipelined slots, opt-in STRATA_PIPED_MTP) | ||
|
|
37e4832ab3 |
layer-major prefill: on by default for a CUDA layer split, STRATA_PREFILL_LAYER_MAJOR=0 and STRATA_DEFAULTS=026 turn it off (#3976)
THIS COMMIT ALONE MAKES THE WALK A DEFAULT. Drop it and the layer-major prefill stays an opt-in (STRATA_PREFILL_LAYER_MAJOR=1) with the chunk-major path as the default. Rule (include/strata/core/sm120_series.hpp, pure, tested in src/core/arch_defaults_test.cpp): - prefill_layer_major_default(hip, stages, v026): on for two or more stages on CUDA, off on one GPU, in a HIP build, and under STRATA_DEFAULTS=026 (qwen_defaults_026()); - prefill_layer_major_resolve(env, ...): STRATA_PREFILL_LAYER_MAJOR=0 / 1 (any text atoi reads) wins in both directions, over the rule and over STRATA_DEFAULTS=026. Every decline of the earlier commits stays and runs in lm_prepare as before (HIP, image prompts, DFlash2 taps, KVA, stop_at_chunk, a pending force_chunk, a peer GPU, APR / NVFP4 / WMMA / fused layers, STRATA_EXPERT_NIBBLE, no VRAM, no pinned RAM): such a prompt reads chunk-major with nothing but a log line. When the walk is on by default (nothing set) the VRAM margin is 512 MiB instead of 96 and the super-chunk target 32768 tokens (the size measured) instead of 8192; "a short prompt" is not logged. STRATA_PREFILL_LM_TOKENS and STRATA_PREFILL_LM_MARGIN_MIB still win. Measured (z440, 2x RTX A4000 16 GB, Qwen3.8-Flash-Next IQ3_XXS, experts streamed, 5 interleaved pairs, time to first token, medians): 8K 2.8x, 20K 4.8-5.7x, 32K 5.1-5.5x faster (141 s to 26-28 s); decode 38.6 vs 38.4 tok/s; needles 12 of 12 found in both arms. The speed-up is larger than the report's 2x because --prefill auto picks 512-token chunks there. The first-token KL numbers are in the gate notes (3976-kl.sh). Not covered: one GPU (stays opt-in), HIP, SYCL, Metal, three or more stages, a card with more VRAM than the pack needs (where the experts are VRAM-resident and the chunk-major path has little to re-read). |
||
|
|
0d4b2cdd43 | Merge f-027-gh-eng-lm up to 0c7de9868 (#3976 layer-major split prefill, opt-in: STRATA_PREFILL_LAYER_MAJOR=1) | ||
|
|
9c624c75a9 |
Merge f-027-gh-eng-d (#3602 #3948 #3638 #3702 #3797 #2409 #3844: audits, fixes and tests)
# Conflicts: # src/core/verify.cpp # src/kernels/cuda/fused_gr.cu |
||
|
|
7d1016f3f4 |
QFUSE: the fused q8_1 producers divide the way the separate quantiser does; they gave a different code at about one element in a million (#3948)
Problem. #3948: with STRATA_QFUSE=1 the verified text changes and MTP acceptance drops (RTX 3080, sm_86). The report suspected the group counter or the nat_xq_ offsets of fused_gr.cu; the audit and the new two-group test (previous commit of this stream) rule those out. What the new test found instead, on an RTX 5070 (sm_120, CUDA 13.0, MSVC), over 10,500 random windows of two groups: in about 1 run of 400 one q8_1 code of the fused image differs by exactly one from native_quantize_q8_1's, in every mode (group-relative, window-indexed, direct, graph replay). The scale/sum pair and the other codes agree. Cause. native_mmvq.cu, which holds native_quantize_q8_1 (the quantiser every consumer of a q8_1 image was written for), is compiled with --use_fast_math (CMakeLists.txt, the native_* list), so its `amax / 127` and `x / d` are the fast full-range division (div.full.f32, up to 2 ulp off). fused_gr.cu (the hyper-connection read's tail, gr_up_q32_kernel) and verify_kernels.cu (the GDN output norm, gdn_q8_1_store) are not in that list and divide with IEEE rounding. roundf(x / d) then lands on the other side of a .5 at the rare element whose quotient is next to a boundary. One changed activation code per ~10^6 values is about one per few hundred tokens at 80 hyper-connection reads of 2560 values per token: enough to move a near-tie in the verify, and the draft (which quantises with the separate kernel) disagrees with the verifier a little more often, which lowers acceptance. That matches the report (acceptance 0.755 against 0.79, different text, and an unchanged text where no draft is made). Change. include/strata/kernels/q8_1_finite.hpp: q81_div(a, b) is `a / b`, except in a translation unit that defines STRATA_Q81_FASTMATH_DIV (CUDA device code only, never HIP), where it is the same PTX division the fast-math file gets (div.full.f32). q8_1_quant and the scale use it. fused_gr.cu and verify_kernels.cu define the macro; nothing else does, so every other kernel, the separate quantiser and every HIP build compile to what they did. STRATA_QFUSE is off by default on CUDA (it is on by default on gfx1151, which is HIP and unchanged), so the default path is bit-identical. Result (RTX 5070, sm_120): gr_parity's two-group window test: 10,500 runs with 1,500 random inputs for each T, all modes, zero differences (before: dozens); the whole of gr_parity, gdn_parity and gdn_parity with STRATA_GDN_SPLIT=1 pass. Tests. gr_parity: the two-group test prints the first differing bytes (block, field), and STRATA_GRP_REPS=N / STRATA_GRP_KEEP_GOING=1 repeat it longer and count every failure. gdn_parity: the q8_1 destination check uses its own stream (native_quantize_q8_1 refuses the null stream, which crashed the test on Windows), unbuffered stdout and STRATA_GDN_PARITY_TRACE=1. Not covered. sm_86 (the report's card) has not run the new test yet (z440 was reserved for other jobs); the cause is not architecture specific. The model run (gates/3948-qfuse.sh) is still owed: QFUSE on against off must now be byte-identical, and the draft counters equal. |
||
|
|
8c0301484e |
Conversation cache: skip a restore only when a card would have to create its copy stream and has no room for it (#2409)
Problem. #2408 / PR #2409: restoring a large parked conversation on a layer split ended the server with a CUDA out of memory on a later card. The PR checks the free VRAM of every card against --vram-reserve-mib before a restore. Its own review points out that a loaded card is always below that reserve, so the check would skip nearly every restore on a split (and on one GPU). It is not ported. What a restore allocates. conversation_snapshot_restore writes into the session's existing buffers (pools(st), the GDN state, the indexer tails); refresh_residency only launches kv_stream_reset or copies into the existing ring. The elastic K/V growth (kvg_ensure) allocates, but only on one GPU. The one thing a restore can create on a card is the calling thread's private copy stream for it (conversation_copy.hpp private_stream), which it takes from the pool of finished threads when there is one (#3350). A failed restore is fatal by contract (the session may be half written). So the need is one stream and one event, and only for a card whose stream does not exist yet (a snapshot loaded from disk, or a restore on a thread that never copied on that card). Change. conv_cache.hpp: kRestoreFirstUseMib (64) and restore_fits(free, stream_ready, n, need): a restore is refused only for a card that has no copy stream yet and less than 64 MiB free. conversation_copy_stream_ready(device) says whether a card has one. generate.cpp: before the restore, each card of the run is checked; a snapshot that would not fit goes back to the cache and the prompt is read again, with a log line. A card that has its stream is never refused, however full. No sample (a failed cudaMemGetInfo) means the restore goes ahead as it did. Tests. conv_cache_test: the predicate (cards with a stream are admitted at any free size; the edge at the need; no sample / no cards / no need). conversation_copy_streams_test: copy_stream_ready before and after the first copy, in the pool after a thread ends, and the measured cost of a card's first copy stream and event (printed; the test requires under 16 MiB, so 64 MiB leaves a wide margin). conversation_snapshot_test: after the first restore, six more restores of two images leave the free VRAM where it was. Not covered. The pure predicate and the generate.cpp code build on z440 (CUDA 13.0); the GPU tests are listed in the stream notes. No model run: gates/2409-restore-guard.sh (a held-VRAM start on a layer split) shows the skip line and an unchanged answer on the second turn. |
||
|
|
2a9a67c174 |
Later-card VRAM: audit fixes for failed allocations, the reserve arithmetic as a tested helper, a per-card out-of-memory report (#3638 #3702 #3797)
Problem. On a layer split the later cards are left with very little VRAM after loading (#3702: 68 MiB on the last card; #3638: 268 and 666 MiB, then every batched prompt read of more than ~400 tokens ends non-finite after hours; #3797: the weight arena fails with 320 MiB free and the message does not say who holds the rest). The window-graph eviction (12b0bce95) and the copy stream pool (#3350) are in already; this is the rest of the code audit of what is allocated after load. Audit. The table of every lazy allocation after load (what, when, size, how a failure is handled) is in phaseA-tests/notes-027-gh-eng-d.md. Bugs found and fixed here, each small: - verify.cpp capture / capture_batch and mtp.cpp finish_capture: the cudaGraphUpload and its sync were only printed. The upload is a warm-up, but a failure (no VRAM) stayed as the thread's pending error and the next kernel wrapper's cudaGetLastError ended the engine. The error is now cleared and the first launch uploads the graph. - verify.cpp capture_commit and mtp.cpp finish_capture: the commit graph called cudaGraphInstantiate directly (no eviction of older layouts, unlike the window graphs) and reported the status of the end-of-capture call, which is success, so the message read "no error". capture_commit now goes through instantiate_evicting and reports the instantiate's status. - instantiate_evicting instantiates into a local and sets the member only on success (what a failed instantiate leaves in its output is not specified, and a non-null member means "captured"). - prefill.cpp carve: after a failed take of the shared region the sub-allocators had no base and each cudaMalloc'd its buffer (hundreds of MiB in all) on the card that had just run out. carve now returns at once; the caller reports the failure as before. - generate.cpp: a failed set_stage_helper / set_peer is reported and the run goes on, but its CUDA error stayed pending; cleared. Found and not changed: relend() re-plans only the first participant (#3638 comment). Read: it runs only from the VRAM command, which is off on a layer split, so it cannot touch a later stage's loan. Other candidates (ignored cudaEventCreate for the pipelined fences, unchecked expert copies, cudaFuncSetAttribute flags set before success) are in the notes. Changes for the report of #3797 and the reserve (#3702). - include/strata/program/gpu_report.hpp: on a failed weight-arena allocation (first card and each stage) the engine now also prints, for every card of the run, the free and total memory and the largest other programs that hold memory on it (NVML, loaded at run time; where the driver does not list them it says so). Text only; the failure is the same. tests/program/gpu_report_test.cpp pins the text. - include/strata/program/stage_reserve.hpp: the arithmetic of stage_room (what the split keeps free on a card) moved out of generate.cpp unchanged; tests/program/stage_reserve_test.cpp compares it with the old expression over a grid. The file also holds a PROPOSAL for a larger window term on a later card (96 MiB + 6 MiB per further window size + 48 MiB, 174 MiB for --spec 4) which nothing calls: the default placement is not changed. gates/3702-later-reserve.sh measures it. - The low-VRAM warning of a later card now adds how many MiB the plan meant to keep free there and how far off that was. Tests: gpu_report_test, stage_reserve_test (host only, built on z440). Not covered: no model was run. What the ~700 MiB the plan does not count on the last card is (window graph sets, kernel code loads) needs the run in gates/3702-later-reserve.sh. |
||
|
|
ba8b2bcb9c |
Merge f-027-gh-eng-a (#3622 ARM64 / DGX Spark port, #3806 Gyro-L TQP5/6/7)
# Conflicts: # cmake/ggml_tq_overlay_test.cmake # src/core/verify.cpp |
||
|
|
38b06316ef |
Gyro-L: read the pair-trellis types TQP5/TQP6/TQP7 (ggml 147-149) on the CPU, CUDA and the MMQ prompt path (#3806)
Gyro-L (agentionai's 50 GiB file) stores its experts as a pair trellis: 128 values per block, a fp16 scale and 64 steps of K bits (K = 5, 6, 7), two weights per step taken from the first pair of the TQ2_T codebook entry the step's state selects. The engine refused the file because it did not know the three type ids. This adds them next to the existing trellis types 144-146 without changing those. What changed: - gguf_reader.hpp / tools/gguf_reader.py: names and block sizes (42 / 50 / 58 bytes). - tq_cpu.*, tq_states.hpp, tq_avx2.cpp: tq_supported / tq_kbits / tq_block_bytes for the new ids (the bytes per block are 2 + 8K for the pair layout, 2 + 4K for the others), a scalar pair kernel (the reference) and an AVX2 pair kernel that is bit for bit equal to it; AVX-512 uses the AVX2 pair kernel. - iq_kernels.cu: TqInfo, the lane decode (tqp_states8, a byte window), the dot product, the decode-once Split, the fp16 dequantizer and the format lists for 147-149. They are reached only by a pack that holds these types. - moe_mmq.cu, strata_ggml_tq_overlay.cmake, third_party/ggml-tq/tq.cuh, ggml-common-tq.h: the MMQ prompt path for the three types (overlay enumerators, traits, tile loader branch, instances). - native_expert_parity: names tqp5-7 and skips its synthetic check, with a message, on a ggml that has no trellis traits. - docs/GYRO.md: the "not supported" sentence now says how Gyro-L is read. Changes to the contributor's patch: - tq_cpu.cpp called the AVX2 pair kernel without the x86 guard the rest of the file has, which breaks the Metal build (it compiles tq_cpu.cpp without tq_avx2.cpp): the pair rows go through one helper that falls back to the scalar kernel. - moe_mmq.cu named GGML_TYPE_TQP5-7 under STRATA_MMQ_TQ, but the public agentionai llama.cpp has the older trellis types and not these: a new STRATA_MMQ_TQP (set for the overlay and for a tree that has the tqp instances) guards them, so that tree still builds. The HIP overlay lists get the three instances too, and ggml_tq_overlay_test checks them (and sets the CMake policy its IN_LIST needs). - native_expert_parity: the skip test compared a type-name pointer to null, but ggml_type_name of an id past the table reads past it (the test crashed on an upstream ggml); it compares against GGML_TYPE_COUNT. - docs/GYRO.md keeps the plain description and leaves out the contributor's measured speeds (we have not repeated them). Tests added: src/kernels/cpu/tqp_cpu_test.cpp (no ggml, no model: the scalar kernel against a bit-by-bit reference from the format definition, every ISA equal to scalar for 1-8 tokens and for gate/up rows, the type predicates for ids 0-299 against the old formulas), the pair types in tq_pascal_bench (fp16 dequantizer bit for bit against the definition, decode kernels within 3e-2, decode-once == per-column), tools/test_gguf_tqp.py, and native_expert_parity tqp5/6/7 registered when the ggml tree has the tqp instances. Checked (no model): tqp_cpu_test passes on x86 (AVX2 on z440; AVX2 and AVX-512 on the owner PC with MSVC); tq_pascal_bench on an RTX 5070 (sm_120, MSVC build): 0 failures, the TQP dequantizer matches the definition in all bits, and the checksum lines of TQ2_T/TQK6/TQK7 are byte-identical to the build without this change. Builds: CUDA sm_86 (gcc), sm_60 (CUDA 12.9), sm_120 (MSVC), SYCL, and the CPU files for aarch64. Not covered: the contributor's own parity runs need a ggml tree that carries the types (not public here), and the 50 GiB model run (load check, coherent answer, 32K prompt, MTP, Gyro-S/M identity) is still to be done. Metal, SYCL and HIP have no kernels for the types; HIP was read, not built. |
||
|
|
1e57a924d0 |
Merge f-027-gh-eng-m (#3416 gated MTP: opt-in proposal law, window-invariant CPU dispatch, draft policy)
# Conflicts: # docs/DETAILS.md |
||
|
|
ca17d0f5cd |
spec: a gated request's lookup policy learns from committed rounds only, DraftPolicy choose() unchanged otherwise (#3416)
Problem (KeyanHu-git): the gated proposal needs the choice between the MTP window and a lookup window to be fixed by the history, not by the draws of the rounds it will verify. Freezing the policy for the whole request (the first commit) does that, but also freezes the cost table, so a repeat-heavy request kept the window sizes it inherited. In the author's diagnostic workload the frozen policy chose mean lookup windows of 5.87 and 3.38 on two repeat requests; with this change 4.31 and 4.05 (from the PR text; not reproduced here). Change: the request's copy of the DraftPolicy (source_policy) gets three calls, used only when gated_proposal is on: - observe_committed(): the round's accept and probe counts, applied at once. A lookup window counts as a probe of its size (tried_), so a size whose cost is only guessed is tried kProbes times, not every round. - defer_cost(end, t, ms): the round's time is held. A time covers the window and the next MTP draft, so it depends on every Philox counter up to max(p + T - 1, p + a + 1 + S_mtp). - apply_costs(committed): applies, in order, the held times whose end is behind the committed position, with the same update observe() makes (including the STRATA_SPEC_COST clamp), in the context bucket the round ran in; delayed_n_ keeps a held time from counting as a second probe. choose() counts the probes as cost_n_ - delayed_n_ + tried_. Port note: the DraftPolicy on the current tree keeps its costs per context bucket (STRATA_SPEC_COST), so tried_, delayed_n_ and the held times carry the bucket. A gated request does not run with STRATA_SPEC_COST (it falls back to the older rule), so its copy stays in bucket 0. Default path: unchanged. choose() reads two new terms; on any path that never calls the new functions tried_ and delayed_n_ are +0.0 and cost_n_ - 0.0 + 0.0 == cost_n_ exactly. Checked by driving the old DraftPolicy (namespace-renamed copy of f-027-gh-eng) and the new one with the same random call sequences (observe, observe_chain, observe_probs, set_context, seed_costs, set_robust, choose, chain, keep_draft; 400 sequences of 3000 steps): 25,983,538 bitwise comparisons of picks, costs and rates, 0 mismatches; one observe_committed call makes the same harness report 60,528 mismatches. generate.cpp: nothing calls the new functions when gated_proposal is false. Tests: draft_policy_test (the PR's added assertions, on the bucketed class) and spec_admission_test pass on z440 and on the owner PC. Not covered: the sampling argument for the delay boundary (that a held time cannot steer a window through a counter that is drawn again) is the author's; a unit test cannot show it, only the distribution run (gate script 3416-spec-prob-dist.sh, arm NEWLK) can. |
||
|
|
499e963593 |
native experts: window-invariant CPU arithmetic for STRATA_SPEC_PROB decode, Default dispatch unchanged (#3416)
Problem (KeyanHu-git): the rejection rule of the previous commit judges each row against the target's probabilities p. For a native (IQ) pack the CPU experts round a token's rows differently depending on how many tokens share its expert in the window (the grouped kernels against ggml's one-token dot, #152). So p of one row moved with the window width, and the same sampled text could depend on the draft length. On random blocks a grouped Default call differs from the token alone in 700 to 12000 of about 18000 output floats for the IQ gate/up and IQ4_NL down formats. Change: NativeArithmetic { Default, WindowInvariant }, fixed for one pool batch. native_gu_rows / native_down_rows become thin wrappers of one template with the arithmetic as a parameter. The Default instance keeps every old branch (the new conditions are compile-time true there). WindowInvariant gives each token the bits of the one-token call on this build and CPU: kernels that already match it stay grouped (NVFP4, Trellis and Hadamard rows, KQ256 when ggml runs its AVX2/FMA dot); the IQ rows that differ use iq512_reference_gu_rows (types 18, 21, 22: the same decode, ggml AVX2's accumulation order, one weight decode per group) or iq4nl_reference_rows (IQ4_NL down), and anything else falls to the one-token dot per token. ExpertPool::run_split_multi_native takes the arithmetic and expert_pool_dispatch_multi passes it; generate.cpp uses the invariant pool only when the MTP drafts probabilistically (mtp.prob(), i.e. only with STRATA_SPEC_PROB=1). Prefill, greedy decode and every other decode run Default. The pool picks the entry point with one compare and a direct call per chunk. Default path (STRATA_SPEC_PROB unset): unchanged, shown by running the old and the new native_gu_rows / native_down_rows (Default) on the same random blocks: 61 format, width and amplitude lines (IQ2_XXS/XS/S, IQ3_XXS/S, IQ4_XS, NVFP4, Q4_K, Trellis with and without folded Hadamard, IQ4_NL / Q2_0 / Q5_1 / Q8_0 down; widths 1 to 8; row sub-ranges), output hashes identical in 10 settings of the environment switches on z440 (AVX2) and in 13 on the owner PC (Zen4, AVX-512, MSVC), including STRATA_NO_IQ512, STRATA_IQ_GATHER and STRATA_IQ_MT_MIN=1. g++ codegen of the AVX-512 row kernels is not byte-identical for 5 of 87 functions (inlining and register allocation of the same source); the AVX-512 kernels were run only under MSVC. Tests: native_arithmetic_parity, eight ctest configurations (default, AVX, KQ256, IQ_MT_MIN=1, no512, ggml only, NVFP4 AVX2, NVFP4 ggml), registered in CMakeLists.txt and sycl/CMakeLists.txt. It compares the invariant entry points at every group width 1..8 with the one-token calls, bitwise, for the IQ, NVFP4, Q4_K/Q5_1/Q8_0, Trellis and Hadamard formats. All eight pass on z440 and on the owner PC; the existing CPU expert tests (iq_avx2_parity, iq_avx1_parity, iq512_gather_parity, pool_tasks_test, nvfp4_cpu_parity, router_dot_parity, q2_bitplane_parity) pass. Not covered: an ARM CPU (not built here), an AVX-512 machine with fast gathers (Sapphire Rapids), the layer-split call site, and any model run. |
||
|
|
f4612b1add |
spec: STRATA_SPEC_PROB=1 keeps the confidence gate in the proposal law, opt-in (#3416)
Problem (KeyanHu-git, refs #2028, #2591): with STRATA_SPEC_PROB=1 the default --spec-min-p gate tests the token drawn from the draft head's distribution q, but the verifier still judged the draft against the unfiltered q and treated a failed gate as a plain sample from p. That shifts the output distribution: with p = (0.5, 0.5), q = (0.875, 0.125) and threshold 0.5 it emits (0.5625, 0.4375). Change: the gate is part of the proposal. Keep q's mass on the tokens that pass the gate without renormalising (mu); a draw that fails the gate becomes NULL. An offered token D is accepted with min(1, p(D)/mu(D)); a rejection and NULL draw from the normalised positive part of p - mu; a position with no attempted proposal is a plain sample from p. Serve and the CLI build the same packet (core/gated_proposal.hpp) and give it to the verifier explicitly (Verifier::set_spec_proposal, sample_tokens_proposal). The explicit call has no plain-p fallback: an invalid packet row is reported, not sampled around. STRATA_SPEC_PROB_GATE=top keeps its normalised-q rule. Default path (STRATA_SPEC_PROB unset): unchanged. mtp.prob() is false, so gated_proposal is false, the new draft-result argument is null, GatedDraftLimit does nothing, Verifier::run takes the old branch (set_spec_q clears the measure flag), and the sampler kernel's old instance is the old code with the new branches compiled out. Read hunk by hunk; no hunk runs a new branch or a new allocation per token. The default-identity model run is written as a gate script and not run yet. Port notes against the PR as submitted: - Unsupported combinations (parallel or multi-device decode, --lookup-chain, --adapt-swaps, PCIe share, --spec-min-p not finite, STRATA_SPEC_COST, DFlash2, STRATA_SPEC_T_CYCLE, --spec-corrupt, Metal) used to be an error that ended the request or the server. They now warn once and keep the older rule, so setting the variable never stops a run. --adapt-swaps 96 and the PCIe share are on by default, so the exact rule needs --lookup-chain 0 --adapt-swaps 0 --pcie-frac 0. - The lookup source of a probabilistic window is chosen by a copy of the policy fixed at the request start, without asking whether the MTP's first guess agrees. Learning from committed rounds inside a request is the policy commit of this series. - The CLI loop on the current tree has the out-of-memory window retry, DFlash2 and STRATA_SPEC_T_CYCLE; the gated path does not use the retry (a narrower window would change the room the packet was built for). Serve keeps merged first windows (STRATA_ADMIT_MERGE_FIRST) at their length. - docs/DETAILS.md: two short bullets instead of the PR's long paragraph (that paragraph no longer exists on this tree). bench/results and the PNGs are not ported. Tests: gated_proposal_test and spec_admission_test (default, pick, top, exact-top-only) pass on z440 (CPU, g++ 13) and on the owner PC (MSVC). On the owner PC's RTX 5070 (sm_120, MSVC build, synthetic data, no model) spec_proposal_parity, spec_verify_parity and sampler_parity (default, one-block and old-kernel configurations) pass. Also built: CUDA sm_86 on z440 and boston, SYCL on P1006 (engine and host tests). The Metal path is not built here. Not covered: a model-level distribution test (chi-square of the first tokens against plain sampling) and the identity run with the variable unset. Both are written as gate scripts (3416-spec-prob-dist.sh, 3416-default-identity.sh) and not run. |
||
|
|
bd8a254453 | Merge f-027-gh-eng into f-027-gh-eng-pm (#4121 on top of the #4010 pipelined adaptive rounds) | ||
|
|
0959545e21 | Merge f-027-gh-eng into f-027-gh-eng-lm | ||
|
|
a4c41a92ee |
Build the engine for ARM64 (DGX Spark / GB10) without changing the x86 build (#3622)
The engine did not build on aarch64: the CPU expert path assumed the x86 AVX kernels, the CPUID probes and the x86 spin/fence intrinsics. After this change the strata target compiles on aarch64 (CUDA host code, native GGUF packs). On x86 nothing is selected differently. What changed: - CMake: STRATA_CPU_X86 is decided from CMAKE_SYSTEM_PROCESSOR (an unset processor stays the x86 build). On aarch64 src/kernels/cpu/portable.cpp stands in for the AVX kernel sources; native experts run on ggml-cpu's NEON dot products. -ffp-contract=off on aarch64. STRATA_ISA_FLOOR is ignored with a warning there. - include/strata/platform/cpu_relax.hpp: strata_cpu_pause / strata_store_fence map to _mm_pause / _mm_sfence on x86 and to yield / dmb oshst on aarch64. verify.cpp, pool.cpp, session.cpp, mtp.cpp and graph.cpp use them. - expert_layout.cpp: the CPUID/XCR0 probes compile on x86 only and report no AVX on other CPUs. - generate.cpp: --cpu-oracle-q8-0 is rejected on a non-x86 CPU. - setup.py: nvidia-smi's "[N/A]" memory on GB10 (unified memory) takes the pool size from /proc/meminfo on ARM64 only; the CPU probe no longer needs the x86 "flags" line; setup warns that the ARM64 engine is compiled on the PC and which packs work. Changes to the contributor's patch, found while moving it onto the 0.2.7 line: - portable.cpp had no iq512x_rows / iq512x_supported / iq512_gather_on (added to the x86 kernels after the PR was written): the aarch64 link would fail. - The Metal build (Apple silicon) shares these files. It keeps its barrier (dmb ishst), its plain router loop (its bf16_rows_dot_multi is a stub), its Metal start-up block in generate.cpp and its "unknown" CPU name. - The CPU side of the GPU doorbell: strata_load_fence() after the spins that wait for a flag the GPU raised (dmb ishld on ARM, nothing on x86 and on Apple silicon), so the data written before the flag is not read early. - A card whose memory nvidia-smi does not report stays unlisted on x86 (the new fallback is for ARM64 only). - tests/terminal/test_setup_arm64.py. Checked: with the x86 CUDA build (sm_86, gcc 13 -O3, z440) the objects of verify, session, mtp, graph, expert_source, pool, expert_layout and generate are byte-identical before and after (the x86 wrappers are macros for the same intrinsics). Every C++ file of the strata target compiles for aarch64 with clang, and the symbols of the CPU kernel library link up (syntax and symbols only: no ARM machine, no ARM run). The Metal-shared files compile for aarch64-macos with STRATA_GPU_METAL. Not covered: no ARM hardware here. The tests that include x86 headers (iq_avx2_parity and the other AVX parity tools) and the DeepSeek target do not build on aarch64; the strata target does not need them. Memory ordering on ARM is reasoned, not run. The Q2_0 and Gyro packs need the x86 kernels. |
||
|
|
2651c4a96b |
Merge f-027-int2 (2a2264c21) into f-027-gh-eng
# Conflicts: # tools/calibrate.py |
||
|
|
2579635138 | sm_80 defaults of #3779 (wide dense dequant, MMVQ-IL sm_80 tables) follow STRATA_DEFAULTS=026: back to the 0.2.6 kernels and the shared table; explicit =1 and =0 still win; arch_defaults_test checks the rule; release-notes line | ||
|
|
1e278a280d |
Merge f-027-gh-eng-n (#3779 sm_80 tuning: wide dequant, MMVQ-IL sm_80 tables and the opt-ins)
# Conflicts: # CMakeLists.txt # docs/MMVQ_IL_TABLE.md # src/kernels/cuda/native_mmvq.cu # src/kernels/mmvq_il_parity.cpp # src/program/generate.cpp |
||
|
|
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). |
||
|
|
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). |
||
|
|
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). |
||
|
|
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). |
||
|
|
17878ac579 |
batch slots: MTP drafts in the pipelined groups, STRATA_PIPED_MTP=N opt-in with --batch-mtp (#4121, #3794)
Problem: a layer split with --batch pipelines the slots in groups, and the pipelined groups run no MTP drafts. --batch-mtp with serial windows leaves all but one card waiting. A multi-stream deployment wants both. What changed: STRATA_PIPED_MTP=N (with --batch-mtp) keeps the pipeline and drafts in it. A group's window carries each of its slots' rows: the slot's token and up to N MTP proposals (at most --spec - 1; the first always, each further one while the draft layer was at least --spec-min-p sure of the one before). The last stage judges each slot's proposals on their own. The number of rows to keep is known only then, and by then the earlier stages run other groups' windows, which reuse the scratch the commit replays from. So a small save graph copies those rows right behind each window (Verifier::batch_launch_rows), and every stage queues the commit of the kept rows after the verdict (Verifier::batch_commit_rows). The slot drafter catches up on its own rows and drafts the next proposals as an asynchronous chain (MtpDrafter::chain_launch). Unset, nothing changes. Changes on top of the PR as sent (review): - The verifier window size is worked out where the verifiers are built, from the slots that fit and the final groups, not earlier from --batch as asked. Unset it is the old expression. - STRATA_PIPED_MTP is decided again once the slots that fit are known. It says it is off, and why, when fewer than 2 groups are left, when STRATA_BATCH_SELF_COMMIT is on, or when a group's window would hold more than kVerifyMaxT rows. The start line names groups and slots correctly. - batch_groups::resolve keeps its old mtp_dropped rule; only mtp_piped is new, and it also applies with --batch-groups given (the PR's fix 1). The "--batch-groups 1" test case now expects "not dropped". - --remote-expert-opt alone no longer blocks --batch-mtp on a layer split: the object it guards is only made with a helper expert cache (the PR's fix 2). - docs/BATCHING.md rewritten with the numbers measured here. Tests: batch_groups_test (the PR's cases, four "unset is as before" cases); builds on CUDA sm_86 (Linux), SYCL (the sycl tree has its own verify.cpp and generate.cpp and does not include this code) and MSVC. Model runs: see docs/BATCHING.md and the gate scripts 4121-*.sh. Not covered: AMD (HIP) was not built or run; the draft layer on the first stage; helper expert caches. |
||
|
|
0afaaa399e | Route prior: the 0.2.7 default on a discrete NVIDIA card of 13 GiB or less drops from 2.0 to 1.5 (owner decision 2026-10-26). On the RTX 3060 12 GB (IQ3_XXS) the copy and code check found real defects at 2.0 and none in 19 tasks at 1.5 or 1.0; 1.5 keeps story +15% and code +37% against off. The value lives in strata::kRoutePriorSmallCard (sm120_series.hpp); scope (CUDA discrete <= 13 GiB), STRATA_ROUTE_PRIOR=0, an explicit value and STRATA_DEFAULTS=026 are unchanged. arch_defaults_test, verify.cpp comments, DETAILS.md and the 0.2.7 release notes follow. | ||
|
|
c77292f09d |
gfx1151 on Windows: the shared-expert fork (STRATA_SH_STREAM) is off by default
Interleaved A/B on a Strix Halo Windows PC (Qwen IQ3_S, engine 0.1.51): chat decode 43.6 tok/s with the fork, 46.6 without (+6.9%), prompts unchanged. Linux gfx1151 and every other architecture keep their table. STRATA_SH_STREAM=1 turns it back on, STRATA_DEFAULTS=026 keeps v0.2.6's table. arch_default_env(arch, defaults026, windows) is a pure rule; arch_defaults_test checks both platforms. |
||
|
|
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). |
||
|
|
663ec80abf |
mmvq_il: the sm_89 (Ada) decode tables are on by default on compute capability 8.9 only, STRATA_MMVQ_IL_89=0 and STRATA_DEFAULTS=026 turn them off (#3453)
Owner decision for 0.2.7: the tables of PR #3453 (the cells where an RTX 4070 and an RTX 4080 community run gave the same rows count, and the one-column Q3_K row) ship on for sm_89 cards, untested on Ada by us. The output is bitwise the same with them off (a table only changes how many rows a warp takes); no end-to-end gain was seen on a 4090 or 4080 in the report, so the reporter tests 0.2.7 and reports. The rule is a pure function in sm120_series.hpp: mmvq_il_89_default(hip, cc, v026) is true for cc 89 only, false in HIP builds and under STRATA_DEFAULTS=026 (defaults_026.hpp, as 38c9080db did for the other defaults); mmvq_il_89_resolve() adds the variable: "1" and "0" win, unset or other text is the rule. native_mmvq.cu reads it once. arch_defaults_test checks cc 89 on, every other cc off, HIP off, 026 off, "0" off, "1" wins over 026, the empty text. mmvq_il_parity expects the on-tables by default and the old ones with =0 or 026. Docs: MMVQ_IL_TABLE.md, DETAILS.md and the 0.2.7 release notes (a line that says it is not measured on an RTX 40 card, with the off switch). |
||
|
|
46a9cd87c7 | Merge f-027-int2 into f-027-gh-eng (brings STRATA_DEFAULTS=026 and the other 0.2.7 integration work) | ||
|
|
551f1cdc30 |
Merge f-027-gh-eng-k1 (#3867 #3751 #3453 #3943 #3820 #3752 #3455: Pascal and sm_89 opt-in kernel ports)
# Conflicts: # src/core/expert_cache.cpp # src/core/verify.cpp |
||
|
|
9067cc64d3 |
iq_kernels: GP100 4-bit gate/up expert slots, opt-in STRATA_EXPERT_NIBBLE=1 (#3455)
Problem: on a GP100 die the verify window's gate/up kernels for the IQ2_S,
IQ3_XXS and IQ3_S expert formats are not held by memory bandwidth but by each
block's serial chain (unpack the codebook indices, the emulated dp4a, the
16-lane reduction); the same kernel with every dot product removed still takes
about two thirds of its time.
Change: with STRATA_EXPERT_NIBBLE=1 the engine, after the expert cache is
filled and every expert is resident, transcodes the gate/up blocks of every
fully resident IQ2_S / IQ3_XXS / IQ3_S layer (n_embd 2560, n_ff 640) into slots
of 4-bit codes, 16 bytes per 32 weights, with the integer scales and fp16 d kept
as they are; the down rows stay GGUF. The decode gate/up reads those slots with
kernels that run the production integer chain and float tail in the production
order (R4S / R4P / R4SV / R4PX by format and group size); the prompt path's MMQ
gather rebuilds the GGUF blocks from a slot on the fly. At load every item is
round-tripped and every slot's rebuilt GGUF blocks are compared with the staged
blob before the cache is sealed (ExpertCache:🦭 a later fill_slot stops the
engine). New: include/strata/core/expert_nibble.hpp (slot contract, switches,
per-layer table), nib_gu_proto.cuh (STRATA_NIB_GU_PROTO=1 variant), the
transcoder, hash and rebuild kernels and the 4-bit gate/up kernels in
iq_kernels.cu, generate.cpp (the fill, the VRAM accounting, STRATA_EXPERT_NIBBLE_
RECHECK), iq_nibble_parity and native_expert_bench --nibble.
Review changes against the PR:
- An option the switch cannot work with (--peer-device, --kv-grow, --vram-elastic,
remote caches, STRATA_MMQ_DIRECT, ..., a card that is not cc 6.0, a build
without the kernels) now prints a warning and the start goes on with the usual
GGUF slots, where the PR refused the start. What is known only later (an expert
out of VRAM, a loan, the prompt chunk) still refuses, since slots are
converted by then.
- The checks this switch adds to expert_source.cpp and prefill.cpp are compiled
out of every build that has no 4-bit kernels, so the default builds add nothing
to the hit split or the prompt loop.
- iq_nibble_parity gets --synthetic-only (every gate/up format x both down
types on random experts, no model file), skips with 77 on a card that is not a
GP100, and the synthetic and --header runs are ctests.
- The PR's docs section is rewritten for these changes and its measurements are
labeled as the author's.
Default path (switch unset): the table is empty, nibble::slot_bytes(l) is
expert_layout().blob_bytes(l) and nibble_max_slot_bytes() is max_blob, every
sizing the PR touched returns what it returned before, and the new branches in
generate.cpp (guard_raw before the adaptive tier's copies, the profile fill's
test), expert_cache.cpp (one bool in the fill calls and admit) and verify.cpp
(a capture-time layout choice, compiled out without the kernels) are not taken.
Proof on the kernels: in the sm_60 build (CUDA 12.9) the SASS of all 446
kernels iq_kernels.cu had before is identical with and without this change,
as is that of the 603 in native_mmvq.cu, 29 in qsa_select.cu and 10 in
moe_mmq.cu; 21 kernels are new.
Tests: iq_nibble_parity --header passes on z440 and boston (the host half of the
contract; also a ctest). The GPU parts (--synthetic-only, a model shard) refuse a
card that is not a GP100, so they were only compiled here (sm_60, CUDA 12.9,
P1004: iq_nibble_parity and native_expert_bench build; the whole tree builds).
sm_86 build without the SM60 option (z440): exit 0, the 4-bit paths compiled out.
Not covered: no GP100 run. The model gate is
phaseA-tests/gh027/gates/3455-expert-nibble.sh: iq_nibble_parity --synthetic-only
and on a model's layers on a P100, then identical replies with the switch on and
off (a layer is converted only when every expert of every layer is resident, so
the rig needs the pack to fit whole), then the decode A/B. The contributor's
numbers (four GP100 dies, Swift 1.5 IQ3_S, 47 of 48 layers converted, +12.7 GiB
VRAM, decode 47.3 -> 51.9 tok/s, +9.7%; prompt reading 2.3-3.0% slower; replies
of 15 requests equal) were not re-measured, and the enabled path was written
against an older base than this branch's.
|
||
|
|
5dbd8774d8 |
prefill: a resident layer's experts weight-stationary on GP100, opt-in STRATA_MMQ_WS=1 (#3752)
Problem: on a GP100 die (compute capability 6.0: no dp4a, no tensor cores) the prompt pass's routed experts run as MMQ launches per 16-expert group: a gate/up, a swiglu, a quantize and a down launch per group, each group's experts gathered and padded to the group's largest row count, every MMQ tile decoding its weight blocks again. With every expert resident the per-group overhead, not the weight bytes, is a large share of a prompt read on this card. Change: with STRATA_MMQ_WS=1, a layer whose routed experts are all resident on this GPU runs quantize_scatter, then gate/up as ONE weight-stationary launch over all its experts (read where they lie in the expert cache), ONE swiglu_quant over all its rows, then the down as ONE launch. New src/prefill/moe_ws*.cu(h): a CTA holds 128 (or 256) weight rows of one expert and runs them against up to 64 of that expert's activation rows, a thread per weight row, so each weight block is decoded once per pass; gate/up for IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS and IQ3_S, down for Q2_0 and IQ4_NL. Every product keeps MMQ's int8 values, scales and per-32-value epilogue in its K order, so GU, H and the down rows are MMQ's bits. ws::faster carries the author's measured ws / MMQ time ratios per format and picks a layer only where both products win at its rows per routed expert. prefill.cpp decides per layer after quantize_scatter (all experts resident, this GPU alone, no peer or CPU share, not the fused layout, not STRATA_MMQ_DIRECT, no Hadamard, no NVFP4 tail, no FP4 activations, aligned, not STRATA_DBG_NAN); every other layer keeps its path. STRATA_WS_FAST=1 (second opt-in, same bits) selects a down kernel for the IQ4_NL 32-token tier with fewer instructions per pass. Gating: the kernels and STRATA_PREFILL_WS exist only in the CUDA build with STRATA_EXPERIMENTAL_SM60 (not HIP, not Metal; prefill.cpp links stubs that answer mode 0 elsewhere). At run time ws::mode() is 1 only with STRATA_MMQ_WS=1 and every visible GPU at compute capability 6.0. Unset, nothing is allocated (the offset and chunk buffers, under 1 MiB per die, exist only when the mode is not 0), the arena layout and the mapped table are the ones before, and the per-layer test short-circuits on the cached mode. Not ported: moe_ws_down_bench (needs a model shard) and its CMake target. Added: ws::set_mode (tests only) and tests/cuda/prefill_ws_parity_test.cpp, a synthetic layer-level check: random experts of all 5 gate/up x 2 down formats, random routing, the per-group MMQ (mmq::Context per expert) against ws::gate_up + swiglu_quant + ws::down, GU, Hq and Dm compared byte for byte, the down also alone on the reference H and with STRATA_WS_FAST on. It gives its verdict on a compute capability 6.0 card only (the kernels follow MMQ's sm_60 SASS); other cards run it for information with --any. Tests: prefill_ws_parity_test on boston (2x RTX A6000, sm_86, CUDA 13.1, gpu lock, SM60 build, --any because it is not a GP100): 40 cases (all 5 gate/up x 2 down formats, four routings each), 0 declined; the largest GU and down-alone error against that card's MMQ is 5.2e-07 of the largest value (float rounding: MMQ's sm_86 epilogue is not the sm_60 one the kernels follow), the full chain's Dm differs up to 1e-3 where int8 rounding of H flips on those rounding differences, and STRATA_WS_FAST output equals the default kernel's in all cases, 0 differing bytes. The byte-for-byte verdict against MMQ is the P100's. sm_60 compile of the whole tree (CUDA 12.9, P1004): exit 0; sm_86 build without the SM60 option (z440): exit 0. SASS of the 10 kernels moe_mmq.cu had before this change is identical in the sm_60 build. Not covered: no GP100 run here. The contributor's numbers (prompt reads 31-37% shorter on four GP100 dies with every expert resident: 240 tokens 2,156 -> 1,364 ms, a fresh 26K read 41,231 -> 28,555 ms; one run per arm) were not re-measured. The model gate is phaseA-tests/gh027/gates/3752-mmq-ws.sh. |
||
|
|
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).
|
||
|
|
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). |
||
|
|
dd97421d3f |
prefill: mmq::swiglu_quant, swiglu and the down product's q8_1 rows in one kernel (#3752)
Problem: the prompt path stores H (swiglu of the gate/up rows) as floats and then quantizes it to the q8_1 rows the down product reads: two kernels and an H round trip per MMQ group. Change: swiglu_quant_kernel, a block per row (128 threads, 4 values each, blockIdx.y the row's 512-value half), computes swiglu_kernel's expression for each value and quantize_mmq_q8_1<D4>'s result for each 32-value block, so hq holds the same bytes and H is never stored. swiglu_quant_ok(type) says where it applies (a q8_1 D4 down type, no FP4 activations). Built only in the CUDA build with STRATA_EXPERIMENTAL_SM60; HIP and the other builds get swiglu_quant_ok() == false and a no-op. Nothing calls it in this commit; the weight-stationary path of the next commit does. prefill.cpp gets the matching stubs for builds without the MMQ sources. Tests: prefill_swiglu_quant_test (new, registered under STRATA_BUILD_TESTS in the SM60 build, skips with 77 without a device) compares the fused kernel with swiglu + quantize byte for byte for Q2_0, IQ4_NL and Q8_0 down types, split and interleaved gate/up rows, a zero row and a row with one huge value. Run on z440 (RTX A4000, sm_86, CUDA 13.0, SM60 build, gpu lock): all 18 cases print "0 of N bytes differ" (1, 37 and 4113 rows) and the test ends "prefill_swiglu_quant_test: ok". sm_60 compile of the tree (CUDA 12.9, P1004): exit 0. This is a partial port of another contributor's prompt-path fusion change; only the kernel is taken, as in PR 3752. |
||
|
|
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). |
||
|
|
b434a8aa6e |
qsa_select: multi-CTA decode top-k and a shuffle-free decode scorer, opt-in STRATA_SELECT_LONG=1 (#3820)
Problem: a decode window's QSA select runs one CTA per query for the top-k (block_topk_wide_kernel past ~135K cells) and the warp-shuffle block scorer (block_scores_multi_kernel), in each QSA layer. Both grow linearly with the context: on one GP100 die at 300K cells a top-k call takes 0.39 ms with 1-5 SMs busy and a scores call 0.22 ms (two queries). At short contexts the same work is small and an extra kernel is pure overhead. Change: qsa_select.cu (inside !__HIPCC__ && STRATA_EXPERIMENTAL_SM60) gets block_topk_multi_* (six kernels over several CTAs per query, one per 2,048 blocks of capacity, at most 32, exchanging through caller scratch: no clusters, no spin waits, capturable) and block_scores_dx_kernel (the multi scorer's per-head sums built in registers as the same 32-leaf xor-butterfly tree, no __shfl_xor_sync, the tail block stays block_scores_tail_kernel's). New public qsa_topk_multi_scratch_ints, qsa_block_topk_long and qsa_block_scores_long forward to qsa_block_topk / qsa_block_scores outside the build gate or their conditions. verify.cpp keeps a second set of window graphs (exec_[sel_long_][T]) for windows that reach STRATA_SELECT_LONG_AT cells (default 65536); the choice is made before a capture and handed to the next stage of an overlapped layer split, capture_all captures both, pl_launch picks by the window's position. The ids and the score bits are the replaced kernels'. STRATA_TOPK_MULTI=0 and STRATA_SCORES_DX=0 turn either half off inside the long graphs. Review changes against the PR: in a build without the multi-CTA kernels STRATA_SELECT_LONG=1 now says so and is ignored (the PR would have kept two sets of graphs for nothing there); Metal gets stubs for the three new calls (the SYCL tree has its own verify.cpp and qsa_select copy). Default path: unset, select_long_on() is a cached false, topk_scratch_ is not allocated, sel_long_ stays 0, and every window uses exec_[0][T], the graph it used before; the index change is the only difference in verify.cpp. Merge note for f-027-gh-eng (#3702 evict_window_graph, not in this branch's base): its exec_ / exec_nr_ / launched_ accesses need the same [sel_long_] first index. Tests: src/kernels/qsa_select_long_parity.cpp (new; registered with STRATA_SCORES_DX=1 STRATA_TOPK_MULTI=1 in the SM60 test block, and a second case with STRATA_TOPK_MULTI_N=3; skips with 77 without the kernels) compares qsa_block_scores_long with qsa_block_scores (nq 1-8, n_bid 8 .. 131072, tail blocks of 0-3 cells, every block 0..n_bid memcmp) and qsa_block_topk_long with qsa_block_topk (nq 1-16, contexts 1,000 .. 524,288, random scores, all-equal scores and 7 distinct values for ties across CTAs, selected ids of every query; the multi scratch is junk-filled and must have been written). z440 (RTX A4000, sm_86, CUDA 13.0, gpu lock, build with -DSTRATA_EXPERIMENTAL_SM60=ON): "172 cases, 0 differ -> PASS" with one CTA per 2,048 blocks and with N=3. sm_60 compile of the whole tree (CUDA 12.9, P1004): exit 0. Not covered: no GP100 run here (the kernels' last word is the P100, and the speed claim). The contributor's numbers (four GP100 dies, every expert resident, --pipeline-windows 3: 400 tokens at 115K context 51.0 -> 52.5 tok/s, +2.9%; prompts below 64K unchanged; replies and state hashes equal on 15 requests) were not re-measured. The model gate is phaseA-tests/gh027/gates/3820-select-long.sh. |
||
|
|
6eff377a79 |
layer-major prefill on a CUDA layer split: each stage runs its layers over the super-chunk and hands its rows to the next stage (#3976)
Problem: layer-major prefill declined every layer split, so a split model kept re-reading each layer's streamed experts once per 8192-token chunk. Changed: - lm_prepare_chain sizes every stage with the same super-chunk (the smallest any stage fits, up to four rounds until they agree) and gives them back together; - a stage runs only its layers [LB, LE); a later stage's rows arrive in its pinned R_host; - a stage before the last writes its final rows into the next stage's R_host on the copy stream, then runs the next stage on a thread (std::async) while it reads its own next super-chunk. There is one hand-off buffer: a stage's final pass waits until the next stage has finished the previous super-chunk; - layer_major_mid() asks the last stage, the one that reports the rows; - run() drains the pipeline after the walk and clears the mid flag on every stage. Not covered: only two stages were tried by the reporter (RTX 3060 + RTX 5060 Ti); the peer-GPU tier and the stage helper have no layer-major form and decline. |
||
|
|
ffe40c1695 |
prefill: layer-major prefill (STRATA_PREFILL_LAYER_MAJOR=1) (#3976, #1670)
A super-chunk of S tokens is read layer by layer: each 512-token sub-chunk runs the attention half, the FFN half hyper-connection read, the router and the shared expert in order (GDN / QSA / PLE state advance as in the default path); then the layer experts run once for the whole super-chunk - each routed expert staged once, its rows of every sub-chunk in one MMQ group, the results added per token. Expert traffic drops by about S / 512 (a 12.9K prompt: ~509 GB -> ~79 GB on ryzen). - STRATA_PREFILL_LM_TOKENS: the super-chunk target (default 8192), shrunk to fit free VRAM minus STRATA_PREFILL_LM_MARGIN_MIB (default 96). - STRATA_PREFILL_LM_R=vram|host|auto: the residual rows of the super-chunk in VRAM, or in pinned RAM with the copies overlapped on the copy stream (auto: VRAM only when the whole target fits there). - STRATA_LM_PREFETCH=0: no prefetch (default on: every streamed expert of a layer goes to the stager when its attention halves start; the ones the routing skips are skipped if not started). - Not for a layer split, a peer GPU, image prompts, the fused layout or a prompt under two chunks. - on_chunk still reports every sub-chunk in order; layer_major_mid() tells serve not to checkpoint before a super-chunk end (the state is already at that end). Port to 0.1.43.1: the copied run_impl body follows the new base. Every blob the stager or the copy stream reads later comes from blob_stable() (blob() may hand out a recycled STRATA_IO_PREFETCH buffer); the token ids go up through tok_up, the QSA step records and the PLE rows' pageable fallback through up_ring (#1712, #1996); the PLE gather threads pin to --aux-cpus; bf16x2 takes m.f16_io; the K8V4 append is upstream's, which writes the host copy and the staging pool by halves. The indexer passes the INT8 pooled keys as the original does, in the QSA port's order (pooled_i8 and pooled_scale after block_pos, the int8 qsa_block_scores(_tc) overloads); STRATA_IDX_INT8 stays opt-in and unsupported on the prompt path, as in the original. stage_one calls the stager's pass() before wait(): with batched claims a routed job after about a ring's depth of skipped prefetch jobs waited forever. lm_prepare reads the fused layout from m.fused_bufs and declines while STRATA_DBG_FEAT, STRATA_DBG_ROUTE_OVERRIDE or STRATA_PREFILL_DUMP_R_ALL is set. serve's near-tail checkpoint (--prompt-cache-tail) is not taken mid-super-chunk, so under layer-major it is taken only when the last super-chunk is a single sub-chunk. From vizdatom's #1670, original commit . |
||
|
|
a6df0023a4 |
prefill: kernels for a layer-major expert pass (moe_shared_init, moe_scatter_add) (#3976, #1670)
moe_shared_init writes the shared expert part of moe_combine before the routed experts are known; moe_scatter_add adds one expert group rows into a per-token accumulator, per token in a fixed order (deterministic, no atomics). From vizdatom's #1670, original commit f0173382d0646907917edf99e59617c1412d898e. |
||
|
|
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) | ||
|
|
a338990186 |
qsa_pattn: sm_6x prompt attention without partials, opt-in STRATA_PATTN_SM60=1 (#3943)
Problem: below sm_70 the prompt reads each QSA layer's attention through the decode kernels (qsa_prompt_attn_batch returns false without tensor cores): 32 queries a call, every chunk's partial results (817 KB a query) written to scratch and merged by a second kernel. Change: src/kernels/cuda/qsa_pattn.cu keeps the contributor's default variant only, ps_score_x_kernel (q in registers, the chunk's K staged with 16-byte loads, two cells at a time through a select-free reduce-scatter) and ps_value_d4_kernel (four dims per thread, merged into the output as the merge kernel does). Every float operation of attn_chunk_kernel_pre75 and attn_merge_kernel is kept in its order, so the output is the decode kernels' bit for bit. The PR's other variants (per-chunk, fused persistent, bench split codes), pattn_bench and the variant argument are not ported; pattn_bench needs a STRATA_QSA_DUMP file from a model run. Gating: compiled only in the CUDA build with STRATA_EXPERIMENTAL_SM60 (HIP and Metal link a stub that answers false; prefill.cpp keeps the call out of the Metal build). At run time only with STRATA_PATTN_SM60=1, on compute capability 6.x, int8 K/V, head_dim 256, 12 query heads per KV head, at most 33 chunks. Unset, the only cost on the default path is one cached int test per QSA layer, and only when qsa_prompt_attn_batch has already declined. Any refusal or a failed launch returns false and the usual 32-query loop runs (one warning, no exit; the PR called exit(1) on a launch failure). Tests: src/kernels/qsa_pattn_parity.cpp (new, registered in CMakeLists.txt in the experimental sm_60 test block, skips with 77 when the kernels are absent) compares the kernels with the Daily's chunk kernel plus attn_merge_kernel on random int8 K/V: a shuffled page table with ~3% unresident pages and a run of 64 unresident pages (whole chunks masked, some queries empty), three selection shapes, caps 64 / 130 / 2051 / 2112, widths 0..cap, n_q up to 40 with a scratch that holds only 2 decode-layout queries (several batches), junk in the scratch and output. On a Pascal card it also requires the checked entry to take the shapes and qsa_decode_attn_batch to match. The kernel entry that skips the compute-capability test (qsa_pattn_batch_any_arch) exists for this test only. Results: z440 (RTX A4000, sm_86, CUDA 13.0, build with -DSTRATA_EXPERIMENTAL_SM60=ON, gpu lock): "qsa_pattn_parity: 468 cases, 0 differ, 29724792 nonzero output values in all -> PASS". sm_60 compile of the whole tree (CUDA 12.9, P1004): exit 0. Not covered: no P100 run here (the Pascal-only checks of the test and the speed claims wait for the gate, phaseA-tests/gh027/gates/3943-pattn.sh). The contributor's numbers (43.3 -> 30.8 ms a 1,536-query chunk per QSA layer at 26K context, 2-3% less time on 8K-150K token prompts on four dies) were not re-measured; compute capability 6.1 is covered by the same switch and was not measured by anyone. |
||
|
|
a3ab37fc03 | Master switches DS4_DEFAULTS=026 (DeepSeek) and STRATA_DEFAULTS=026 (Qwen): every default changed since v0.2.6 gives v0.2.6's behaviour; explicit per-feature variables and flags still win; every rule is a pure function with a v026 argument and a test | ||
|
|
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. |
||
|
|
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. |