Skip to content

Fast local LLM inference on plain CPUs. No GPU, 8 GB of RAM. OpenAI-compatible server.

fix(install): skip graft dependency setup when the model is already cached (#62)

Afloatb5e1f7fca740
diff --git a/install.sh b/install.sh
index 199e31f..23d7147 100755
--- a/install.sh
+++ b/install.sh
@@ -103,7 +103,7 @@ if [ ${#need_tools[@]} -gt 0 ]; then
apt_install "${need_tools[@]}" || true
fi
PY=python3
-if [ "$MTP" = 1 ] && ! python3 -c 'import numpy, yaml' 2>/dev/null; then # the MTP graft reads GGUF (gguf-py: numpy, pyyaml)
+if [ "$MTP" = 1 ] && [ ! -f "$PREFIX/models/model.gguf" ] && ! python3 -c 'import numpy, yaml' 2>/dev/null; then # the MTP graft reads GGUF (gguf-py: numpy, pyyaml)
say "Setting up a Python venv with numpy + pyyaml (to attach the multi-token-prediction head)"
if python3 -m venv "$PREFIX/venv" >/dev/null 2>&1 || { apt_install python3-venv && python3 -m venv "$PREFIX/venv"; }; then
"$PREFIX/venv/bin/pip" install -q numpy pyyaml && PY=$PREFIX/venv/bin/python
diff --git a/tests/test_install_cached_model.py b/tests/test_install_cached_model.py
new file mode 100644
index 0000000..1e06ad6
--- /dev/null
+++ b/tests/test_install_cached_model.py
@@ -0,0 +1,54 @@
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
+class InstallRegression(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp.cleanup)
+ self.work = Path(self.temp.name)
+ self.prefix = self.work / "installation"
+ self.tools = self.work / "tools"
+ self.tools.mkdir()
+ (self.prefix / "bin").mkdir(parents=True)
+ (self.prefix / "models").mkdir()
+ self.command(self.prefix / "bin/llama-server", "#!/bin/sh\nexit 0\n")
+ for name in ("dirname", "uname", "grep", "cut", "sed", "awk", "cat", "mkdir", "id",
+ "mv", "rm", "touch", "tar", "gzip", "head", "mktemp", "basename", "flock"):
+ executable = shutil.which(name)
+ if executable:
+ (self.tools / name).symlink_to(executable)
+ self.command(self.tools / "df", "#!/bin/sh\nprintf 'Filesystem 1024-blocks Used Available Capacity Mounted\nfixture 999999999 0 999999999 0%% /\n'\n")
+ self.command(self.tools / "du", "#!/bin/sh\nprintf '0 fixture\n'\n")
+ self.command(self.tools / "python3", "#!/bin/sh\nexit 0\n")
+ self.command(self.tools / "curl", "#!/bin/sh\nprintf download >> \"$DOWNLOAD_LOG\"\nwhile [ \"$#\" -gt 0 ]; do if [ \"$1\" = -o ]; then shift; printf fixture > \"$1\"; fi; shift; done\n")
+ self.env = {**os.environ, "OPENSET_LLM_HOME": str(self.prefix),
+ "PATH": str(self.tools), "DOWNLOAD_LOG": str(self.work / "downloads")}
+ self.env.pop("OPENSET_LLM_BIN_URL", None)
+ self.env.pop("HF_TOKEN", None)
+
+ def command(self, path, content):
+ path.write_text(content)
+ path.chmod(0o755)
+
+ def install(self, *args):
+ return subprocess.run(["/bin/bash", str(ROOT / "install.sh"), *args],
+ env=self.env, text=True, capture_output=True, timeout=15)
+
+ def test_cached_model_does_not_bootstrap_unused_graft_dependencies(self):
+ (self.prefix / "models/model.gguf").write_bytes(b"cached")
+ self.command(self.tools / "python3", "#!/bin/sh\nprintf called >> \"$DOWNLOAD_LOG\"\nexit 1\n")
+ result = self.install("--model-only")
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertFalse((self.work / "downloads").exists())
+ self.assertEqual((self.prefix / "models/model.gguf").read_bytes(), b"cached")
+
+
+if __name__ == "__main__":
+ unittest.main()