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 branch 'f-132-pr' into rel-0.1.32
Niko1221b0abdeb446a6
diff --cc CMakeLists.txtindex c7ee9dcf0,cdfaca57c..bd77b5620--- a/CMakeLists.txt+++ b/CMakeLists.txt@@@ -35,10 -35,7 +35,11 @@@ 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)+ option(STRATA_ORCA_Q4KS_MMQ "Build the GGML Q5_0 MMQ instance for OrcaRouter Q4_K_S" OFF)if(STRATA_PREFILL_MMQ AND NOT STRATA_ENABLE_HIP)message(FATAL_ERROR "STRATA_PREFILL_MMQ requires STRATA_ENABLE_HIP=ON")endif()@@@ -837,13 -826,7 +846,14 @@@ if(STRATA_NATIVE_EXPERTSendif()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); 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)- foreach(_t IN LISTS _strata_mmq_types) # q8_0: the drafter's matrices (E-9)++ # 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)++ set(_strata_mmq_cuda_types ${_strata_mmq_types})+ 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}@@@ -853,18 -836,11 +863,21 @@@target_compile_options(strata_mmq PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/bigobj>)endif()target_link_libraries(strata_mmq PUBLIC ggml-base ${_strata_gpu_runtime_target})+ if(STRATA_MMQ_KQUANTS)+ target_compile_definitions(strata_mmq PRIVATE STRATA_MMQ_KQUANTS=1)+ endif()+ if(STRATA_ORCA_Q4KS_MMQ)+ target_compile_definitions(strata_mmq PRIVATE STRATA_ORCA_Q4KS_MMQ=1)+ endif()target_link_libraries(strata_prefill PUBLIC strata_mmq)target_compile_definitions(strata_prefill PUBLIC STRATA_PREFILL_MMQ=1)+ 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})+ add_test(NAME prefill_mmq_kquant_test COMMAND prefill_mmq_kquant_test)+ set_tests_properties(prefill_mmq_kquant_test PROPERTIES TIMEOUT 120)+ endif()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 serve/server.pyindex 9642ad455,5bba3c0ef..39271b998--- a/serve/server.py+++ b/serve/server.py@@@ -99,11 -101,15 +101,20 @@@ class EngineDied(RuntimeError)"""The engine process ended in the middle of a request (issue #27: on Linux, the out-of-memory killer)."""+class EngineStarting(RuntimeError):+ """The engine is (re)starting and has not said READY yet (#344): no context size to plan a request with - a 503,+ not a 400 about the prompt."""+++ class ModelBusy(RuntimeError):+ """Explicit model controls must not interrupt active or queued requests."""+++ class EngineStuck(RuntimeError):+ """The engine process did not end after QUIT, terminate and kill: the server keeps it (and says so) rather than+ reporting its GPU and RAM as given back."""++class GpuBusy(RuntimeError):"""The model is unloaded and the GPU has less free VRAM than min_free_vram_mib: something else (a game, anothermodel server) is using it, so the engine is not started into the little that is left."""@@@ -211,18 -257,16 +262,19 @@@ class StrataEngine# report their own version (INFO engine=, 0.1.8+) win, the manifest stays the fallback for older onesif self.info.get("engine"):self.info["version"] = str(self.info["engine"])+ self.ended = False # READY: alive from here (restart() set it True, #344)# the engine's stdout on a thread, so a request can wait with a timeout (heartbeats, cancel checks)self.lines: queue.Queue = queue.Queue()- threading.Thread(target=self._pump, daemon=True).start()+ self.pump = threading.Thread(target=self._pump, daemon=True)+ self.pump.start()def _pump(self):- for line in self.proc.stdout:- self.lines.put(line)- self.ended = True # its output closed: it is gone, even before the OS says so- self.lines.put(None)+ proc, lines = self.proc, self.lines # this process's: a restart replaces both (#344)+ for line in proc.stdout:+ lines.put(line)+ if self.proc is proc: # a killed engine's pump must not mark its successor dead+ self.ended = True # its output closed: it is gone, even before the OS says so+ lines.put(None)def death_note(self) -> str:"""Why the engine most likely ended, from the end of its log: its own watchdog (issue #29), else RAM."""@@@ -277,15 -309,9 +317,12 @@@def restart(self):"""Start the engine again (the same command) after it died; the new process has its own line queue."""- try:- self.proc.kill()- except OSError:- pass+ self.close()info = dict(self.info)- self.ended = False+ # #344: not alive until READY - __init__ sets max_context to 0 and blocks until the engine says READY, and a+ # request that saw alive() in that window skipped load() and failed with "context (0)". __init__ clears+ # `ended` itself once READY (before its pump thread can set it again).+ self.ended = Trueself.__init__(*self.spawn)self.info = {**info, **self.info}@@@ -1684,7 -1881,12 +1928,12 @@@ def make_handler(svc: Service)self._json(404, {"error": {"message": "not found"}})except ValueError as e:self._json(400, {"error": {"type": "invalid_request_error", "message": str(e)}})+ except ModelBusy as e:+ self._json(409, {"error": {"type": "model_busy", "message": str(e)}})+ except StructuredOutputError as e:+ self._json(502, {"error": {"type": "structured_output_failed", "code": "structured_output_failed",+ "message": str(e)}})- except GpuBusy as e:+ except (GpuBusy, EngineStarting) as e:self._json(503, {"error": {"type": "server_error", "message": str(e)}})except EngineDied as e: # before the answer started (not streamed)self._json(503, {"error": {"type": "server_error", "message": f"{e}; the next request restarts it"}})diff --cc setup.pyindex 77ffe77a0,a5cbb38be..c2d63ed4f--- a/setup.py+++ b/setup.py@@@ -1978,23 -1811,24 +1978,35 @@@ def start(cfg_path: Path, port: int | NOLD_DRAFT_VOCABS = {"369151522226a5edaa5f12cfd1e2ae7db8f4fbdbd222f3dcf327dced9597fb25"} # to 0.1.26: 27 Han tokens- DRAFT_VOCABS = {"cjk": "draft_vocab.bin", "en": "draft_vocab_en.bin"}+ DRAFT_VOCABS = {"cjk": "draft_vocab.bin", "en": "draft_vocab_en.bin", "cyrillic": "draft_vocab_cyrillic.bin"}+++ def saved_draft_vocab(cfg_path: Path) -> str | None:+ """The draft subset a model's config chose earlier (--draft-vocab), or None: a setup run again without the flag+ rewrites the config, and would otherwise put the default subset back."""+ try:+ v = json.loads(cfg_path.read_text(encoding="utf-8-sig")).get("draft_vocab")+ except (OSError, ValueError, AttributeError):+ return None+ return v if v in DRAFT_VOCABS else None+def mtp_corrupt(mtp: Path, env=None) -> bool:+ """#327: True when the MTP tensors an install fetched are not the pinned checkpoint's (tools/mtp_fetch.py verify,+ which hashes only files that changed since they last checked out). A mirror that ignored range requests left the+ shards' starts there instead, and the draft layer built from them accepted nothing - with no error anywhere."""+ if not (mtp / "tensors").is_dir():+ return False+ r = subprocess.run([sys.executable, str(ROOT / "tools" / "mtp_fetch.py"), "verify", "--out", str(mtp)], env=env,+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)+ return r.returncode == 3++def refresh_draft_vocab(rt: Path, choice: str = "cjk") -> None:- """The draft layer's token subset in the MTP folder: `cjk` (data/draft_vocab.bin, since 0.1.27, #137) or `en`- (data/draft_vocab_en.bin, the English/code subset before it: ~110 MiB less VRAM, English answers 1-2% faster).+ """The draft layer's token subset in the MTP folder: `cjk` (data/draft_vocab.bin, since 0.1.27, #137), `en`+ (data/draft_vocab_en.bin, the English/code subset before it: ~110 MiB less VRAM, English answers 1-2% faster) or+ `cyrillic` (data/draft_vocab_cyrillic.bin: English/code and the whole Cyrillic script, for Ukrainian, Russian,+ Bulgarian, Serbian... answers).Copied when missing or when a shipped subset other than the chosen one is there; a subset made by hand is kept."""new, dst = ROOT / "data" / DRAFT_VOCABS.get(choice, "draft_vocab.bin"), rt / "draft_vocab.bin"if not new.exists() or not rt.is_dir():diff --cc src/prefill/moe_mmq.cuindex 27b52ad51,f78fdb102..f1e398748--- a/src/prefill/moe_mmq.cu+++ b/src/prefill/moe_mmq.cu@@@ -91,12 -91,13 +91,16 @@@ bool built() { return true;bool supported(int t) {switch ((ggml_type) t) {- case GGML_TYPE_Q2_0: case GGML_TYPE_IQ2_XXS: case GGML_TYPE_IQ2_XS: case GGML_TYPE_IQ2_S:+ case GGML_TYPE_Q2_0:+ #ifdef STRATA_ORCA_Q4KS_MMQ+ case GGML_TYPE_Q5_0: // #296 (Q4_K and Q5_1: STRATA_MMQ_KQUANTS)+ #endif+ 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)+#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)+#endifreturn true;default:return false;diff --cc src/program/generate.cppindex 79da91bba,d36942f5d..7f1e3e960--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@@ -4127,16 -4081,12 +4232,17 @@@ int main(int argc, char** argv)estimate = fresh_estimate;err.clear();}- if (!reuse.kv.empty() && !conversations.can_fit(estimate, held)) {- // Optional growth capacity must not evict useful conversations.- reuse = {};- estimate = fresh_estimate;- }+ // A park carrying its own retained K/V replaces memory the cache+ // already held, so capacity is make_room's call - it runs next either+ // way, and put()'s accounting still bounds the budget. The with-reuse+ // estimate must stay uncapped: it counts the retained buffers'+ // capacity and directories, and put() charges that same true size -+ // a capped figure would under-evict and overfill the budget.+ // #342: before make_room evicts oldest-first, the copies of this conversation a turn back go (they hold+ // nothing the outgoing chain does not, apart from the tail this conversation rewrote)+ if (const size_t dropped = conversations.drop_superseded(live, live_imgs, checks, cvec_cached))+ std::fprintf(stderr, "strata serve: conversation cache: dropped %zu superseded cop%s of this "+ "conversation; parked=%zu\n", dropped, dropped == 1 ? "y" : "ies", conversations.size());if (!conversations.make_room(estimate, held)) {std::fprintf(stderr, "strata serve: conversation cache: skip parking (snapshot %zu MiB exceeds available budget)\n",estimate >> 20);