diff --git a/CMakeLists.txt b/CMakeLists.txt index b01a1b30..daab2444 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,10 @@ endif() option(STRATA_ENABLE_CUDA "Build the CUDA targets (Phase 2+)" OFF) option(STRATA_ENABLE_HIP "Build the HIP targets for wave32 AMD GPUs (gfx1100, gfx1201)" OFF) option(STRATA_PREFILL_MMQ "Build the optional GGML MMQ prefill path for HIP" OFF) +# CUDA: MMQ prompt kernels for Q4_K / Q5_K / Q5_1 (Unsloth's UD-Q4_K_XL experts). Off by default: the engine loads +# every kernel when it starts (CUDA_MODULE_LOADING=EAGER), so these took ~5 MB of VRAM - 1-3 expert slots - from every +# model, and the UD-Q4_K_XL prompt is SSD-bound with or without them (docs/UNSLOTH_Q4.md) +option(STRATA_MMQ_KQUANTS "Build the CUDA MMQ prompt kernels for Q4_K / Q5_K / Q5_1 experts" OFF) if(STRATA_PREFILL_MMQ AND NOT STRATA_ENABLE_HIP) message(FATAL_ERROR "STRATA_PREFILL_MMQ requires STRATA_ENABLE_HIP=ON") endif() @@ -817,9 +821,13 @@ if(STRATA_NATIVE_EXPERTS) endif() set(_strata_mmq ${_strata_gg}/src/ggml-cuda) add_library(strata_mmq STATIC src/prefill/moe_mmq.cu src/prefill/ggml_cuda_host.cu ${_strata_mmq}/quantize.cu) - # q8_0: the drafter's matrices (E-9); q4_k q5_k q5_1: the experts of Unsloth's UD-Q4_K_XL (docs/UNSLOTH_Q4.md; - # the dispatch follows eddoursul/Strata 7706c1b), compiled in with STRATA_MMQ_KQUANTS - foreach(_t q2_0 iq2_xxs iq2_xs iq2_s iq3_xxs iq3_s iq4_nl iq4_xs q8_0 q4_k q5_k q5_1) + # q8_0: the drafter's matrices (E-9); with STRATA_MMQ_KQUANTS q4_k q5_k q5_1, the experts of Unsloth's UD-Q4_K_XL + # (docs/UNSLOTH_Q4.md; the dispatch follows eddoursul/Strata 7706c1b) + set(_strata_mmq_cuda_types q2_0 iq2_xxs iq2_xs iq2_s iq3_xxs iq3_s iq4_nl iq4_xs q8_0) + if(STRATA_MMQ_KQUANTS) + list(APPEND _strata_mmq_cuda_types q4_k q5_k q5_1) + endif() + foreach(_t IN LISTS _strata_mmq_cuda_types) target_sources(strata_mmq PRIVATE ${_strata_mmq}/template-instances/mmq-instance-${_t}.cu) endforeach() target_include_directories(strata_mmq PRIVATE ${_strata_gg}/include ${_strata_gg}/src ${_strata_mmq} @@ -829,10 +837,12 @@ if(STRATA_NATIVE_EXPERTS) target_compile_options(strata_mmq PRIVATE $<$:-Xcompiler=/bigobj>) endif() target_link_libraries(strata_mmq PUBLIC ggml-base ${_strata_gpu_runtime_target}) - target_compile_definitions(strata_mmq PRIVATE STRATA_MMQ_KQUANTS=1) + if(STRATA_MMQ_KQUANTS) + target_compile_definitions(strata_mmq PRIVATE STRATA_MMQ_KQUANTS=1) + endif() target_link_libraries(strata_prefill PUBLIC strata_mmq) target_compile_definitions(strata_prefill PUBLIC STRATA_PREFILL_MMQ=1) - if(STRATA_BUILD_TESTS) + if(STRATA_BUILD_TESTS AND STRATA_MMQ_KQUANTS) # the UD-Q4_K_XL expert formats through MMQ against ggml's dequantized weights (synthetic, a few seconds) add_executable(prefill_mmq_kquant_test tests/cuda/prefill_mmq_kquant_test.cpp) target_link_libraries(prefill_mmq_kquant_test PRIVATE strata_mmq ggml-base ${_strata_gpu_runtime_target}) diff --git a/docs/UNSLOTH_Q4.md b/docs/UNSLOTH_Q4.md index dc81ca46..039b11b0 100644 --- a/docs/UNSLOTH_Q4.md +++ b/docs/UNSLOTH_Q4.md @@ -151,10 +151,13 @@ low-RAM mode; `STRATA_RESIDENT_PIN=0` keeps the budget locked only (the CPU then 273-282 s). Reading a prompt streams every expert once per 4K chunk, and the third of them outside the RAM budget come from the SSD (~35 GB per chunk), so the prompt path now reads them with 32 threads and up to 128 blobs in flight when the experts are read from the GGUF in place (`STRATA_STAGER_THREADS` / `STRATA_STAGER_RING` override - it; 4 and 16 before, still the default for every other model). The experts' products go through llama.cpp's MMQ - kernels for Q4_K / Q5_K / Q5_1 / Q8_0 (as for the other models' formats; `STRATA_PREFILL_MMQ=0` for FP16): 4x less - GPU time for them, but on this PC the prompt waits for the SSD either way (the same 29 s per 4K chunk with or - without). Between the chunks, the 28.8 GB PLE table's rows take ~5 s per chunk. + it; 4 and 16 before, still the default for every other model). Between the chunks, the 28.8 GB PLE table's rows + take ~5 s per chunk. +- An engine compiled with `-DSTRATA_MMQ_KQUANTS=ON` multiplies the Q4_K / Q5_K / Q5_1 experts of a prompt with + llama.cpp's MMQ kernels (as the other models' formats always are) instead of dequantizing them to FP16: 4x less GPU + time for those products, but on this PC the prompt waits for the SSD either way (29 s per 4K chunk with or + without). Off in the released engine: it loads every kernel at start, and these took 1-3 expert slots of VRAM from + every model. - The speed varies from run to run (6.7-8.6 tok/s at 40 GiB for the same prompt), with what the OS file cache holds. - For comparison, IQ3_S (all its experts in RAM) writes ~53 tok/s on the same PC ([the speed tables](DETAILS.md#speed-measured)). - Where the time goes (`--stats` on the command line): at 40 GiB about 550-750 ms of each verify round (3.5 tokens) is @@ -191,8 +194,8 @@ positions after only 512 tokens agree a little less (89.2%), and the perplexitie scale, Strata's own greedy run and its teacher-forced rerun of the continuation pick different tokens at 6% of the positions (93.8% the same: other window sizes, other experts in VRAM), the same kind of near-tie flips. The 16K prompts were read by Strata's batched prompt path (15,872 tokens), the rest through the verify windows. These numbers -are engine 0.1.31's prompt path (FP16 products); with 0.1.32's MMQ prompt path the continuation after the 16K prompt -agrees at 92.2% (KL 0.029, three runs, identical). +are the FP16 prompt path's (the released engine's); with the MMQ prompt path (`-DSTRATA_MMQ_KQUANTS=ON`, above) the +continuation after the 16K prompt agrees at 92.2% (KL 0.029, three runs, identical). To repeat it: Strata's side is `STRATA_LOGPOS=` with `STRATA_LOGPOS_TOPK=20` (engine 0.1.32) on a serve engine with `--short-read` covering the positions to compare; llama.cpp's side was a short program over @@ -213,8 +216,8 @@ engine with `--short-read` covering the positions to compare; llama.cpp's side w have kernels for; the engine checks every layer's formats at start and refuses an unsupported one by name. - Tests: the packer's synthetic 4-shard and conversion tests (`.venv/bin/python -m unittest discover -s tools -p test_iq_pack.py`); CTests `gguf_split_test`, `expert_layout_test`, `native_expert_parity_*` (the three real expert - format pairs against ggml-cpu, the Q5_1 min term, Q8_0 rows), `prefill_mmq_kquant_test` (the prompt path's MMQ - products for Q4_K / Q5_K / Q5_1 / Q8_0 against ggml's dequantized weights); the in-place mode against `experts.bin` on the Coder + format pairs against ggml-cpu, the Q5_1 min term, Q8_0 rows), `prefill_mmq_kquant_test` (with `-DSTRATA_MMQ_KQUANTS=ON`: the + prompt path's MMQ products for Q4_K / Q5_K / Q5_1 / Q8_0 against ggml's dequantized weights); the in-place mode against `experts.bin` on the Coder (identical tokens and logits). - Real runs: greedy answers to a coding prompt (correct) at every budget and setting above, identical across them; the same tokens as llama.cpp at 97.5-99% of the positions of short greedy answers and 90-91% after a 16K prompt, diff --git a/include/strata/prefill/moe_mmq.hpp b/include/strata/prefill/moe_mmq.hpp index 4d1e4d88..a8c6714e 100644 --- a/include/strata/prefill/moe_mmq.hpp +++ b/include/strata/prefill/moe_mmq.hpp @@ -12,8 +12,8 @@ namespace strata::prefill::mmq { /// This build has the MMQ path (the ggml sources were available to the build). bool built(); -/// MMQ covers this ggml type (the i-quants and Q2_0 the packs use, Q8_0, and on CUDA the Q4_K / Q5_K / Q5_1 of -/// Unsloth's UD-Q4_K_XL; IQ1_M is not covered). +/// MMQ covers this ggml type (the i-quants and Q2_0 the packs use, Q8_0, and in a CUDA build with STRATA_MMQ_KQUANTS +/// the Q4_K / Q5_K / Q5_1 of Unsloth's UD-Q4_K_XL; IQ1_M is not covered). bool supported(int ggml_type); /// Bytes of one expert's gate+up ([2*n_ff, n_embd]) or down ([n_embd, n_ff]) weights in `ggml_type`. size_t matrix_bytes(int ggml_type, int64_t rows, int64_t cols);