Skip to content

Commit

Permalink
performance: check for nans in unet only once, after all steps have b…
Browse files Browse the repository at this point in the history
…een completed
  • Loading branch information
AUTOMATIC1111 authored and pull[bot] committed Jun 12, 2024
1 parent ea5e5a4 commit 9f38baf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 5 additions & 0 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,9 @@ class DecodedSamples(list):
def decode_latent_batch(model, batch, target_device=None, check_for_nans=False):
samples = DecodedSamples()

if check_for_nans:
devices.test_for_nans(batch, "unet")

for i in range(batch.shape[0]):
sample = decode_first_stage(model, batch[i:i + 1])[0]

Expand Down Expand Up @@ -987,6 +990,8 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
if getattr(samples_ddim, 'already_decoded', False):
x_samples_ddim = samples_ddim
else:
devices.test_for_nans(samples_ddim, "unet")

if opts.sd_vae_decode_method != 'Full':
p.extra_generation_params['VAE Decoder'] = opts.sd_vae_decode_method
x_samples_ddim = decode_latent_batch(p.sd_model, samples_ddim, target_device=devices.cpu, check_for_nans=True)
Expand Down
2 changes: 0 additions & 2 deletions modules/sd_samplers_cfg_denoiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ def apply_blend(current_latent):
denoised_params = CFGDenoisedParams(x_out, state.sampling_step, state.sampling_steps, self.inner_model)
cfg_denoised_callback(denoised_params)

devices.test_for_nans(x_out, "unet")

if is_edit_model:
denoised = self.combine_denoised_for_edit_model(x_out, cond_scale)
elif skip_uncond:
Expand Down

0 comments on commit 9f38baf

Please sign in to comment.