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-q4' into rel-0.1.32
Niko1221d9fe3019e0db
diff --cc setup.pyindex e15af279e,33e87c7ab..77ffe77a0--- a/setup.py+++ b/setup.py@@@ -704,29 -713,39 +733,62 @@@ def whole_shard(s: Path) -> boolreturn False+SHARD_NAME = re.compile(r"-(\d{5})-of-(\d{5})\.gguf$")+++def gguf_dir_shards(folder: Path, fam: dict, model: str) -> list[Path]:+ """--gguf-dir's shards (#305): every -0000i-of-0000N file of the model, N read from the first shard's name as the+ engine and tools/iq_pack.py do. The published name first; else the one first shard in the folder whose name has+ the size in it (an upload split or named differently: -00001-of-00003, Unsloth's ...-00001-of-00004.gguf). A+ missing shard is check_shards' error later, as before."""+ first = folder / fam["file"].format(q=model, i=1)+ if not first.exists():+ found = sorted(p for p in folder.glob("*-00001-of-*.gguf") if SHARD_NAME.search(p.name))+ mine = [p for p in found if model.lower() in p.name.lower()]+ pick = mine if mine else found+ if len(pick) == 1:+ first = pick[0]+ m = SHARD_NAME.search(first.name)+ total = int(m.group(2)) if m else 1+ if not m or total < 1:+ return [first]+ stem = first.name[:m.start()]+ return [first.with_name("%s-%05d-of-%05d.gguf" % (stem, i, total)) for i in range(1, total + 1)]+++ def verify_sha256(s: Path, size: int, sha: str) -> None:+ """A shard's size and SHA-256 against the pinned values (the Unsloth file); the result is kept in its finish mark,+ so the ~5 minutes of hashing 111 GB happen once. A wrong file is deleted, so the next run downloads it again."""+ m = s.with_name(s.name + ".done")+ if m.exists() and f"sha256 {sha}" in m.read_text(encoding="utf-8", errors="replace"):+ return+ have = s.stat().st_size if s.exists() else -1+ if have != size:+ fail(f"{s.name} is {have:,} bytes, not {size:,}", "delete it and run setup again (the download restarts)")+ say(f" checking {s.name} (SHA-256, {size / 1e9:.1f} GB) ...")+ h = hashlib.sha256()+ with open(s, "rb") as f:+ while True:+ b = f.read(16 << 20)+ if not b:+ break+ h.update(b)+ if h.hexdigest() != sha:+ s.unlink(missing_ok=True)+ m.unlink(missing_ok=True)+ fail(f"{s.name} has the wrong SHA-256 ({h.hexdigest()}, expected {sha}): deleted",+ "run setup again to download it again")+ mark(s, f"sha256 {sha}")+++ def resident_budget_gib(model, ram, kv_ram_gb=0.0) -> int:+ """UD-Q4_K_XL: the GiB of experts the engine keeps in RAM (--resident-budget-gib): the RAM (GiB, ram_gb()) less+ 24 for the OS, the engine and the file cache the other experts are read through, less a KV cache streamed to+ RAM; at most all of them, at least 8. 64 GB: 40, the measured setting (docs/UNSLOTH_Q4.md)."""+ gib = round(ram) - UNSLOTH_RAM_LEFT_GB - math.ceil(kv_ram_gb)+ return max(8, min(gib, int(MODELS[model]["arena_gb"] / 1.073741824)))++def check_shards(shards):"""Every shard present and whole, or setup stops naming the file and the numbers. Whole means as long asits own tensor directory says (the header is read, the data is not): a truncated copy (--gguf-dir, a .part@@@ -2344,8 -2319,10 +2434,12 @@@ def main() -> intkv = ["int8", "q4_0"][int(ask("KV cache?", ["1", "2"], "1", a.yes)) - 1]if ctx > 8192:ok(f"KV cache: {'8-bit' if kv == 'int8' else '4-bit (Hadamard-rotated)'}")- if hip:- if hip or fam.get("vision") is False:++ if fam.get("vision") is False:+ vision = "none"+ if a.vision not in (None, "no", "none"):- warn("images are not available " + ("with the AMD backend" if hip else f"with {model}") + " yet: off")++ warn(f"images are not available with {model} yet: off")++ elif hip:+ vision = hip_vision(a.vision)elif a.vision:vision = {"yes": "gpu", "no": "none"}.get(a.vision, a.vision)else:@@@ -2393,10 -2370,10 +2487,11 @@@fail(f"the experimental speed projection's vector is missing: {esp}")ok("experimental speed projection: " + ("ON (experimental)" if esp else "off"))elif esp_choice.lower() not in ("", "off", "no", "n", "0"):- warn("the experimental speed projection is made for the original Qwen3.8-Flash-Next, not Swift 1.5: left off")+ warn("the experimental speed projection is made for the original Qwen3.8-Flash-Next, not Swift 1.5: left off"+ if family == "swift" else f"the experimental speed projection is not tested with {model}: left off")models_dir = Path(a.gguf_dir) if a.gguf_dir else Path(a.models_dir) / tag- shards = [models_dir / fam["file"].format(q=model, i=i) for i in range(1, fam.get("shards", 2) + 1)]+ shards = gguf_dir_shards(models_dir, fam, model) if a.gguf_dir else \- [models_dir / fam["file"].format(q=model, i=i) for i in (1, 2)]++ [models_dir / fam["file"].format(q=model, i=i) for i in range(1, fam.get("shards", 2) + 1)]if not a.gguf_dir and not all(sh.exists() and done(sh) for sh in shards):for r in elsewhere: # already downloaded in a Strata folder on another drivecand = [r / "models" / tag / sh.name for sh in shards]@@@ -2429,12 -2406,20 +2524,16 @@@if vision != "none" and not (eng / VEXE).exists():warn("the ready-made engine has no image encoder: compiling it")eng = None- elif vision == "gpu": # the encoder can cover fewer cards than the engine (RTX 20)- m = json.loads((eng / "BUILD.json").read_text())- va = [int(x) for x in m.get("vision_archs", m.get("archs", []))]- if va and int(gpu["arch"]) not in va and not (m.get("ptx") and int(gpu["arch"]) > max(va)):- warn(f"the ready-made image encoder has no code for your GPU (sm_{gpu['arch']}): compiling it")- eng = None+ else:+ vision = prebuilt_vision(json.loads((eng / "BUILD.json").read_text()), gpu, vision)if eng is None:- eng = build_engine_hip(gpu, llama) if hip else build_engine(gpu, vision, a.yes, llama)+ eng = build_engine_hip(gpu, llama, vision) if hip else build_engine(gpu, vision, a.yes, llama)meta = json.loads((eng / "BUILD.json").read_text())lib_dirs = meta.get("lib_dirs") or meta.get("cuda_dirs") or cuda_lib_dirs()+ engine_ver = tuple(int(x) for x in str(meta.get("version", "0")).split(".")[:3] if x.isdigit())+ if budget is not None and engine_ver < UNSLOTH_ENGINE: # checked before the 111 GB download+ fail(f"{model} needs engine {'.'.join(map(str, UNSLOTH_ENGINE))} or newer; this one is {meta.get('version')}",+ "update Strata (or compile the engine with --build) and run setup again")ok(f"engine: {eng / EXE}")# ---- 5. the model files