"""Base-model tensor cache.""" from pathlib import Path import json import os import struct from vlib import ctx from vlib.ui import _fail, _now_iso, _say, _step, _warn from vlib.net import _cleanup_tmp, _safe_id, http_get_json from vlib.tensors import _is_ggml_quant, _write_safetensors_streaming, read_safetensors, write_safetensors from vlib.sources import _base_paths, open_source, role_of, is_tied from vlib.fetch import _fetch_tensor, _resolve_output_name, _source_arch from vlib.registry import _assert_not_symlink def _base_rev(base_id, base_file): """Pinned commit sha for a base cache: sidecar .rev wins, else API HEAD (then pin).""" rev_path = base_file.with_suffix(".rev") try: if rev_path.exists(): rev = rev_path.read_text().strip() if rev: return rev except Exception: pass rev = None try: rev = http_get_json(f"https://huggingface.co/api/models/{base_id}", timeout=20).get("sha") except Exception: rev = None if rev: try: base_file.parent.mkdir(parents=True, exist_ok=True) tmp = rev_path.with_suffix(".rev.tmp") tmp.write_text(rev + "\n") tmp.replace(rev_path) except Exception: pass return rev return "main" def _cache_validate(base_file, names): """Names neither in the header nor fully covered by file bytes. Empty = trusted.""" try: with open(base_file, "rb") as f: hs = struct.unpack(" same lineage, pin HEAD. Differ -> wipe, start over. # Probe failure (offline?) keeps the cache with a loud warning, never wipes. try: with open(base_file, "rb") as f: hs = struct.unpack("