ACloudCenter commited on
Commit
ceacaca
·
verified ·
1 Parent(s): 90cced7

fix sem_conn_all undefined-name bug

Browse files
Files changed (1) hide show
  1. diag.py +11 -9
diag.py CHANGED
@@ -4,7 +4,7 @@ Variants (head-only overfits, one fixed batch, per-frame-mean loss, lr 2e-4):
4
  B cond = frozen connect features of the target frames
5
  C cond = LLM hidden states (real pathway)
6
  D cond = hidden states with voice slots acoustic-only (inference-style _process_speech_inputs)
7
- Plus: initial per-element loss bucketed by timestep range; then a 30-step full overfit (C).
8
  """
9
  import io, math, random, sys
10
  sys.path.insert(0, "/VibeVoice-classic")
@@ -43,9 +43,11 @@ def load_dialogues(shard_idx, min_turns=4, max_turns=10, min_sec=20.0, max_sec=6
43
  try:
44
  wav, sr = sf.read(io.BytesIO(auds[i]["bytes"]))
45
  except Exception:
46
- ok = False; break
 
47
  if sr != SR or wav.ndim > 1:
48
- ok = False; break
 
49
  turns.append((1 + int(spks[i]), texts[i], wav.astype(np.float32)))
50
  if not ok:
51
  continue
@@ -76,7 +78,7 @@ def build_sample(model, proc, tok, dialogue, refs, turn_sec_cap, gap_sec=0.45):
76
  voice_masks = out["speech_masks"].cpu().numpy().astype(bool)
77
  n_voice = voice_np.shape[0]
78
  with torch.no_grad():
79
- _enc = model.model.acoustic_tokenizer.encode(torch.from_numpy(target := np.concatenate(parts)).float()[None, None, :])
80
  t_lat, _ = _enc.sample("fix")
81
  T_t = t_lat.shape[1]
82
  lat_segs = []
@@ -125,7 +127,8 @@ def build_sample(model, proc, tok, dialogue, refs, turn_sec_cap, gap_sec=0.45):
125
  "sems": torch.from_numpy(sems),
126
  }
127
 
128
- random.seed(0); torch.manual_seed(0)
 
129
  model = VibeVoiceForConditionalGeneration.from_pretrained(
130
  MODEL, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True).to(device).eval()
131
  proc = VibeVoiceProcessor.from_pretrained(MODEL)
@@ -193,16 +196,15 @@ def overfit(name, cond, steps=10):
193
  model.model.prediction_head.load_state_dict(head0)
194
 
195
  overfit("A cond = clean latent x0 (cheat)", x0r)
196
- conn_all = conn[smask] + sem_conn_all if (sem_conn := model.model.semantic_connector(b["sems"].to(device).type_as(x))) is not None else conn[smask]
197
  conn_t = conn_all[-N:]
198
  overfit("B cond = target connect feats", conn_t.repeat_interleave(mul, 0))
199
  overfit("C cond = LLM hidden states", condr)
200
  # D: inference-style — voice slots get acoustic-only connect features
201
  with torch.no_grad():
202
  xe_d = x.clone()
203
- xe_d[b["in_mask"].unsqueeze(0).to(device)] = torch.cat([conn[smask], sem_conn[smask]], 0) * 0
204
- xe_d[b["in_mask"].unsqueeze(0).to(device)] = torch.cat([
205
- conn[smask], conn[smask][-N:] + sem_conn[smask][-N:]], 0)
206
  hidden_d = model.model.language_model(
207
  inputs_embeds=xe_d, attention_mask=torch.ones(1, L, device=device), use_cache=False).last_hidden_state
208
  cond_d = hidden_d[b["lo_mask"].unsqueeze(0).to(device)].repeat_interleave(mul, 0)
 
4
  B cond = frozen connect features of the target frames
5
  C cond = LLM hidden states (real pathway)
6
  D cond = hidden states with voice slots acoustic-only (inference-style _process_speech_inputs)
7
+ Plus: initial per-element loss bucketed by timestep range.
8
  """
9
  import io, math, random, sys
10
  sys.path.insert(0, "/VibeVoice-classic")
 
43
  try:
44
  wav, sr = sf.read(io.BytesIO(auds[i]["bytes"]))
45
  except Exception:
46
+ ok = False
47
+ break
48
  if sr != SR or wav.ndim > 1:
49
+ ok = False
50
+ break
51
  turns.append((1 + int(spks[i]), texts[i], wav.astype(np.float32)))
52
  if not ok:
53
  continue
 
78
  voice_masks = out["speech_masks"].cpu().numpy().astype(bool)
79
  n_voice = voice_np.shape[0]
80
  with torch.no_grad():
81
+ _enc = model.model.acoustic_tokenizer.encode(torch.from_numpy(target).float()[None, None, :])
82
  t_lat, _ = _enc.sample("fix")
83
  T_t = t_lat.shape[1]
84
  lat_segs = []
 
127
  "sems": torch.from_numpy(sems),
128
  }
129
 
130
+ random.seed(0)
131
+ torch.manual_seed(0)
132
  model = VibeVoiceForConditionalGeneration.from_pretrained(
133
  MODEL, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True).to(device).eval()
134
  proc = VibeVoiceProcessor.from_pretrained(MODEL)
 
196
  model.model.prediction_head.load_state_dict(head0)
197
 
198
  overfit("A cond = clean latent x0 (cheat)", x0r)
199
+ conn_all = conn[smask] + sem_conn[smask]
200
  conn_t = conn_all[-N:]
201
  overfit("B cond = target connect feats", conn_t.repeat_interleave(mul, 0))
202
  overfit("C cond = LLM hidden states", condr)
203
  # D: inference-style — voice slots get acoustic-only connect features
204
  with torch.no_grad():
205
  xe_d = x.clone()
206
+ voice_rows = b["in_mask"].sum() - N
207
+ xe_d[b["in_mask"].unsqueeze(0).to(device)] = torch.cat([conn[smask][:-N], conn_all[-N:]], 0)
 
208
  hidden_d = model.model.language_model(
209
  inputs_embeds=xe_d, attention_mask=torch.ones(1, L, device=device), use_cache=False).last_hidden_state
210
  cond_d = hidden_d[b["lo_mask"].unsqueeze(0).to(device)].repeat_interleave(mul, 0)