"""Build the boot's own int8 served plan (model + drafter checkpoints) and a_prep, GPU-free."""
import json
import time
from pathlib import Path

import arbi_serve._prebake_loader  # noqa: F401

t0 = time.time()
from arbi_serve.weight_quant.exl3 import a_prep as ap

ap._load_now()
print("a_prep built/loaded", round(time.time() - t0, 1), flush=True)
from arbi_serve.weight_quant.exl3 import int8_kernel as ik
from arbi_serve.weight_quant.exl3 import int8_served_set as s

pairs = set()
for d in ("/models/Qwen3.8-27B-exl3-4.0bpw-vision6", "/models/Qwen3.8-27B-DFlash2-exl3-6.0bpw"):
    pairs |= s.exl3_checkpoint_pairs(Path(d))
s.select_int8_build(s.exl3_plan(pairs))
print("plan", sorted(pairs), ik._extension_name(), flush=True)
t1 = time.time()
mod = ik._load()
print("int8", getattr(mod, "__file__", mod), round(time.time() - t1, 1), flush=True)
assert mod is not None
print(json.dumps({"has_split_dense": hasattr(mod, "split_dense_gemm")}), flush=True)
# The decode GEMV is built separately (build_gemv.py), from a tree whose loader finds turbo-attn's headers.
