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
@@ -115,8 +115,8 @@ class ImagePipelineOutput(BaseOutput):
|
|
115
115
|
|
116
116
|
Args:
|
117
117
|
images (`List[PIL.Image.Image]` or `np.ndarray`)
|
118
|
-
List of denoised PIL images of length `batch_size` or
|
119
|
-
num_channels)`.
|
118
|
+
List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width,
|
119
|
+
num_channels)`.
|
120
120
|
"""
|
121
121
|
|
122
122
|
images: Union[List[PIL.Image.Image], np.ndarray]
|
@@ -129,8 +129,7 @@ class AudioPipelineOutput(BaseOutput):
|
|
129
129
|
|
130
130
|
Args:
|
131
131
|
audios (`np.ndarray`)
|
132
|
-
List of denoised samples of shape `(batch_size, num_channels, sample_rate)`.
|
133
|
-
denoised audio samples of the diffusion pipeline.
|
132
|
+
List of denoised audio samples of a NumPy array of shape `(batch_size, num_channels, sample_rate)`.
|
134
133
|
"""
|
135
134
|
|
136
135
|
audios: np.ndarray
|
@@ -205,7 +204,7 @@ def variant_compatible_siblings(filenames, variant=None) -> Union[List[os.PathLi
|
|
205
204
|
transformers_index_format = r"\d{5}-of-\d{5}"
|
206
205
|
|
207
206
|
if variant is not None:
|
208
|
-
# `diffusion_pytorch_model.fp16.bin` as well as `model.fp16-00001-of-00002.
|
207
|
+
# `diffusion_pytorch_model.fp16.bin` as well as `model.fp16-00001-of-00002.safetensors`
|
209
208
|
variant_file_re = re.compile(
|
210
209
|
rf"({'|'.join(weight_prefixes)})\.({variant}|{variant}-{transformers_index_format})\.({'|'.join(weight_suffixs)})$"
|
211
210
|
)
|
@@ -214,7 +213,7 @@ def variant_compatible_siblings(filenames, variant=None) -> Union[List[os.PathLi
|
|
214
213
|
rf"({'|'.join(weight_prefixes)})\.({'|'.join(weight_suffixs)})\.index\.{variant}\.json$"
|
215
214
|
)
|
216
215
|
|
217
|
-
# `diffusion_pytorch_model.bin` as well as `model-00001-of-00002.
|
216
|
+
# `diffusion_pytorch_model.bin` as well as `model-00001-of-00002.safetensors`
|
218
217
|
non_variant_file_re = re.compile(
|
219
218
|
rf"({'|'.join(weight_prefixes)})(-{transformers_index_format})?\.({'|'.join(weight_suffixs)})$"
|
220
219
|
)
|
@@ -458,20 +457,20 @@ def load_sub_model(
|
|
458
457
|
|
459
458
|
class DiffusionPipeline(ConfigMixin):
|
460
459
|
r"""
|
461
|
-
Base class for all
|
460
|
+
Base class for all pipelines.
|
462
461
|
|
463
|
-
[`DiffusionPipeline`]
|
464
|
-
|
462
|
+
[`DiffusionPipeline`] stores all components (models, schedulers, and processors) for diffusion pipelines and
|
463
|
+
provides methods for loading, downloading and saving models. It also includes methods to:
|
465
464
|
|
466
465
|
- move all PyTorch modules to the device of your choice
|
467
466
|
- enabling/disabling the progress bar for the denoising iteration
|
468
467
|
|
469
468
|
Class attributes:
|
470
469
|
|
471
|
-
- **config_name** (`str`) --
|
472
|
-
|
473
|
-
- **_optional_components** (List[`str`]) --
|
474
|
-
|
470
|
+
- **config_name** (`str`) -- The configuration filename that stores the class and module names of all the
|
471
|
+
diffusion pipeline's components.
|
472
|
+
- **_optional_components** (List[`str`]) -- List of all optional components that don't have to be passed to the
|
473
|
+
pipeline to function (should be overridden by subclasses).
|
475
474
|
"""
|
476
475
|
config_name = "model_index.json"
|
477
476
|
_optional_components = []
|
@@ -541,17 +540,17 @@ class DiffusionPipeline(ConfigMixin):
|
|
541
540
|
variant: Optional[str] = None,
|
542
541
|
):
|
543
542
|
"""
|
544
|
-
Save all variables of the pipeline
|
545
|
-
|
546
|
-
|
543
|
+
Save all saveable variables of the pipeline to a directory. A pipeline variable can be saved and loaded if its
|
544
|
+
class implements both a save and loading method. The pipeline is easily reloaded using the
|
545
|
+
[`~DiffusionPipeline.from_pretrained`] class method.
|
547
546
|
|
548
547
|
Arguments:
|
549
548
|
save_directory (`str` or `os.PathLike`):
|
550
|
-
Directory to
|
549
|
+
Directory to save a pipeline to. Will be created if it doesn't exist.
|
551
550
|
safe_serialization (`bool`, *optional*, defaults to `False`):
|
552
|
-
Whether to save the model using `safetensors` or the traditional PyTorch way
|
551
|
+
Whether to save the model using `safetensors` or the traditional PyTorch way with `pickle`.
|
553
552
|
variant (`str`, *optional*):
|
554
|
-
If specified, weights are saved in the format pytorch_model.<variant>.bin
|
553
|
+
If specified, weights are saved in the format `pytorch_model.<variant>.bin`.
|
555
554
|
"""
|
556
555
|
model_index_dict = dict(self.config)
|
557
556
|
model_index_dict.pop("_class_name", None)
|
@@ -714,69 +713,51 @@ class DiffusionPipeline(ConfigMixin):
|
|
714
713
|
@classmethod
|
715
714
|
def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.PathLike]], **kwargs):
|
716
715
|
r"""
|
717
|
-
Instantiate a PyTorch diffusion pipeline from
|
716
|
+
Instantiate a PyTorch diffusion pipeline from pretrained pipeline weights.
|
718
717
|
|
719
|
-
The pipeline is set in evaluation mode
|
718
|
+
The pipeline is set in evaluation mode (`model.eval()`) by default.
|
720
719
|
|
721
|
-
|
722
|
-
pretrained with the rest of the model. It is up to you to train those weights with a downstream fine-tuning
|
723
|
-
task.
|
720
|
+
If you get the error message below, you need to finetune the weights for your downstream task:
|
724
721
|
|
725
|
-
|
726
|
-
weights are
|
722
|
+
```
|
723
|
+
Some weights of UNet2DConditionModel were not initialized from the model checkpoint at runwayml/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
|
724
|
+
- conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
|
725
|
+
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
|
726
|
+
```
|
727
727
|
|
728
728
|
Parameters:
|
729
729
|
pretrained_model_name_or_path (`str` or `os.PathLike`, *optional*):
|
730
730
|
Can be either:
|
731
731
|
|
732
|
-
- A string, the *repo id* of a pretrained pipeline
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
732
|
+
- A string, the *repo id* (for example `CompVis/ldm-text2im-large-256`) of a pretrained pipeline
|
733
|
+
hosted on the Hub.
|
734
|
+
- A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
|
735
|
+
saved using
|
736
|
+
[`~DiffusionPipeline.save_pretrained`].
|
737
737
|
torch_dtype (`str` or `torch.dtype`, *optional*):
|
738
|
-
Override the default `torch.dtype` and load the model
|
739
|
-
|
738
|
+
Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
|
739
|
+
dtype is automatically derived from the model's weights.
|
740
740
|
custom_pipeline (`str`, *optional*):
|
741
741
|
|
742
742
|
<Tip warning={true}>
|
743
743
|
|
744
|
-
|
744
|
+
🧪 This is an experimental feature and may change in the future.
|
745
745
|
|
746
746
|
</Tip>
|
747
747
|
|
748
748
|
Can be either:
|
749
749
|
|
750
|
-
- A string, the *repo id*
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
<Tip>
|
755
|
-
|
756
|
-
It is required that the model repo has a file, called `pipeline.py` that defines the custom
|
757
|
-
pipeline.
|
758
|
-
|
759
|
-
</Tip>
|
760
|
-
|
750
|
+
- A string, the *repo id* (for example `hf-internal-testing/diffusers-dummy-pipeline`) of a custom
|
751
|
+
pipeline hosted on the Hub. The repository must contain a file called pipeline.py that defines
|
752
|
+
the custom pipeline.
|
761
753
|
- A string, the *file name* of a community pipeline hosted on GitHub under
|
762
|
-
https://github.com/huggingface/diffusers/tree/main/examples/community. Valid file
|
763
|
-
match
|
764
|
-
`clip_guided_stable_diffusion
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
Community pipelines are always loaded from the current `main` branch of GitHub.
|
769
|
-
|
770
|
-
</Tip>
|
771
|
-
|
772
|
-
- A path to a *directory* containing a custom pipeline, e.g., `./my_pipeline_directory/`.
|
773
|
-
|
774
|
-
<Tip>
|
775
|
-
|
776
|
-
It is required that the directory has a file, called `pipeline.py` that defines the custom
|
777
|
-
pipeline.
|
754
|
+
[Community](https://github.com/huggingface/diffusers/tree/main/examples/community). Valid file
|
755
|
+
names must match the file name and not the pipeline script (`clip_guided_stable_diffusion`
|
756
|
+
instead of `clip_guided_stable_diffusion.py`). Community pipelines are always loaded from the
|
757
|
+
current main branch of GitHub.
|
758
|
+
- A path to a directory (`./my_pipeline_directory/`) containing a custom pipeline. The directory
|
759
|
+
must contain a file called `pipeline.py` that defines the custom pipeline.
|
778
760
|
|
779
|
-
</Tip>
|
780
761
|
|
781
762
|
For more information on how to load and create custom pipelines, please have a look at [Loading and
|
782
763
|
Adding Custom
|
@@ -786,78 +767,71 @@ class DiffusionPipeline(ConfigMixin):
|
|
786
767
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
787
768
|
cached versions if they exist.
|
788
769
|
cache_dir (`Union[str, os.PathLike]`, *optional*):
|
789
|
-
Path to a directory
|
790
|
-
|
770
|
+
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
|
771
|
+
is not used.
|
791
772
|
resume_download (`bool`, *optional*, defaults to `False`):
|
792
|
-
Whether or not to
|
793
|
-
|
773
|
+
Whether or not to resume downloading the model weights and configuration files. If set to `False`, any
|
774
|
+
incompletely downloaded files are deleted.
|
794
775
|
proxies (`Dict[str, str]`, *optional*):
|
795
|
-
A dictionary of proxy servers to use by protocol or endpoint,
|
776
|
+
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
796
777
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
797
778
|
output_loading_info(`bool`, *optional*, defaults to `False`):
|
798
779
|
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
|
799
|
-
local_files_only(`bool`, *optional*, defaults to `False`):
|
800
|
-
Whether
|
780
|
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
781
|
+
Whether to only load local model weights and configuration files or not. If set to `True`, the model
|
782
|
+
won't be downloaded from the Hub.
|
801
783
|
use_auth_token (`str` or *bool*, *optional*):
|
802
|
-
The token to use as HTTP bearer authorization for remote files. If `True`,
|
803
|
-
|
784
|
+
The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
|
785
|
+
`diffusers-cli login` (stored in `~/.huggingface`) is used.
|
804
786
|
revision (`str`, *optional*, defaults to `"main"`):
|
805
|
-
The specific model version to use. It can be a branch name, a tag name,
|
806
|
-
|
807
|
-
|
808
|
-
custom_revision (`str`, *optional*, defaults to `"main"` when loading from the Hub and to local version of `diffusers` when loading from GitHub):
|
787
|
+
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
|
788
|
+
allowed by Git.
|
789
|
+
custom_revision (`str`, *optional*, defaults to `"main"`):
|
809
790
|
The specific model version to use. It can be a branch name, a tag name, or a commit id similar to
|
810
|
-
`revision` when loading a custom pipeline from the Hub. It can be a
|
811
|
-
custom pipeline from GitHub.
|
791
|
+
`revision` when loading a custom pipeline from the Hub. It can be a 🤗 Diffusers version when loading a
|
792
|
+
custom pipeline from GitHub, otherwise it defaults to `"main"` when loading from the Hub.
|
812
793
|
mirror (`str`, *optional*):
|
813
|
-
Mirror source to
|
814
|
-
|
815
|
-
|
794
|
+
Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
|
795
|
+
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
|
796
|
+
information.
|
816
797
|
device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
|
817
|
-
A map that specifies where each submodule should go. It doesn
|
818
|
-
parameter/buffer name
|
798
|
+
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
799
|
+
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
819
800
|
same device.
|
820
801
|
|
821
|
-
|
802
|
+
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
822
803
|
more information about each option see [designing a device
|
823
804
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
824
805
|
max_memory (`Dict`, *optional*):
|
825
|
-
A dictionary device identifier
|
826
|
-
GPU and the available CPU RAM if unset.
|
806
|
+
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
807
|
+
each GPU and the available CPU RAM if unset.
|
827
808
|
offload_folder (`str` or `os.PathLike`, *optional*):
|
828
|
-
|
809
|
+
The path to offload weights if device_map contains the value `"disk"`.
|
829
810
|
offload_state_dict (`bool`, *optional*):
|
830
|
-
If `True`,
|
831
|
-
|
832
|
-
|
811
|
+
If `True`, temporarily offloads the CPU state dict to the hard drive to avoid running out of CPU RAM if
|
812
|
+
the weight of the CPU state dict + the biggest shard of the checkpoint does not fit. Defaults to `True`
|
813
|
+
when there is some disk offload.
|
833
814
|
low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
|
834
|
-
Speed up model loading
|
835
|
-
|
836
|
-
|
837
|
-
|
815
|
+
Speed up model loading only loading the pretrained weights and not initializing the weights. This also
|
816
|
+
tries to not use more than 1x model size in CPU memory (including peak memory) while loading the model.
|
817
|
+
Only supported for PyTorch >= 1.9.0. If you are using an older version of PyTorch, setting this
|
818
|
+
argument to `True` will raise an error.
|
838
819
|
use_safetensors (`bool`, *optional*, defaults to `None`):
|
839
|
-
If set to `None`, the
|
840
|
-
|
841
|
-
|
820
|
+
If set to `None`, the safetensors weights are downloaded if they're available **and** if the
|
821
|
+
safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
|
822
|
+
weights. If set to `False`, safetensors weights are not loaded.
|
842
823
|
kwargs (remaining dictionary of keyword arguments, *optional*):
|
843
|
-
Can be used to overwrite load
|
844
|
-
|
845
|
-
|
824
|
+
Can be used to overwrite load and saveable variables (the pipeline components of the specific pipeline
|
825
|
+
class). The overwritten components are passed directly to the pipelines `__init__` method. See example
|
826
|
+
below for more information.
|
846
827
|
variant (`str`, *optional*):
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
<Tip>
|
851
|
-
|
852
|
-
It is required to be logged in (`huggingface-cli login`) when you want to use private or [gated
|
853
|
-
models](https://huggingface.co/docs/hub/models-gated#gated-models), *e.g.* `"runwayml/stable-diffusion-v1-5"`
|
854
|
-
|
855
|
-
</Tip>
|
828
|
+
Load weights from a specified variant filename such as `"fp16"` or `"ema"`. This is ignored when
|
829
|
+
loading `from_flax`.
|
856
830
|
|
857
831
|
<Tip>
|
858
832
|
|
859
|
-
|
860
|
-
|
833
|
+
To use private or [gated](https://huggingface.co/docs/hub/models-gated#gated-models) models, log-in with
|
834
|
+
`huggingface-cli login`.
|
861
835
|
|
862
836
|
</Tip>
|
863
837
|
|
@@ -1099,13 +1073,6 @@ class DiffusionPipeline(ConfigMixin):
|
|
1099
1073
|
|
1100
1074
|
# 8. Instantiate the pipeline
|
1101
1075
|
model = pipeline_class(**init_kwargs)
|
1102
|
-
|
1103
|
-
return_cached_folder = kwargs.pop("return_cached_folder", False)
|
1104
|
-
if return_cached_folder:
|
1105
|
-
message = f"Passing `return_cached_folder=True` is deprecated and will be removed in `diffusers=0.18.0`. Please do the following instead: \n 1. Load the cached_folder via `cached_folder={cls}.download({pretrained_model_name_or_path})`. \n 2. Load the pipeline by loading from the cached folder: `pipeline={cls}.from_pretrained(cached_folder)`."
|
1106
|
-
deprecate("return_cached_folder", "0.18.0", message)
|
1107
|
-
return model, cached_folder
|
1108
|
-
|
1109
1076
|
return model
|
1110
1077
|
|
1111
1078
|
@classmethod
|
@@ -1115,12 +1082,12 @@ class DiffusionPipeline(ConfigMixin):
|
|
1115
1082
|
|
1116
1083
|
Parameters:
|
1117
1084
|
pretrained_model_name (`str` or `os.PathLike`, *optional*):
|
1118
|
-
A string, the repository id (for example `CompVis/ldm-text2im-large-256`) of a pretrained pipeline
|
1085
|
+
A string, the *repository id* (for example `CompVis/ldm-text2im-large-256`) of a pretrained pipeline
|
1119
1086
|
hosted on the Hub.
|
1120
1087
|
custom_pipeline (`str`, *optional*):
|
1121
1088
|
Can be either:
|
1122
1089
|
|
1123
|
-
- A string, the repository id (for example `CompVis/ldm-text2im-large-256`) of a pretrained
|
1090
|
+
- A string, the *repository id* (for example `CompVis/ldm-text2im-large-256`) of a pretrained
|
1124
1091
|
pipeline hosted on the Hub. The repository must contain a file called `pipeline.py` that defines
|
1125
1092
|
the custom pipeline.
|
1126
1093
|
|
@@ -1146,27 +1113,26 @@ class DiffusionPipeline(ConfigMixin):
|
|
1146
1113
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
1147
1114
|
cached versions if they exist.
|
1148
1115
|
resume_download (`bool`, *optional*, defaults to `False`):
|
1149
|
-
Whether or not to resume downloading the model weights and configuration files. If set to False
|
1116
|
+
Whether or not to resume downloading the model weights and configuration files. If set to `False`, any
|
1150
1117
|
incompletely downloaded files are deleted.
|
1151
1118
|
proxies (`Dict[str, str]`, *optional*):
|
1152
1119
|
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
1153
1120
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
1154
1121
|
output_loading_info(`bool`, *optional*, defaults to `False`):
|
1155
1122
|
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
|
1156
|
-
local_files_only(`bool`, *optional*, defaults to `False`):
|
1157
|
-
Whether to only load local model weights and configuration files or not. If set to True
|
1158
|
-
won
|
1123
|
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
1124
|
+
Whether to only load local model weights and configuration files or not. If set to `True`, the model
|
1125
|
+
won't be downloaded from the Hub.
|
1159
1126
|
use_auth_token (`str` or *bool*, *optional*):
|
1160
1127
|
The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
|
1161
1128
|
`diffusers-cli login` (stored in `~/.huggingface`) is used.
|
1162
1129
|
revision (`str`, *optional*, defaults to `"main"`):
|
1163
1130
|
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
|
1164
1131
|
allowed by Git.
|
1165
|
-
custom_revision (`str`, *optional*, defaults to `"main"`
|
1166
|
-
`diffusers` when loading from GitHub):
|
1132
|
+
custom_revision (`str`, *optional*, defaults to `"main"`):
|
1167
1133
|
The specific model version to use. It can be a branch name, a tag name, or a commit id similar to
|
1168
|
-
`revision` when loading a custom pipeline from the Hub. It can be a
|
1169
|
-
custom pipeline from GitHub.
|
1134
|
+
`revision` when loading a custom pipeline from the Hub. It can be a 🤗 Diffusers version when loading a
|
1135
|
+
custom pipeline from GitHub, otherwise it defaults to `"main"` when loading from the Hub.
|
1170
1136
|
mirror (`str`, *optional*):
|
1171
1137
|
Mirror source to resolve accessibility issues if you're downloading a model in China. We do not
|
1172
1138
|
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
|
@@ -1202,7 +1168,7 @@ class DiffusionPipeline(ConfigMixin):
|
|
1202
1168
|
|
1203
1169
|
if use_safetensors and not is_safetensors_available():
|
1204
1170
|
raise ValueError(
|
1205
|
-
"`use_safetensors`=True but safetensors is not installed. Please install safetensors with `pip install
|
1171
|
+
"`use_safetensors`=True but safetensors is not installed. Please install safetensors with `pip install safetensors"
|
1206
1172
|
)
|
1207
1173
|
|
1208
1174
|
allow_pickle = False
|
@@ -1247,6 +1213,15 @@ class DiffusionPipeline(ConfigMixin):
|
|
1247
1213
|
filenames = {sibling.rfilename for sibling in info.siblings}
|
1248
1214
|
model_filenames, variant_filenames = variant_compatible_siblings(filenames, variant=variant)
|
1249
1215
|
|
1216
|
+
if len(variant_filenames) == 0 and variant is not None:
|
1217
|
+
deprecation_message = (
|
1218
|
+
f"You are trying to load the model files of the `variant={variant}`, but no such modeling files are available."
|
1219
|
+
f"The default model files: {model_filenames} will be loaded instead. Make sure to not load from `variant={variant}`"
|
1220
|
+
"if such variant modeling files are not available. Doing so will lead to an error in v0.22.0 as defaulting to non-variant"
|
1221
|
+
"modeling files is deprecated."
|
1222
|
+
)
|
1223
|
+
deprecate("no variant default", "0.22.0", deprecation_message, standard_warn=False)
|
1224
|
+
|
1250
1225
|
# remove ignored filenames
|
1251
1226
|
model_filenames = set(model_filenames) - set(ignore_filenames)
|
1252
1227
|
variant_filenames = set(variant_filenames) - set(ignore_filenames)
|
@@ -1254,7 +1229,7 @@ class DiffusionPipeline(ConfigMixin):
|
|
1254
1229
|
# if the whole pipeline is cached we don't have to ping the Hub
|
1255
1230
|
if revision in DEPRECATED_REVISION_ARGS and version.parse(
|
1256
1231
|
version.parse(__version__).base_version
|
1257
|
-
) >= version.parse("0.
|
1232
|
+
) >= version.parse("0.20.0"):
|
1258
1233
|
warn_deprecated_model_variant(
|
1259
1234
|
pretrained_model_name, use_auth_token, variant, revision, model_filenames
|
1260
1235
|
)
|
@@ -1336,7 +1311,7 @@ class DiffusionPipeline(ConfigMixin):
|
|
1336
1311
|
snapshot_folder = Path(config_file).parent
|
1337
1312
|
pipeline_is_cached = all((snapshot_folder / f).is_file() for f in expected_files)
|
1338
1313
|
|
1339
|
-
if pipeline_is_cached:
|
1314
|
+
if pipeline_is_cached and not force_download:
|
1340
1315
|
# if the pipeline is cached, we can directly return it
|
1341
1316
|
# else call snapshot_download
|
1342
1317
|
return snapshot_folder
|
@@ -1372,9 +1347,11 @@ class DiffusionPipeline(ConfigMixin):
|
|
1372
1347
|
@property
|
1373
1348
|
def components(self) -> Dict[str, Any]:
|
1374
1349
|
r"""
|
1375
|
-
|
1376
1350
|
The `self.components` property can be useful to run different pipelines with the same weights and
|
1377
|
-
configurations
|
1351
|
+
configurations without reallocating additional memory.
|
1352
|
+
|
1353
|
+
Returns (`dict`):
|
1354
|
+
A dictionary containing all the modules needed to initialize the pipeline.
|
1378
1355
|
|
1379
1356
|
Examples:
|
1380
1357
|
|
@@ -1389,9 +1366,6 @@ class DiffusionPipeline(ConfigMixin):
|
|
1389
1366
|
>>> img2img = StableDiffusionImg2ImgPipeline(**text2img.components)
|
1390
1367
|
>>> inpaint = StableDiffusionInpaintPipeline(**text2img.components)
|
1391
1368
|
```
|
1392
|
-
|
1393
|
-
Returns:
|
1394
|
-
A dictionary containing all the modules needed to initialize the pipeline.
|
1395
1369
|
"""
|
1396
1370
|
expected_modules, optional_parameters = self._get_signature_keys(self)
|
1397
1371
|
components = {
|
@@ -1409,7 +1383,7 @@ class DiffusionPipeline(ConfigMixin):
|
|
1409
1383
|
@staticmethod
|
1410
1384
|
def numpy_to_pil(images):
|
1411
1385
|
"""
|
1412
|
-
Convert a
|
1386
|
+
Convert a NumPy image or a batch of images to a PIL image.
|
1413
1387
|
"""
|
1414
1388
|
return numpy_to_pil(images)
|
1415
1389
|
|
@@ -1433,13 +1407,17 @@ class DiffusionPipeline(ConfigMixin):
|
|
1433
1407
|
|
1434
1408
|
def enable_xformers_memory_efficient_attention(self, attention_op: Optional[Callable] = None):
|
1435
1409
|
r"""
|
1436
|
-
Enable memory efficient attention
|
1410
|
+
Enable memory efficient attention from [xFormers](https://facebookresearch.github.io/xformers/).
|
1411
|
+
|
1412
|
+
When this option is enabled, you should observe lower GPU memory usage and a potential speed up during
|
1413
|
+
inference. Speed up during training is not guaranteed.
|
1437
1414
|
|
1438
|
-
|
1439
|
-
time. Speed up at training time is not guaranteed.
|
1415
|
+
<Tip warning={true}>
|
1440
1416
|
|
1441
|
-
|
1442
|
-
|
1417
|
+
⚠️ When memory efficient attention and sliced attention are both enabled, memory efficient attention takes
|
1418
|
+
precedent.
|
1419
|
+
|
1420
|
+
</Tip>
|
1443
1421
|
|
1444
1422
|
Parameters:
|
1445
1423
|
attention_op (`Callable`, *optional*):
|
@@ -1465,7 +1443,7 @@ class DiffusionPipeline(ConfigMixin):
|
|
1465
1443
|
|
1466
1444
|
def disable_xformers_memory_efficient_attention(self):
|
1467
1445
|
r"""
|
1468
|
-
Disable memory efficient attention
|
1446
|
+
Disable memory efficient attention from [xFormers](https://facebookresearch.github.io/xformers/).
|
1469
1447
|
"""
|
1470
1448
|
self.set_use_memory_efficient_attention_xformers(False)
|
1471
1449
|
|
@@ -1493,8 +1471,8 @@ class DiffusionPipeline(ConfigMixin):
|
|
1493
1471
|
r"""
|
1494
1472
|
Enable sliced attention computation.
|
1495
1473
|
|
1496
|
-
When this option is enabled, the attention module
|
1497
|
-
|
1474
|
+
When this option is enabled, the attention module splits the input tensor in slices to compute attention in
|
1475
|
+
several steps. This is useful to save some memory in exchange for a small speed decrease.
|
1498
1476
|
|
1499
1477
|
Args:
|
1500
1478
|
slice_size (`str` or `int`, *optional*, defaults to `"auto"`):
|
@@ -1507,8 +1485,8 @@ class DiffusionPipeline(ConfigMixin):
|
|
1507
1485
|
|
1508
1486
|
def disable_attention_slicing(self):
|
1509
1487
|
r"""
|
1510
|
-
Disable sliced attention computation. If `enable_attention_slicing` was previously
|
1511
|
-
|
1488
|
+
Disable sliced attention computation. If `enable_attention_slicing` was previously called, attention is
|
1489
|
+
computed in one step.
|
1512
1490
|
"""
|
1513
1491
|
# set slice_size = `None` to disable `attention slicing`
|
1514
1492
|
self.enable_attention_slicing(None)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from ...utils import (
|
2
|
+
OptionalDependencyNotAvailable,
|
3
|
+
is_torch_available,
|
4
|
+
is_transformers_available,
|
5
|
+
is_transformers_version,
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
try:
|
10
|
+
if not (is_transformers_available() and is_torch_available()):
|
11
|
+
raise OptionalDependencyNotAvailable()
|
12
|
+
except OptionalDependencyNotAvailable:
|
13
|
+
from ...utils.dummy_torch_and_transformers_objects import ShapEPipeline
|
14
|
+
else:
|
15
|
+
from .camera import create_pan_cameras
|
16
|
+
from .pipeline_shap_e import ShapEPipeline
|
17
|
+
from .pipeline_shap_e_img2img import ShapEImg2ImgPipeline
|
18
|
+
from .renderer import (
|
19
|
+
BoundingBoxVolume,
|
20
|
+
ImportanceRaySampler,
|
21
|
+
MLPNeRFModelOutput,
|
22
|
+
MLPNeRSTFModel,
|
23
|
+
ShapEParamsProjModel,
|
24
|
+
ShapERenderer,
|
25
|
+
StratifiedRaySampler,
|
26
|
+
VoidNeRFModel,
|
27
|
+
)
|