ba8b2bcb9c1f9eb11a1fdf8ccdd11e7db4bf83e9
685
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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. |
||
|
|
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). |
||
|
|
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. |
||
|
|
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. |
||
|
|
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. |
||
|
|
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. |
||
|
|
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. |
||
|
|
f213f78bae |
mtp: the drafter's Q8_0 draft head and projections on the Pascal GEMV, opt-in STRATA_MTP_Q8_SM60=1 (#3751)
Problem: with STRATA_Q8_SM60=1 the main model's Q8_0 matrices run on the GP100 Q8_0 kernel, but the MTP drafter's own Q8_0 draft head and projections kept the generic kernels. Change: with STRATA_MTP_Q8_SM60=1 (on top of STRATA_Q8_SM60=1) the drafter packs its Q8_0 projections as packed copies, as the main model does (the prompt path's draft_kv still reads the GGUF layout, so a copy is kept), and packs the draft head's subset in place when every column count fits the kernel's shared-memory planes and the data is 16-byte aligned (otherwise a packed copy). The in-place pack writes the GGUF blocks back if the device write fails. Release unregisters the entry without a cudaFree when the data was packed in place. New native_q8_0_sm60_pack_quiet and native_q8_0_sm60_pack_in_place; HIP returns false; metal/src/engine/stubs_0145.cpp gets matching stubs that answer "nothing packed". Replies do not depend on the drafts (they are verified); only the draft rounding changes, because the Pascal kernel sums in another order. Default path: mtp_q8_sm60() is false unless the env is set, so the packing calls are skipped. The destructor now walks the tensor list once at teardown, not in a hot loop. The SYCL tree has its own sycl/src/core/mtp.cpp, so it is not touched. Tests: compile-only on sm_60 (CUDA 12.9) on P1004. Model gate (identical replies with the flag on and off, decode speed on a P100) is written down in phaseA-tests/gh027/gates/3751-mtp-q8-sm60.sh. Not covered: no GPU run here; the contributor measured +4.4% on four GP100 dies with all experts resident, one run per arm, not on a single streamed P100. |
||
|
|
54d9363c97 | CUDA Plan opt-ins become defaults where measured: STRATA_GR_V3 on a discrete 12.0 card above 13 GiB, STRATA_PROMPT_ATTN_IMMA on CUDA sm_80+ (env =0 turns each off); DeepSeek Faster mode (5 experts) by default on 2+ RDNA4 cards that hold half the experts; the route-prior/GR_V3/IMMA rules are pure functions with tests; gr_parity and fused_gr_bench pin STRATA_GR_V3=0 for their bitwise contract | ||
|
|
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). |
||
|
|
c8596ec391 | Merge f-027-marlin (DeepSeek on 4x R9700: staging ring from the room, copy pin auto, chunk 1024 where the cards hold most experts, whole-chunk attention slab, F16 gate/up activations, drafter cumulative cut on HIP, diagnostics). Conflicts resolved: attention slab = one rule (attn_slab_rows: Marlin's share >= 0.5 branch plus the automatic growth, unified memory and DS4_ATTN_SLAB=0/N untouched); staging ring = one function (staging_ring_mb: 16 MB where the cards hold the experts, Marlin's small per-device ring at 0.5..0.82, main's streamed 400..1200 MB on unified memory and under half); DS4_COPY_PIN auto = huge-page arena OR cards hold >= half; DS4_FAST_ATTN stays gfx12-only; chunk 1024 for multi-card tp runs too, but not for --threads on or one card on the default tp | ||
|
|
4abccbb360 | Merge f-027-cuda (CUDA speed work: wide HC up read on sm_120, residency-biased routing on small cards, STRATA_TRACE, release-notes draft) | ||
|
|
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> |
||
|
|
bda3005082 |
KVA, when switched on, approximates layers 36-47 with a 2048-token exact tail (the measured configuration); STRATA_KVA_SPLIT / STRATA_KVA_SUFFIX override
On the RTX 5070 (--agent-long, 22 tasks) split 36 kept agents at 6/10 (exact 4 and 7) and extraction at 585/606 facts (exact 585) for +11% prompt speed at 14K and +18% at 30K; the split-24 default passed 0/10 agent runs and found 556 facts, a tail of 8192 with split 24 found 574. KVA stays off unless STRATA_KVA=1. docs/KVA.md gives the numbers and the reasons; kva_test checks the opt-in's split 36 / tail 2048 and the overrides. The geometry gate is unchanged. |
||
|
|
25a62e0fb3 |
KVA: keep the geometry gate - a model whose shape KVA was not measured on reads exactly; STRATA_KVA_ANY_MODEL=1 is the research override
The app toggle will write STRATA_KVA=1 for Qwen models in general; the split layer, the tail and the measured quality apply to Qwen3.8-Flash-Next's shape only (48 layers, 512 experts). Any other shape (Qwen3.6-35B-A3B, ...) now logs "KVA configured but NOT applied: this model's shape (L layers, E experts) is not one KVA was measured on" and reads exactly; the routine reasons (short prompt, continuation) still come first. STRATA_KVA_ANY_MODEL=1 allows it, with one warning. kva_test and docs/KVA.md cover both. |
||
|
|
e3450e4552 |
KVA ships OFF in 0.2.7: STRATA_KVA unset is the exact 0.2.6 engine, STRATA_KVA=1 turns it on with an 8192-token exact tail
The quality runs found lost records and invented rows in long extraction tasks and defects in agent loops with a ~10K system prompt when most of the prompt was approximated. Opt-in now: unset (or 0) nothing runs, the draft layer included. Switched on, the tail is 8192 tokens (STRATA_KVA_SUFFIX overrides), the safest configuration measured. A model other than Qwen3.8-Flash-Next's geometry gets a one-line warning instead of a refusal. Kept: the untouched draft layer (cell floor behind STRATA_KVA_DRAFT_FLOOR=1), the decline reasons, STRATA_KVA_SKIP=moe, the tests. docs/KVA.md says why it is off and how to turn it on; kva_test checks unset = off and STRATA_KVA=1 = on with the 8192 tail. |