lllyasviel / stable-diffusion-webui-forge

GNU Affero General Public License v3.0
8.55k stars 839 forks source link

NotImplementedError: Failed to recognize PNDMScheduler #2267

Closed anonymous-person closed 2 weeks ago

anonymous-person commented 2 weeks ago

I pulled the latest build today (e2fe29c104a3893372898281a4c355ef30fb00f0) and now I get this error when I try to run txt2img.

Startup looks like this:

Launching launch.py...
################################################################
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
Version: f2.0.1v1.10.1-previous-608-ge2fe29c1
Commit hash: e2fe29c104a3893372898281a4c355ef30fb00f0
removing nvidia-cudnn-cu11
Launching Web UI with arguments: --enable-insecure-extension-access --listen --cors-allow-origins=http://bonobo.local:3456 --xformers --no-gradio-queue --api
Total VRAM 12044 MB, total RAM 31807 MB
pytorch version: 2.3.1+cu121
xformers version: 0.0.27
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3060 : native
Hint: your device supports --cuda-malloc for potential speed improvements.
VAE dtype preferences: [torch.bfloat16, torch.float32] -> torch.bfloat16
CUDA Using Stream: False
Using xformers cross attention
Using xformers attention for VAE
ControlNet preprocessor location: /home/anon/stable-diffusion-webui-forge/models/ControlNetPreprocessor
Tag Autocomplete: Could not locate model-keyword extension, Lora trigger word completion will be limited to those added through the extra networks menu.
[-] ADetailer initialized. version: 24.9.0, num models: 10
CivitAI Browser+: Aria2 RPC started
/home/anon/stable-diffusion-webui-forge/venv/lib/python3.10/site-packages/numba/np/ufunc/parallel.py:371: NumbaWarning: The TBB threading layer requires TBB version 2021 update 6 or later i.e., TBB_INTERFACE_VERSION >= 12060. Found TBB_INTERFACE_VERSION = 12050. The TBB threading layer is disabled.
  warnings.warn(problem)
Loading additional modules ... done.
2024-11-05 16:14:10,344 - ControlNet - INFO - ControlNet UI callback registered.
/home/anon/stable-diffusion-webui-forge/extensions/Stable-Diffusion-WebUI-TensorRT/ui_trt.py:414: GradioDeprecationWarning: unexpected argument for Dropdown: default
  version = gr.Dropdown(
/home/anon/stable-diffusion-webui-forge/extensions/Stable-Diffusion-WebUI-TensorRT/ui_trt.py:614: GradioDeprecationWarning: unexpected argument for Dropdown: default
  trt_lora_dropdown = gr.Dropdown(
[ERROR]: Config states /home/anon/stable-diffusion-webui-forge/config_states/civitai_subfolders.json, "created_at" does not exist
Model selected: {'checkpoint_info': {'filename': '/home/anon/stable-diffusion-webui-forge/models/Stable-diffusion/mymodel.safetensors', 'hash': '1234567'}, 'additional_modules': ['/home/anon/stable-diffusion-webui-forge/models/VAE/vae-ft-mse-840000-ema-pruned-sd15.safetensors'], 'unet_storage_dtype': None}
Using online LoRAs in FP16: False
Running on local URL:  http://0.0.0.0:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 18.7s (prepare environment: 1.3s, launcher: 0.2s, import torch: 2.9s, load scripts: 2.0s, initialize google blockly: 6.3s, create ui: 2.7s, gradio launch: 1.8s, add APIs: 1.3s).
Environment vars changed: {'stream': False, 'inference_memory': 1024.0, 'pin_shared_memory': False}
[GPU Setting] You will use 91.50% GPU memory (11020.00 MB) to load weights, and use 8.50% GPU memory (1024.00 MB) to do matrix computation.

When I click Generate, I get this:

[Unload] Trying to free all memory for cuda:0 with 0 models keep loaded ... Done.
StateDict Keys: {'unet': 686, 'vae': 250, 'text_encoder': 197, 'ignore': 0}
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
IntegratedAutoencoderKL Unexpected: ['model_ema.decay', 'model_ema.num_updates']
K-Model Created: {'storage_dtype': torch.float16, 'computation_dtype': torch.float16}
Traceback (most recent call last):
  File "/home/anon/stable-diffusion-webui-forge/modules_forge/main_thread.py", line 30, in work
    self.result = self.func(*self.args, **self.kwargs)
  File "/home/anon/stable-diffusion-webui-forge/modules/txt2img.py", line 124, in txt2img_function
    processed = processing.process_images(p)
  File "/home/anon/stable-diffusion-webui-forge/modules/processing.py", line 836, in process_images
    manage_model_and_prompt_cache(p)
  File "/home/anon/stable-diffusion-webui-forge/modules/processing.py", line 804, in manage_model_and_prompt_cache
    p.sd_model, just_reloaded = forge_model_reload()
  File "/home/anon/stable-diffusion-webui-forge/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/anon/stable-diffusion-webui-forge/modules/sd_models.py", line 504, in forge_model_reload
    sd_model = forge_loader(state_dict, additional_state_dicts=additional_state_dicts)
  File "/home/anon/stable-diffusion-webui-forge/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/anon/stable-diffusion-webui-forge/backend/loader.py", line 331, in forge_loader
    return M(estimated_config=estimated_config, huggingface_components=huggingface_components)
  File "/home/anon/stable-diffusion-webui-forge/backend/diffusion_engine/sd15.py", line 30, in __init__
    unet = UnetPatcher.from_model(
  File "/home/anon/stable-diffusion-webui-forge/backend/patcher/unet.py", line 11, in from_model
    model = KModel(model=model, diffusers_scheduler=diffusers_scheduler, k_predictor=k_predictor, config=config)
  File "/home/anon/stable-diffusion-webui-forge/backend/modules/k_model.py", line 21, in __init__
    self.predictor = k_prediction_from_diffusers_scheduler(diffusers_scheduler)
  File "/home/anon/stable-diffusion-webui-forge/backend/modules/k_prediction.py", line 300, in k_prediction_from_diffusers_scheduler
    raise NotImplementedError(f'Failed to recognize {scheduler}')
NotImplementedError: Failed to recognize PNDMScheduler {
  "_class_name": "PNDMScheduler",
  "_diffusers_version": "0.31.0",
  "beta_end": 0.012,
  "beta_schedule": "scaled_linear",
  "beta_start": 0.00085,
  "clip_sample": false,
  "num_train_timesteps": 1000,
  "prediction_type": "epsilon",
  "set_alpha_to_one": false,
  "skip_prk_steps": true,
  "steps_offset": 1,
  "timestep_spacing": "leading",
  "trained_betas": null
}

I tried choosing different Sampling Method and Schedule Type in the UI, but it didn't help. I also tried clicking Apply Settings and restarted webui, but it didn't help either.

I roll back to e5b34baae646077bd2a70155f0a92f42bb763a29, and the problem goes away.

DenOfEquity commented 2 weeks ago

Very weird error. The code in e2fe29c runs after inference, when the image is saved, but this error is occurring on model load. The raise NotImplementedError happens when the model scheduler config is wrong/unsupported, but the values printed are all as expected. Try a different model.

anonymous-person commented 2 weeks ago

Hmm, with the latest code, it works with public models I've downloaded, like sd15, flux1d, dreamshaper. But I get the error when I try to use any of my DreamBooth custom trained models. 😭

So 90a6970 gives this error:

Loading Model: {'checkpoint_info': {'filename': '/home/anon/stable-diffusion-webui-forge/models/Stable-diffusion/myDreamboothModel2.safetensors', 'hash': 'a5922235'}, 'additional_modules': ['/home/anon/stable-diffusion-webui-forge/models/VAE/vae-ft-mse-840000-ema-pruned-sd15.safetensors'], 'unet_storage_dtype': None}
[Unload] Trying to free all memory for cuda:0 with 0 models keep loaded ... Done.
StateDict Keys: {'unet': 686, 'vae': 250, 'text_encoder': 197, 'ignore': 0}
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
IntegratedAutoencoderKL Unexpected: ['model_ema.decay', 'model_ema.num_updates']
Traceback (most recent call last):
  File "/home/anon/stable-diffusion-webui-forge/modules_forge/main_thread.py", line 30, in work
    self.result = self.func(*self.args, **self.kwargs)
  File "/home/anon/stable-diffusion-webui-forge/modules/txt2img.py", line 124, in txt2img_function
    processed = processing.process_images(p)
  File "/home/anon/stable-diffusion-webui-forge/modules/processing.py", line 836, in process_images
    manage_model_and_prompt_cache(p)
  File "/home/anon/stable-diffusion-webui-forge/modules/processing.py", line 804, in manage_model_and_prompt_cache
    p.sd_model, just_reloaded = forge_model_reload()
  File "/home/anon/stable-diffusion-webui-forge/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/anon/stable-diffusion-webui-forge/modules/sd_models.py", line 504, in forge_model_reload
    sd_model = forge_loader(state_dict, additional_state_dicts=additional_state_dicts)
  File "/home/anon/stable-diffusion-webui-forge/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/anon/stable-diffusion-webui-forge/backend/loader.py", line 318, in forge_loader
    or  yaml_config.get('model', {}).get('params', {}).get('denoiser_config', {}).get('params', {}).get('scaling_config').get('target', '')
AttributeError: 'NoneType' object has no attribute 'get'
'NoneType' object has no attribute 'get'

I've seen similar errors before, so I deleted my config.json and restarted webui. But as soon as I use a DreamBooth model, I get the same AttributeError: 'NoneType' object has no attribute 'get' error.

Can anybody else confirm this with a sd15 based DreamBooth model? Is it just me?

@catboxanon Any ideas?

DenOfEquity commented 2 weeks ago

I think I can now replicate the issue by creating a dummy YAML file for a checkpoint. The issue seems to be that the check for prediction_type in the YAML defaults to an empty string, instead it should default to 'epsilon'. Can you try editing /home/anon/stable-diffusion-webui-forge/backend/loader.py line 318: currently: or yaml_config.get('model', {}).get('params', {}).get('denoiser_config', {}).get('params', {}).get('scaling_config', {}).get('target', '') change to: or yaml_config.get('model', {}).get('params', {}).get('denoiser_config', {}).get('params', {}).get('scaling_config', {}).get('target', 'epsilon')

This fixes it with my fake YAML test.

catboxanon commented 2 weeks ago

Actual fix would be to simply check if the .yaml config's prediction type is truthy or not (before I mistakenly was only comparing if it was None). The estimated config's prediction type (which for most cases will be epsilon) should be read from if no prediction type is set in the .yaml, rather than forcefully falling back to epsilon if the .yaml exists.

These (now merged) PRs should fix it. https://github.com/lllyasviel/stable-diffusion-webui-forge/pull/2272 https://github.com/lllyasviel/stable-diffusion-webui-forge/pull/2273

anonymous-person commented 2 weeks ago

@catboxanon Unfortunately, #2272 #2273 did not fix the problem. I've attached a copy of my model's yaml. myDreamBoothModel.yaml.txt

@DenOfEquity However, your suggested loader.py hack solves my problem. Can you please commit this fix? Thanks!

catboxanon commented 2 weeks ago

@anonymous-person I just tested with that .yaml config, and with both of my PRs applied (which are currently merged to main), the returned result is epsilon (which is identical to the fix DenOfEquity made). Are you sure you're on the latest commit?

anonymous-person commented 2 weeks ago

@catboxanon I pulled main again, and this time it works without the manual hack. Thanks.