File size: 1,935 Bytes
1212aed
 
 
30828da
1212aed
 
 
 
 
 
 
30828da
 
 
 
 
 
 
 
 
1212aed
 
 
 
 
 
 
 
 
 
 
 
 
 
30828da
1212aed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Load the pinned public runtime and reference head; no training or downloads."""
from pathlib import Path
import hashlib
import json
import sys
import zipfile

ROOT = Path(__file__).resolve().parent
RUNTIME_SHA256 = "e9533a149f93cb872fbef7413936a60de876e501151540132190ea48f76df470"

def load_predictor(encoder):
    config = json.loads((ROOT / "config.json").read_text(encoding="utf-8"))
    if (config.get("configuration_version") != "wex-config-v1"
            or config.get("model_type") != "wex_decision_core"
            or config.get("weights_file") != "semantic128.npz"
            or config.get("weights_sha256") != "645a82c68576b207723a21ee413edbc9e69980a41520cdcb475bf28455c94887"
            or config.get("runtime_archive") != "subllm_runtime.zip"
            or config.get("runtime_archive_sha256") != RUNTIME_SHA256):
        raise ValueError("Public Wex configuration does not match the pinned release")
    archive = ROOT / config["runtime_archive"]
    if hashlib.sha256(archive.read_bytes()).hexdigest() != RUNTIME_SHA256:
        raise ValueError("Runtime archive hash mismatch")
    destination = ROOT / ".runtime"
    with zipfile.ZipFile(archive) as z:
        for entry in z.infolist():
            path = (destination / entry.filename).resolve()
            if not path.is_relative_to(destination.resolve()):
                raise ValueError("Runtime path escapes extraction directory")
            path.parent.mkdir(parents=True, exist_ok=True)
            payload = z.read(entry)
            if not path.exists() or path.read_bytes() != payload:
                path.write_bytes(payload)
    sys.path.insert(0, str(destination / "src"))
    from subllm.lah_inference import create_predictor
    return create_predictor(source=destination / "src", weights=ROOT / config["weights_file"],
                            encoder_model=Path(encoder).resolve(), cache_size=2048)