Commit 07c31b7d authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: emit model meta sidecar (.meta.json) on L1/L2 TorchScript export

Each export now writes a small <model>.ts.pt.meta.json so the native side
(tp_dnn.cpp / CuasDnnLocal, pieces 3-4) reads the model's params from a bundled
sidecar instead of hardcoding them — single source of truth.
  L1: {N, P, vr, out_ch, velocity_mode, vmax}
  L2: {ch_hidden, vmax, grid, ch_in}
Co-Authored-By: 's avatarClaude Opus 4.8 (1M context) <noreply@anthropic.com>
parent 7a351e9e
......@@ -36,7 +36,7 @@ Usage: python export_l2_torchscript.py runs/mexhat_gaps_boost40/model.pt [out.t
Also writes <out>.test_*.bin reference vectors (a T-step recurrence) for the C++ probe to verify
the native output against PyTorch. By Claude on 06/26/2026.
"""
import sys, struct, torch
import sys, struct, json, torch
import torch.nn as nn
from layer2 import Layer2Net
......@@ -119,6 +119,13 @@ def main():
print(f"wrote reference vectors: seq{tuple(seq.shape)} det{tuple(det_eager.shape)} "
f"vel{tuple(vel_eager.shape)} h{tuple(h_eager.shape)}")
# Model self-describes its params so native LibTorch (tp_dnn.cpp / CuasDnnLocal) reads ch_hidden
# (the L2 init param) from a bundled sidecar instead of hardcoding. By Claude on 06/26/2026.
meta = {"kind": "L2", "ch_hidden": int(ch_hidden), "vmax": float(vmax),
"grid": int(grid), "ch_in": 3}
open(out + ".meta.json", "w").write(json.dumps(meta))
print("wrote", out + ".meta.json", meta)
if __name__ == "__main__":
main()
......@@ -24,7 +24,7 @@ Usage: python export_torchscript.py runs/weighted9_pm_s/model.pt [out.ts.pt]
Also writes <out>.test_input.bin / <out>.test_output.bin (raw little-endian f32) reference
vectors for the C++ probe to verify the native output against PyTorch. By Claude on 06/27/2026.
"""
import sys, struct, torch
import sys, struct, json, torch
from model import RawFCN
ckpt = sys.argv[1]
......@@ -55,3 +55,10 @@ def _w(path, t):
_w(out + ".test_input.bin", x)
_w(out + ".test_output.bin", y)
print(f"wrote reference vectors: {out}.test_input.bin {tuple(x.shape)}, {out}.test_output.bin {tuple(y.shape)}")
# Model self-describes its params so native LibTorch (tp_dnn.cpp / CuasDnnLocal) reads them from a
# bundled sidecar instead of hardcoding (single source of truth). By Claude on 06/26/2026.
meta = {"kind": "L1", "N": kw["n_frames"], "P": kw["patch"], "vr": kw["vel_radius"],
"out_ch": int(m.out_ch), "velocity_mode": kw["velocity_mode"], "vmax": kw["vmax"]}
open(out + ".meta.json", "w").write(json.dumps(meta))
print("wrote", out + ".meta.json", meta)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment