"tests/git@developer.sourcefind.cn:OpenDAS/fairscale.git" did not exist on "29aae007fffa965c3bcbae7692f1e3d4f301cff8"
Unverified Commit 6fedbd85 authored by YiYi Xu's avatar YiYi Xu Committed by GitHub
Browse files

fix doc example for fom_single_file (#7015)



* fix doc

* remove use_safetensors from signature

* more

---------
Co-authored-by: default avataryiyixuxu <yixu310@gmail,com>
parent 1b3cfb1b
...@@ -63,11 +63,12 @@ from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipelin ...@@ -63,11 +63,12 @@ from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipelin
import torch import torch
pipeline = StableDiffusionXLPipeline.from_single_file( pipeline = StableDiffusionXLPipeline.from_single_file(
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors", torch_dtype=torch.float16, variant="fp16", use_safetensors=True "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors",
torch_dtype=torch.float16
).to("cuda") ).to("cuda")
refiner = StableDiffusionXLImg2ImgPipeline.from_single_file( refiner = StableDiffusionXLImg2ImgPipeline.from_single_file(
"https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/sd_xl_refiner_1.0.safetensors", torch_dtype=torch.float16, use_safetensors=True, variant="fp16" "https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/sd_xl_refiner_1.0.safetensors", torch_dtype=torch.float16
).to("cuda") ).to("cuda")
``` ```
......
...@@ -313,12 +313,12 @@ from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipelin ...@@ -313,12 +313,12 @@ from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipelin
import torch import torch
pipe = StableDiffusionXLPipeline.from_single_file( pipe = StableDiffusionXLPipeline.from_single_file(
"./sd_xl_base_1.0.safetensors", torch_dtype=torch.float16, variant="fp16", use_safetensors=True "./sd_xl_base_1.0.safetensors", torch_dtype=torch.float16
) )
pipe.to("cuda") pipe.to("cuda")
refiner = StableDiffusionXLImg2ImgPipeline.from_single_file( refiner = StableDiffusionXLImg2ImgPipeline.from_single_file(
"./sd_xl_refiner_1.0.safetensors", torch_dtype=torch.float16, use_safetensors=True, variant="fp16" "./sd_xl_refiner_1.0.safetensors", torch_dtype=torch.float16
) )
refiner.to("cuda") refiner.to("cuda")
``` ```
......
...@@ -75,10 +75,6 @@ class FromOriginalVAEMixin: ...@@ -75,10 +75,6 @@ class FromOriginalVAEMixin:
diffusion model. When decoding, the latents are scaled back to the original scale with the formula: `z diffusion model. When decoding, the latents are scaled back to the original scale with the formula: `z
= 1 / scaling_factor * z`. For more details, refer to sections 4.3.2 and D.1 of the [High-Resolution = 1 / scaling_factor * z`. For more details, refer to sections 4.3.2 and D.1 of the [High-Resolution
Image Synthesis with Latent Diffusion Models](https://arxiv.org/abs/2112.10752) paper. Image Synthesis with Latent Diffusion Models](https://arxiv.org/abs/2112.10752) paper.
use_safetensors (`bool`, *optional*, defaults to `None`):
If set to `None`, the safetensors weights are downloaded if they're available **and** if the
safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
weights. If set to `False`, safetensors weights are not loaded.
kwargs (remaining dictionary of keyword arguments, *optional*): kwargs (remaining dictionary of keyword arguments, *optional*):
Can be used to overwrite load and saveable variables (for example the pipeline components of the Can be used to overwrite load and saveable variables (for example the pipeline components of the
specific pipeline class). The overwritten components are directly passed to the pipelines `__init__` specific pipeline class). The overwritten components are directly passed to the pipelines `__init__`
...@@ -111,7 +107,6 @@ class FromOriginalVAEMixin: ...@@ -111,7 +107,6 @@ class FromOriginalVAEMixin:
local_files_only = kwargs.pop("local_files_only", None) local_files_only = kwargs.pop("local_files_only", None)
revision = kwargs.pop("revision", None) revision = kwargs.pop("revision", None)
torch_dtype = kwargs.pop("torch_dtype", None) torch_dtype = kwargs.pop("torch_dtype", None)
use_safetensors = kwargs.pop("use_safetensors", True)
class_name = cls.__name__ class_name = cls.__name__
...@@ -131,7 +126,6 @@ class FromOriginalVAEMixin: ...@@ -131,7 +126,6 @@ class FromOriginalVAEMixin:
token=token, token=token,
revision=revision, revision=revision,
local_files_only=local_files_only, local_files_only=local_files_only,
use_safetensors=use_safetensors,
cache_dir=cache_dir, cache_dir=cache_dir,
) )
......
...@@ -65,10 +65,6 @@ class FromOriginalControlNetMixin: ...@@ -65,10 +65,6 @@ class FromOriginalControlNetMixin:
revision (`str`, *optional*, defaults to `"main"`): revision (`str`, *optional*, defaults to `"main"`):
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
allowed by Git. allowed by Git.
use_safetensors (`bool`, *optional*, defaults to `None`):
If set to `None`, the safetensors weights are downloaded if they're available **and** if the
safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
weights. If set to `False`, safetensors weights are not loaded.
image_size (`int`, *optional*, defaults to 512): image_size (`int`, *optional*, defaults to 512):
The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable
Diffusion v2 base model. Use 768 for Stable Diffusion v2. Diffusion v2 base model. Use 768 for Stable Diffusion v2.
...@@ -101,7 +97,6 @@ class FromOriginalControlNetMixin: ...@@ -101,7 +97,6 @@ class FromOriginalControlNetMixin:
local_files_only = kwargs.pop("local_files_only", None) local_files_only = kwargs.pop("local_files_only", None)
revision = kwargs.pop("revision", None) revision = kwargs.pop("revision", None)
torch_dtype = kwargs.pop("torch_dtype", None) torch_dtype = kwargs.pop("torch_dtype", None)
use_safetensors = kwargs.pop("use_safetensors", True)
class_name = cls.__name__ class_name = cls.__name__
if (config_file is not None) and (original_config_file is not None): if (config_file is not None) and (original_config_file is not None):
...@@ -120,7 +115,6 @@ class FromOriginalControlNetMixin: ...@@ -120,7 +115,6 @@ class FromOriginalControlNetMixin:
token=token, token=token,
revision=revision, revision=revision,
local_files_only=local_files_only, local_files_only=local_files_only,
use_safetensors=use_safetensors,
cache_dir=cache_dir, cache_dir=cache_dir,
) )
......
...@@ -181,10 +181,6 @@ class FromSingleFileMixin: ...@@ -181,10 +181,6 @@ class FromSingleFileMixin:
revision (`str`, *optional*, defaults to `"main"`): revision (`str`, *optional*, defaults to `"main"`):
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
allowed by Git. allowed by Git.
use_safetensors (`bool`, *optional*, defaults to `None`):
If set to `None`, the safetensors weights are downloaded if they're available **and** if the
safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
weights. If set to `False`, safetensors weights are not loaded.
Examples: Examples:
```py ```py
...@@ -216,7 +212,6 @@ class FromSingleFileMixin: ...@@ -216,7 +212,6 @@ class FromSingleFileMixin:
local_files_only = kwargs.pop("local_files_only", False) local_files_only = kwargs.pop("local_files_only", False)
revision = kwargs.pop("revision", None) revision = kwargs.pop("revision", None)
torch_dtype = kwargs.pop("torch_dtype", None) torch_dtype = kwargs.pop("torch_dtype", None)
use_safetensors = kwargs.pop("use_safetensors", True)
class_name = cls.__name__ class_name = cls.__name__
...@@ -230,7 +225,6 @@ class FromSingleFileMixin: ...@@ -230,7 +225,6 @@ class FromSingleFileMixin:
token=token, token=token,
revision=revision, revision=revision,
local_files_only=local_files_only, local_files_only=local_files_only,
use_safetensors=use_safetensors,
cache_dir=cache_dir, cache_dir=cache_dir,
) )
......
...@@ -227,14 +227,7 @@ def fetch_ldm_config_and_checkpoint( ...@@ -227,14 +227,7 @@ def fetch_ldm_config_and_checkpoint(
cache_dir=None, cache_dir=None,
local_files_only=None, local_files_only=None,
revision=None, revision=None,
use_safetensors=True,
): ):
file_extension = pretrained_model_link_or_path.rsplit(".", 1)[-1]
from_safetensors = file_extension == "safetensors"
if from_safetensors and use_safetensors is False:
raise ValueError("Make sure to install `safetensors` with `pip install safetensors`.")
if os.path.isfile(pretrained_model_link_or_path): if os.path.isfile(pretrained_model_link_or_path):
checkpoint = load_state_dict(pretrained_model_link_or_path) checkpoint = load_state_dict(pretrained_model_link_or_path)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment