mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
The pack tools, the NVFP4-local conversion and the fixture generator read GGUF files with gguf-py; until now setup downloaded the whole llama.cpp zip for it. third_party/strata-gguf-py holds gguf/ (gguf-py), converter/ (convert_hf_to_gguf.py, conversion/) and the licences, byte-identical to llama.cpp 3cf03257f (UPSTREAM.md lists every file with its sha256; tools/check_vendored.py verifies it, also against a llama.cpp tree with --upstream). tools/_paths.py finds it first (STRATA_GGUF_PY stays as an override); nvfp4_convert/verify import the vendored converter.
58 lines
2.6 KiB
Python
58 lines
2.6 KiB
Python
"""tools/_paths.py - where the tools find llama.cpp's gguf-py (for the MTP packer and the fixtures).
|
|
|
|
Order: $STRATA_GGUF_PY (a folder that holds the `gguf` package, e.g. <llama.cpp>/gguf-py), then the vendored copy
|
|
<engine>/third_party/strata-gguf-py (frozen at the pinned llama.cpp commit, no download), then the development tree's
|
|
../../.ref/llama.cpp/gguf-py, then (#3269) the install folders: in the Control package setup.py's per-user install folder
|
|
($STRATA_INSTALL_DIR, else the app's folder, the Terminal's remembered installs), so a tool run by hand from the package finds it there.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ENGINE = Path(__file__).resolve().parents[1]
|
|
VENDORED = ENGINE / "third_party" / "strata-gguf-py" # holds gguf/ (the package) and converter/ (llama.cpp's HF converter)
|
|
|
|
|
|
def _install_dirs() -> list[Path]:
|
|
"""The per-user install folders a Control-mode setup.py works in. Best effort: never raises."""
|
|
out: list[Path] = []
|
|
raw = os.environ.get("STRATA_INSTALL_DIR")
|
|
if raw:
|
|
out.append(Path(raw).expanduser())
|
|
try:
|
|
if str(ENGINE) not in sys.path:
|
|
sys.path.append(str(ENGINE))
|
|
from strata_control import discovery
|
|
out.append(discovery.app_install_dir())
|
|
out += [pl.path for pl in discovery.places(here=ENGINE)]
|
|
except Exception:
|
|
pass
|
|
return out
|
|
|
|
|
|
def gguf_py() -> str:
|
|
cands = [os.environ.get("STRATA_GGUF_PY"), ENGINE / "third_party" / "strata-gguf-py",
|
|
ENGINE.parents[min(1, len(ENGINE.parents) - 1)] / ".ref" / "llama.cpp" / "gguf-py"] # the dev tree; a shallow install (G:\Strata) has no grandparent
|
|
cands += [d / "third_party" / "strata-gguf-py" for d in _install_dirs()]
|
|
for c in cands:
|
|
if c and (Path(c) / "gguf").is_dir():
|
|
return str(c)
|
|
sys.exit("gguf-py was not found. It ships with Strata in third_party/strata-gguf-py; set STRATA_GGUF_PY to the folder that holds the "
|
|
"`gguf` package (for example <llama.cpp>/gguf-py) to use another copy")
|
|
|
|
|
|
def add_gguf_py() -> None:
|
|
p = gguf_py()
|
|
if p not in sys.path:
|
|
sys.path.insert(0, p)
|
|
|
|
|
|
def converter_dir() -> str:
|
|
"""llama.cpp's Hugging Face converter (convert_hf_to_gguf.py and conversion/), vendored beside gguf-py (the NVFP4-local preparation)."""
|
|
for c in (ENGINE / "third_party" / "strata-gguf-py" / "converter", *[d / "third_party" / "strata-gguf-py" / "converter" for d in _install_dirs()]):
|
|
if (c / "convert_hf_to_gguf.py").is_file():
|
|
return str(c)
|
|
sys.exit("llama.cpp's converter was not found (third_party/strata-gguf-py/converter)")
|