"""Prepare the existing BF16 MTP captures for the owner's new Trellis MTP arm.""" import hashlib import json import os from pathlib import Path import numpy as np import torch from huggingface_hub import snapshot_download from safetensors.torch import save_file root = Path(os.environ["CV2_ROOT"]) out = Path(os.environ["CV2_OUT"]) dest = out / "mtp-inputs" dest.mkdir(exist_ok=True) repo = "brandonmusic/GLM-5.3-Flash-BF16-Teacher-Logits" rev = "95f4fdd94bf29989db2e0d1054e4931f55edb6aa" snapshot_download(repo, repo_type="dataset", revision=rev, local_dir=dest / "source", allow_patterns=["calibration/mtp45-ep4-full/*"], max_workers=4) source = dest / "source/calibration/mtp45-ep4-full" manifest = json.loads((source / "capture-manifest.json").read_text()) receipt = json.loads((source / "capture-receipt.json").read_text()) assert receipt["complete"] is True assert hashlib.sha256((source / "capture-manifest.json").read_bytes()).hexdigest() == receipt["capture_manifest_file_sha256"] assert manifest["layer"] == 45 and manifest["geometry"]["experts"] == 288 assert manifest["model_revision"] == "a6c167b62691b2bac901344b65cb651a70f53e43" for info in manifest["files"].values(): path = source / info["path"] assert path.stat().st_size == info["bytes"] with path.open("rb") as stream: assert hashlib.file_digest(stream, "sha256").hexdigest() == info["sha256"] roles = json.loads((root / "data/roles-v5.json").read_text())["roles"]["fit"] assert len(roles) == 64 role_map = {r["id"]: r for r in roles} windows = [w for w in manifest["windows"] if w["window_id"] in role_map] assert len(windows) == 64 offset = 0 offsets = {} for window in manifest["windows"]: offsets[window["window_id"]] = offset offset += window["rows"] assert offset == manifest["rows"] for window in windows: assert window["role"] == "fit" and window["rows"] == 2047 assert window["token_ids_sha256"] == role_map[window["window_id"]]["input_sha256"] streams = [("hidden_bf16", "