mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-08 22:35:09 +00:00
Fix issues found in review
This commit is contained in:
@@ -411,7 +411,7 @@ def train(args):
|
|||||||
loss = loss.mean() # mean over batch dimension
|
loss = loss.mean() # mean over batch dimension
|
||||||
else:
|
else:
|
||||||
loss = train_util.conditional_loss(
|
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)
|
accelerator.backward(loss)
|
||||||
|
|||||||
@@ -5829,8 +5829,8 @@ def save_sd_model_on_train_end_common(
|
|||||||
|
|
||||||
|
|
||||||
def get_timesteps(min_timestep, max_timestep, b_size, device):
|
def get_timesteps(min_timestep, max_timestep, b_size, device):
|
||||||
timesteps = torch.randint(min_timestep, max_timestep, (b_size,), device=device)
|
timesteps = torch.randint(min_timestep, max_timestep, (b_size,), device="cpu")
|
||||||
timesteps = timesteps.long()
|
timesteps = timesteps.long().to(device)
|
||||||
return timesteps
|
return timesteps
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
alpha = -math.log(args.huber_c) / noise_scheduler.config.num_train_timesteps
|
||||||
result = torch.exp(-alpha * timesteps) * args.huber_scale
|
result = torch.exp(-alpha * timesteps) * args.huber_scale
|
||||||
elif args.huber_schedule == "snr":
|
elif args.huber_schedule == "snr":
|
||||||
if not hasattr(noise_scheduler, 'alphas_cumprod'):
|
if not hasattr(noise_scheduler, "alphas_cumprod"):
|
||||||
raise NotImplementedError(f"Huber schedule 'snr' is not supported with the current model.")
|
raise NotImplementedError("Huber schedule 'snr' is not supported with the current model.")
|
||||||
alphas_cumprod = torch.index_select(noise_scheduler.alphas_cumprod, 0, timesteps.cpu())
|
alphas_cumprod = torch.index_select(noise_scheduler.alphas_cumprod, 0, timesteps.cpu())
|
||||||
sigmas = ((1.0 - alphas_cumprod) / alphas_cumprod) ** 0.5
|
sigmas = ((1.0 - alphas_cumprod) / alphas_cumprod) ** 0.5
|
||||||
result = (1 - args.huber_c) / (1 + sigmas) ** 2 + args.huber_c
|
result = (1 - args.huber_c) / (1 + sigmas) ** 2 + args.huber_c
|
||||||
|
|||||||
Reference in New Issue
Block a user