Download projects/core-api/scripts/export_checkpoint.py from KineJIng/kinejing-open-source: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/datasets/KineJIng/kinejing-open-source/resolve/main/projects/core-api/scripts/export_checkpoint.py
- Command line
-
hf download hf://datasets/KineJIng/kinejing-open-source/projects/core-api/scripts/export_checkpoint.py
-
curl -L -o export_checkpoint.py https://huggingface.co/datasets/KineJIng/kinejing-open-source/resolve/main/projects/core-api/scripts/export_checkpoint.py
1.69 kB
| """Private, deterministic tensor export. Run only against the pinned checkpoint.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import sys | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from kinejing_core.engine import CHECKPOINT_SHA256, ENCODER_SHA256, sha256 | |
| def main(): | |
| import numpy as np | |
| import torch | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("checkpoint", type=Path) | |
| parser.add_argument("output", type=Path) | |
| args = parser.parse_args() | |
| if sha256(args.checkpoint) != CHECKPOINT_SHA256: | |
| raise ValueError("Checkpoint is not the reviewed trained model") | |
| checkpoint = torch.load(args.checkpoint, map_location="cpu", weights_only=True) | |
| if checkpoint["encoder_provenance"]["weights_sha256"] != ENCODER_SHA256: | |
| raise ValueError("Unexpected trained feature space") | |
| if checkpoint["config"] != {"feature_dim": 768, "action_dim": 14, "views": 3, "hidden": 256}: | |
| raise ValueError("Unexpected trained architecture") | |
| tensors = {name: value.detach().cpu().numpy() for name, value in checkpoint["state_dict"].items()} | |
| tensors.update({name: checkpoint[name].detach().cpu().numpy() | |
| for name in ("feature_mean", "feature_std", "action_mean", "action_std")}) | |
| if args.output.exists(): | |
| raise FileExistsError("Refusing to overwrite an existing model export") | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| np.savez_compressed(args.output, **tensors) | |
| print(json.dumps({"checkpoint_sha256": CHECKPOINT_SHA256, | |
| "inference_asset_sha256": sha256(args.output), "tensor_count": len(tensors)})) | |
| if __name__ == "__main__": | |
| main() | |