ar_generate: sample under no_grad, detach latents (fixes leak)
Browse files- kaggle/train_voices.py +5 -2
kaggle/train_voices.py
CHANGED
|
@@ -310,8 +310,11 @@ def ar_generate(mm, dit, n_steps, text, task_prompt, prompt_latent, prompt_text,
|
|
| 310 |
past = hidden.past_key_values
|
| 311 |
z = hidden.hidden_states[-1][:, -1:, :]
|
| 312 |
noise = torch.randn(1, 1, mm.latent_dim, device=device, dtype=dtype)
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
| 315 |
inputs_embeds = mm.linear_proj_audio(latent)
|
| 316 |
position_ids = position_ids[:, -1:] + 1
|
| 317 |
attention_mask = torch.ones(inputs_embeds.shape[0], 1, device=device)
|
|
|
|
| 310 |
past = hidden.past_key_values
|
| 311 |
z = hidden.hidden_states[-1][:, -1:, :]
|
| 312 |
noise = torch.randn(1, 1, mm.latent_dim, device=device, dtype=dtype)
|
| 313 |
+
# no_grad matters: the DiT params require grad, so an unguarded sample
|
| 314 |
+
# builds a graph per frame that stays alive through `hist`.
|
| 315 |
+
with torch.no_grad():
|
| 316 |
+
latent = sample_latent(dit, z, hist, noise, n_steps).to(device=device, dtype=dtype)
|
| 317 |
+
out.append(latent.detach())
|
| 318 |
inputs_embeds = mm.linear_proj_audio(latent)
|
| 319 |
position_ids = position_ids[:, -1:] + 1
|
| 320 |
attention_mask = torch.ones(inputs_embeds.shape[0], 1, device=device)
|