Skip to content

Commit

Permalink
Fix issues found in review
Browse files Browse the repository at this point in the history
  • Loading branch information
recris committed Nov 28, 2024
1 parent 420a180 commit 740ec1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fine_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def fn_recursive_set_mem_eff(module: torch.nn.Module):
loss = loss.mean() # mean over batch dimension
else:
loss = train_util.conditional_loss(
args, noise_pred.float(), target.float(), timesteps, "none", noise_scheduler
args, noise_pred.float(), target.float(), timesteps, "mean", noise_scheduler
)

accelerator.backward(loss)
Expand Down
8 changes: 4 additions & 4 deletions library/train_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5829,8 +5829,8 @@ def save_sd_model_on_train_end_common(


def get_timesteps(min_timestep, max_timestep, b_size, device):
timesteps = torch.randint(min_timestep, max_timestep, (b_size,), device=device)
timesteps = timesteps.long()
timesteps = torch.randint(min_timestep, max_timestep, (b_size,), device="cpu")
timesteps = timesteps.long().to(device)
return timesteps


Expand Down Expand Up @@ -5875,8 +5875,8 @@ def get_huber_threshold(args, timesteps: torch.Tensor, noise_scheduler) -> torch
alpha = -math.log(args.huber_c) / noise_scheduler.config.num_train_timesteps
result = torch.exp(-alpha * timesteps) * args.huber_scale
elif args.huber_schedule == "snr":
if not hasattr(noise_scheduler, 'alphas_cumprod'):
raise NotImplementedError(f"Huber schedule 'snr' is not supported with the current model.")
if not hasattr(noise_scheduler, "alphas_cumprod"):
raise NotImplementedError("Huber schedule 'snr' is not supported with the current model.")
alphas_cumprod = torch.index_select(noise_scheduler.alphas_cumprod, 0, timesteps.cpu())
sigmas = ((1.0 - alphas_cumprod) / alphas_cumprod) ** 0.5
result = (1 - args.huber_c) / (1 + sigmas) ** 2 + args.huber_c
Expand Down

0 comments on commit 740ec1d

Please sign in to comment.