Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug]: Colab error while training hypernetwork
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

I've been using fast-stable-diffusion notebook in google Colab. And training process is stopped at the step when an image should be saved to textual_inversion log. I’ve already tried to change checkpoint models, training settings and materials

Traceback (most recent call last):
File "/sd/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 701, in train_hypernetwork
p.sampler_name = sd_samplers.samplers[preview_sampler_index].name
TypeError: list indices must be integers or slices, not str

### Steps to reproduce the problem

1. Go to .... 
2. Press ....
3. ...
4...

### What should have happened?

Save a training progress image to log directory every N steps

### Sysinfo

-

### What browsers do you use to access the UI ?

Apple Safari

### Console logs

```Shell
Startup time: 38.3s (import torch: 15.0s, import gradio: 2.0s, setup paths: 4.0s, initialize shared: 0.5s, other imports: 3.3s, setup codeformer: 0.6s, setup gfpgan: 0.1s, list SD models: 0.2s, load scripts: 4.2s, create ui: 3.2s, gradio launch: 4.9s, add APIs: 0.2s).
9aba26abdfcd46073e0a1d42027a3a3bcc969f562d58a03637bf0a0ded6586c9
Loading weights [9aba26abdf] from /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/deliberate_v2.safetensors
Creating model from config: /content/gdrive/MyDrive/sd/stable-diffusion-webui/configs/v1-inference.yaml
Downloading (…)olve/main/vocab.json100% 961k/961k [00:00<00:00, 15.4MB/s]
Downloading (…)olve/main/merges.txt100% 525k/525k [00:00<00:00, 7.23MB/s]
Downloading (…)cial_tokens_map.json100% 389/389 [00:00<00:00, 1.92MB/s]
Downloading (…)okenizer_config.json100% 905/905 [00:00<00:00, 6.89MB/s]
Downloading (…)lve/main/config.json100% 4.52k/4.52k [00:00<00:00, 27.0MB/s]
Applying attention optimization: xformers... done.
Model loaded in 47.5s (calculate hash: 24.9s, load weights from disk: 1.3s, create model: 1.8s, apply weights to model: 15.5s, calculate empty prompt: 3.9s).
Preprocessing [Image 10/11]: 100% 11/11 [00:04<00:00,  2.63it/s]
Applying attention optimization: xformers... done.
*** Error completing request
*** Arguments: ('task(egtmx3f2ofk35e0)', '', '2e-5:800, 8e-6:1600, 5e-6', 1, 1, '/content/gdrive/MyDrive/sd/Processed', 'textual_inversion', 512, 512, False, 10000, 'disabled', '0.1', False, 0, 'once', False, 100, 100, 'custom.txt', True, 'a photo of a young woman ', '', 20, 'Euler a', 7, -1, 512, 512) {}
    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/hypernetworks/ui.py", line 25, in train_hypernetwork
        hypernetwork, filename = modules.hypernetworks.hypernetwork.train_hypernetwork(*args)
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 477, in train_hypernetwork
        textual_inversion.validate_train_inputs(hypernetwork_name, learn_rate, batch_size, gradient_step, data_root, template_file, template_filename, steps, save_hypernetwork_every, create_image_every, log_directory, name="hypernetwork")
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 366, in validate_train_inputs
        assert model_name, f"{name} not selected"
    AssertionError: hypernetwork not selected
Calculating sha256 for /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/hypernetworks/Joki .pt: ee9e9198f019b24aad90f2d54ee7b78f2e9f557763f594e1bb9cd1521fbf6dc7
Training at rate of 2e-05 until step 800
Preparing dataset...
100% 11/11 [00:02<00:00,  4.34it/s]
Training hypernetwork [Epoch 9: 1/11]loss: 0.0650765:   1% 99/10000 [01:14<1:52:48,  1.46it/s] *** Exception in training hypernetwork
    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 701, in train_hypernetwork
        p.sampler_name = sd_samplers.samplers[preview_sampler_index].name
    TypeError: list indices must be integers or slices, not str
```


### Additional information

_No response_


Discussion:

Resolving patch:
diff --git a/modules/hypernetworks/hypernetwork.py b/modules/hypernetworks/hypernetwork.py
--- a/modules/hypernetworks/hypernetwork.py
+++ b/modules/hypernetworks/hypernetwork.py
@@ -468,7 +468,7 @@ def create_hypernetwork(name, enable_sizes, overwrite_old, layer_structure=None,
     shared.reload_hypernetworks()
 
 
-def train_hypernetwork(id_task, hypernetwork_name, learn_rate, batch_size, gradient_step, data_root, log_directory, training_width, training_height, varsize, steps, clip_grad_mode, clip_grad_value, shuffle_tags, tag_drop_out, latent_sampling_method, use_weight, create_image_every, save_hypernetwork_every, template_filename, preview_from_txt2img, preview_prompt, preview_negative_prompt, preview_steps, preview_sampler_index, preview_cfg_scale, preview_seed, preview_width, preview_height):
+def train_hypernetwork(id_task, hypernetwork_name:str, learn_rate:float, batch_size:int, gradient_step:int, data_root:str, log_directory:str, training_width:int, training_height:int, varsize:bool, steps:int, clip_grad_mode:str, clip_grad_value:float, shuffle_tags:bool, tag_drop_out:bool, latent_sampling_method:str, use_weight:bool, create_image_every:int, save_hypernetwork_every:int, template_filename:str, preview_from_txt2img:bool, preview_prompt:str, preview_negative_prompt:str, preview_steps:int, preview_sampler_name:str, preview_cfg_scale:float, preview_seed:int, preview_width:int, preview_height:int):
     from modules import images, processing
 
     save_hypernetwork_every = save_hypernetwork_every or 0
@@ -698,7 +698,7 @@ def train_hypernetwork(id_task, hypernetwork_name, learn_rate, batch_size, gradi
                         p.prompt = preview_prompt
                         p.negative_prompt = preview_negative_prompt
                         p.steps = preview_steps
-                        p.sampler_name = sd_samplers.samplers[preview_sampler_index].name
+                        p.sampler_name = sd_samplers.samplers_map[preview_sampler_name.lower()]
                         p.cfg_scale = preview_cfg_scale
                         p.seed = preview_seed
                         p.width = preview_width
diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py
--- a/modules/textual_inversion/textual_inversion.py
+++ b/modules/textual_inversion/textual_inversion.py
@@ -386,7 +386,7 @@ def validate_train_inputs(model_name, learn_rate, batch_size, gradient_step, dat
         assert log_directory, "Log directory is empty"
 
 
-def train_embedding(id_task, embedding_name, learn_rate, batch_size, gradient_step, data_root, log_directory, training_width, training_height, varsize, steps, clip_grad_mode, clip_grad_value, shuffle_tags, tag_drop_out, latent_sampling_method, use_weight, create_image_every, save_embedding_every, template_filename, save_image_with_stored_embedding, preview_from_txt2img, preview_prompt, preview_negative_prompt, preview_steps, preview_sampler_index, preview_cfg_scale, preview_seed, preview_width, preview_height):
+def train_embedding(id_task, embedding_name, learn_rate, batch_size, gradient_step, data_root, log_directory, training_width, training_height, varsize, steps, clip_grad_mode, clip_grad_value, shuffle_tags, tag_drop_out, latent_sampling_method, use_weight, create_image_every, save_embedding_every, template_filename, save_image_with_stored_embedding, preview_from_txt2img, preview_prompt, preview_negative_prompt, preview_steps, preview_sampler_name, preview_cfg_scale, preview_seed, preview_width, preview_height):
     from modules import processing
 
     save_embedding_every = save_embedding_every or 0
@@ -590,7 +590,7 @@ def train_embedding(id_task, embedding_name, learn_rate, batch_size, gradient_st
                         p.prompt = preview_prompt
                         p.negative_prompt = preview_negative_prompt
                         p.steps = preview_steps
-                        p.sampler_name = sd_samplers.samplers[preview_sampler_index].name
+                        p.sampler_name = sd_samplers.samplers_map[preview_sampler_name.lower()]
                         p.cfg_scale = preview_cfg_scale
                         p.seed = preview_seed
                         p.width = preview_width


Test patch: