Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion examples/dreambooth/train_dreambooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ def parse_args(input_args=None):
),
)

parser.add_argument(
"--offset_noise",
action="store_true",
default=False,
help=(
"Fine-tuning against a modified noise"
" See: https://www.crosslabs.org//blog/diffusion-with-offset-noise for more information."
),
)

if input_args is not None:
args = parser.parse_args(input_args)
else:
Expand Down Expand Up @@ -943,7 +953,12 @@ def load_model_hook(models, input_dir):
latents = latents * vae.config.scaling_factor

# Sample noise that we'll add to the latents
noise = torch.randn_like(latents)
if args.offset_noise:
noise = torch.randn_like(latents) + 0.1 * torch.randn(
latents.shape[0], latents.shape[1], 1, 1, device=latents.device
)
else:
noise = torch.randn_like(latents)
bsz = latents.shape[0]
# Sample a random timestep for each image
timesteps = torch.randint(0, noise_scheduler.config.num_train_timesteps, (bsz,), device=latents.device)
Expand Down