Skip to content

Commit 1051f21

Browse files
gameofdimensionsayakpaulyiyixuxu
committed
[bugfix] reduce float value error when adding noise (#9004)
* Update train_controlnet.py reduce float value error for bfloat16 * Update train_controlnet_sdxl.py * style --------- Co-authored-by: Sayak Paul <[email protected]> Co-authored-by: yiyixuxu <[email protected]>
1 parent 0e1e923 commit 1051f21

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

examples/controlnet/train_controlnet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,9 @@ def load_model_hook(models, input_dir):
10481048

10491049
# Add noise to the latents according to the noise magnitude at each timestep
10501050
# (this is the forward diffusion process)
1051-
noisy_latents = noise_scheduler.add_noise(latents, noise, timesteps)
1051+
noisy_latents = noise_scheduler.add_noise(latents.float(), noise.float(), timesteps).to(
1052+
dtype=weight_dtype
1053+
)
10521054

10531055
# Get the text embedding for conditioning
10541056
encoder_hidden_states = text_encoder(batch["input_ids"], return_dict=False)[0]

examples/controlnet/train_controlnet_sdxl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,9 @@ def compute_embeddings(batch, proportion_empty_prompts, text_encoders, tokenizer
12101210

12111211
# Add noise to the latents according to the noise magnitude at each timestep
12121212
# (this is the forward diffusion process)
1213-
noisy_latents = noise_scheduler.add_noise(latents, noise, timesteps)
1213+
noisy_latents = noise_scheduler.add_noise(latents.float(), noise.float(), timesteps).to(
1214+
dtype=weight_dtype
1215+
)
12141216

12151217
# ControlNet conditioning.
12161218
controlnet_image = batch["conditioning_pixel_values"].to(dtype=weight_dtype)

0 commit comments

Comments
 (0)