Integrate real reviewer with measured Actions execution and live Jenkins pipeline
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"""Download and checksum the pinned public GGUF model and llama.cpp CPU archive."""
|
||||
"""Prepare checksum-pinned model, llama.cpp CPU runtime, and libgomp1."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
import urllib.request
|
||||
|
||||
@@ -36,25 +37,48 @@ def fetch(url, target, expected):
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--dest", type=Path, required=True, help="directory outside Git for model/runtime files")
|
||||
parser.add_argument("--model-dir", type=Path, help="optional private tmpfs model directory")
|
||||
args = parser.parse_args()
|
||||
lock = json.loads(LOCK.read_text())
|
||||
args.dest.mkdir(parents=True, exist_ok=True)
|
||||
model = args.dest / lock["quantized_filename"]
|
||||
model_dir = args.model_dir or args.dest
|
||||
model_dir.mkdir(parents=True, exist_ok=True)
|
||||
model = model_dir / lock["quantized_filename"]
|
||||
archive = args.dest / lock["runtime_archive"]
|
||||
fetch(lock["quantized_url"], model, lock["quantized_sha256"])
|
||||
fetch(lock["runtime_url"], archive, lock["runtime_archive_sha256"])
|
||||
package = args.dest / lock["libgomp_package"]
|
||||
fetch(lock["libgomp_url"], package, lock["libgomp_package_sha256"])
|
||||
with tarfile.open(archive) as bundle:
|
||||
members = bundle.getmembers()
|
||||
root_name = "llama-" + lock["runtime_tag"]
|
||||
if any(member.name != root_name and not member.name.startswith(root_name + "/") for member in members):
|
||||
raise ValueError("unexpected runtime archive layout")
|
||||
bundle.extractall(args.dest, filter="data")
|
||||
# The pinned compiler has Python 3.11 without tarfile.data_filter.
|
||||
# Reject traversal, special files and escaping link targets before extraction.
|
||||
from pathlib import PurePosixPath
|
||||
for member in members:
|
||||
for name in (member.name, member.linkname):
|
||||
path = PurePosixPath(name)
|
||||
if path.is_absolute() or ".." in path.parts:
|
||||
raise ValueError("unsafe archive member/link")
|
||||
if not (member.isfile() or member.isdir() or member.issym() or member.islnk()):
|
||||
raise ValueError("special archive member")
|
||||
if hasattr(tarfile, "data_filter"):
|
||||
bundle.extractall(args.dest, filter="data")
|
||||
else:
|
||||
bundle.extractall(args.dest)
|
||||
server = args.dest / f"llama-{lock['runtime_tag']}" / lock["entrypoint"]
|
||||
if not server.is_file():
|
||||
raise FileNotFoundError("runtime entrypoint missing from verified archive")
|
||||
if not server.is_file() or digest(server) != lock["runtime_entrypoint_sha256"]:
|
||||
raise ValueError("runtime entrypoint checksum mismatch")
|
||||
libgomp_root = args.dest / "libgomp-root"
|
||||
subprocess.run(["dpkg-deb", "--extract", str(package), str(libgomp_root)], check=True)
|
||||
library = libgomp_root / lock["libgomp_library_path"]
|
||||
if not library.is_file() or digest(library) != lock["libgomp_library_sha256"]:
|
||||
raise ValueError("libgomp1 library checksum mismatch")
|
||||
print(f"REVIEWER_MODEL_PATH={model}")
|
||||
print(f"REVIEWER_LLAMA_COMPLETION={server}")
|
||||
print("Install libgomp1 in the execution image and ensure its directory is on the loader path.")
|
||||
print(f"LD_LIBRARY_PATH={library.parent}:{server.parent}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user