Skip to content

hip: mmq is false, as this backend has no int8 GEMM - #1

Closed
hun wants to merge 582 commits into
mainfrom
hip/mmq-false
Closed

hun wants to merge 582 commits into
mainfrom
hip/mmq-false

Conversation

@hun

@hun hun commented Dec 5, 2026

Copy link
Copy Markdown
Owner

The trait default of Backend::mmq is CUDA's per-type policy, with no device in it. HIP never overrode it, so the backend claimed the int8 prefill GEMM for every integer weight type while int8_gemm returns false and gemm_raw runs gemm_* on f16.

Nothing in src/ reads mmq (7 call sites, all in tests/), so this changes no engine behaviour. The tests built their reference math from it, and gemv_partial_superblocks_and_q2_0 failed on main because it compared HIP's f16 GEMM against an int8-x reference:

hip Q2_0 cols 640: gemm rel err 0.004293356

With mmq false on HIP the whole type list passes (TQ2_T included). On pristine main the same run fails; moe_mailbox_round_trip and tensor_scale_applies_to_all_gpu_ops fail on main too and are unrelated.

Callers that want the type policy itself use cuda::Gpu::mmq, which is unchanged. Implementing an int8 GEMM on HIP later flips this back to that state's condition without touching any caller.

PedroRossi and others added 30 commits November 30, 2026 21:01
…rings, nor that GigaChat 4 has no tool calls
TQ2_T/TQK6/TQK7 kernels load the 16 KB tq_lut into shared memory once per
block (gemv, moe_gemv, gemvn, gemm_q) and the GEMV runs 4 rows a warp with
shared x loads (rows 0/1/2/4 via STRATA_RPW_TQ; 0 = one row a warp on the
global table, the default for 1-token GEMV of fewer than 2048 columns).
Output is bitwise identical to before (tests/tq_probe.rs digests); greedy
generate with --fixed-experts on Qwen3.8-Flash-Next-Gyro-S matches md5.

RTX 3060, tests/tq_probe.rs, median us before -> after:
  TQK6 moe_gemv 640x2560 k10 gate+up  231 -> 121
  TQK7 moe_gemv 2560x640 k10          147 -> 105
  TQK6 gemm c8/c32/c64/c128  238/269/372/558 -> 169/206/309/488
  TQK7 gemm c8/c32/c64/c128  221/259/375/591 -> 165/206/327/513
  TQK6 gemv 14.0 -> 10.8, gemvn3 17.2 -> 11.7
  TQK7 gemv 15.0 -> 16.2, gemvn3 18.0 -> 25.1 (dense trellis; the
  Flash-Next models have trellis experts only)
tests/kernels.rs moe_gemv case uses 42 rows to cover a partial 4-row warp.
A VBMI byte permute and a shift pull 16 trellis states at once and vpdpwssd sums
the products, 22% less time a block on a 7600X (16.4 -> 12.6 ns TQK6, 16.3 -> 12.7
TQK7, one thread). Same bits as the AVX2 dot (test tq_avx512_matches_avx2); picked
at run time, TQ2_T and CPUs without AVX-512 keep the AVX2 path.
… refuses reserved, NAT64 and 6to4 forms

The download agent resolves through PublicResolver, which wraps ureq's DefaultResolver and refuses a host when any
address it returns fails is_public_ip (unless STRATA_ALLOW_PRIVATE_IMAGE_URLS=1). A DNS answer that changes after
check_public_url, or a redirect target, is so judged when the connection is made, and redirects are followed again
(ureq's default of 10). is_public_ip also refuses 192.0.0.0/24 and 240.0.0.0/4, and judges NAT64 (64:ff9b::/96) and
6to4 (2002::/16) addresses as the IPv4 address they carry; 198.18.0.0/15 stays allowed for fake-IP DNS proxies. With
an env proxy (HTTP(S)_PROXY, ALL_PROXY), ureq resolves only the proxy, so the rule applies to the proxy's address.
Tests check the guard on the new literals, and that the agent alone refuses a 127.0.0.1 listener without connecting.
…eeps io's UnexpectedEof

The 30 s read timeout applied to each read, so a client that sent a byte every 29 s kept its connection, and a place
in --max-waiting, for as long as it liked (one byte every 25 s kept a connection past 65 s). The accept loop now reads
through serve::Deadline: each read waits for what is left of REQUEST_TIME (120 s; an 8 MiB body still gets through at
about 70 KB/s), at most 30 s, and the request fails with io's TimedOut, "the request did not arrive within 120 s",
also when the time runs out inside a read (Unix reports that one as WouldBlock). With the built server, one byte every
25 s now gets that 400 at 120.0 s. A body shorter than it claims is io's UnexpectedEof again, as read_exact gave before
374855f. tests/serve.rs a_request_that_trickles_in_fails_at_its_deadline (a byte every 100 ms against 400 ms; the same
request sent at once is read) and a_cut_off_body_is_an_unexpected_eof.
…ant K)

On a device without cooperative matrices, prefill attention against a TurboQuant K cache rotated the uninitialized
query registers and then overwrote them with the unrotated query, so every score was wrong. The rotation now runs
after the load, as in attn_prefill_dp. tests/vulkan_split_kv.rs::vulkan_turbo_k_tile_prefill (STRATA_VK_NO_COOP=1,
turbo4/turbo4 and turbo4/f16): prefill vs decode 8.0e-1 before, 2.3e-7 after on the RTX 3060.
…or (RustingStudio#149)

Without --mmproj or an mmproj*.gguf next to the model, a model file that carries
clip.vision.* metadata under its own architecture opens as the projector.
…ices) (RustingStudio#149)

vit_attn_tc_80/128 (sm_80+) and vit_attn_cm (Vulkan with cooperative
matrices) run the non-causal encoder attention as flash attention over
f16 copies, the head padded to 80 (128) with zero columns. The scalar
kernels stay for other GPUs and under STRATA_VIT_SCALAR=1.

Qwen3.6 mmproj, 2048x1536 image (12288 patches), RTX 3060: attention
15.6 s -> 1.7 s, encode 30.3-32.0 s -> 16.1-20.4 s on CUDA; Vulkan
encode 32.6-34.1 s -> 26.7 s. GPU vs CPU token cosine >= 0.99985.
…round trip for q_b and the indexer q_b

sections() hands out a grow-only per-GPU scratch instead of an allocation, memset and free per call; mla_attn
keeps its split partials the same way. A decode token past the indexer window runs q_b and the indexer's q_b
in one rows() call.
…s, a chunk never evicts, its own CPU share

swiglu_chunk (CUDA) orders the experts resident-first and copies the staged ones group by group into three
64 MB slots on the side stream, so a group uploads while the one before runs its GEMMs; no per-call allocation.
A prefill chunk no longer admits its misses (with STRATA_DS_CPU_SHARE=0 every miss evicted, and pp3584 fell to
~83 tok/s). The decode and the prefill chunks balance their CPU share of the misses apart.

RTX 3060, warm runs, box loaded by other jobs: pp512 150-181 -> 283-346 tok/s, pp3584 median 308 -> 374 tok/s;
STRATA_DS_CPU_SHARE=0 pp3584 83 -> 345 tok/s. Parity vs llama.cpp 620/640 (baseline run 619/640).
Each layer's f16 key rows (raw rows, plus the compressed rows of the source
layers it reads) live on the GPU that holds the layer's matrices, and
mla_attn runs there (mla_attn_on), so no key row crosses between cards.
DsModel::new picks the GPU per layer before loading it, so a layer's plain
weights stay together. STRATA_DS_ROOM_GB sets the plain-weight room per GPU
by hand. The synthetic test runs a two-GPU configuration (device 0 listed
twice) with the layers split and checks parity.
One readback per layer for the attention block instead of three: a ds_rope
kernel applies the YaRN rope (and its inverse) on the device, so the query
projection, MLA attention and both output projections run back to back.
Falls back to the old path when the layer's matrices are not on one card.

load_groups now reads the matrix from the host: Mat::load uploaded a whole
second copy of wo_a that nothing used, which pushed layers past their card.
The config now requires an even rope width no larger than the head. ds_attn_on
falls back to the CPU path (None) unless wq_b, each wo_a group and wo_b agree
with n_head, head_dim and the query rank, and every key index is a cached row
(chain_ok, with a unit test). ds_rope refuses a rope wider than the head on the
host side and in the kernel.
… expert passes in decode

Prefill reads each CPU expert row once for four tokens on these types too
(IQ2_XXS 48x8 prefill 101.5 -> 38.2 ms, Q4_K 55.9 -> 35.2 ms, 6 threads,
Ryzen 5 7600X). Decode runs all gate/up rows in one rayon pass and all downs
in another (IQ2_XXS 6 experts 1.59 -> 1.48 ms). Same bits as before.
…IQ3_S

One generic kernel per type serves 1 and 4 activations, so the single dot keeps its bits and the 4-token one
matches it (dot4_matches_four_dots covers the six types). ds_cpu_bench prints the 1-thread dot4 rate.
Prefill, 48 experts x 8 tokens, 6 threads on the 7600X: IQ2_XS 109-187 -> 35-54 ms, IQ2_S 82-88 -> 41-46,
IQ3_XXS 120-121 -> 40-71, IQ3_S 141-167 -> 45, IQ1_S 101-110 -> 38, IQ1_M 106 -> 41-45.
The release binary targets x86-64-v3. On a CPU with AVX-512VL and VNNI,
int_dot4 now returns the same AVX2 kernels compiled with those features
(target_feature wrappers), so the compiler can use 32 registers,
vpdpwssd and vpternlog. The source and sum order are unchanged and
dot4_matches_four_dots passes in an x86-64-v3 build against the plain
AVX2 single dots.

Ryzen 5 7600X, x86-64-v3 build, 1 thread, ns/row for 4 activations:
Q2_K 234 -> 174, Q3_K 293 -> 212, Q6_K 352 -> 298, IQ1_M 376 -> 309,
IQ2_S 357 -> 322, IQ2_XXS 276 -> 261. Prefill, 6 threads, 48 experts x
8 tokens: Q2_K 27.7 -> 21.6 ms, IQ1_M 42.0 -> 36.0 ms.

Docs: prefill numbers for the new i-quant 4-token kernels and for this.
k, q, v, beta and g of 16 tokens go to shared memory per stage and the sums
read k and q from there. Registers drop from 119 to 48, so 5 blocks fit an
SM and a 32-head GigaChat4 GDN layer runs in one wave instead of three.
Same arithmetic per token: outputs and states are bit-identical.
The sigmoid gate over all heads and the residual adds after the post
attention/FFN norms ran on one thread over the whole prompt; fuse norm and
add per row and split both across rayon. Bit-identical results.
…s up

The first prefill after load reads the experts off disk while the page cache is cold, which is load time rather than prefill speed. GigaChat 4 Q4_K_M on an RTX 3060, pp512/tg128, 3 reps after the warm-up: prefill 420.4 (363.4-460.4) tok/s, decode 46.2 (42.7-48.8) tok/s.
… one read

The shared copy of tq_lut was float2 (16 KB); the codebook is f16, so u32 f16
pairs hold it exactly in 8 KB and a 32-bit gather meets fewer bank conflicts.
deq8s now reads the 4 bytes holding the states of both steps once instead of
3 bytes per step. Same bits (tq_probe digests unchanged, greedy 64 tokens
identical with --fixed-experts).

RTX 3060, tq_probe at the Gyro-S shapes: TQK6 moe_gemv pair 130 -> 81 us,
TQK7 moe_gemv 105 -> 67 us. Qwen3.8-Flash-Next Gyro-S, bench --pp 512 --tg 128,
5 interleaved pairs, medians: decode 27.1 -> 28.7 tok/s, prefill 170.9 -> 174.4.
serve::warm_up runs the untimed 512-token prefill that GigaChat 4 had, now for
the generic GPU path when the model has an expert cache and for the models
outside the main engine (DeepSeek, Hy4, Kolibri, Raon, Inkling 2, GLM, Gemma 4).
STRATA_WARMUP=0 still skips it.

Qwen3.8-Flash-Next Gyro-S (58 GB) on the RTX 3060 / 30 GB RAM, page cache
emptied before each start: first 482-token request 125 -> 202 tok/s (medians
of 3); warm-up 6.5 s. Docs: Gyro-S bench numbers in MODELS.md.
ds_cpu_bench: STRATA_BENCH_GAP_US idles before each timed run and prints
the mean, to time thread pool wake-up after the GPU part of a layer.
Docs: decode expert step reads Q4_K at 55.5 GB/s, Q2_K at 52.8 GB/s
against 60-65 GB/s DRAM on the 7600X; prefill within 1.35x of llama.cpp
MUL_MAT_ID; a ggml-style spinning pool was not faster than rayon. NUMA
note on the single preload thread, and what to send from the L40S host.
… copies

Baking turned every target into an F32 tensor, which the fast path then read through the float kernel: Ternary
Bonsai 2B with its rank-1 adapter on 48 tensors (about 2 GB as F32) decoded at 1 tok/s. On --fast-cpu the targets
stay quantized and each product adds m * B * (A * x) for its input; the reference path and the GPU upload keep
baking. With the adapter: prefill 16.6 tok/s and decode 8.7 tok/s on an i5-8365U, against 17.3 and 8.5 without.
Hannes Klas and others added 29 commits December 5, 2026 09:05
A failed range releases the ranges locked before it.
…hreads

- qwen4exp prefills a chunk at a time on the CPU: hyper-connection reads,
  PLE projections, QSA indexer projections and the mixer matrices run once
  per chunk; the recurrence, QSA selection and attention stay per token.
- MoE prefill groups the chunk's tokens by expert (moe_batch), so each
  expert's rows are read once per chunk; sums keep each token's route order.
- Routed experts and the shared expert run in parallel when decoding.
- BF16 rows dequantize in one vectorized loop; F32 matvecs read in place.
- --fast-cpu defaults to one thread per physical core.

Same bits as before: greedy output unchanged, new test
qwen4exp_batched_prefill_matches_steps checks prefill against steps.

Qwen4-35B-A3B UD-IQ4_XS, Ryzen 9 7945HX, --fast-cpu:
prefill 8.3 -> 40.6 tok/s (512 tokens), decode 8.5 -> 14.1 tok/s.
…pters and DFlash drafters (RustingStudio#211)

/api/models asked each model for its projector, which opened every mmproj
file in full (a whole-file page-cache read, logged each time) and opened
any model without a projector the same way. The probes now read the header
only. Files with general.type "adapter" or the dflash architecture are not
listed: they load with --lora and --draft-model, not as a model.
…#210)

The name in /v1/models, the page and the logs was the first shard's file
name, so it ended in -00001-of-0000N. A request that names the model with
the shard number still finds it.
…stingStudio#209)

The parent opens only the first device, for its name, so its log showed one
device while every sample ran on all of them.
…ne per slot (RustingStudio#213)

The patch from issue RustingStudio#213 by citydirector: the state after a system prompt
is also kept among the parked states, flagged sys. It stays when a longer
conversation that starts with it is parked, and a prompt that starts from
it takes a copy. A client that sends new conversations with two system
prompts in turn no longer reads each from scratch. --cache-ram bounds the
memory as before.

The new part of prefill_cached_reuses_history covers it on a GPU.
…oad (RustingStudio#204)

POST /api/load options gain parallel (1 to 255), device (a string such as "0,1") and auto_unload (seconds, 0: never),
and GET /api/models returns them. A load that goes back to one slot gives MTP its default back, since a load with
several slots turned it off. --threads stays a flag: the thread pool is made once, at the first load.
…the same file name apart by their folder

Only the first shard's -00001-of-0000N is cut from a name, so another shard loaded by path keeps its number.
The Hugging Face file picker shows the folder of a file in its rows too.
The default output keeps the lines a user acts on. Driver capability lists,
shared-memory sizes, mailbox counters and the chat template go through the new
`detail!` macro, which prints only with STRATA_VERBOSE=1.

- `GPU memory:` replaces the `plan:` line (tools/knob_matrix_v100.sh reads the new name).
- The page cache line prints once per file.
- Notes are one short sentence and name no issue.
- Expert lines print only for a model with an expert cache; worker stalls print only when there were some.
calibrate had its own flag list, so it refused flags that change what is
measured. It now takes --k, --v, every --kv value, --ple, --threads,
--cache-ram, --ram-margin, --max-ram, --arena, --pin, --prefill-cpu,
--cpu-frac and --host-share (also `calibrate spec`), and hands them to every
measurement.

The load options of the server take every --kv value too.
Every page is rewritten as a short guide: what to run first, then tables for
flags and variables. Nothing measured was changed and no number was added.

- USAGE.md is the one home of commands, flags, variables and the server API.
- MODELS.md holds the per-model notes; the other pages link to it.
- Flags and variables the pages named but the source does not have are gone.
- Flags the source has but the pages missed are added from the clap definitions.
A split model whose shard with the old n-gram table was deleted now loads
when --ple names another file with the table. The file gives only its
table, whatever split.no it has, and the shard can be any one of them.
A table too small for the model stops the load with a plain error; it
panicked at the first token before.
The trait default is CUDA's type policy alone, so HIP claimed the int8
prefill GEMM for every integer weight type and the kernel tests built their
reference from int8 x. gemv_partial_superblocks_and_q2_0 read Q2_0 0.0043 off
on main. Nothing in src/ reads mmq; callers wanting the type policy use
cuda::Gpu::mmq.
@hun hun closed this Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.