Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Merge f-nvfp4 into f-144-rel
Niko122166db34dc402e
diff --cc CMakeLists.txtindex ca8d467f7,557aa81d4..604977c3a--- a/CMakeLists.txt+++ b/CMakeLists.txt@@@ -1391,20 -1367,17 +1395,21 @@@ if(STRATA_NATIVE_EXPERTS# #136: the Q2_0 pack's prompt experts on Strata's own int8 kernels (moe_fused.cu, opt-in STRATA_PF_FUSED=1; CUDA# only: the HIP branch below keeps MMQ, and an sm_75 device or an sm_75-only build reports them unavailable)add_library(strata_mmq STATIC src/prefill/moe_mmq.cu src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu+ src/prefill/mmq_nvfp4_w4a8.cusrc/prefill/ggml_cuda_host.cu ${_strata_mmq}/quantize.cu)# q8_0: the drafter's matrices (E-9); STRATA_ORCA_Q4KS_MMQ adds q5_0 (#296, in _strata_mmq_types), and- # 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); q6_k is HIP only+ # STRATA_MMQ_KQUANTS q4_k q5_k q5_1 q6_k, the experts of Unsloth's UD-Q4/Q5/Q6_K_XL (docs/QUANTS.md; the dispatch+ # follows eddoursul/Strata 7706c1b). MODEL-UPDATE Phase 1: on CUDA they are a library of their own, strata_kq+ # (below), loaded only for a model with these experts: the engine loads every kernel of its own binary at start+ # (CUDA_MODULE_LOADING=EAGER), and these four took ~3.8 MB of VRAM (3 expert slots of IQ3_XXS on a P100) from every+ # model. gfx906 (HIP: code objects load on first use) keeps them in strata_mmq.set(_strata_mmq_cuda_types ${_strata_mmq_types})- if(STRATA_MMQ_KQUANTS)- list(APPEND _strata_mmq_cuda_types q4_k q5_k q5_1)- if(STRATA_Q6K_EXPERTS OR STRATA_HIP_GFX906) # UD-Q6_K_XL gate/up (docs/UNSLOTH_Q6.md),- list(APPEND _strata_mmq_cuda_types q6_k) # and gfx906: moe_mmq.cu calls it under __HIPCC__- endif()+ set(_strata_kq_types q4_k q5_k q5_1 q6_k)+ set(_strata_kq_dso OFF)+ if(STRATA_MMQ_KQUANTS AND STRATA_HIP_GFX906)+ list(APPEND _strata_mmq_cuda_types ${_strata_kq_types})+ elseif(STRATA_MMQ_KQUANTS)+ set(_strata_kq_dso ON)endif()foreach(_t IN LISTS _strata_mmq_cuda_types)target_sources(strata_mmq PRIVATE ${_strata_mmq}/template-instances/mmq-instance-${_t}.cu)@@@ -1474,9 -1434,17 +1495,18 @@@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})add_test(NAME prefill_mmq_kquant_test COMMAND prefill_mmq_kquant_test)- set_tests_properties(prefill_mmq_kquant_test PROPERTIES TIMEOUT 120)+ # the K-quant MMQ is opt-in at run time (STRATA_MMQ_KQ=1), and on CUDA it is strata_kq next to the test+ set_tests_properties(prefill_mmq_kquant_test PROPERTIES TIMEOUT 120 ENVIRONMENT STRATA_MMQ_KQ=1)endif()+ # the NVFP4 expert products (w4a8 / w4a4, STRATA_PREFILL_NVFP4) against a double-precision reference+ add_executable(mmq_nvfp4_parity src/prefill/mmq_nvfp4_parity.cpp)+ target_link_libraries(mmq_nvfp4_parity PRIVATE strata_mmq ggml-base CUDA::cudart)+ if(NOT MSVC) # its FP16 rounding helper uses the F16C intrinsics (GCC/Clang need the target flag)+ target_compile_options(mmq_nvfp4_parity PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mf16c>)+ endif()+ # the routed-expert products (MMQ) timed at the prompt path's shapes (16 experts a launch)+ add_executable(mmq_expert_bench src/prefill/mmq_expert_bench.cpp)+ target_link_libraries(mmq_expert_bench PRIVATE strata_mmq ggml-base CUDA::cudart)elseif(STRATA_PREFILL_MMQ)# Compile only the pinned GGML MMQ and activation-quantizer sources used by prefill. This uses# common.cuh's native HIP path without enabling a second GGML HIP backend.diff --cc setup.pyindex 8b80704e9,f7deb36ca..7d8cfe367--- a/setup.py+++ b/setup.py@@@ -221,32 -271,23 +262,49 @@@ MODELS ="download_gb": 93.7, "ram_gb": 48, "arena_gb": 59.5, "families": ("unsloth",), "budget": True,"shards": 3, "file": "Qwen3.8-Flash-Next-{q}-0000{i}-of-00003.gguf", "engine": (0, 1, 38),"vision": True},+ # Unsloth's 4-bit file (docs/UNSLOTH_Q4.md); experimental until MODEL-UPDATE Phase 2. Its 77 GB of experts stay in+ # RAM from ~94 GB of RAM (unsloth_budget); on a 64 GB PC the engine keeps a RAM budget of them+ # (--resident-budget-gib, chosen below) and reads the rest from the GGUF on the SSD. It runs on AMD too (R9700:+ # the quality yardstick and the decode/prompt numbers in docs/QUANTS.md), so it is no longer NVIDIA-only (#429).+ "UD-Q4_K_XL": {"about": "4-bit (Unsloth Dynamic): K-quant experts, between UD-IQ4_XS and UD-Q5_K_XL in quality",+ "download_gb": 111.3, "ram_gb": 48, "arena_gb": 77.0, "families": ("unsloth",), "budget": True,+ # #967 / MODEL-UPDATE: images run end to end with this file (CUDA: RTX A4000, GPU encoder; HIP:+ # R9700, CPU encoder; the test picture's text and shapes as the IQ3_XXS pack answers them)+ "vision": True},+ # MODEL-UPDATE: Unsloth's larger files (docs/QUANTS.md). The same GGUF-in-place mode: every expert in RAM where it+ # fits with UNSLOTH_RESIDENT_BESIDE_GB more (unsloth_budget), else a RAM budget of them and the rest read from the+ # SSD while it answers - so "ram_gb" is the all-in-RAM need, and below it setup asks first (default no). Their+ # shards 2 (the head) and 3 (the 54 GB Q8_0 PLE table) are the same bytes in all three files. UD-Q5_K_XL and+ # UD-Q6_K_XL need the Q6_K expert kernels every engine has from MODEL-UPDATE Phase 1 on (Q5: layer 2's gate/up).+ "UD-Q5_K_XL": {"about": "5-bit (Unsloth Dynamic): Q5_K experts with Q8_0 downs, close to Q8_0 in quality",+ "download_gb": 158.3, "ram_gb": 108, "arena_gb": 98.4, "families": ("unsloth",), "budget": True,+ "shards": 6, "file": "Qwen3.8-Flash-Next-{q}-0000{i}-of-00006.gguf", "engine": (0, 1, 44),+ "vision": True},+ "UD-Q6_K_XL": {"about": "6-bit (Unsloth Dynamic): Q6_K experts with Q8_0 downs",+ "download_gb": 169.2, "ram_gb": 118, "arena_gb": 109.2, "families": ("unsloth",), "budget": True,+ "shards": 6, "file": "Qwen3.8-Flash-Next-{q}-0000{i}-of-00006.gguf", "engine": (0, 1, 44),+ "vision": True},+ "Q8_0": {"about": "8-bit, the reference quality (every expert Q8_0); for a 192 GB PC",+ "download_gb": 188.2, "ram_gb": 136, "arena_gb": 128.3, "families": ("unsloth",), "budget": True,+ "shards": 6, "file": "Qwen3.8-Flash-Next-{q}-0000{i}-of-00006.gguf", "engine": (0, 1, 38),+ "vision": True},+ # MODEL-UPDATE Phase 4: NVFP4 experts, ready-made packs (NVFP4_REPOS). 63.3 GiB (68.0 GB) of experts in the+ # pack's experts.bin; the low-RAM mode reads them from there on a PC whose RAM does not hold them. NVIDIA only+ # (the HIP and SYCL engines have no NVFP4 kernels). Images: both packs keep Qwen's vision tower unquantized, so the+ # original's image encoder (ISTA's mmproj, the same file as for every Flash-Next model) reads pictures for them;+ # checked end to end on an RTX 5070 and an RTX 3060 against IQ3_XXS's answers on the same picture.+ "NVFP4": {"about": "4-bit NVFP4 experts, GPTQ (sergqwer's strata-nvfp4 pack); RTX 50 has FP4 tensor cores, other "+ "NVIDIA cards run it at 8-bit precision", "download_gb": 128.0, "ram_gb": 80, "arena_gb": 68.0,+ "families": ("nvfp4",), "nvidia_only": True, "vision": True, "repo": NVFP4_GPTQ_REPO,+ "engine": NVFP4_ENGINE,+ "license": "Qwen Community License 1.0 (Qwen3.8-Flash-Next's): https://huggingface.co/Qwen/Qwen3.8-Flash-Next"},+ "NVFP4-NVIDIA": {"about": "NVIDIA's own NVFP4 checkpoint (plain rounding), converted by sergqwer; the same size "+ "and speed as NVFP4", "download_gb": 128.0, "ram_gb": 80, "arena_gb": 68.0,+ "families": ("nvfp4",), "nvidia_only": True, "vision": True, "repo": NVFP4_NVIDIA_REPO,+ "engine": NVFP4_ENGINE,+ "license": "NVIDIA Open Model License (Licensed by NVIDIA Corporation under the NVIDIA Open Model "+ "License) with Qwen3.8-Flash-Next's Qwen Community License 1.0: "+ "https://huggingface.co/nvidia/Qwen3.8-Flash-Next-NVFP4"},}# The experimental Unsloth file's four shards at the pinned revision: name -> (bytes, sha256), checked after the# download (setup trusts no other model file by name and size alone either: check_shards reads their directories).@@@ -354,7 -354,14 +412,14 @@@ FAMILIES ="mmproj_hf": hf("ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF"),"mmproj": "mmproj-Qwen3.8-Flash-Next-BF16.gguf", "name": "qwen3.8-flash-next-unsloth","vision": False, "pack_args": ["--compat-bf16"],- "sha256": {**UNSLOTH_SHARDS, **UNSLOTH_IQ4_XS_SHARDS}},+ "sha256": {**UNSLOTH_SHARDS, **UNSLOTH_IQ4_XS_SHARDS, **UNSLOTH_BIG_SHARDS}},+ # MODEL-UPDATE Phase 4: the original model with NVFP4 experts, as ready-made packs (NVFP4_REPOS): the files come+ # as the engine reads them (no GGUF to pack), each size has its own repository ("repo" in MODELS)+ "nvfp4": {"title": "Qwen3.8-Flash-Next (NVFP4)", "by": "NVFP4 packs by sergqwer (strata-nvfp4)",+ "about": "4-bit NVFP4 experts, NVIDIA cards; a 128 GB download, ~80 GB of RAM to keep every expert in RAM",+ "tag": "nvfp4-", "name": "qwen3.8-flash-next-nvfp4", "ready": True,+ "mmproj_hf": hf("ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF"), "mmproj": "mmproj-Qwen3.8-Flash-Next-BF16.gguf",+ "mmproj_sha256": (907543008, "b1a82259702816a5330d7bd7607cd9676b11780e79ff7348c21103ff3ce49bd0")},}MMPROJ = "mmproj-Qwen3.8-Flash-Next-BF16.gguf"# EXPERIMENTAL, off by default (setup asks): a control vector shipped with the repository, see its README@@@ -5339,9 -5328,10 +5464,12 @@@ def main() -> intverdict = (f"fits in the low-RAM mode (the GPU holds ~{100 * low_ram_gpu_share(m, low_ram_vram(gpu)):.0f}% ""of its experts, " + ("the rest stays in RAM)" if low_ram_resident(m, ram, low_ram_vram(gpu))else "the rest is read from the SSD as needed)"))+ if d.get("budget") and hip and d.get("nvidia_only"): # #429: not run on AMD yet+ verdict += " - NVIDIA only so far, untested on AMD"- any_fits = any_fits or not verdict.startswith("does not fit")+ if hip and d.get("repo"): # the ready-made NVFP4 packs: no AMD kernels at all+ verdict = "NVIDIA only (the AMD engine has no NVFP4 kernels)"+ else:+ any_fits = any_fits or not verdict.startswith("does not fit")say(f" {m:8s} needs ~{d['ram_gb']} GB RAM: {verdict}")if not any_fits:# #977: every size says "does not fit", so the verdict says so too (and the exit code, for scripts). It onlydiff --cc src/prefill/moe_mmq.cuindex 8569e9102,31e8d3fe2..9861b6075--- a/src/prefill/moe_mmq.cu+++ b/src/prefill/moe_mmq.cu@@@ -7,33 -7,12 +7,34 @@@#include "mmq.cuh"#include "quantize.cuh"+#include "strata/prefill/mmq_kq_abi.hpp"+#include <cstdio>#include <cstdlib>+ #include <cstring>namespace strata::prefill::mmq {+#if defined(STRATA_KQ_DSO)+namespace kq {+int abi_args_size() { return (int) sizeof(mmq_args); }+} // namespace kq+#endifnamespace {+#if defined(STRATA_MMQ_KQUANTS)+// MODEL-UPDATE Phase 1: the K-quant products through MMQ are opt-in at run time (STRATA_MMQ_KQ=1); on CUDA their+// kernels are the strata_kq library (mmq_kq_loader.cpp), opened only then+bool kq_ok() {+#if defined(STRATA_KQ_DSO)+ return kq::available();+#else+ static const bool on = [] {+ const char* v = std::getenv("STRATA_MMQ_KQ");+ return v != nullptr && v[0] == '1';+ }();+ return on;+#endif+}+#endifvoid ck(cudaError_t e, const char* what) {if (e != cudaSuccess) {@@@ -149,11 -184,16 +206,15 @@@ bool supported(int t)case GGML_TYPE_IQ2_XXS: case GGML_TYPE_IQ2_XS: case GGML_TYPE_IQ2_S:case GGML_TYPE_IQ3_XXS: case GGML_TYPE_IQ3_S: case GGML_TYPE_IQ4_NL: case GGML_TYPE_IQ4_XS:case GGML_TYPE_Q8_0: // the draft layer's dense matrices (E-9)+ return true;#ifdef STRATA_MMQ_KQUANTS- case GGML_TYPE_Q4_K: case GGML_TYPE_Q5_K: case GGML_TYPE_Q5_1: // Unsloth's UD-Q4_K_XL experts (CUDA)-#if defined(__HIPCC__) || defined(STRATA_Q6K_EXPERTS)- case GGML_TYPE_Q6_K: // HIP: the dense GGUF projections (STRATA_DENSE_MMQ); CUDA: only the opt-in -DSTRATA_Q6K_EXPERTS=ON build-#endif+ // Unsloth's UD-Q4/Q5/Q6_K_XL experts; on HIP also the dense GGUF projections (STRATA_DENSE_MMQ)+ case GGML_TYPE_Q4_K: case GGML_TYPE_Q5_K: case GGML_TYPE_Q5_1: case GGML_TYPE_Q6_K:+ return kq_ok();+ #endif- return true;+ #if !defined(GGML_USE_HIP)+ case GGML_TYPE_NVFP4:+ return nvfp4_mode() != Nvfp4Mode::FP16;#endifdefault:return false;@@@ -234,20 -334,19 +355,26 @@@ void Context::run(const Product& p, voicase GGML_TYPE_IQ4_NL: mul_mat_q_case<GGML_TYPE_IQ4_NL>(ctx, a, s); break;case GGML_TYPE_IQ4_XS: mul_mat_q_case<GGML_TYPE_IQ4_XS>(ctx, a, s); break;case GGML_TYPE_Q8_0: mul_mat_q_case<GGML_TYPE_Q8_0>(ctx, a, s); break;-#ifdef STRATA_MMQ_KQUANTS+#if defined(STRATA_MMQ_KQUANTS) && defined(STRATA_KQ_DSO)+ case GGML_TYPE_Q4_K: case GGML_TYPE_Q5_K: case GGML_TYPE_Q6_K: case GGML_TYPE_Q5_1: {+ const int e = kq::run((int) t, &a, s);+ if (e != 0) {+ std::fprintf(stderr, "prefill mmq: the K-quant library failed on type %d (error %d)\n", (int) t, e);+ std::exit(1);+ }+ break;+ }+#elif defined(STRATA_MMQ_KQUANTS)case GGML_TYPE_Q4_K: mul_mat_q_case<GGML_TYPE_Q4_K>(ctx, a, s); break;case GGML_TYPE_Q5_K: mul_mat_q_case<GGML_TYPE_Q5_K>(ctx, a, s); break;-#if defined(__HIPCC__) || defined(STRATA_Q6K_EXPERTS)case GGML_TYPE_Q6_K: mul_mat_q_case<GGML_TYPE_Q6_K>(ctx, a, s); break;-#endifcase GGML_TYPE_Q5_1: mul_mat_q_case<GGML_TYPE_Q5_1>(ctx, a, s); break;+ #endif+ #if !defined(GGML_USE_HIP) // NVFP4: CUDA only (no HIP instance, no W4A8 unit)+ case GGML_TYPE_NVFP4:+ if (fp4_activations(t)) run_nvfp4_w4a4(ctx, a, s);+ else run_nvfp4_w4a8(ctx, a, s);+ break;#endifdefault:std::fprintf(stderr, "prefill mmq: type %d is not covered\n", (int) t);