Repository: stable-diffusion-webui
Issue: [Bug]: NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check. 
Labels: asking-for-help-with-local-system-issues

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

Normally A1111 features work fine with SDXL Base and SDXL Refiner. But on 3 occasions over par 4-6 weeks I have had this same bug, I've tried all suggestions and A1111 troubleshoot page with no success. The only way I have successfully fixed it is with re-install from scratch. I run SDXL Base txt2img, works fine. Then I run SDXL Refiner img2img and receive the error regardless if I use "send to img2img" or "Batch img2img"

Error Message: NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check. 
![Screenshot (4245)](https://github.com/AUTOMATIC1111/stable-diffusion-webui/assets/93432254/cbbd8b2f-4e41-4801-b89c-eeaffb145ee6)


### Steps to reproduce the problem

1. Go to .... img2img
2. Press .... Generate
3. ... Receive Error Message
![Screenshot (4245)](https://github.com/AUTOMATIC1111/stable-diffusion-webui/assets/93432254/73f1447b-1797-4e19-b929-a71c86a52501)

### What should have happened?

Normally when working, it will batch refine and generate all the images from the input directory into the output directory

### Sysinfo

[sysinfo-2023-08-31-18-35.txt](https://github.com/AUTOMATIC1111/stable-diffusion-webui/files/12489234/sysinfo-2023-08-31-18-35.txt)


### What browsers do you use to access the UI ?

Google Chrome

### Console logs

```Shell
venv "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\venv\Scripts\Python.exe"
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: 1.5.1
Commit hash: <none>
Launching Web UI with arguments:
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Loading weights [7440042bbd] from C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\models\Stable-diffusion\sd_xl_refiner_1.0.safetensors
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 14.7s (launcher: 3.4s, import torch: 4.7s, import gradio: 1.3s, setup paths: 1.0s, other imports: 1.2s, load scripts: 1.6s, create ui: 1.0s, gradio launch: 0.4s).
Creating model from config: C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\repositories\generative-models\configs\inference\sd_xl_refiner.yaml
Applying attention optimization: Doggettx... done.
Model loaded in 7.1s (load weights from disk: 1.8s, create model: 0.3s, apply weights to model: 1.4s, apply half(): 1.3s, move model to device: 1.8s, calculate empty prompt: 0.4s).
Will process 100 images, creating 1 new images for each.
  0%|                                                                                            | 0/6 [00:03<?, ?it/s]
*** Error completing request
*** Arguments: ('task(19bmqwbr6wil1q8)', 5, 'Photo of a scuba diving Hamster wearing a diving suit and googles surrounded by exotic fish and coral deep in the ocean', '', [], None, None, None, None, None, None, None, 20, 0, 4, 0, 1, False, False, 1, 1, 7, 1.5, 0.25, -1.0, -1.0, 0, 0, 0, False, 0, 1024, 1024, 1, 0, 0, 32, 0, 'C:\\Users\\Mono\\Desktop\\stable-diffusion-webui-master\\stable-diffusion-webui-master\\outputs\\txt2img-images\\2023-08-30', 'C:\\Users\\Mono\\Desktop\\stable-diffusion-webui-master\\stable-diffusion-webui-master\\outputs\\img2img-images', '', [], False, [], '', <gradio.routes.Request object at 0x0000021B4D7A2B30>, 0, True, False, False, False, 'base', '<ul>\n<li><code>CFG Scale</code> should be 2 or lower.</li>\n</ul>\n', True, True, '', '', True, 50, True, 1, 0, False, 4, 0.5, 'Linear', 'None', '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, 'positive', 'comma', 0, False, False, '', '<p style="margin-bottom:0.75em">Will upscale the image by the selected scale factor; use width and height sliders to set tile size</p>', 64, 0, 2, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0) {}    Traceback (most recent call last):
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\call_queue.py", line 58, in f
        res = list(func(*args, **kwargs))
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\call_queue.py", line 37, in f
        res = func(*args, **kwargs)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\img2img.py", line 226, in img2img
        process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, args, to_scale=selected_scale_tab == 1, scale_by=scale_by, use_png_info=img2img_batch_use_png_info, png_info_props=img2img_batch_png_info_props, png_info_dir=img2img_batch_png_info_dir)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\img2img.py", line 114, in process_batch
        proc = process_images(p)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\processing.py", line 677, in process_images
        res = process_images_inner(p)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\processing.py", line 794, in process_images_inner
        samples_ddim = p.sample(conditioning=p.c, unconditional_conditioning=p.uc, seeds=p.seeds, subseeds=p.subseeds, subseed_strength=p.subseed_strength, prompts=p.prompts)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\processing.py", line 1381, in sample
        samples = self.sampler.sample_img2img(self, self.init_latent, x, conditioning, unconditional_conditioning, image_conditioning=self.image_conditioning)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\sd_samplers_kdiffusion.py", line 434, in sample_img2img
        samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\sd_samplers_kdiffusion.py", line 303, in launch_sampling
        return func()
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\sd_samplers_kdiffusion.py", line 434, in <lambda>
        samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\repositories\k-diffusion\k_diffusion\sampling.py", line 145, in sample_euler_ancestral
        denoised = model(x, sigmas[i] * s_in, **extra_args)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\sd_samplers_kdiffusion.py", line 215, in forward
        devices.test_for_nans(x_out, "unet")
      File "C:\Users\Mono\Desktop\stable-diffusion-webui-master\stable-diffusion-webui-master\modules\devices.py", line 155, in test_for_nans
        raise NansException(message)
    modules.devices.NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check.

---
```


### Additional information

1st time it happened was when nvidia notified me of a driver update.

The last time it happened was after I generated 100 images successfully using txt2img, it generated all 100 images, but the ui froze up for 10 minutes before I manually closed the ui and cmd window and hasn't worked since. I will have to re-install to get it working again.

I have just noticed my PC has switched to game ready driver, but normally I use Studio Driver