# yue2_oracle_dump.py - reference-stage dumps for the native YuE2 port.
#
# Dev tool only (like music3_oracle_dump.py): it runs the official yue2
# package once, in an isolated venv on the CUDA dev node, and writes raw
# little-endian tensors + meta.json that the native port compares against
# (`yue2_render --check
`). Nothing in the product imports or runs it.
#
# Usage (node 165):
# ~/ref/yue2-venv/bin/python yue2_oracle_dump.py \
# --model-dir ~/.makepad/weights/music/YuE2-3B \
# --vae-dir ~/.makepad/weights/music/YuE2-Vae \
# --fixture ~/.makepad/weights/music/YuE2-3B/examples/tonight-awake.json \
# --out-dir ~/ref/yue2_oracle/tonight-awake
#
# Files (all little-endian, shapes in meta.json):
# prefix_abc.i32 ABC-stage prefix ids (tokenizer check)
# tok_.i32 tokenizer fixtures (style, lyrics, abc text)
# abc_prefill_logits.f32 [vocab] last-position logits of the ABC prefix
# greedy_abc.i32 temperature-0 ABC ids (eager, no CUDA graph)
# abc.i32 / abc.txt sampled ABC ids + decoded score (release path)
# semantic.i32 sampled codec ids (0..32768, offset removed)
# tf_abc_logits.f32 [n, 151649] teacher-forced logits, ABC phase rows 0..ABC_END
# tf_sem_logits.f32 [n, 32769] teacher-forced logits, rows MUSIC_END..codec end
# nar_noise.f32 / nar_v0.f32 / nar_vmid.f32 chunk-0 noise, velocity at t=1, at the first midpoint
# latents.f32 [frames, 64] final ODE state (release path)
# audio.f32 / audio.wav [samples, 2] VAE decode of latents.f32
import argparse
import json
import os
import struct
import sys
import time
import wave
os.environ.setdefault("HF_HUB_OFFLINE", "1")
os.environ.setdefault("TRANSFORMERS_OFFLINE", "1")
os.environ.setdefault("HF_HUB_DISABLE_TELEMETRY", "1")
TF_ABC_ROWS = 64
TF_SEM_ROWS = 256
def save(out_dir, name, array, meta):
import numpy as np
array = np.ascontiguousarray(array)
if array.dtype.kind == "f":
array = array.astype("