Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when generating a preview image #23

Closed
Trauter1 opened this issue Nov 8, 2022 · 11 comments
Closed

Error when generating a preview image #23

Trauter1 opened this issue Nov 8, 2022 · 11 comments

Comments

@Trauter1
Copy link

Trauter1 commented Nov 8, 2022

Traceback (most recent call last):
  File "/notebooks/stable-diffusion-webui/modules/ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "/notebooks/stable-diffusion-webui/webui.py", line 54, in f
    res = func(*args, **kwargs)
  File "/notebooks/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/notebooks/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 829, in main
    g_cuda = torch.Generator(device=accelerator.device).manual_seed(args.seed)
AttributeError: 'DreamboothConfig' object has no attribute 'seed'

Worked fine before updating to the latest version.

@gonjay
Copy link

gonjay commented Nov 8, 2022

Change this line

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

to:

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

Then reload webui

@ThereforeGames
Copy link

ThereforeGames commented Nov 8, 2022

I'm receiving the same error after updating train_dreambooth.py as @gonjay suggested. Seems like another edit is needed somewhere?

@Trauter1
Copy link
Author

Trauter1 commented Nov 8, 2022

Sadly, it doesn't work for me. Im running paperspace notebook it that matters. @gonjay

@rabidcopy
Copy link

rabidcopy commented Nov 8, 2022

Same.

Traceback (most recent call last):
  File "/notebooks/SDW/modules/ui.py", line 180, in f
    res = list(func(*args, **kwargs))
  File "/notebooks/SDW/webui.py", line 55, in f
    res = func(*args, **kwargs)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 829, in main
    g_cuda = torch.Generator(device=accelerator.device).manual_seed(args.seed)

Edit: Upon trying to manually hardcode a seed, I then run into this.

Traceback (most recent call last):
  File "/notebooks/SDW/modules/ui.py", line 180, in f
    res = list(func(*args, **kwargs))
  File "/notebooks/SDW/webui.py", line 55, in f
    res = func(*args, **kwargs)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 831, in main~
    image = pipeline(
  File "/usr/local/lib/python3.9/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-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 "/usr/local/lib/python3.9/dist-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 "/usr/local/lib/python3.9/dist-packages/diffusers/schedulers/scheduling_pndm.py", line 336, in step_plms
    prev_sample = self._get_prev_sample(sample, timestep, prev_timestep, model_output)
  File "/usr/local/lib/python3.9/dist-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

Reverting to a354abd is the only way I can train with preview images, but then they are just the base instance prompts again and generation settings aren't used. I tried to do the old pipeline with the args for generation parameters and prompt input but still a no-go.

I small workaround for the instance prompt issue is to change line 829 of train_dreambooth.py in this older commit to prompt = f'{args.instance_prompt} {args.class_prompt}' so that at least generates previews with the full instance+class prompt so it's a better look at how your training is going.

@Dawgmastah
Copy link

Can confirm the issue, last night preview images worked fine

@entmike
Copy link

entmike commented Nov 8, 2022

Same issue I just reported here (didn't notice you already had one open here based on subject line) #30

@rabidcopy
Copy link

rabidcopy commented Nov 8, 2022

Possibly fixed by 43ec3b6. Can't test right now.
Edit: Still getting the same error, I think there's still a problem with there being no default seed specified in the argument parser?

Traceback (most recent call last):
  File "/notebooks/SDW/modules/ui.py", line 180, in f
    res = list(func(*args, **kwargs))
  File "/notebooks/SDW/webui.py", line 55, in f
    res = func(*args, **kwargs)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/notebooks/SDW/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'

Changing the --seed line to parser.add_argument("--seed", type=int, default=5013, help="A seed for reproducible training.") still produces the same error claiming there isn't an attribute.

Manually setting a seed with args.seed = int(5013) just before line 451 gets past that error but again throws this same error from before.

Traceback (most recent call last):
  File "/notebooks/SDW/modules/ui.py", line 180, in f
    res = list(func(*args, **kwargs))
  File "/notebooks/SDW/webui.py", line 55, in f
    res = func(*args, **kwargs)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/dreambooth.py", line 256, in start_training
    trained_steps = main(config)
  File "/notebooks/SDW/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 838, in main
    image = pipeline(
  File "/usr/local/lib/python3.9/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 334, in __call__
    latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs).prev_sample
  File "/usr/local/lib/python3.9/dist-packages/diffusers/schedulers/scheduling_pndm.py", line 217, in step
    return self.step_plms(model_output=model_output, timestep=timestep, sample=sample, return_dict=return_dict)
  File "/usr/local/lib/python3.9/dist-packages/diffusers/schedulers/scheduling_pndm.py", line 332, in step_plms
    prev_sample = self._get_prev_sample(sample, timestep, prev_timestep, model_output)
  File "/usr/local/lib/python3.9/dist-packages/diffusers/schedulers/scheduling_pndm.py", line 367, 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

I don't know if anyone else is experiencing this problem. I guess for now I'm going to stick to an older commit (a354abd) and change the preview generation section at around 820 lines into train_dreambooth.py to this.

                            if save_img:
                                shared.state.textinfo = "Generating preview..."
                                pipeline.safety_checker = dumb_safety
                                prompt = f'{args.instance_prompt} {args.save_sample_prompt}'
                                negativeprompt = f'{args.save_sample_negative_prompt}'
                                last_saved_image = os.path.join(args.output_dir, "logging",
                                                                f'{prompt}_{lifetime_step}.png')
                                image = pipeline(prompt, negative_prompt=negativeprompt, num_inference_steps=40, guidance_scale=7.5).images[0]
                                shared.state.current_image = image
                                image.save(last_saved_image)

Seems to work and passes positive and negative prompts on to the generation. Didn't really bother with plugging in steps and scale though.

Edit: I think the IndexError: tensors used as indices must be long, byte or bool tensors is being caused by trying to use a negative prompt for preview generation.

@d8ahazard
Copy link
Owner

Think I got it now:

9e6ebef

@Wakzor
Copy link

Wakzor commented Nov 8, 2022

Im still having an error when generating preview. CPU: False Adam: True, Prec: bf16, Prior: False, Grad: True, TextTr: True
File "C:\Users\user\stable-diffusion-webui\modules\ui.py", line 185, in f res = list(func(*args, **kwargs)) File "C:\Users\user\stable-diffusion-webui\webui.py", line 54, in f res = func(*args, **kwargs) File "C:\Users\user\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\dreambooth.py", line 265, in start_training trained_steps = main(config) File "C:\Users\user\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 829, in main revision=args.revision, AttributeError: 'DreamboothConfig' object has no attribute 'revision'

@f8upd8
Copy link

f8upd8 commented Nov 9, 2022

Still broken as of right now (IndexError: tensors used as indices must be long, byte or bool tensors)

@d8ahazard
Copy link
Owner

This issue has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants