Skip to content

Commit 740ec1d

Browse files
committed
Fix issues found in review
1 parent 420a180 commit 740ec1d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

fine_tune.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def fn_recursive_set_mem_eff(module: torch.nn.Module):
411411
loss = loss.mean() # mean over batch dimension
412412
else:
413413
loss = train_util.conditional_loss(
414-
args, noise_pred.float(), target.float(), timesteps, "none", noise_scheduler
414+
args, noise_pred.float(), target.float(), timesteps, "mean", noise_scheduler
415415
)
416416

417417
accelerator.backward(loss)

library/train_util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5829,8 +5829,8 @@ def save_sd_model_on_train_end_common(
58295829

58305830

58315831
def get_timesteps(min_timestep, max_timestep, b_size, device):
5832-
timesteps = torch.randint(min_timestep, max_timestep, (b_size,), device=device)
5833-
timesteps = timesteps.long()
5832+
timesteps = torch.randint(min_timestep, max_timestep, (b_size,), device="cpu")
5833+
timesteps = timesteps.long().to(device)
58345834
return timesteps
58355835

58365836

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

0 commit comments

Comments
 (0)