Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
103 lines
5.3 KiB
Python
103 lines
5.3 KiB
Python
"""Getting the DFlash2 drafter onto this computer: a pinned download, checked against the repository's own SHA-256, packed for the engine.
|
|
|
|
strata drafting plan [--data-dir DIR] what it would download (nothing is changed)
|
|
strata drafting fetch [--data-dir DIR] download, check, pack; progress in plain words
|
|
|
|
Only an explicit command reaches the network (strata_control/acquisition.py): a start never downloads. The drafter is
|
|
incoai/Qwen3.8-Flash-Next-DFlash2 at one revision (strata_control/drafting.py has the revision, the file sizes and hashes). The 1.2 GB
|
|
safetensors file is packed (tools/dflash2_pack.py, numpy only) into the engine's 0.76 GB runtime file and then removed.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import os
|
|
import sys
|
|
import threading
|
|
from pathlib import Path
|
|
from typing import Callable
|
|
|
|
from strata_control import acquisition, drafting, transfer
|
|
|
|
Progress = Callable[[str, int, int], None] # (step in plain words, bytes done, bytes total)
|
|
|
|
|
|
class DraftingError(RuntimeError):
|
|
"""The drafter could not be fetched or packed. The message is plain words and says what to do."""
|
|
|
|
|
|
def plan(data_dir: str | Path) -> dict:
|
|
"""What fetching would do, in numbers and words. ``gb`` is 0 when the drafter is already here."""
|
|
ready = drafting.pack_ready(data_dir)
|
|
gb = 0.0 if ready else drafting.DOWNLOAD_GB
|
|
if ready:
|
|
text = "The DFlash2 drafter is already on this computer."
|
|
else:
|
|
text = (f"The DFlash2 drafter is {drafting.DOWNLOAD_GB:.1f} GB to download (it is packed to {drafting.PACK_GB:.2f} GB for the engine and the "
|
|
f"download is removed), from {drafting.REPO}, {drafting.LICENSE}. It needs about {drafting.VRAM_GB:.1f} GB of graphics memory; "
|
|
"if it does not fit, the model starts with the MTP instead.")
|
|
return {"ready": ready, "gb": gb, "pack": str(drafting.pack_path(data_dir)), "repo": drafting.REPO, "revision": drafting.REVISION, "text": text}
|
|
|
|
|
|
def _packer():
|
|
"""tools/dflash2_pack.py as a module: beside strata_control in a source checkout and in the packaged Control (TOOLS_SUBSET)."""
|
|
path = Path(__file__).resolve().parents[1] / "tools" / "dflash2_pack.py"
|
|
if not path.is_file():
|
|
raise DraftingError("The packing tool is missing from this installation. Update Strata, then try again.")
|
|
spec = importlib.util.spec_from_file_location("strata_dflash2_pack", path)
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules.setdefault("strata_dflash2_pack", module)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def ensure(data_dir: str | Path, *, progress: Progress | None = None, cancel: threading.Event | None = None,
|
|
base_url: str | None = None, files=None) -> Path:
|
|
"""Make the packed drafter exist under ``data_dir`` and return its path. A pack that is there is kept. Resumable: an interrupted
|
|
download is continued, a file whose hash differs is deleted and the person is told. ``base_url`` / ``files`` are for tests."""
|
|
report = progress or (lambda *_: None)
|
|
out = drafting.pack_path(data_dir)
|
|
if drafting.pack_ready(data_dir):
|
|
report("The DFlash2 drafter is ready.", 1, 1)
|
|
return out
|
|
acquisition.require("the DFlash2 drafter", "strata drafting fetch")
|
|
folder = out.parent
|
|
src = folder / "src"
|
|
src.mkdir(parents=True, exist_ok=True)
|
|
spec = tuple(files if files is not None else drafting.FILES)
|
|
total = sum(size for _n, size, _h in spec)
|
|
done_before = 0
|
|
for name, size, sha in spec:
|
|
target = src / name
|
|
if not (target.is_file() and target.stat().st_size == size and transfer.sha256_file(target) == sha):
|
|
base = done_before
|
|
partial = src / (name + ".part")
|
|
try:
|
|
transfer.download((base_url or drafting.BASE_URL) + name, partial, size=size, sha256=sha, cancel=cancel,
|
|
progress=lambda d, _s, base=base: report("Downloading the DFlash2 drafter…", base + d, total))
|
|
except transfer.ChecksumMismatch:
|
|
raise DraftingError("The downloaded DFlash2 file did not pass the safety check, so it was deleted. Try again; if it keeps "
|
|
"happening, use MTP for now.") from None
|
|
except transfer.TransferError as exc:
|
|
raise DraftingError(f"The DFlash2 download did not finish: {exc}. Try again; it continues where it stopped.") from None
|
|
os.replace(partial, target)
|
|
done_before += size
|
|
report("Packing the DFlash2 drafter for the engine…", total, total)
|
|
tmp = out.with_suffix(".tmp")
|
|
try:
|
|
_packer().pack(str(src / "model.safetensors"), str(src / "config.json"), str(tmp), say=lambda *_: None)
|
|
os.replace(tmp, out)
|
|
except DraftingError:
|
|
raise
|
|
except Exception as exc: # noqa: BLE001 - a plain sentence for any packing failure; the cause stays in the chain
|
|
tmp.unlink(missing_ok=True)
|
|
raise DraftingError("The DFlash2 drafter could not be prepared on this computer. The model keeps using the MTP.") from exc
|
|
for name, _size, _sha in spec: # the source files are 1.2 GB of nothing the engine reads
|
|
(src / name).unlink(missing_ok=True)
|
|
try:
|
|
src.rmdir()
|
|
except OSError:
|
|
pass
|
|
report("The DFlash2 drafter is ready.", total, total)
|
|
return out
|