mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-09 06:45:09 +00:00
format by black
This commit is contained in:
@@ -12,14 +12,26 @@ def apply_snr_weight(loss, timesteps, noise_scheduler, gamma):
|
|||||||
sigma = sqrt_one_minus_alphas_cumprod
|
sigma = sqrt_one_minus_alphas_cumprod
|
||||||
all_snr = (alpha / sigma) ** 2
|
all_snr = (alpha / sigma) ** 2
|
||||||
snr = torch.stack([all_snr[t] for t in timesteps])
|
snr = torch.stack([all_snr[t] for t in timesteps])
|
||||||
gamma_over_snr = torch.div(torch.ones_like(snr)*gamma,snr)
|
gamma_over_snr = torch.div(torch.ones_like(snr) * gamma, snr)
|
||||||
snr_weight = torch.minimum(gamma_over_snr,torch.ones_like(gamma_over_snr)).float() #from paper
|
snr_weight = torch.minimum(gamma_over_snr, torch.ones_like(gamma_over_snr)).float() # from paper
|
||||||
loss = loss * snr_weight
|
loss = loss * snr_weight
|
||||||
return loss
|
return loss
|
||||||
|
|
||||||
|
|
||||||
def add_custom_train_arguments(parser: argparse.ArgumentParser):
|
def add_custom_train_arguments(parser: argparse.ArgumentParser):
|
||||||
parser.add_argument("--min_snr_gamma", type=float, default=None, help="gamma for reducing the weight of high loss timesteps. Lower numbers have stronger effect. 5 is recommended by paper. / 低いタイムステップでの高いlossに対して重みを減らすためのgamma値、低いほど効果が強く、論文では5が推奨")
|
parser.add_argument(
|
||||||
parser.add_argument("--weighted_captions", action="store_true", default=False, help="Enable weighted captions in the standard style (token:1.3). No commas inside parens, or shuffle/dropout may break the decoder.")
|
"--min_snr_gamma",
|
||||||
|
type=float,
|
||||||
|
default=None,
|
||||||
|
help="gamma for reducing the weight of high loss timesteps. Lower numbers have stronger effect. 5 is recommended by paper. / 低いタイムステップでの高いlossに対して重みを減らすためのgamma値、低いほど効果が強く、論文では5が推奨",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--weighted_captions",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Enable weighted captions in the standard style (token:1.3). No commas inside parens, or shuffle/dropout may break the decoder.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
re_attention = re.compile(
|
re_attention = re.compile(
|
||||||
r"""
|
r"""
|
||||||
|
|||||||
Reference in New Issue
Block a user