"""Flow-matching targets for the SS-flow LoRA: sparse-structure latents z_s sampled by the frozen SS flow from the ground-truth stimulus tokens (frame 24, default sampler settings, as in the oracle run), several seeds per object.""" import os import sys import argparse import numpy as np import torch sys.path.insert(0, "/home/hubin/trellis_work/TRELLIS.2") from trellis2.pipelines import Trellis2ImageTo3DPipeline from pca_tools import load_tokens, split_ids def main(): p = argparse.ArgumentParser() p.add_argument("--weights", default="/home/hubin/trellis_work/weights/TRELLIS.2-4B-merged") p.add_argument("--config_file", default="pipeline_local_512.json") p.add_argument("--out", default="/home/hubin/trellis_work/outputs/sslora/ss_targets.npz") p.add_argument("--n_seeds", type=int, default=2) p.add_argument("--shard", type=int, default=0) p.add_argument("--num_shards", type=int, default=1) args = p.parse_args() train_ids = split_ids()[0] pipe = Trellis2ImageTo3DPipeline.from_pretrained(args.weights, config_file=args.config_file) pipe.low_vram = False pipe.cuda() flow, dec = pipe.models["sparse_structure_flow_model"], pipe.models["sparse_structure_decoder"] z_all, n_vox = [], [] rows = list(range(args.shard, len(train_ids), args.num_shards)) for i in rows: obj = train_ids[i] cond = torch.from_numpy(load_tokens([obj])).float().cuda().expand(args.n_seeds, -1, -1) torch.manual_seed(i) noise = torch.randn(args.n_seeds, flow.in_channels, *[flow.resolution] * 3, device="cuda") with torch.no_grad(): z = pipe.sparse_structure_sampler.sample(flow, noise, cond=cond, neg_cond=torch.zeros_like(cond), **pipe.sparse_structure_sampler_params, verbose=False).samples n_vox.append((dec(z) > 0).flatten(1).sum(1).cpu().numpy()) z_all.append(z.half().cpu().numpy()) if i % 100 == 0: print(i, obj, n_vox[-1], flush=True) os.makedirs(os.path.dirname(args.out), exist_ok=True) np.savez(args.out, ids=np.array(train_ids), rows=np.array(rows), z=np.stack(z_all), n_vox=np.stack(n_vox)) print("DONE", np.stack(z_all).shape, flush=True) if __name__ == "__main__": main()