diff --git a/docs/BATCHING.md b/docs/BATCHING.md index 69e5e2f7..8ce4b45a 100644 --- a/docs/BATCHING.md +++ b/docs/BATCHING.md @@ -9,6 +9,9 @@ conversations at the same time instead of waiting for each other. It is opt-in and changes nothing when the options are absent (#465; the engine part is PR #559). +**Qwen3.6-35B-A3B** has the same option on its own engine path (`"parallel": N`, `--batch N`, `--batch-mtp`, up to 8 slots, the same +engine protocol and the same server): its numbers, what a slot costs and where setup recommends it are in [QWEN36.md](QWEN36.md). + ## Turning it on One GPU: add `"parallel": 2` to the model's config (`strata-.json`) and restart, or run setup with diff --git a/docs/DETAILS.md b/docs/DETAILS.md index ad64e20e..12a35f21 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1463,6 +1463,8 @@ The config snippets for every client, the tool arguments and the safety rules ar ## Images (vision) +(Qwen3.6-35B-A3B reads pictures the same way, with its own `mmproj-F16.gguf`: [QWEN36.md](QWEN36.md).) + The model has a vision encoder: [`mmproj-Qwen3.8-Flash-Next-BF16.gguf`](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF) (0.9 GB, a 27-layer ViT plus the projector into the language model). It is **optional**: say yes when the setup asks "Images?", or run it again with `--vision gpu` (or `--vision cpu`). The setup downloads the encoder, builds a small diff --git a/docs/QWEN36.md b/docs/QWEN36.md new file mode 100644 index 00000000..76efb57d --- /dev/null +++ b/docs/QWEN36.md @@ -0,0 +1,107 @@ +# Qwen3.6-35B-A3B: pictures and several requests at once + +Strata runs [Qwen3.6-35B-A3B](https://huggingface.co/Qwen/Qwen3.6-35B-A3B) (35B mixture of experts, 3B active, 256 experts, top-8) from +[Unsloth's GGUFs with the MTP layer](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-MTP-GGUF) (UD-Q4_K_XL, UD-Q6_K_XL, Q8_0) on its own +engine path (`src/qwen35`; `strata` switches to it from the file's architecture). Pick it in setup (`--family qwen36`). Besides text it +reads **pictures** and serves **several requests at once**, the same two options the Flash-Next models have. + +Measured on an AMD Radeon AI PRO R9700 32 GB (HIP, Linux, UD-Q4_K_XL, every expert in VRAM) and on an RTX 3060 12 GB (CUDA, 20 threads, +UD-Q4_K_XL in the hybrid mode: 22-37 of 256 experts per layer in VRAM, the rest on the CPU), llama.cpp 972b5fc on the same files. + +## Pictures + +The vision encoder is Unsloth's `mmproj-F16.gguf` (0.9 GB, pinned revision, SHA-256 checked by setup): a 27-layer ViT with a 2x2 merger, +the same projector family as the Flash-Next models' (`qwen3vl_merger`; only its output width differs: 2048 here, 2560 there). Strata runs +it with the same helper (`strata-vision`, llama.cpp's `mtmd`), so the encoder choices are the Flash-Next ones +([Images](DETAILS.md#images-vision)): **setup asks "Do you want images?"**, the default answer is yes on an NVIDIA card of 16 GB or more +(GPU encoder, ~1.2 GB of VRAM at up to 1,024 image tokens) and on AMD under Linux (CPU encoder, no VRAM); `--vision yes|no|gpu|cpu` +and `--vision-tokens N` work as there. A card under 16 GB is recommended the CPU encoder (the GPU one takes room from the experts); +`--vision gpu` is kept as asked, with a note. + +| Encoder | Time per picture (640x400 = 260 tokens / 800x450 = 350 tokens) | VRAM | +| --- | --- | --- | +| GPU, RTX 3060 | 0.10 s / 0.15 s | 1.18 GiB at up to 1,024 tokens (1.34 GiB at 2,048) | +| CPU, 32 threads (R9700 box) | 0.9 s / 1.1 s | none | +| CPU, 10 threads (3060 box) | 1.6 s / 2.1 s | none | + +A picture becomes up to 1,024 tokens of the context (the CPU default is 300). The engine puts the encoder's rows where the prompt has +`<|image_pad|>` tokens and gives every row its 2-D position, interleaved M-RoPE exactly as llama.cpp does for this model (rotary sections +11 / 11 / 10, a picture's rows at (t, h, w) = (p, p + row, p + column), the text after it continuing at p + max(columns, rows)). + +**Checked against llama.cpp** (its `mtmd` and its own graph, the encoder on the CPU on both sides, the same prompt ids, the answer +llama.cpp gives fed to both so the logits are compared step by step, 24 steps; the "floor" is llama.cpp's CPU backend against its own +HIP run, the noise two correct engines have on this model): + +| Picture and question | Prompt tokens | First token | Mean KL, llama.cpp HIP vs Strata | Floor (llama.cpp CPU vs HIP) | +| --- | ---: | --- | ---: | ---: | +| 640x400, text in the image | 288 | same | 0.029 | 0.056 | +| 640x400, list the shapes | 294 | same | 0.035 | 0.039 | +| 800x450, text in the image | 378 | same | 0.021 | 0.031 | +| 800x450, describe the shapes | 381 | same | 0.0005 | 0.0019 | + +The answers are the same text as llama.cpp's: `STRATA 42` (with llama.cpp's own spelling ` STRATA42`), `CODE 4217`, `Red circle / Blue square +/ Green triangle`, `A red square is positioned on the left ... A blue circle is positioned on the right ...`. With the picture options on, +a request without pictures gives the same tokens as without them (10 prompts x 128 greedy tokens, identical). + +Pictures work with several requests at once, with the MTP drafts and with the conversation cache: the same conversation sent again (a chat +app resends its pictures) continues from the held state when its pictures are the same (they are matched by the server's key for each +picture); a different picture starts that conversation again. + +## Several requests at once + +`"parallel": N` in the model's config (`strata-qwen36-.json`, or `--parallel N` at setup) makes the engine keep N conversations open +(`--batch N`, up to 8) and decode them together: every window carries one token of each conversation, so the dense weights, the head and +every routed expert two conversations share are read once for all of them. The server needs no change: it speaks the same engine protocol +as for Flash-Next ([BATCHING.md](BATCHING.md)). A request that arrives while another is read waits only for that read: the prompt of a +new request is read **between** the decode windows of the others (one window per prompt chunk), and a conversation continues in the slot +that holds its start (or the engine copies the longer held start from another slot). + +Aggregate decode speed, N requests at once, same prompts, greedy, 128 new tokens each, wall time from the first request to the last +answer, **R9700 32 GB, UD-Q4_K_XL, llama.cpp `llama-server -np N`** (5 interleaved pairs, median; Strata `--batch 8 --mtp 0`): + +| Requests at once | Strata | llama.cpp | Ratio | Pairs faster | +| ---: | ---: | ---: | ---: | ---: | +| 1 | 83.9 tok/s | 73.8 | 1.14 | 5/5 | +| 2 | 173.5 | 107.4 | 1.61 | 5/5 | +| 4 | 252.0 | 165.0 | 1.53 | 5/5 | +| 8 | 325.4 | 208.1 | 1.56 | 5/5 | + +Every slot's tokens equal the tokens of the same request alone (the base engine's), at 2, 4 and 8 slots, with a 2.5K-token prompt read beside +decoding slots, with slots reused for later requests, with pictures and with sampling (same seed). Through the server: four concurrent chat +requests give the texts of the same four one after the other. + +**MTP drafts.** A request that has the engine to itself keeps its MTP drafts (the server sends it alone while nothing else runs). With +several requests the batch window has no drafts unless `--batch-mtp` is in the config's `args` (opt-in): every slot's window then also +carries the proposal its MTP block made (one per slot, up to the rows to spare in the 8-row window) and a confirmed proposal moves two +tokens in the window. Same prompts, 5 interleaved pairs, R9700: + +| Requests at once | `--mtp 0` | `--mtp 2 --batch-mtp` | Ratio | Pairs faster | +| ---: | ---: | ---: | ---: | ---: | +| 1 | 83.7 tok/s | 134.0 | 1.60 | 5/5 | +| 2 | 173.1 | 207.0 | 1.20 | 5/5 | +| 4 | 251.0 | 275.0 | 1.10 | 5/5 | +| 8 | 324.0 | 320.5 | 0.99 | 0/5 (no row to spare: no proposals) | + +The text is the same with and without it (every slot equal to its solo tokens). + +**What a slot costs.** Each slot keeps its own cache in VRAM: 1.5 GB at a context of 32K (fp32 keys and values of the 10 attention layers +and the MTP block, 45 KB per token) and 0.07 GB of recurrent state. Setup writes the context for one conversation, so N slots take N times +that from the room the experts would have: on a card that does not hold every expert (12 and 16 GB, the hybrid mode) that is room the +expert slots lose, and a batch reads more distinct experts from RAM. Setup therefore **recommends `--parallel` only where every expert still +fits** (about 3 on a 32 GB card at 32K) and says why it leaves it at one otherwise; any number you give is kept. On the RTX 3060 12 GB with +`--batch 4` the engine kept 22 of 256 experts per layer (the sessions, the picture encoder and the MTP block took the rest) and four +requests at once ran 45 tok/s together against 42 one after the other: not worth it there. The engine says what the sessions take before it +allocates them and refuses (with the numbers) a count that cannot fit. + +In the hybrid mode the text of a request can differ a little between running alone and running beside others: the experts that sit on the +GPU or on the CPU change with the routing of all the requests, and the two compute with different rounding. With the slot tables fixed (`STRATA_Q36_FIXED_SLOTS=1`, a test setting) every slot equals its +solo run there too, with and without `--batch-mtp`. + +## Not done / limits + +- Eight slots at most (the window holds 8 rows); `--batch-mtp` shares those rows between slots and proposals. +- A sampling request in a batch decodes one token per window without proposals. `logit_bias` is not available on this engine path: the + server refuses a request that has it (as it does with `--batch` for Flash-Next). +- A slot that stopped being alone goes back to the solo path only through the server's own hand-over; the MTP block's cache has holes for + the tokens a slot decoded in batch windows (the drafts of a later solo stretch are a little worse; the text is not affected). +- Intel Arc (SYCL) does not run this family. diff --git a/serve/test_q36_config.py b/serve/test_q36_config.py new file mode 100644 index 00000000..981ae5f3 --- /dev/null +++ b/serve/test_q36_config.py @@ -0,0 +1,48 @@ +"""serve/test_q36_config.py - what the server hands the Qwen3.6-35B-A3B engine (arch qwen35moe): the config's pictures +("vision" section -> --vision) and parallel requests ("parallel": N -> --batch N), as for Flash-Next's engine. + + python -m unittest serve.test_q36_config +""" +from __future__ import annotations + +import unittest +from unittest import mock + +from serve.server import engine_args, parallel_args + + +def cfg(**kw): + base = {"arch": "qwen35moe", "exe": "strata", "args": ["--native", "/m/Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", + "--max-context", "32768", "--prefill", "auto", "--mtp", "2"]} + base.update(kw) + return base + + +class Q36Config(unittest.TestCase): + def test_parallel_becomes_batch(self): + a = engine_args(cfg(parallel=4)) + self.assertEqual(a[a.index("--batch") + 1], "4") + self.assertNotIn("--batch", engine_args(cfg())) + self.assertNotIn("--batch", engine_args(cfg(parallel=1))) + + def test_more_than_the_window_is_said(self): + with mock.patch("builtins.print") as pr: + a = engine_args(cfg(parallel=12)) + self.assertEqual(a[a.index("--batch") + 1], "12") # the engine caps it at 8 and says so + self.assertTrue(any("at most 8" in str(c) for c in pr.call_args_list)) + + def test_a_vision_section_starts_the_engine_with_pictures(self): + v = {"exe": "strata-vision", "mmproj": "/m/mmproj-F16.gguf", "model": "/m/Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", + "gpu": False, "max_tokens": 300} + self.assertIn("--vision", engine_args(cfg(vision=v))) + self.assertIn("--vision", engine_args(cfg(vision=v, args=cfg()["args"] + ["--vision"]))) + self.assertEqual(engine_args(cfg(vision=v, args=cfg()["args"] + ["--vision"])).count("--vision"), 1) + self.assertNotIn("--vision", engine_args(cfg())) + + def test_an_explicit_batch_in_the_args_wins(self): + c = cfg(parallel=4, args=cfg()["args"] + ["--batch", "2"]) + self.assertEqual(parallel_args(c, c["args"]), []) + + +if __name__ == "__main__": + unittest.main() diff --git a/setup.py b/setup.py index aac1bc1b..9d205980 100644 --- a/setup.py +++ b/setup.py @@ -453,7 +453,10 @@ OWN_PATH_FAMILIES = { # V in fp32 (strata-q36) "kv_bytes_per_token": 11 * 2 * 256 * 2 * 4, "mtp": 2, # drafts per step (greedy requests): measured best on the R9700 - "vision": False}, # the image encoder for this family is not wired up yet + # pictures: Unsloth's mmproj (the same projector family as Flash-Next's: qwen3vl_merger) through + # strata-vision; a parallel slot's session: its KV cache (kv_bytes_per_token) and the recurrent state of + # the 30 GDN layers (state_gb) + "vision": True, "state_gb": 0.07} } PREVIEW_FAMILIES = OWN_PATH_FAMILIES # the earlier name (tools and tests that import it) # EXPERIMENTAL, off by default (setup asks): a control vector shipped with the repository, see its README @@ -4555,8 +4558,9 @@ def choices_from_config(cfg_path: Path) -> dict: size = next((m for m in d["models"] if m.lower() == tag[len(d["tag"]):].lower()), None) a = cfg.get("args", []) ctx = a[a.index("--max-context") + 1] if "--max-context" in a and a.index("--max-context") + 1 < len(a) else None + vis = cfg.get("vision") return {"family": own, "model": size, "context": int(ctx) if ctx and ctx.isdigit() else None, "kv": None, - "vision": "none", "esp": "off", "host": cfg.get("host"), "api_key": cfg.get("api_key"), + "vision": ("gpu" if vis.get("gpu") else "cpu") if isinstance(vis, dict) else "none", "esp": "off", "host": cfg.get("host"), "api_key": cfg.get("api_key"), "port": cfg.get("port"), "gpu": cfg.get("gpu"), "layer_split": None, "cuda": 12 if config_toolkit(cfg) == 12 else None, "vram_reserve_mib": None} family = next((f for f, d in FAMILIES.items() if d["tag"] and tag.startswith(d["tag"])), "qwen") @@ -5507,6 +5511,89 @@ def own_path_size(fam: dict, ram: float) -> str: return max(fits, key=lambda m: fam["sha256"][fam["file"].format(q=m)][0]) if fits else next(iter(fam["models"])) +def own_path_vision(a, fam: dict, gpu: dict, hip: bool) -> str: + """The image encoder for an own-path family (Qwen3.6-35B-A3B): "gpu", "cpu" or "none". The Flash-Next families' rules: + --vision yes|no|gpu|cpu, else a question whose default answer is yes where the GPU encoder costs little - an NVIDIA + card of 16 GB or more (its ~1.4 GB is under a tenth of it) - and, on AMD under Linux, yes with the CPU encoder (it takes + no VRAM; there is no GPU encoder for AMD yet). A smaller NVIDIA card is recommended the CPU encoder (the GPU one takes + room from the experts); what is asked for with --vision gpu is kept, with a note (recommend, never force).""" + asked = a.vision + vram = float(gpu.get("vram_gb", 0.0)) + big = vram >= UNSLOTH_IMAGES_MIN_VRAM_GB + if asked in ("no", "none"): + return "none" + if asked is None: + say() + say(f" Images: {fam['title']} can also read pictures (screenshots, photos, scanned pages). This adds a " + f"{fam['sha256'][fam['mmproj']][0] / 1e9:.1f} GB download" + ( + "; the encoder runs on the CPU (no VRAM), a few seconds per picture." if hip else + " and the image encoder runs on the GPU (~1.4 GB of VRAM kept free, 0.1-0.5 s per picture)." if big else + "; the encoder runs on the CPU (a few seconds per picture), because the GPU encoder would take ~1.4 GB " + "of VRAM from the experts on this card.")) + default = "n" if (hip and WIN) else "y" if (big or hip) else "n" + if ask("Do you want images?", ["y", "n"], default, a.yes) != "y": + return "none" + asked = "cpu" if (hip or not big) else "gpu" + if hip: + if asked == "gpu": + say(" The AMD backend has no GPU image encoder yet: the encoder runs on the CPU.") + if WIN: + warn("images on the CPU with an AMD card are Linux-only for now (the ready-made Windows AMD engine has no " + "image encoder): images off") + return "none" + return "cpu" + if asked == "yes": + asked = "gpu" if big else "cpu" + if asked == "gpu" and not big and vram > 0: + warn(f"the GPU image encoder takes ~1.4 GB of VRAM, which on a {vram:.0f} GB card is room the experts would use: " + "--vision cpu reads pictures on the CPU instead (a few seconds each); kept as you chose") + return asked + + +def own_path_parallel_slot_gb(fam: dict, ctx: int) -> float: + """The VRAM one batch slot's session takes: its KV cache (fp32 K and V of the attention layers and the MTP block) and + the recurrent state of the GDN layers.""" + return ctx * fam["kv_bytes_per_token"] / 1e9 + fam["state_gb"] + + +def own_path_parallel_recommend(fam: dict, model: str, vram_gb: float, ctx: int) -> int: + """How many requests at once to recommend: 0 = one at a time. Only where every routed expert still fits in VRAM with + the slots' sessions (a batch then reads each expert once for all its rows); where some experts run on the CPU the + batch reads more distinct experts from RAM and every slot's VRAM is room the expert slots lose.""" + size = fam["sha256"][fam["file"].format(q=model)][0] / 1e9 + base = size * 0.93 + 4.5 # the routed experts + the dense weights and buffers (the file's 7% beyond them) + slot = own_path_parallel_slot_gb(fam, ctx) + best = 0 + for n in (2, 3, 4): + if base + (n + 1) * slot <= vram_gb: + best = n + return best + + +def own_path_parallel_note(a_parallel, fam: dict, model: str, vram_gb: float, ctx: int) -> list: + """What setup says about "parallel" for an own-path family: the recommendation, or how the asked count compares with + it (kept as asked: recommend, never force).""" + rec = own_path_parallel_recommend(fam, model, vram_gb, ctx) + slot = own_path_parallel_slot_gb(fam, ctx) + if a_parallel is None or a_parallel <= 1: + if not rec: + return ["Several requests at once: left at one at a time - this card does not hold every expert beside more " + "sessions, and the experts that run on the CPU make a batch read more of them (docs/BATCHING.md)."] + return [f"Several requests at once (opt-in): --parallel {rec} decodes up to {rec} together instead of one after " + f"the other (each takes ~{slot:.1f} GB of VRAM at this context; docs/BATCHING.md)."] + lines = [f"parallel requests: {a_parallel} at once (each takes ~{slot:.1f} GB of VRAM at this context, " + f"{a_parallel * slot:.1f} GB in all)"] + if a_parallel > PARALLEL_MAX: + lines.append(f"the engine runs at most {PARALLEL_MAX} at once; it will use {PARALLEL_MAX}") + if not rec: + lines.append("recommended for this card: one at a time - not every expert fits in VRAM beside more sessions; " + "kept as you chose") + elif a_parallel > rec: + lines.append(f"recommended for this card: {rec} - more slots leave fewer experts in VRAM, which can make every " + "request slower; kept as you chose") + return lines + + def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted): """Steps 2-7 for a family with its own engine path (OWN_PATH_FAMILIES: Qwen3.6-35B-A3B): the size, the context, the engine, the GGUF (pinned revision, size and SHA-256), the tokenizer from the GGUF, the config and the start @@ -5558,8 +5645,8 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte warn(f"{ctx // 1024}K is past {fam['title']}'s trained 262,144 positions and this engine path has no rope " "scaling yet: kept as you chose, but answers past 256K are untested") ok(f"context: {ctx} tokens") - if a.vision not in (None, "no", "none"): - warn(f"images are not available with {fam['title']} yet: off") + vision = own_path_vision(a, fam, gpu, hip) + ok("images: " + {"none": "off", "gpu": "on", "cpu": "on (encoder on the CPU)"}[vision]) if a.rope_scaling or a.rope_scale or a.kv or a.resident_budget_gib is not None or a.low_ram not in (None, "auto"): warn(f"--rope-scaling / --kv / --resident-budget-gib / --low-ram are Flash-Next settings: {fam['title']} " "does not use them") @@ -5576,7 +5663,10 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte "numpy, jinja2, regex, pyyaml, tqdm, requests, cmake, ninja, pillow, psutil") step(4, "the Strata engine") - llama, eng, meta, lib_dirs, gpu, _ = engine_step(a, gpu, hip, amd, cuda_tk, "none") + llama, eng, meta, lib_dirs, gpu, vision = engine_step(a, gpu, hip, amd, cuda_tk, vision) + if vision != "none" and not (eng / VEXE).exists(): + warn("this engine has no image encoder: images off (run setup again with --build to compile it)") + vision = "none" if fam["arch"] not in engine_families(eng): fail(f"this engine ({meta.get('version')}) does not run {fam['title']} yet", "update Strata, or compile the engine with --build, and run setup again") @@ -5591,6 +5681,16 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte download(fam["hf"] + gguf.name, gguf) verify_sha256(gguf, *fam["sha256"][gguf.name]) ok(f"model file: {gguf}") + mmproj = folder / fam["mmproj"] + if vision != "none": # the image encoder: Unsloth's mmproj, pinned, size + SHA-256 checked + if mmproj.exists() and done(mmproj): + ok(f"{mmproj.name} already downloaded") + else: + if a.gguf_dir: + fail(f"{mmproj} is missing", f"put {mmproj.name} in {folder}, or drop --gguf-dir to download it") + download(fam["mmproj_hf"] + mmproj.name, mmproj, "vision encoder") + verify_sha256(mmproj, *fam["sha256"][mmproj.name]) + ok(f"vision encoder: {mmproj}") step(6, "preparing the model for Strata") data, _ = data_folder(a.data_dir) @@ -5625,6 +5725,27 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte cfg["open_browser"] = a.browser cfg["args"] = recommend_pool_workers(cfg["args"]) # --pool-workers: this engine path's CPU expert threads too cfg_path = ROOT / f"strata-{tag.lower()}.json" + if vision != "none": + old_cfg = cfg_path if cfg_path.is_file() else adopted + vt = vision_tokens(getattr(a, "vision_tokens", None), vision, old_cfg) + cfg["args"].append("--vision") + cfg["vision"] = {"exe": str(eng / VEXE), "mmproj": str(mmproj), "model": str(gguf), "gpu": vision == "gpu", + "max_tokens": vt} # the text model, opened vocab-only + if vision == "cpu": + cfg["vision"]["threads"] = max(1, (os.cpu_count() or 8) // 2) + elif getattr(a, "vision_tokens", None) is not None: + warn("--vision-tokens: images are off, so it is not used") + # requests at once ("parallel", opt-in): written only when given; the recommendation is said once + vram_gb = float(gpu.get("vram_gb", 0.0)) + par = getattr(a, "parallel", None) + if par is not None: + if par >= 2: + cfg["parallel"] = par + for i, line in enumerate(own_path_parallel_note(par, fam, model, vram_gb, ctx)): + (ok if i == 0 else warn)(line) + else: + cfg["parallel"] = 1 + ok("parallel requests: one at a time (--parallel 1)") write_setup_config(cfg_path, cfg, adopted if adopted is not None and adopted.name == cfg_path.name else None) script = write_run_script(tag, cfg_path, port, cfg.get("open_browser") is not False) ok(f"start script: {script.name}") @@ -5633,6 +5754,11 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte say(f" API (OpenAI): http://127.0.0.1:{port}/v1 (any API key; model name: anything)") say(f" API (Anthropic): http://127.0.0.1:{port}/v1/messages") say(f" Next time: just run {'START-HERE.bat' if WIN else './setup.sh'} (or {script.name}) - it starts right away") + if vision != "none": + say(" Images: send them in the chat page, in chat.py (/image ) or over the API") + if par is None: # the opt-in, said once (nothing changes) + for line in own_path_parallel_note(None, fam, model, vram_gb, ctx): + say(" " + line) if a.no_start: return 0 return start(cfg_path, port) @@ -5687,8 +5813,8 @@ def main() -> int: return mac_setup(sys.argv[1:]) ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) ap.add_argument("--family", choices=list(FAMILIES) + list(PREVIEW_FAMILIES), - help="qwen = Qwen3.8-Flash-Next, swift = Swift 1.5 (qwen36 = Qwen3.6-35B-A3B: download only, the " - "engine does not run it yet)") + help="qwen = Qwen3.8-Flash-Next, swift = Swift 1.5, qwen36 = Qwen3.6-35B-A3B (pictures with --vision, " + "several requests at once with --parallel; docs/QWEN36.md)") ap.add_argument("--model", choices=list(dict.fromkeys([*MODELS, *(m for f in PREVIEW_FAMILIES.values() for m in f["models"])]))) ap.add_argument("--context", type=int) diff --git a/tools/test_setup_qwen36.py b/tools/test_setup_qwen36.py index 7358a3d8..3c76181c 100644 --- a/tools/test_setup_qwen36.py +++ b/tools/test_setup_qwen36.py @@ -93,6 +93,9 @@ class InstallOwnPath(unittest.TestCase): def engine_step(a, gpu, hip, amd, cuda_tk, vision): self.calls.append(("engine", vision)) + if vision != "none": # the image encoder beside the engine + eng.mkdir(parents=True, exist_ok=True) + (eng / setup.VEXE).write_text("x") return self.root / "llama", eng, {"version": "0.1.44"}, ["/libs"], gpu, vision def write_cfg(path, cfg, source=None): @@ -115,13 +118,13 @@ class InstallOwnPath(unittest.TestCase): p.start() self.addCleanup(p.stop) - def install(self, ram=64.0, vram=16.0, **kw): + def install(self, ram=64.0, vram=16.0, hip=False, **kw): gpu = {"index": 0, "count": 1, "vram_gb": vram, "name": "Test GPU"} - return run(setup.install_own_path, args(models_dir=str(self.root / "models"), **kw), "qwen36", gpu, False, [], + return run(setup.install_own_path, args(models_dir=str(self.root / "models"), **kw), "qwen36", gpu, hip, [], 13, [], 8080, ram, None) def test_installs_the_pinned_file_and_writes_the_config(self): - rc, out = self.install(model="UD-Q4_K_XL") + rc, out = self.install(model="UD-Q4_K_XL", vision="no") self.assertEqual(rc, 0, out) get = [c for c in self.calls if c[0] == "get"] self.assertEqual(len(get), 1) @@ -129,7 +132,9 @@ class InstallOwnPath(unittest.TestCase): self.assertEqual(get[0][1], setup.hf(REPO) + gguf.name) self.assertEqual(get[0][2], gguf) self.assertIn(("sha", gguf.name), self.calls) - self.assertIn(("engine", "none"), self.calls) # no image encoder for this family yet + self.assertIn(("engine", "none"), self.calls) # --vision no: no image encoder + self.assertNotIn("--vision", self.cfg["args"]) + self.assertNotIn("vision", self.cfg) tok = [c for c in self.calls if c[0] == "run"] self.assertTrue(tok and "strata_tokenizer.py" in str(tok[0][1])) a = self.cfg["args"] @@ -176,12 +181,74 @@ class InstallOwnPath(unittest.TestCase): self.assertEqual(rc, 1) self.assertIn("not enough free disk space", out) - def test_bigger_card_bigger_context_and_vision_said_off(self): - rc, out = self.install(model="UD-Q4_K_XL", vram=32.0, vision="yes") + def test_bigger_card_bigger_context(self): + rc, out = self.install(model="UD-Q4_K_XL", vram=32.0, vision="no") self.assertEqual(rc, 0, out) a = self.cfg["args"] self.assertEqual(a[a.index("--max-context") + 1], "131072") - self.assertIn("images are not available", out) + + def test_images_by_default_on_a_16gb_nvidia_card_use_the_gpu_encoder(self): + rc, out = self.install(model="UD-Q4_K_XL", vram=16.0) # --yes: the question's default answer + self.assertEqual(rc, 0, out) + self.assertIn(("engine", "gpu"), self.calls) + mm = self.root / "models" / "qwen36-UD-Q4_K_XL" / "mmproj-F16.gguf" + self.assertIn(("get", setup.hf(REPO) + "mmproj-F16.gguf", mm), self.calls) + self.assertIn(("sha", "mmproj-F16.gguf"), self.calls) # pinned: size + SHA-256 (899283584 bytes) + self.assertEqual(setup.OWN_PATH_FAMILIES["qwen36"]["sha256"]["mmproj-F16.gguf"][0], 899283584) + a = self.cfg["args"] + self.assertIn("--vision", a) + v = self.cfg["vision"] + self.assertTrue(v["gpu"]) + self.assertEqual(v["mmproj"], str(mm)) + self.assertTrue(v["model"].endswith("Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf")) # the text model, opened vocab-only + self.assertEqual(Path(v["exe"]).name, setup.VEXE) + self.assertEqual(v["max_tokens"], 1024) + self.assertIn("images: on", out) + + def test_a_12gb_card_is_recommended_the_cpu_encoder_never_forced(self): + rc, out = self.install(model="UD-Q4_K_XL", vram=12.0) # the default answer is no + self.assertEqual(rc, 0, out) + self.assertNotIn("vision", self.cfg) + rc, out = self.install(model="UD-Q4_K_XL", vram=12.0, vision="yes") # yes: the CPU encoder, said why + self.assertEqual(rc, 0, out) + self.assertFalse(self.cfg["vision"]["gpu"]) + self.assertEqual(self.cfg["vision"]["max_tokens"], 300) + self.assertIn("threads", self.cfg["vision"]) + rc, out = self.install(model="UD-Q4_K_XL", vram=12.0, vision="gpu") # gpu asked for: kept, with a note + self.assertEqual(rc, 0, out) + self.assertTrue(self.cfg["vision"]["gpu"]) + self.assertIn("kept as you chose", out) + + def test_amd_reads_pictures_on_the_cpu(self): + with mock.patch.object(setup, "WIN", False): + rc, out = self.install(model="UD-Q4_K_XL", vram=32.0, hip=True, vision="yes") + self.assertEqual(rc, 0, out) + self.assertFalse(self.cfg["vision"]["gpu"]) + self.assertIn("--vision", self.cfg["args"]) + with mock.patch.object(setup, "WIN", True): + rc, out = self.install(model="UD-Q4_K_XL", vram=32.0, hip=True, vision="cpu") + self.assertNotIn("vision", self.cfg) + self.assertIn("Linux-only", out) + + def test_parallel_is_opt_in_and_recommended_where_the_experts_fit(self): + fam = setup.OWN_PATH_FAMILIES["qwen36"] + # nothing written without --parallel; the recommendation is said + rc, out = self.install(model="UD-Q4_K_XL", vram=32.0, vision="no", context=32768) + self.assertEqual(rc, 0, out) + self.assertNotIn("parallel", self.cfg) + self.assertIn("--parallel 3", out) + # a 12 GB card runs the hybrid mode: one at a time recommended, any asked number kept + self.assertEqual(setup.own_path_parallel_recommend(fam, "UD-Q4_K_XL", 12.0, 32768), 0) + rc, out = self.install(model="UD-Q4_K_XL", vram=12.0, vision="no", parallel=4) + self.assertEqual(self.cfg["parallel"], 4) + self.assertIn("recommended for this card: one at a time", out) + self.assertIn("kept as you chose", out) + rc, out = self.install(model="UD-Q4_K_XL", vram=12.0, vision="no", parallel=1) + self.assertEqual(self.cfg["parallel"], 1) + rc, out = self.install(model="UD-Q4_K_XL", vram=32.0, vision="no", parallel=12) + self.assertIn("at most 8", out) + self.assertEqual(self.cfg["parallel"], 12) # written as asked; the server and the engine cap it + self.assertGreater(setup.own_path_parallel_slot_gb(fam, 32768), 1.4) def test_config_read_back(self): self.install(model="UD-Q6_K_XL", context=65536) @@ -189,6 +256,7 @@ class InstallOwnPath(unittest.TestCase): p.write_text(json.dumps(self.cfg), encoding="utf-8") ch = setup.choices_from_config(p) self.assertEqual((ch["family"], ch["model"], ch["context"]), ("qwen36", "UD-Q6_K_XL", 65536)) + self.assertEqual(ch["vision"], "gpu") # 16 GB NVIDIA, the default answer self.assertTrue(setup.own_path_config(self.cfg)) self.assertEqual(setup.calibration_targets([p], None, None), []) # the tuning is Flash-Next's