diffusers 0.17.1__py3-none-any.whl → 0.18.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diffusers/__init__.py +26 -1
- diffusers/configuration_utils.py +34 -29
- diffusers/dependency_versions_table.py +4 -0
- diffusers/image_processor.py +125 -12
- diffusers/loaders.py +169 -203
- diffusers/models/attention.py +24 -1
- diffusers/models/attention_flax.py +10 -5
- diffusers/models/attention_processor.py +3 -0
- diffusers/models/autoencoder_kl.py +114 -33
- diffusers/models/controlnet.py +131 -14
- diffusers/models/controlnet_flax.py +37 -26
- diffusers/models/cross_attention.py +17 -17
- diffusers/models/embeddings.py +67 -0
- diffusers/models/modeling_flax_utils.py +64 -56
- diffusers/models/modeling_utils.py +193 -104
- diffusers/models/prior_transformer.py +207 -37
- diffusers/models/resnet.py +26 -26
- diffusers/models/transformer_2d.py +36 -41
- diffusers/models/transformer_temporal.py +24 -21
- diffusers/models/unet_1d.py +31 -25
- diffusers/models/unet_2d.py +43 -30
- diffusers/models/unet_2d_blocks.py +210 -89
- diffusers/models/unet_2d_blocks_flax.py +12 -12
- diffusers/models/unet_2d_condition.py +172 -64
- diffusers/models/unet_2d_condition_flax.py +38 -24
- diffusers/models/unet_3d_blocks.py +34 -31
- diffusers/models/unet_3d_condition.py +101 -34
- diffusers/models/vae.py +5 -5
- diffusers/models/vae_flax.py +37 -34
- diffusers/models/vq_model.py +23 -14
- diffusers/pipelines/__init__.py +24 -1
- diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py +1 -1
- diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py +5 -3
- diffusers/pipelines/consistency_models/__init__.py +1 -0
- diffusers/pipelines/consistency_models/pipeline_consistency_models.py +337 -0
- diffusers/pipelines/controlnet/multicontrolnet.py +120 -1
- diffusers/pipelines/controlnet/pipeline_controlnet.py +59 -17
- diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +60 -15
- diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py +60 -17
- diffusers/pipelines/controlnet/pipeline_flax_controlnet.py +1 -1
- diffusers/pipelines/kandinsky/__init__.py +1 -1
- diffusers/pipelines/kandinsky/pipeline_kandinsky.py +4 -6
- diffusers/pipelines/kandinsky/pipeline_kandinsky_inpaint.py +1 -0
- diffusers/pipelines/kandinsky/pipeline_kandinsky_prior.py +1 -0
- diffusers/pipelines/kandinsky2_2/__init__.py +7 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +317 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +372 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py +434 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +398 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py +531 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +541 -0
- diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py +605 -0
- diffusers/pipelines/pipeline_flax_utils.py +2 -2
- diffusers/pipelines/pipeline_utils.py +124 -146
- diffusers/pipelines/shap_e/__init__.py +27 -0
- diffusers/pipelines/shap_e/camera.py +147 -0
- diffusers/pipelines/shap_e/pipeline_shap_e.py +390 -0
- diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py +349 -0
- diffusers/pipelines/shap_e/renderer.py +709 -0
- diffusers/pipelines/stable_diffusion/__init__.py +2 -0
- diffusers/pipelines/stable_diffusion/convert_from_ckpt.py +261 -66
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +3 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +5 -3
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +4 -2
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py +6 -6
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_k_diffusion.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_ldm3d.py +719 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py +1 -1
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_paradigms.py +832 -0
- diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py +17 -7
- diffusers/pipelines/stable_diffusion_xl/__init__.py +26 -0
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +823 -0
- diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +896 -0
- diffusers/pipelines/stable_diffusion_xl/watermark.py +31 -0
- diffusers/pipelines/text_to_video_synthesis/__init__.py +2 -1
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py +5 -1
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth_img2img.py +771 -0
- diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_zero.py +92 -6
- diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py +3 -3
- diffusers/pipelines/versatile_diffusion/modeling_text_unet.py +209 -91
- diffusers/schedulers/__init__.py +3 -0
- diffusers/schedulers/scheduling_consistency_models.py +380 -0
- diffusers/schedulers/scheduling_ddim.py +28 -6
- diffusers/schedulers/scheduling_ddim_inverse.py +19 -4
- diffusers/schedulers/scheduling_ddim_parallel.py +642 -0
- diffusers/schedulers/scheduling_ddpm.py +53 -7
- diffusers/schedulers/scheduling_ddpm_parallel.py +604 -0
- diffusers/schedulers/scheduling_deis_multistep.py +66 -11
- diffusers/schedulers/scheduling_dpmsolver_multistep.py +55 -13
- diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py +19 -4
- diffusers/schedulers/scheduling_dpmsolver_sde.py +73 -11
- diffusers/schedulers/scheduling_dpmsolver_singlestep.py +23 -7
- diffusers/schedulers/scheduling_euler_ancestral_discrete.py +58 -9
- diffusers/schedulers/scheduling_euler_discrete.py +58 -8
- diffusers/schedulers/scheduling_heun_discrete.py +89 -14
- diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py +73 -11
- diffusers/schedulers/scheduling_k_dpm_2_discrete.py +73 -11
- diffusers/schedulers/scheduling_lms_discrete.py +57 -8
- diffusers/schedulers/scheduling_pndm.py +46 -10
- diffusers/schedulers/scheduling_repaint.py +19 -4
- diffusers/schedulers/scheduling_sde_ve.py +5 -1
- diffusers/schedulers/scheduling_unclip.py +43 -4
- diffusers/schedulers/scheduling_unipc_multistep.py +48 -7
- diffusers/training_utils.py +1 -1
- diffusers/utils/__init__.py +2 -1
- diffusers/utils/dummy_pt_objects.py +60 -0
- diffusers/utils/dummy_torch_and_transformers_and_invisible_watermark_objects.py +32 -0
- diffusers/utils/dummy_torch_and_transformers_objects.py +180 -0
- diffusers/utils/hub_utils.py +1 -1
- diffusers/utils/import_utils.py +20 -3
- diffusers/utils/logging.py +15 -18
- diffusers/utils/outputs.py +3 -3
- diffusers/utils/testing_utils.py +15 -0
- {diffusers-0.17.1.dist-info → diffusers-0.18.2.dist-info}/METADATA +4 -2
- {diffusers-0.17.1.dist-info → diffusers-0.18.2.dist-info}/RECORD +120 -94
- {diffusers-0.17.1.dist-info → diffusers-0.18.2.dist-info}/WHEEL +1 -1
- {diffusers-0.17.1.dist-info → diffusers-0.18.2.dist-info}/LICENSE +0 -0
- {diffusers-0.17.1.dist-info → diffusers-0.18.2.dist-info}/entry_points.txt +0 -0
- {diffusers-0.17.1.dist-info → diffusers-0.18.2.dist-info}/top_level.txt +0 -0
@@ -44,7 +44,11 @@ class DDPMSchedulerOutput(BaseOutput):
|
|
44
44
|
pred_original_sample: Optional[torch.FloatTensor] = None
|
45
45
|
|
46
46
|
|
47
|
-
def betas_for_alpha_bar(
|
47
|
+
def betas_for_alpha_bar(
|
48
|
+
num_diffusion_timesteps,
|
49
|
+
max_beta=0.999,
|
50
|
+
alpha_transform_type="cosine",
|
51
|
+
):
|
48
52
|
"""
|
49
53
|
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
|
50
54
|
(1-beta) over time from t = [0,1].
|
@@ -57,19 +61,30 @@ def betas_for_alpha_bar(num_diffusion_timesteps, max_beta=0.999):
|
|
57
61
|
num_diffusion_timesteps (`int`): the number of betas to produce.
|
58
62
|
max_beta (`float`): the maximum beta to use; use values lower than 1 to
|
59
63
|
prevent singularities.
|
64
|
+
alpha_transform_type (`str`, *optional*, default to `cosine`): the type of noise schedule for alpha_bar.
|
65
|
+
Choose from `cosine` or `exp`
|
60
66
|
|
61
67
|
Returns:
|
62
68
|
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
|
63
69
|
"""
|
70
|
+
if alpha_transform_type == "cosine":
|
64
71
|
|
65
|
-
|
66
|
-
|
72
|
+
def alpha_bar_fn(t):
|
73
|
+
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2
|
74
|
+
|
75
|
+
elif alpha_transform_type == "exp":
|
76
|
+
|
77
|
+
def alpha_bar_fn(t):
|
78
|
+
return math.exp(t * -12.0)
|
79
|
+
|
80
|
+
else:
|
81
|
+
raise ValueError(f"Unsupported alpha_tranform_type: {alpha_transform_type}")
|
67
82
|
|
68
83
|
betas = []
|
69
84
|
for i in range(num_diffusion_timesteps):
|
70
85
|
t1 = i / num_diffusion_timesteps
|
71
86
|
t2 = (i + 1) / num_diffusion_timesteps
|
72
|
-
betas.append(min(1 -
|
87
|
+
betas.append(min(1 - alpha_bar_fn(t2) / alpha_bar_fn(t1), max_beta))
|
73
88
|
return torch.tensor(betas, dtype=torch.float32)
|
74
89
|
|
75
90
|
|
@@ -114,6 +129,13 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
|
|
114
129
|
(https://arxiv.org/abs/2205.11487). Valid only when `thresholding=True`.
|
115
130
|
sample_max_value (`float`, default `1.0`):
|
116
131
|
the threshold value for dynamic thresholding. Valid only when `thresholding=True`.
|
132
|
+
timestep_spacing (`str`, default `"leading"`):
|
133
|
+
The way the timesteps should be scaled. Refer to Table 2. of [Common Diffusion Noise Schedules and Sample
|
134
|
+
Steps are Flawed](https://arxiv.org/abs/2305.08891) for more information.
|
135
|
+
steps_offset (`int`, default `0`):
|
136
|
+
an offset added to the inference steps. You can use a combination of `offset=1` and
|
137
|
+
`set_alpha_to_one=False`, to make the last step use step 0 for the previous alpha product, as done in
|
138
|
+
stable diffusion.
|
117
139
|
"""
|
118
140
|
|
119
141
|
_compatibles = [e.name for e in KarrasDiffusionSchedulers]
|
@@ -134,6 +156,8 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
|
|
134
156
|
dynamic_thresholding_ratio: float = 0.995,
|
135
157
|
clip_sample_range: float = 1.0,
|
136
158
|
sample_max_value: float = 1.0,
|
159
|
+
timestep_spacing: str = "leading",
|
160
|
+
steps_offset: int = 0,
|
137
161
|
):
|
138
162
|
if trained_betas is not None:
|
139
163
|
self.betas = torch.tensor(trained_betas, dtype=torch.float32)
|
@@ -228,11 +252,33 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
|
|
228
252
|
)
|
229
253
|
|
230
254
|
self.num_inference_steps = num_inference_steps
|
231
|
-
|
232
|
-
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
|
233
|
-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
|
234
255
|
self.custom_timesteps = False
|
235
256
|
|
257
|
+
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
|
258
|
+
if self.config.timestep_spacing == "linspace":
|
259
|
+
timesteps = (
|
260
|
+
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
|
261
|
+
.round()[::-1]
|
262
|
+
.copy()
|
263
|
+
.astype(np.int64)
|
264
|
+
)
|
265
|
+
elif self.config.timestep_spacing == "leading":
|
266
|
+
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
|
267
|
+
# creates integer timesteps by multiplying by ratio
|
268
|
+
# casting to int to avoid issues when num_inference_step is power of 3
|
269
|
+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
|
270
|
+
timesteps += self.config.steps_offset
|
271
|
+
elif self.config.timestep_spacing == "trailing":
|
272
|
+
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
|
273
|
+
# creates integer timesteps by multiplying by ratio
|
274
|
+
# casting to int to avoid issues when num_inference_step is power of 3
|
275
|
+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
|
276
|
+
timesteps -= 1
|
277
|
+
else:
|
278
|
+
raise ValueError(
|
279
|
+
f"{self.config.timestep_spacing} is not supported. Please make sure to choose one of 'linspace', 'leading' or 'trailing'."
|
280
|
+
)
|
281
|
+
|
236
282
|
self.timesteps = torch.from_numpy(timesteps).to(device)
|
237
283
|
|
238
284
|
def _get_variance(self, t, predicted_variance=None, variance_type=None):
|