Bug?

#4
by thomwatk - opened

It threw an error, and I am 50/50 on the source of the error. However "UnboundLocalError: local variable 'noise_pred_uncond' referenced before assignment" came from pipeline_stable_diffusion_upscale.py. Here is how I got here.

My hardware is a dual nvidia M40 with 24gb of memory each (not the 12gb variant) so I am pulling larger images (1344*1344) out of the models initially. I am increasing those sizes with multiple runs of the upscaler. everything is going nice, then the upscaler decided to go rouge on a mostly black corner of a Work In Progress. I dumped the before and after "chunks" and found it was adding too much noise to a black background and I get a rouge square added to a PIL canvas. I checked what documentation I could find. i believe that noise is disabled with guidance < 1, which should cause the pipeline_stable_diffusion_upscale.py to skip the creation of variable name "noise_pred_uncond". I don't know why its referenced in line 480, nor have I poked around in the model's source.

Work around: For now, is to increase iterations which will eventually get the corner darker, but it never seams together as well as the lighter more vibrant colors.

Question: is there a more direct specific way to turn off noise than with guidance_scale?

Here's my error msg and my python script.

Traceback (most recent call last):
File "/../exploded.py", line 50, in
upscaled_chunk = pipe(prompt=prompt, image=chunk, num_inference_steps=steps, guidance_scale=1).images[0] # , noise_level=0
File "/usr/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/thom/.local/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py", line 480, in call
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
UnboundLocalError: local variable 'noise_pred_uncond' referenced before assignment

affected portion of my script:
chunk = High.crop((rowchunk_size, cellchunk_size, (rowchunk_size)+chunk_size, (cellchunk_size)+chunk_size))
#chunk.save("chunk_row_"+str(row)+"cell"+str(cell)+".png")
upscaled_chunk = pipe(prompt=prompt, image=chunk, num_inference_steps=steps, noise_level=0, guidance_scale=1 ).images[0]
#upscaled_chunk.save("UPchunk_row_"+str(row)+"cell"+str(cell)+".png")
result.paste(upscaled_chunk, (rowchunk_size4,cellchunk_size4))

Sign up or log in to comment