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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""eval_joint2.py v2.0 — closed-loop eval of the POLISHED joint model (epoch2/checkpoint-900/lora).
|
| 2 |
+
Standalone: no runtime patching; adapter path baked to ground-truth layout (verified via repo ls).
|
| 3 |
+
Baked fixes: shutil.copyfile download (HF cache = relative symlinks), isfile asserts after copy,
|
| 4 |
+
Whisper return_timestamps, safe drift aggregation, demo-exact generate.
|
| 5 |
+
Env: ARMS (default "joint2"). Pushes to ACloudCenter/vibevoice-eval-jointv1. Prints EVAL DONE.
|
| 6 |
+
"""
|
| 7 |
+
VERSION = "eval_joint2.py v2.0 (SUB=epoch2/checkpoint-900/lora)"
|
| 8 |
+
import importlib.util, json, os, shutil, sys, time
|
| 9 |
+
sys.path.insert(0, "/VibeVoice-classic")
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import soundfile as sf
|
| 13 |
+
import torch
|
| 14 |
+
import jiwer
|
| 15 |
+
from huggingface_hub import hf_hub_download, HfApi
|
| 16 |
+
from resemblyzer import VoiceEncoder, preprocess_wav
|
| 17 |
+
|
| 18 |
+
from vibevoice.modular.modeling_vibevoice_inference import VibeVoiceForConditionalGenerationInference
|
| 19 |
+
from vibevoice.processor.vibevoice_processor import VibeVoiceProcessor
|
| 20 |
+
|
| 21 |
+
_spec = importlib.util.spec_from_file_location(
|
| 22 |
+
"vibevoice.modular.lora_loading", "/vv-main/vibevoice/modular/lora_loading.py")
|
| 23 |
+
assert _spec is not None and _spec.loader is not None, "lora_loading.py not found at /vv-main"
|
| 24 |
+
lora_loading = importlib.util.module_from_spec(_spec)
|
| 25 |
+
sys.modules[_spec.name] = lora_loading
|
| 26 |
+
_spec.loader.exec_module(lora_loading)
|
| 27 |
+
load_lora_assets = lora_loading.load_lora_assets
|
| 28 |
+
|
| 29 |
+
MODEL = "microsoft/VibeVoice-1.5B"
|
| 30 |
+
ADAPTER_REPO = "ACloudCenter/vibevoice-lora-joint"
|
| 31 |
+
ADAPTER_SUB = "epoch2/checkpoint-900/lora"
|
| 32 |
+
OUT_REPO = "ACloudCenter/vibevoice-eval-jointv1"
|
| 33 |
+
SR = 24000
|
| 34 |
+
device = "cuda"
|
| 35 |
+
ARMS = [a.strip() for a in os.environ.get("ARMS", "joint2").split(",")]
|
| 36 |
+
|
| 37 |
+
SHORTS = [
|
| 38 |
+
"Speaker 1: Did you see the meteor shower last night?\nSpeaker 2: I missed it! Was it worth staying up for?\nSpeaker 1: Absolutely. The sky lit up green for a full minute.\nSpeaker 2: Okay, now I'm actually upset I slept through it.",
|
| 39 |
+
"Speaker 1: The bread machine finally arrived.\nSpeaker 2: So you're a baker now?\nSpeaker 1: I'm a disaster with a bread machine. The first loaf came out like a brick.\nSpeaker 2: Send me a photo. Immediately.",
|
| 40 |
+
"Speaker 1: My flight lands at six, so don't wait for dinner.\nSpeaker 2: I'll keep something warm anyway.\nSpeaker 1: You really don't have to.\nSpeaker 2: I know. That's why I'm doing it.",
|
| 41 |
+
]
|
| 42 |
+
MEDIUMS = [
|
| 43 |
+
"Speaker 1: I've been reading about how old lighthouse keepers kept journals.\nSpeaker 2: What did they write about?\nSpeaker 1: Mostly weather, ships passing, and how lonely it was.\nSpeaker 2: That sounds peaceful and terrible at the same time.\nSpeaker 1: One keeper wrote that the light was his only conversation for months.\nSpeaker 2: Honestly, that might fix my screen time problem.\nSpeaker 1: Or break you completely. There was no off switch on the ocean.",
|
| 44 |
+
"Speaker 1: The city is redoing the bike lane on Fifth Street.\nSpeaker 2: Finally. That stretch is dangerous.\nSpeaker 1: They're adding a physical barrier between cars and cyclists.\nSpeaker 2: About time. I've almost been clipped twice this month.\nSpeaker 1: Construction starts Monday, so expect detours.\nSpeaker 2: Worth it if it means I stop white-knuckling my handlebars.",
|
| 45 |
+
"Speaker 1: My grandmother used to make bread every Sunday morning.\nSpeaker 2: Sourdough?\nSpeaker 1: A dense rye. She said the recipe came from her grandmother.\nSpeaker 2: Four generations of the same loaf.\nSpeaker 1: I still have her mixing bowl. It's older than the house.\nSpeaker 2: That bowl has earned a museum display.",
|
| 46 |
+
]
|
| 47 |
+
LONGS = [
|
| 48 |
+
"Speaker 1: Let's talk about sleep. Everyone says eight hours, but nobody agrees on anything else.\nSpeaker 2: Right, and half the advice contradicts the other half.\nSpeaker 1: Some people swear by cold rooms. Others say the temperature barely matters.\nSpeaker 2: The one thing that's consistent is the schedule. Same bedtime, same wake time.\nSpeaker 1: Even on weekends, which is where everyone cheats.\nSpeaker 2: That's exactly where I cheat.\nSpeaker 1: The researchers say your body doesn't know it's Saturday.\nSpeaker 2: My body absolutely knows it's Saturday.\nSpeaker 1: Apparently not, biologically speaking.\nSpeaker 2: Fine, I'll set an alarm for Sunday too. This conversation is costing me my weekend.\nSpeaker 1: Sleep hygiene comes with sacrifices.\nSpeaker 2: Don't lecture me at nine on a Sunday morning.",
|
| 49 |
+
"Speaker 1: The bakery on the corner closed last week.\nSpeaker 2: No! That place had the best almond croissants in the city.\nSpeaker 1: Rent tripled. The owner said she couldn't make the numbers work anymore.\nSpeaker 2: Where does a neighborhood bakery even go from there?\nSpeaker 1: She's moving production to a shared kitchen across the river and doing delivery only.\nSpeaker 2: So no more counter, no more coffee, just a website?\nSpeaker 1: Just a website. She seemed okay about it, which surprised me.\nSpeaker 2: Thirty years behind that counter and she seemed okay?\nSpeaker 1: Maybe she's more practical than sentimental.\nSpeaker 2: I'm going to miss walking past that smell every morning.\nSpeaker 1: Delivery still smells. It just doesn't linger.",
|
| 50 |
+
"Speaker 1: I finally fixed the shed door.\nSpeaker 2: The one that's been hanging crooked since spring?\nSpeaker 1: Since spring. The hinges were stripped, not the frame, which saved me a full rebuild.\nSpeaker 2: How long did that take?\nSpeaker 1: Four hours, two of which were finding screws that actually fit.\nSpeaker 2: The hardware store run is always the real project.\nSpeaker 1: Two trips. One for the wrong screws, one for the right ones.\nSpeaker 2: Classic. Did you paint it?\nSpeaker 1: Not yet. The wood needs to dry out first, apparently.\nSpeaker 2: So the project continues.\nSpeaker 1: The project continues. But the door closes now, which is more than March could say.",
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def download_adapter(dest="/adapter"):
|
| 55 |
+
api = HfApi()
|
| 56 |
+
files = [f for f in api.list_repo_files(ADAPTER_REPO) if f.startswith(ADAPTER_SUB + "/")]
|
| 57 |
+
assert len(files) >= 4, f"adapter files not found under {ADAPTER_SUB}: {files}"
|
| 58 |
+
for f in files:
|
| 59 |
+
local = hf_hub_download(ADAPTER_REPO, f)
|
| 60 |
+
name = f[len(ADAPTER_SUB) + 1:]
|
| 61 |
+
op = os.path.join(dest, name)
|
| 62 |
+
os.makedirs(os.path.dirname(op), exist_ok=True)
|
| 63 |
+
shutil.copyfile(local, op) # HF cache paths are relative symlinks — copy content, never move
|
| 64 |
+
assert os.path.isfile(op) and os.path.getsize(op) > 0, f"copy failed for {name}"
|
| 65 |
+
listing = sorted(os.listdir(dest))
|
| 66 |
+
print(f"ADAPTER OK: {listing}", flush=True)
|
| 67 |
+
for must in ("adapter_config.json", "adapter_model.safetensors", "diffusion_head_full.bin"):
|
| 68 |
+
assert os.path.isfile(os.path.join(dest, must)), f"dangling or missing: {must}"
|
| 69 |
+
return dest
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def load_model(arm):
|
| 73 |
+
model = VibeVoiceForConditionalGenerationInference.from_pretrained(
|
| 74 |
+
MODEL, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True,
|
| 75 |
+
attn_implementation="sdpa").to(device).eval()
|
| 76 |
+
if arm == "joint2":
|
| 77 |
+
report = load_lora_assets(model, "/adapter")
|
| 78 |
+
loaded = [n for n, ok in (("language_model", report.language_model),
|
| 79 |
+
("diffusion_head_lora", report.diffusion_head_lora),
|
| 80 |
+
("diffusion_head_full", report.diffusion_head_full),
|
| 81 |
+
("acoustic_connector", report.acoustic_connector),
|
| 82 |
+
("semantic_connector", report.semantic_connector)) if ok]
|
| 83 |
+
print(f"JOINT2 LOADED: {loaded}", flush=True)
|
| 84 |
+
assert "language_model" in loaded and "diffusion_head_full" in loaded, loaded
|
| 85 |
+
return model
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def gt_text(script):
|
| 89 |
+
return " ".join(line.split(": ", 1)[1].strip() for line in script.strip().splitlines())
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
api = HfApi()
|
| 94 |
+
print(VERSION, flush=True)
|
| 95 |
+
download_adapter()
|
| 96 |
+
scripts = ([("short", i, t) for i, t in enumerate(SHORTS)]
|
| 97 |
+
+ [("medium", i, t) for i, t in enumerate(MEDIUMS)]
|
| 98 |
+
+ [("long", i, t) for i, t in enumerate(LONGS)])
|
| 99 |
+
|
| 100 |
+
os.makedirs("/ref", exist_ok=True)
|
| 101 |
+
ref_wavs = {}
|
| 102 |
+
for spk, name in ((1, "en-Carter_man.wav"), (2, "en-Maya_woman.wav")):
|
| 103 |
+
wav, sr = sf.read(f"/VibeVoice-classic/demo/voices/{name}")
|
| 104 |
+
assert sr == SR
|
| 105 |
+
ref_wavs[spk] = wav.astype(np.float32)
|
| 106 |
+
sf.write(f"/ref/s{spk}.wav", ref_wavs[spk], SR)
|
| 107 |
+
ref_paths = {spk: f"/ref/s{spk}.wav" for spk in (1, 2)}
|
| 108 |
+
|
| 109 |
+
proc = VibeVoiceProcessor.from_pretrained(MODEL)
|
| 110 |
+
from transformers import pipeline
|
| 111 |
+
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3",
|
| 112 |
+
device=device, torch_dtype=torch.float16)
|
| 113 |
+
encoder = VoiceEncoder(device)
|
| 114 |
+
ref_wav = np.concatenate([ref_wavs[1], np.zeros(SR // 4, dtype=np.float32), ref_wavs[2]])
|
| 115 |
+
emb_ref = encoder.embed_utterance(preprocess_wav(ref_wav, SR))
|
| 116 |
+
|
| 117 |
+
results = []
|
| 118 |
+
os.makedirs("/out", exist_ok=True)
|
| 119 |
+
for arm in ARMS:
|
| 120 |
+
print(f"=== ARM {arm} ===", flush=True)
|
| 121 |
+
model = load_model(arm)
|
| 122 |
+
model.set_ddpm_inference_steps(num_steps=10)
|
| 123 |
+
for tier, idx, script in scripts:
|
| 124 |
+
t0 = time.time()
|
| 125 |
+
with torch.no_grad():
|
| 126 |
+
inputs = proc(text=[script], voice_samples=[[ref_paths[1], ref_paths[2]]],
|
| 127 |
+
padding=True, return_tensors="pt", return_attention_mask=True)
|
| 128 |
+
out = model.generate(
|
| 129 |
+
**inputs, max_new_tokens=None, cfg_scale=1.3,
|
| 130 |
+
tokenizer=proc.tokenizer, generation_config={"do_sample": False})
|
| 131 |
+
gen_s = time.time() - t0
|
| 132 |
+
fn = f"{arm}_{tier}_{idx}.wav"
|
| 133 |
+
proc.save_audio(out.speech_outputs[0], output_path=f"/out/{fn}")
|
| 134 |
+
wav = sf.read(f"/out/{fn}", dtype="float32")[0]
|
| 135 |
+
wav = np.asarray(wav, dtype=np.float32)
|
| 136 |
+
audio_s = len(wav) / SR
|
| 137 |
+
rtf = gen_s / max(audio_s, 1e-6)
|
| 138 |
+
hyp = transcriber(f"/out/{fn}", generate_kwargs={"language": "english"},
|
| 139 |
+
return_timestamps=True)["text"].strip()
|
| 140 |
+
gt = gt_text(script)
|
| 141 |
+
wer = float(jiwer.wer(gt, hyp))
|
| 142 |
+
emb_gen = encoder.embed_utterance(preprocess_wav(f"/out/{fn}"))
|
| 143 |
+
sim = float(np.dot(emb_gen, emb_ref) / (np.linalg.norm(emb_gen) * np.linalg.norm(emb_ref)))
|
| 144 |
+
drift = None
|
| 145 |
+
if tier == "long" and audio_s > 60:
|
| 146 |
+
e1 = encoder.embed_utterance(preprocess_wav(wav[: 30 * SR], SR))
|
| 147 |
+
e2 = encoder.embed_utterance(preprocess_wav(wav[-30 * SR:], SR))
|
| 148 |
+
n = np.linalg.norm(e1) * np.linalg.norm(e2)
|
| 149 |
+
drift = float(np.dot(e1, e2) / n) if n > 0 else None
|
| 150 |
+
results.append({"arm": arm, "tier": tier, "idx": idx, "audio_s": round(audio_s, 1),
|
| 151 |
+
"rtf": round(rtf, 3), "wer": round(wer, 3), "sim": round(sim, 3),
|
| 152 |
+
"drift": round(drift, 3) if drift is not None else None})
|
| 153 |
+
api.upload_file(path_or_fileobj=f"/out/{fn}", path_in_repo=fn, repo_id=OUT_REPO)
|
| 154 |
+
print(f"{arm} {tier}{idx}: rtf {rtf:.3f} wer {wer:.3f} sim {sim:.3f} "
|
| 155 |
+
f"dur {audio_s:.1f}s drift {drift}", flush=True)
|
| 156 |
+
del model
|
| 157 |
+
torch.cuda.empty_cache()
|
| 158 |
+
|
| 159 |
+
import statistics as stat
|
| 160 |
+
def agg(arm, key):
|
| 161 |
+
vals = [r[key] for r in results if r["arm"] == arm and r[key] is not None]
|
| 162 |
+
return round(stat.mean(vals), 3) if vals else None
|
| 163 |
+
summary = {arm: {"wer": agg(arm, "wer"), "sim": agg(arm, "sim"),
|
| 164 |
+
"rtf": agg(arm, "rtf"), "drift": agg(arm, "drift")} for arm in ARMS}
|
| 165 |
+
blob = {"summary": summary, "results": results}
|
| 166 |
+
with open("/out/results_joint2.json", "w") as f:
|
| 167 |
+
json.dump(blob, f, indent=1)
|
| 168 |
+
api.upload_file(path_or_fileobj="/out/results_joint2.json", path_in_repo="results_joint2.json", repo_id=OUT_REPO)
|
| 169 |
+
print("SUMMARY:", json.dumps(summary), flush=True)
|
| 170 |
+
print("EVAL DONE", flush=True)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
if __name__ == "__main__":
|
| 174 |
+
main()
|