Skip to content

Commit

Permalink
Fix missing seed error.
Browse files Browse the repository at this point in the history
  • Loading branch information
d8ahazard committed Nov 8, 2022
1 parent caeee02 commit 43ec3b6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dreambooth/train_dreambooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from PIL import Image
from accelerate import Accelerator
from accelerate.logging import get_logger
from accelerate.utils import set_seed
from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableDiffusionPipeline, UNet2DConditionModel
from diffusers.optimization import get_scheduler
from huggingface_hub import HfFolder, whoami
Expand Down Expand Up @@ -447,6 +448,8 @@ def main(args):
args.train_text_encoder = False

concepts_loaded = False
if args.seed is not None:
set_seed(args.seed)
if args.concepts_list is not None and args.concepts_list != "":
is_json = False
try:
Expand Down

8 comments on commit 43ec3b6

@entmike
Copy link

@entmike entmike commented on 43ec3b6 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not fix it, unfortunately.

 1, True, 5e-06, False, 'constant', 0, False, 0.9, 0.999, 0.01, 1e-08, 1, 500, 500, 'no', True, '', False) {}
Traceback (most recent call last):
  File "/home/stable/stable-diffusion-webui/modules/ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "/home/stable/stable-diffusion-webui/webui.py", line 54, in f
    res = func(*args, **kwargs)
  File "/home/stable/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/home/stable/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 451, in main
    if args.seed is not None:
AttributeError: 'DreamboothConfig' object has no attribute 'seed'

The error now moves to line 451:

    if args.seed is not None:
        set_seed(args.seed)

Could we simply just make it a Gradio UI parameter with a default value, or at least populate a default value in argparser? Currently it is set to None:

parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.")

@rabidcopy
Copy link

@rabidcopy rabidcopy commented on 43ec3b6 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting a seed manually still doesn't resolve it either. Something about the rewritten preview pipeline just doesn't work. (for me?)
#23 (comment)

@entmike
Copy link

@entmike entmike commented on 43ec3b6 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting a seed manually still doesn't resolve it either. Something about the rewritten preview pipeline just doesn't work. #23 (comment)

@rabidcopy - I just changed this line for now until a proper fix comes:

parser.add_argument("--seed", type=int, default=1234, help="A seed for reproducible training.")

EDIT:
Also here since apparently the arg is getting nullified from Gradio:

# g_cuda = torch.Generator(device=accelerator.device).manual_seed(args.seed)
g_cuda = torch.Generator(device=accelerator.device).manual_seed(1234)

@rabidcopy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting a seed manually still doesn't resolve it either. Something about the rewritten preview pipeline just doesn't work. #23 (comment)

@rabidcopy - I just changed this line for now until a proper fix comes:

parser.add_argument("--seed", type=int, default=1234, help="A seed for reproducible training.")

EDIT: Also here since apparently the arg is getting nullified from Gradio:

# g_cuda = torch.Generator(device=accelerator.device).manual_seed(args.seed)
g_cuda = torch.Generator(device=accelerator.device).manual_seed(1234)

But are you actually able to train with preview images after doing that without any further errors?

@Dawgmastah
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually broke things more for me, getting the seed error when STARTING training, not even when generating preview images

@entmike
Copy link

@entmike entmike commented on 43ec3b6 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But are you actually able to train with preview images after doing that without any further errors?

Sorry, you are right. I spoke too soon. I am now stuck here:

Traceback (most recent call last):
  File "/home/stable/stable-diffusion-webui/modules/ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "/home/stable/stable-diffusion-webui/webui.py", line 54, in f
    res = func(*args, **kwargs)
  File "/home/stable/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/home/stable/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 836, in main
    image = pipeline(
  File "/home/stable/stable-diffusion-webui/venv/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/stable/stable-diffusion-webui/venv/lib/python3.8/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 395, in __call__
    latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs).prev_sample
  File "/home/stable/stable-diffusion-webui/venv/lib/python3.8/site-packages/diffusers/schedulers/scheduling_pndm.py", line 220, in step
    return self.step_plms(model_output=model_output, timestep=timestep, sample=sample, return_dict=return_dict)
  File "/home/stable/stable-diffusion-webui/venv/lib/python3.8/site-packages/diffusers/schedulers/scheduling_pndm.py", line 336, in step_plms
    prev_sample = self._get_prev_sample(sample, timestep, prev_timestep, model_output)
  File "/home/stable/stable-diffusion-webui/venv/lib/python3.8/site-packages/diffusers/schedulers/scheduling_pndm.py", line 371, in _get_prev_sample
    alpha_prod_t_prev = self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.final_alpha_cumprod
IndexError: tensors used as indices must be long, byte or bool tensors

@Luke2642
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added
"seed": 1234
to db_config.py line 108

@OWKenobi
Copy link

@OWKenobi OWKenobi commented on 43ec3b6 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone else stumbles here via google: Updating DreamBooth in the Automatic UI resolves this issue ;-)

Please sign in to comment.