setup and the plan accept an Unsloth mmproj-F16.gguf the person already has as the Flash-Next picture reader (lane 15, item 7)

A person who already has Unsloth's picture-reader file next to their model files no longer downloads the pinned BF16 reader (0.9 GB) a second time.
lane 14's answers check: the F16 file against the pinned BF16 file on the same tower and card gives 58 of 72 answers word for word (60 after
whitespace), none of the 12 differences wrong about the picture, while the same BF16 file on two different cards gives 55 of 72; embeddings
0.9998 mean / 0.998 worst. Owner's word 11-10: setup may accept it when the check passes.

The rule (setup.ALT_READERS, accepted_alt_reader, resolve_reader; the plan asks the same function through modelstate.reader_present):
- a file named mmproj-F16.gguf with exactly 904,004,000 bytes and SHA-256 1f7b7f0b984cf065c604360c29c8098362ed61b290db0ff12c6f360bb1a8a980
  (Unsloth, revision 38bb39ee97821de2c9009abb7e93950eec396e66);
- in a place where setup already looks for the pinned reader: the data folder's models/, an earlier install's models/, and the person's own GGUF
  folder (beside the shards, the folder above, that folder's models/);
- only when no pinned BF16 file is found anywhere: the pinned file always wins;
- anything else with that name is ignored as before (not deleted, not renamed); setup never downloads the F16 file, and with no accepted reader it
  downloads the pinned file as today.
The SHA-256 (a few seconds) is remembered in a mark in Strata's own marks/ folder, never beside the person's file. The mark is keyed by the file's
real path, size and modification time (_kept_mark), so a replaced file, even one of the same size, is hashed again. The plan hashes without
writing a mark and says nothing; `strata launch --plan` shows no 0.9 GB reader part when an accepted file is there, and still shows it for a wrong
size, a wrong hash or another file of that name, because the start still downloads it.

Wording (owner-approved 11-10, exactly):
  "  checking mmproj-F16.gguf (SHA-256, 0.9 GB) ..."
  "vision encoder: <path> (Unsloth's mmproj-F16.gguf, SHA-256 checked)"
  "  note: <path> has the name of Unsloth's picture reader but is a different file, so it is not used. The picture reader is downloaded (0.9 GB)."

With the F16 file the engine's own tower runs its F16 mode (nothing changes on the engine side).

Tests: tests/terminal/test_net_alt_reader.py (accepted and checked once; the folders above and models/; wrong size; wrong hash with the note and a
remembered answer; another name; both files present, the pinned one wins; a file accepted once and then replaced by another of the same size is
hashed again and refused; a changed size; a linked folder shares the mark and cannot hide a replacement; plan and start agree in each case; the plan
writes no mark; the pinned values are the owner's).
This commit is contained in:
Niko1221 committed 2026-11-10 20:19:14 +01:00
1 parent f88ea5bb00
commit a7f384efe7
3 files changed
+319 -14

No files matched your search

+89 -12
View File
@@ -7375,6 +7375,84 @@ def mmproj_beside(gguf_dir, name: str, size: int | None = None):
return None
# A picture reader the person may already have instead of the pinned one: Unsloth's mmproj-F16.gguf for Flash-Next (the same vision tower in F16;
# lane 14: 58 of 72 answers word for word with the pinned BF16 file on the same card, none of the differences wrong about the picture; embeddings 0.9998
# mean / 0.998 worst). Accepted ONLY when it is already there, with this size and this SHA-256 (Unsloth rev 38bb39ee97821de2c9009abb7e93950eec396e66),
# and only when no pinned file is found: pinned name -> (file name, bytes, sha256). It is never downloaded.
ALT_READERS = {MMPROJ: ("mmproj-F16.gguf", 904004000, "1f7b7f0b984cf065c604360c29c8098362ed61b290db0ff12c6f360bb1a8a980")}
_ALT_MARK = re.compile(r"alt-reader sha256 ([0-9a-f]{64})")
def alt_reader_places(pinned: str, models_dir, roots, gguf_dir) -> list:
"""Where the alternative reader of `pinned` is looked for: the same places as the pinned one (the data folder's models/, an earlier install's
models/, and a person's own GGUF folder: beside the shards, the folder above and that folder's models/)."""
alt = ALT_READERS.get(pinned)
if alt is None:
return []
places = [Path(models_dir) / alt[0]] + [Path(r) / "models" / alt[0] for r in roots or []]
if gguf_dir:
base = Path(gguf_dir)
places += [base / alt[0], base.parent / alt[0], base.parent / "models" / alt[0]]
return places
def accepted_alt_reader(pinned: str, places, *, start: bool = True):
"""The first file in `places` that is the alternative reader of `pinned` (name, size and SHA-256 all as pinned in ALT_READERS), else None. Anything
else with that name is ignored (never deleted, never renamed). The SHA-256 (0.9 GB, a few seconds) is remembered in a mark in Strata's own
marks/ folder, never beside the person's file; the mark is keyed by the real path, size and modification time (_kept_mark), so a file that was
replaced is hashed again. start=True is the setup run (says what it does, writes the mark); start=False is the plan (the same answer, says
nothing, writes nothing)."""
alt = ALT_READERS.get(pinned)
if alt is None:
return None
name, size, sha = alt
for p in places:
p = Path(p)
try:
if p.name != name or not p.is_file() or p.stat().st_size != size:
continue # absent, another name or another size: ignored exactly as before
except OSError:
continue
digest = None
kept = _kept_mark(p)
try:
found = _ALT_MARK.match(kept.read_text(encoding="utf-8", errors="replace")) if kept is not None and kept.exists() else None
digest = found.group(1) if found else None
except OSError:
digest = None
if digest is None:
if start:
say(f" checking {p.name} (SHA-256, {size / 1e9:.1f} GB) ...")
digest = _hash_file(p, size)
if start and kept is not None:
try:
kept.parent.mkdir(parents=True, exist_ok=True)
kept.write_text(f"alt-reader sha256 {digest}\n", encoding="utf-8")
except OSError:
pass # (not remembered: the next run hashes again; nothing else changes)
if digest == sha:
return p
if start:
say(f" note: {p} has the name of Unsloth's picture reader but is a different file, so it is not used. "
"The picture reader is downloaded (0.9 GB).")
return None
def resolve_reader(pinned: str, mmproj: Path, models_dir, roots, gguf_dir, size):
"""Which picture reader this run uses: (kind, path). `mmproj` is where the pinned file would be (the data folder's models/, or an earlier
install's copy when there is one). kind "fetch": the pinned file at `mmproj` (it exists, or it is downloaded); "near": the pinned file in the
person's own folder (mmproj_beside); "alt": a verified Unsloth mmproj-F16.gguf the person already has (only when no pinned file is anywhere)."""
if mmproj.exists():
return "fetch", mmproj
near = mmproj_beside(gguf_dir, pinned, size)
if near is not None:
return "near", near
alt = accepted_alt_reader(pinned, alt_reader_places(pinned, models_dir, roots, gguf_dir), start=True)
if alt is not None:
return "alt", alt
return "fetch", mmproj
def share_sibling_file(dst: Path, parent: Path, name: str, size: int) -> bool:
"""A shared file that sits in another model's folder under `parent` (parent/<model folder>/<name>; Qwen3.6 keeps its picture file beside each size) is made
available at `dst` without the network: a hard link, else a copy. Only a file of the pinned `size`; its SHA-256 is checked by the caller's download(), as for
@@ -10097,14 +10175,12 @@ def mac_control_setup(a) -> int:
mmproj = Path(models_root) / fam["mmproj"]
if not mmproj.exists(): # an earlier install's copy (the same file for every family)
mmproj = find_in(roots, f"models/{fam['mmproj']}") or mmproj
near = None if mmproj.exists() else mmproj_beside(a.gguf_dir, fam["mmproj"], (ISTA_FILES.get(fam["mmproj"]) or (None,))[0])
if near is not None:
mmproj = near
elif not (mmproj.exists() and done(mmproj)):
kind, mmproj = resolve_reader(fam["mmproj"], mmproj, models_root, roots, a.gguf_dir, (ISTA_FILES.get(fam["mmproj"]) or (None,))[0])
if kind == "fetch" and not (mmproj.exists() and done(mmproj)):
download(fam["mmproj_hf"] + fam["mmproj"], mmproj, "vision encoder")
if fam["mmproj"] in ISTA_FILES:
if fam["mmproj"] in ISTA_FILES and kind != "alt": # (a verified Unsloth F16 file was checked against its own pin)
verify_sha256(mmproj, *ISTA_FILES[fam["mmproj"]])
ok(f"vision encoder: {mmproj}")
ok(f"vision encoder: {mmproj}" + (" (Unsloth's mmproj-F16.gguf, SHA-256 checked)" if kind == "alt" else ""))
step(6, "preparing the model for Strata")
pack = find_in(roots, f"packs/{tag.lower()}") or data / "packs" / tag.lower()
@@ -11180,14 +11256,15 @@ def main() -> int:
if not mmproj.exists(): # an earlier install's copy (the same file for every family)
mmproj = find_in(roots, f"models/{fam.get('mmproj', MMPROJ)}") or mmproj # a feed model without a picture reader has no fam["mmproj"]
if vision != "none":
near = None if mmproj.exists() else mmproj_beside(a.gguf_dir, fam["mmproj"], (fam.get("mmproj_sha256") or ISTA_FILES.get(fam["mmproj"]) or (None,))[0])
if near is not None: # the person's own folder (or the one above it) has the picture file: used where it is
mmproj = near
else:
# the person's own folder (or the one above it) has the pinned picture file: used where it is ('near'); a verified Unsloth mmproj-F16.gguf they
# already have is used when no pinned file is anywhere ('alt'); else the pinned file is downloaded
kind, mmproj = resolve_reader(fam["mmproj"], mmproj, a.models_dir, roots, a.gguf_dir,
(fam.get("mmproj_sha256") or ISTA_FILES.get(fam["mmproj"]) or (None,))[0])
if kind == "fetch":
download(fam["mmproj_hf"] + fam["mmproj"], mmproj, "vision encoder")
if fam.get("mmproj_sha256"): # the NVFP4 family pins it by size and SHA-256 too
if fam.get("mmproj_sha256") and kind != "alt": # the NVFP4 family pins it by size and SHA-256 too
verify_sha256(mmproj, *fam["mmproj_sha256"])
ok(f"vision encoder: {mmproj}")
ok(f"vision encoder: {mmproj}" + (" (Unsloth's mmproj-F16.gguf, SHA-256 checked)" if kind == "alt" else ""))
if vision == "cpu" and "BF16" in mmproj.name: # a tip only (recommend, never force; #625)
say(" tip: on the CPU a Q8_0 copy of this encoder is a third smaller and about as exact (embedding "
"cosine 0.999 vs BF16); see 'A Q8_0 encoder' in docs/DETAILS.md")
+13 -2
View File
@@ -235,7 +235,8 @@ def mmproj_size(catalog, family: str | None, name: str) -> int | None:
def reader_present(catalog, family: str | None, data_folders, own: Path | None = None) -> bool:
"""Whether setup will find the picture reader without a download - setup's own rule (setup.py step 5 and mmproj_beside), not any
mmproj*.gguf: the family's pinned file name in a data folder's models/ (the one in use, or a folder setup reuses), or with the person's own
files in their folder (by name), or in the folder above it or that folder's models/ (by name, at the pinned size)."""
files in their folder (by name), or in the folder above it or that folder's models/ (by name, at the pinned size). Or, when there is no pinned
file, a verified Unsloth mmproj-F16.gguf (setup.accepted_alt_reader: the same function the start uses)."""
name = mmproj_name(catalog, family)
for base in data_folders:
if not base:
@@ -258,7 +259,17 @@ def reader_present(catalog, family: str | None, data_folders, own: Path | None =
return True
except OSError:
pass
return False
try: # no pinned file: a verified Unsloth mmproj-F16.gguf the person already has counts, as in setup
mod = catalog.strata.setup_module()
alt = (getattr(mod, "ALT_READERS", None) or {}).get(name) if mod is not None else None
if alt is None:
return False
places = [Path(b) / sub / alt[0] for b in data_folders if b for sub in ("models", "Models")]
if own is not None:
places += [Path(own) / alt[0], Path(own).parent / alt[0], Path(own).parent / "models" / alt[0]]
return mod.accepted_alt_reader(name, places, start=False) is not None # (the plan hashes without writing a mark and says nothing)
except Exception: # noqa: BLE001 - the plan must not fail on this
return False
def _first_gguf(path: Path) -> Path | None:
+217
View File
@@ -0,0 +1,217 @@
"""Lane NET item 7: setup may use an Unsloth mmproj-F16.gguf that the person already has as the Flash-Next picture reader, and the plan says the same.
The rule (setup.ALT_READERS, setup.accepted_alt_reader, setup.resolve_reader; the plan asks the same function through modelstate.reader_present):
* only a file named mmproj-F16.gguf with the pinned size AND SHA-256, in a place where setup already looks for the pinned reader;
* only when no pinned BF16 file is found anywhere (the pinned file always wins); anything else with that name is ignored, as before;
* never downloaded, never deleted, never given a mark beside it: the SHA-256 is remembered in Strata's marks/ (keyed by real path, size and
modification time, so a replaced file is hashed again);
* the plan hashes without writing a mark and says nothing.
The tests use a small stand-in file and patch the pin; one test holds the real pin."""
from __future__ import annotations
import contextlib
import hashlib
import io
import os
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from strata_cli.launch import modelstate
from tests.terminal.launch_support import HW_12, Home, catalog
ALT = "mmproj-F16.gguf"
GOOD = b"unsloth-reader " * 100
BAD = b"another-reader " * 100 # the same size, another content
assert len(GOOD) == len(BAD)
NOTE = (" note: {path} has the name of Unsloth's picture reader but is a different file, so it is not used. "
"The picture reader is downloaded (0.9 GB).")
class Base(unittest.TestCase):
def setUp(self):
home = Home().__enter__()
self.addCleanup(home.__exit__, None, None, None)
t = tempfile.TemporaryDirectory(prefix="strata-altreader-")
self.addCleanup(t.cleanup)
self.base = Path(t.name)
self.cat = catalog(HW_12)
self.mod = self.cat.strata.setup_module() # the module the plan asks too
self.pinned = self.mod.MMPROJ
for p in (mock.patch.dict(self.mod.ALT_READERS, {self.pinned: (ALT, len(GOOD), hashlib.sha256(GOOD).hexdigest())}),
mock.patch.object(self.mod, "ROOT", self.base / "strata-root")):
p.start()
self.addCleanup(p.stop)
self.own = self.base / "mine" / "IQ3_XXS" # a person's own folder of shards
self.own.mkdir(parents=True)
self.models = self.base / "data" / "models" # Strata's own models folder (the pinned file would be here)
self.models.mkdir(parents=True)
def start(self, gguf_dir="own"):
"""What setup does for the reader: (kind, path, printed text)."""
out = io.StringIO()
gd = self.own if gguf_dir == "own" else gguf_dir
with contextlib.redirect_stdout(out):
kind, path = self.mod.resolve_reader(self.pinned, self.models / self.pinned, self.models, [], gd, 907543008)
return kind, path, out.getvalue()
def plan(self):
"""What the plan believes: does setup find a reader without a download (and what it printed)."""
out = io.StringIO()
with contextlib.redirect_stdout(out):
present = modelstate.reader_present(self.cat, "qwen", [self.base / "data"], own=self.own)
return present, out.getvalue()
def marks(self):
d = self.mod.ROOT / "marks"
return sorted(d.iterdir()) if d.is_dir() else []
def hashes(self):
"""Count the files setup hashes from here on."""
real = self.mod._hash_file
calls = []
def counting(path, size):
calls.append(Path(path).name)
return real(path, size)
p = mock.patch.object(self.mod, "_hash_file", counting)
p.start()
self.addCleanup(p.stop)
return calls
class TheRealPin(unittest.TestCase):
def test_the_pinned_values_are_the_owners(self):
import setup
self.assertEqual(setup.ALT_READERS[setup.MMPROJ], ("mmproj-F16.gguf", 904004000,
"1f7b7f0b984cf065c604360c29c8098362ed61b290db0ff12c6f360bb1a8a980"))
self.assertEqual(setup.MMPROJ, "mmproj-Qwen3.8-Flash-Next-BF16.gguf")
self.assertEqual(list(setup.ALT_READERS), [setup.MMPROJ], "Flash-Next's pinned file only, no other family")
class Accepted(Base):
def test_a_file_with_the_pinned_size_and_hash_is_used_and_checked_once(self):
(self.own / ALT).write_bytes(GOOD)
hashed = self.hashes()
present, said = self.plan() # the plan first: hashes, says nothing, writes nothing
self.assertTrue(present)
self.assertEqual(said, "")
self.assertEqual(self.marks(), [], "the plan writes no mark")
kind, path, said = self.start()
self.assertEqual((kind, path), ("alt", self.own / ALT))
self.assertEqual(said, f" checking {ALT} (SHA-256, 0.0 GB) ...\n")
self.assertEqual(len(self.marks()), 1, "one mark in Strata's own folder")
self.assertEqual(sorted(p.name for p in self.own.iterdir()), [ALT], "nothing was written beside the person's file")
before = len(hashed)
kind, _path, said = self.start() # the next run: the mark answers
self.assertEqual((kind, said), ("alt", ""))
self.assertTrue(self.plan()[0])
self.assertEqual(len(hashed), before, "no second hash")
def test_the_folder_above_and_its_models_folder_and_the_data_models_folder_count_too(self):
for where in (self.own.parent, self.own.parent / "models", self.models):
where.mkdir(parents=True, exist_ok=True)
f = where / ALT
f.write_bytes(GOOD)
self.assertEqual(self.start()[:2], ("alt", f), str(where))
self.assertTrue(self.plan()[0], str(where))
f.unlink()
self.assertEqual(self.start()[0], "fetch")
self.assertFalse(self.plan()[0])
class NotAccepted(Base):
def test_a_wrong_size_is_ignored_exactly_as_before(self):
(self.own / ALT).write_bytes(GOOD[:-1])
hashed = self.hashes()
kind, path, said = self.start()
self.assertEqual((kind, path, said), ("fetch", self.models / self.pinned, ""))
self.assertEqual(hashed, [], "not even hashed")
self.assertEqual(self.plan(), (False, ""))
self.assertEqual((self.own / ALT).read_bytes(), GOOD[:-1])
def test_a_wrong_hash_is_ignored_with_the_note_and_the_pinned_file_is_downloaded(self):
(self.own / ALT).write_bytes(BAD)
hashed = self.hashes()
kind, path, said = self.start()
self.assertEqual((kind, path), ("fetch", self.models / self.pinned))
self.assertEqual(said, f" checking {ALT} (SHA-256, 0.0 GB) ...\n" + NOTE.format(path=self.own / ALT) + "\n")
self.assertEqual(self.plan(), (False, ""), "the plan agrees with the start: the reader is downloaded")
self.assertEqual((self.own / ALT).read_bytes(), BAD, "the person's file is never touched")
self.assertEqual(sorted(p.name for p in self.own.iterdir()), [ALT])
before = len(hashed)
kind, _path, said = self.start() # remembered: not hashed again, the note says it again
self.assertEqual(kind, "fetch")
self.assertEqual(said, NOTE.format(path=self.own / ALT) + "\n")
self.assertEqual(len(hashed), before)
def test_another_name_is_never_looked_at(self):
(self.own / "mmproj-BF16.gguf").write_bytes(GOOD)
(self.own / "mmproj-Q8_0.gguf").write_bytes(GOOD)
self.assertEqual(self.start()[0], "fetch")
self.assertFalse(self.plan()[0])
def test_the_pinned_file_always_wins(self):
(self.own / ALT).write_bytes(GOOD)
pinned = self.own / self.pinned
pinned.write_bytes(b"x" * 10) # beside the files: by name, any size (setup's mmproj_beside)
hashed = self.hashes()
kind, path, said = self.start()
self.assertEqual((kind, path, said), ("near", pinned, ""))
self.assertEqual(hashed, [], "the alternative is not even hashed")
self.assertTrue(self.plan()[0])
pinned.unlink()
(self.models / self.pinned).write_bytes(b"y") # Strata's own models folder
kind, path, said = self.start()
self.assertEqual((kind, path, said), ("fetch", self.models / self.pinned, ""), "the pinned file is used (and verified later by setup)")
self.assertTrue(self.plan()[0])
self.assertEqual(hashed, [])
class Replaced(Base):
def test_a_file_accepted_once_and_then_replaced_by_another_of_the_same_size_is_hashed_again_and_refused(self):
f = self.own / ALT
f.write_bytes(GOOD)
self.assertEqual(self.start()[0], "alt")
self.assertEqual(len(self.marks()), 1)
hashed = self.hashes()
stat = f.stat()
f.write_bytes(BAD) # the same size and place, other bytes
os.utime(f, ns=(stat.st_atime_ns, stat.st_mtime_ns + 5_000_000_000)) # (a new modification time, as any real replacement has)
kind, _path, said = self.start()
self.assertEqual(kind, "fetch")
self.assertIn("is a different file", said)
self.assertEqual(hashed, [ALT], "hashed again")
self.assertEqual(self.plan(), (False, ""))
def test_a_changed_size_has_no_mark_either(self):
f = self.own / ALT
f.write_bytes(GOOD)
self.assertEqual(self.start()[0], "alt")
f.write_bytes(GOOD + b"!")
self.assertEqual(self.start(), ("fetch", self.models / self.pinned, ""))
def test_the_mark_is_keyed_by_the_real_path_so_a_linked_folder_shares_it_and_cannot_hide_a_replacement(self):
real = self.base / "real"
real.mkdir()
(real / ALT).write_bytes(GOOD)
link = self.base / "link"
try:
os.symlink(real, link, target_is_directory=True)
except (OSError, NotImplementedError, AttributeError):
self.skipTest("this account cannot make symbolic links")
self.assertEqual(self.start(gguf_dir=real)[0], "alt")
hashed = self.hashes()
self.assertEqual(self.start(gguf_dir=link)[0], "alt")
self.assertEqual(hashed, [], "the same file through the link: the same mark")
stat = (real / ALT).stat()
(real / ALT).write_bytes(BAD)
os.utime(real / ALT, ns=(stat.st_atime_ns, stat.st_mtime_ns + 5_000_000_000))
self.assertEqual(self.start(gguf_dir=link)[0], "fetch", "replaced behind the link: hashed again, refused")
self.assertEqual(hashed, [ALT])
if __name__ == "__main__":
unittest.main()