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

fix a bug in from_config #7192

Merged
merged 3 commits into from Mar 4, 2024
Merged

fix a bug in from_config #7192

merged 3 commits into from Mar 4, 2024

Conversation

yiyixuxu
Copy link
Collaborator

@yiyixuxu yiyixuxu commented Mar 3, 2024

fix #7183

this script now runs expected

from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler, LCMScheduler, AutoencoderKL
import torch

model_id = "stabilityai/stable-diffusion-xl-base-1.0"

pipe = DiffusionPipeline.from_pretrained(model_id, variant="fp16", torch_dtype=torch.float16)

#print correct value
print(f" test1: should print EulerAncestralDiscreteScheduler")
print(pipe.scheduler.config._class_name)
print(pipe.scheduler)
print(pipe.scheduler.config._class_name)

pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

#gives Euler not LCM
print(f" test2: shuld print LCMScheduler")
print(pipe.scheduler.config._class_name)
print(pipe.scheduler)
print(pipe.scheduler.config._class_name)

pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)

#prints LCM not EulerA
print(f" test3: shuld print EulerAncestralDiscreteScheduler")
print(pipe.scheduler.config._class_name)
print(pipe.scheduler)
print(pipe.scheduler.config._class_name)

output

Loading pipeline components...: 100%|█████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:02<00:00,  3.33it/s]
 test1: should print EulerAncestralDiscreteScheduler
EulerDiscreteScheduler
EulerDiscreteScheduler {
  "_class_name": "EulerDiscreteScheduler",
  "_diffusers_version": "0.27.0.dev0",
  "beta_end": 0.012,
  "beta_schedule": "scaled_linear",
  "beta_start": 0.00085,
  "clip_sample": false,
  "interpolation_type": "linear",
  "num_train_timesteps": 1000,
  "prediction_type": "epsilon",
  "rescale_betas_zero_snr": false,
  "sample_max_value": 1.0,
  "set_alpha_to_one": false,
  "sigma_max": null,
  "sigma_min": null,
  "skip_prk_steps": true,
  "steps_offset": 1,
  "timestep_spacing": "leading",
  "timestep_type": "discrete",
  "trained_betas": null,
  "use_karras_sigmas": false
}

EulerDiscreteScheduler
The config attributes {'skip_prk_steps': True} were passed to LCMScheduler, but are not expected and will be ignored. Please verify your scheduler_config.json configuration file.
 hidden_dict: {'interpolation_type': 'linear', 'use_karras_sigmas': False, '_class_name': 'LCMScheduler', '_diffusers_version': '0.27.0.dev0', 'skip_prk_steps': True}
 test2: shuld print LCMScheduler
LCMScheduler
LCMScheduler {
  "_class_name": "LCMScheduler",
  "_diffusers_version": "0.27.0.dev0",
  "beta_end": 0.012,
  "beta_schedule": "scaled_linear",
  "beta_start": 0.00085,
  "clip_sample": false,
  "clip_sample_range": 1.0,
  "dynamic_thresholding_ratio": 0.995,
  "interpolation_type": "linear",
  "num_train_timesteps": 1000,
  "original_inference_steps": 50,
  "prediction_type": "epsilon",
  "rescale_betas_zero_snr": false,
  "sample_max_value": 1.0,
  "set_alpha_to_one": false,
  "skip_prk_steps": true,
  "steps_offset": 1,
  "thresholding": false,
  "timestep_scaling": 10.0,
  "timestep_spacing": "leading",
  "trained_betas": null,
  "use_karras_sigmas": false
}

LCMScheduler
 hidden_dict: {'clip_sample': False, 'set_alpha_to_one': False, 'sample_max_value': 1.0, 'interpolation_type': 'linear', 'use_karras_sigmas': False, '_class_name': 'EulerAncestralDiscreteScheduler', '_diffusers_version': '0.27.0.dev0', 'skip_prk_steps': True}
 test3: shuld print EulerAncestralDiscreteScheduler
EulerAncestralDiscreteScheduler
EulerAncestralDiscreteScheduler {
  "_class_name": "EulerAncestralDiscreteScheduler",
  "_diffusers_version": "0.27.0.dev0",
  "beta_end": 0.012,
  "beta_schedule": "scaled_linear",
  "beta_start": 0.00085,
  "clip_sample": false,
  "interpolation_type": "linear",
  "num_train_timesteps": 1000,
  "prediction_type": "epsilon",
  "rescale_betas_zero_snr": false,
  "sample_max_value": 1.0,
  "set_alpha_to_one": false,
  "skip_prk_steps": true,
  "steps_offset": 1,
  "timestep_spacing": "leading",
  "trained_betas": null,
  "use_karras_sigmas": false
}

EulerAncestralDiscreteScheduler

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yiyixuxu yiyixuxu requested a review from DN6 March 4, 2024 04:41
Copy link
Collaborator

@DN6 DN6 left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏽

@yiyixuxu yiyixuxu merged commit 8f206a5 into main Mar 4, 2024
17 checks passed
@yiyixuxu yiyixuxu deleted the fix-from-config branch March 4, 2024 17:19
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

Successfully merging this pull request may close these issues.

scheduler.config._class_name displays wrong class name if the scheduler is changed
3 participants