#!/usr/bin/env python3 """Reference dumps for the shape-SLAT stage ("512" pipeline type, geometry only). Produces dumps/reference_slat.gguf with: coords [L, 4] f32 active voxels at 32^3 (from the SS stage) slat_noise [L, 32] fixed sampling noise (seed 4321) flow_t500_out [L, 32] SLAT flow forward at t=500 (f32) slat [L, 32] full 12-step sampler output, denormalized slat_mean/std [32] shape_slat_normalization lvl{i}.in_coords [L_i, 4] decoder level i active voxels lvl{i}.pre_up [L_i, C_i] features after level i's ConvNeXt blocks lvl{i}.subdiv [L_i, 8] subdivision logits of level i's up-block out7 [L_4, 7] decoder output (pre split/sigmoid) out_coords [L_4, 4] The coords come from decoding tests/ss_sample_ref.bin's reference latent, so the same scaffold is reproducible from the validated C++ SS stages. Run inside the container: see scripts/refgen.sh. """ import argparse import json import os import struct import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import ref_common # noqa: E402 ref_common.setup() # sdpa sparse attention + pure-torch sparse conv import numpy as np # noqa: E402 import torch # noqa: E402 import torch.nn.functional as F # noqa: E402 def load_ss_sample_latent(path): """Read the z_s reference produced by tests/ref_ss_sample.py (SSSAMP01).""" with open(path, "rb") as f: assert f.read(8) == b"SSSAMP01", "bad magic" R, cin, lkv, cctx, steps = struct.unpack("<5i", f.read(20)) f.read(4 * 3) # gs, rescale, rescale_t f.read(8) # seed n = cin * R * R * R f.seek(-(n * 4), os.SEEK_END) z = np.frombuffer(f.read(n * 4), dtype=" 0 # [1,1,64,64,64] occ = (F.max_pool3d(occ.float(), 2, 2, 0) > 0.5) # ss_res 32 coords = torch.argwhere(occ)[:, [0, 2, 3, 4]].int().contiguous() L = coords.shape[0] print(f"coords: {L} active voxels at 32^3 " f"({100.0 * L / 32**3:.2f}% occupancy)") caps["coords"] = coords.float() del ss_dec # ── conditioning ───────────────────────────────────────────────────────── with open(args.dinodata, "rb") as f: assert f.read(8) == b"DINOCOND" _, _, ndim = struct.unpack(" 0).float().mean().item():.4f}") import gguf writer = gguf.GGUFWriter(args.out, "reference") manifest = {"shapes": {}, "atol": 2e-3, "rtol": 2e-3} for name, t in caps.items(): a = t.detach().cpu().float().numpy() manifest["shapes"][name] = list(a.shape) writer.add_tensor(name, np.ascontiguousarray(a.reshape(-1), dtype=np.float32)) writer.write_header_to_file() writer.write_kv_data_to_file() writer.write_tensors_to_file() writer.close() with open(os.path.join(ref_common.DUMPS, "manifest_slat.json"), "w") as f: json.dump(manifest, f, indent=1) print(f"wrote {args.out} ({os.path.getsize(args.out):,} bytes), {len(caps)} tensors") if __name__ == "__main__": main()