Repository: stable-diffusion-webui
Issue: [Bug]: When using refiner with  an SDXL embedding, webui loses sight of embeddings after 1 generation
Labels: bug

### Is there an existing issue for this?

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

### What happened?

When I start up webui and generate an image with SDXL + refiner using an SDXL embedding, only the first generation uses the embedding. Thereafter the SDXL embedding is ignored. The Textual Inversion tab shows an error "Nothing here. Add some content to the following directories: G:\stable-diffusion-webui-master\webui\embeddings" evem though there are SDXL embeddings in that folder. (On startup the Textual Inversion tab shows my 2 embeddings correctly.)
Restarting webui has the same effect; 1st gen OK, subsequent gens not.
Minimum activity to recover embeddings in the Textual Inversion tab is: load a different SDXL checkpoint, then load the original SDXL checkpoint. Again, 1st gen wih refiner is OK, subsequent gens are not.
NOTE: **Without using refiner**, the SDXL embedding is successfully applied to all images in a batch. I'm trying to use the refiner because it gives a better result with my overpowered embedding.
![20230906_a1111_bug_report_re_SDXL_refiner_and_embeddings_02](https://github.com/AUTOMATIC1111/stable-diffusion-webui/assets/115795576/fe023887-5c41-4371-86ab-9cd6c45a3017)
Before Generate:
![20230906_a1111_bug_report_re_SDXL_refiner_and_embeddings_06](https://github.com/AUTOMATIC1111/stable-diffusion-webui/assets/115795576/e3b00c1f-5ccb-4de9-9cea-3b9f1e80d92e)
After Generate:
![20230906_a1111_bug_report_re_SDXL_refiner_and_embeddings_04](https://github.com/AUTOMATIC1111/stable-diffusion-webui/assets/115795576/096c0e8d-d70f-458e-bad6-9abc12ef8a48)


### Steps to reproduce the problem

1. Start up webui (in this case I have only built-in extensions and Dynamic Prompts enabled; the same problem happens even if Dynamic Prompts is disabled).
2. Check SDXL embeddings are showing up in Textual Inversion tab.
3. There are very few SDXL embeddings so far, so I'm using my own one from [https://civitai.com/models/139230/crystalitixl](url)
4. Load an SDXL checkpoint, add a prompt with an SDXL embedding, set width/height to 1024/1024, select a refiner. Set Batch Count greater than 1. (Also happens when Generating 1 image at a time: first OK, subsequent not.)
5. Hit Generate.
6. First image will have the SDXL embedding applied, subsequent ones not.
7. Refresh Textual Inversion tab: "Nothing here. Add some content to the following directories:"
8. Load a different SDXL checkpoint, then reload first SDXL checkpoint.
9. Refresh Textual Inversion tab: SDXL embeddings now show up OK.
10. Again, generating images will have first one OK with the embedding, subsequent ones not.

### What should have happened?

When using an SDXL base + SDXL refiner + SDXL embedding, all images in a batch should have the embedding applied.

### Sysinfo

[sysinfo-2023-09-06-15-41.txt](https://github.com/AUTOMATIC1111/stable-diffusion-webui/files/12542772/sysinfo-2023-09-06-15-41.txt)


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

Mozilla Firefox, Microsoft Edge

### Console logs

```Shell
venv "G:\stable-diffusion-webui-master\webui\venv\Scripts\Python.exe"
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]
Version: v1.6.0
Commit hash: 5ef669de080814067961f28357256e8fe27544f4
Launching Web UI with arguments: --medvram --xformers --no-half-vae --listen --api --disable-safe-unpickle --ckpt G:\stable-diffusion-webui-master\webui\models\Stable-diffusion\SDXL\crystalClearXL_ccxl.safetensors
Loading weights [0b76532e03] from G:\stable-diffusion-webui-master\webui\models\Stable-diffusion\SDXL\crystalClearXL_ccxl.safetensors
Running on local URL:  http://0.0.0.0:7860
Creating model from config: G:\stable-diffusion-webui-master\webui\repositories\generative-models\configs\inference\sd_xl_base.yaml
Loading VAE weights specified in settings: G:\stable-diffusion-webui-master\webui\models\VAE\sdxl_vae.safetensors
Applying attention optimization: xformers... done.

To create a public link, set `share=True` in `launch()`.
Startup time: 67.5s (prepare environment: 9.5s, import torch: 19.1s, import gradio: 4.6s, setup paths: 4.0s, initialize shared: 0.9s, other imports: 3.3s, setup codeformer: 0.8s, setup gfpgan: 0.2s, load scripts: 19.0s, create ui: 1.2s, gradio launch: 4.7s, add APIs: 0.2s).
Model loaded in 10.6s (load weights from disk: 2.0s, create model: 0.7s, apply weights to model: 2.7s, load VAE: 0.2s, load textual inversion embeddings: 1.1s, calculate empty prompt: 3.6s).
INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 2 images in a total of 2 batches.
 60%|████████████████████████████████████████████████████████████▌                                        | 12/20 [00:11<00:06,  1.29it/s]Loading model SDXL\sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016] (2 out of 2)                          | 12/40 [00:08<00:21,  1.32it/s]
Loading weights [8d0ce6c016] from G:\stable-diffusion-webui-master\webui\models\Stable-diffusion\SDXL\sd_xl_refiner_1.0_0.9vae.safetensors
Creating model from config: G:\stable-diffusion-webui-master\webui\repositories\generative-models\configs\inference\sd_xl_refiner.yaml
Loading VAE weights specified in settings: G:\stable-diffusion-webui-master\webui\models\VAE\sdxl_vae.safetensors
Applying attention optimization: xformers... done.
Model loaded in 5.4s (load weights from disk: 0.7s, create model: 0.4s, apply weights to model: 2.4s, load VAE: 0.2s, load textual inversion embeddings: 0.9s, calculate empty prompt: 0.7s).
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:25<00:00,  1.26s/it]
Using already loaded model SDXL\crystalClearXL_ccxl.safetensors [0b76532e03]: done in 0.0s                | 20/40 [00:22<00:16,  1.22it/s]
 60%|████████████████████████████████████████████████████████████▌                                        | 12/20 [00:10<00:06,  1.29it/s]Using already loaded model SDXL\sd_xl_refiner_1.0_0.9vae.safetensors [8d0ce6c016]: done in 1.5s (send model to cpu: 1.5s)<00:06,  1.23it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:19<00:00,  1.03it/s]
Total progress: 100%|█████████████████████████████████████████████████████████████████████████████████████| 40/40 [00:55<00:00,  1.39s/it]
Total progress: 100%|█████████████████████████████████████████████████████████████████████████████████████| 40/40 [00:55<00:00,  1.44it/s]
```


### Additional information

Don't know if relevant: when doing an SDXL batch using an SDXL embedding, the embedding name gets added over and over and over... to the generated images' PNG info. E.g.:
![20230906_a1111_bug_report_re_SDXL_refiner_and_embeddings_07](https://github.com/AUTOMATIC1111/stable-diffusion-webui/assets/115795576/d4ac9558-3953-4393-9e91-881d94ec54d2)


Occasionally, when restarting webui and looking at the Textual Inversion tab, the console shows this error:
<<<
Traceback (most recent call last):
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "G:\stable-diffusion-webui-master\webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks.py", line 392, in pages_html
    return refresh()
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks.py", line 400, in refresh
    ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages]
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks.py", line 400, in <listcomp>
    ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages]
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks.py", line 162, in create_html
    self.items = {x["name"]: x for x in self.list_items()}
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks.py", line 162, in <dictcomp>
    self.items = {x["name"]: x for x in self.list_items()}
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks_checkpoints.py", line 35, in list_items
    yield self.create_item(name, index)
  File "G:\stable-diffusion-webui-master\webui\modules\ui_extra_networks_checkpoints.py", line 18, in create_item
    path, ext = os.path.splitext(checkpoint.filename)
AttributeError: 'NoneType' object has no attribute 'filename'
>>>