text
stringlengths
0
5.54k
pipeline.enable_model_cpu_offload()
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
pipeline.enable_xformers_memory_efficient_attention()
prompt = "elden ring style astronaut in a jungle" # include the token "elden ring style" in the prompt
negative_prompt = "ugly, deformed, disfigured, poor details, bad anatomy"
image_elden_ring = pipeline(prompt, negative_prompt=negative_prompt, image=image_control_net, strength=0.45, guidance_scale=10.5).images[0]
make_image_grid([init_image, depth_image, image_control_net, image_elden_ring], rows=2, cols=2) Optimize Running diffusion models is computationally expensive and intensive, but with a few optimization tricks, it is entirely possible to run them on consumer and free-tier GPUs. For example, you can use a more memory-e...
+ pipeline.enable_xformers_memory_efficient_attention() With torch.compile, you can boost your inference speed even more by wrapping your UNet with it: Copied pipeline.unet = torch.compile(pipeline.unet, mode="reduce-overhead", fullgraph=True) To learn more, take a look at the Reduce memory usage and Torch 2.0 guides...
Textual Inversion Textual Inversion is a training method for personalizing models by learning new text embeddings from a few example images. The file produced from training is extremely small (a few KBs) and the new embeddings can be loaded into the text encoder. TextualInversionLoaderMixin provides a function for load...
Can be either one of the following or a list of them:
A string, the model id (for example sd-concepts-library/low-poly-hd-logos-icons) of a
pretrained model hosted on the Hub.
A path to a directory (for example ./my_text_inversion_directory/) containing the textual
inversion weights.
A path to a file (for example ./my_text_inversions.pt) containing textual inversion weights.
A torch state
dict.
token (str or List[str], optional) —
Override the token to use for the textual inversion weights. If pretrained_model_name_or_path is a
list, then token must also be a list of equal length. text_encoder (CLIPTextModel, optional) —
Frozen text-encoder (clip-vit-large-patch14).
If not specified, function will take self.tokenizer. tokenizer (CLIPTokenizer, optional) —
A CLIPTokenizer to tokenize text. If not specified, function will take self.tokenizer. weight_name (str, optional) —
Name of a custom weight file. This should be used when:
The saved textual inversion file is in 🤗 Diffusers format, but was saved under a specific weight
name such as text_inv.bin.
The saved textual inversion file is in the Automatic1111 format.
cache_dir (Union[str, os.PathLike], optional) —
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used. force_download (bool, optional, defaults to False) —
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist. resume_download (bool, optional, defaults to False) —
Whether or not to resume downloading the model weights and configuration files. If set to False, any
incompletely downloaded files are deleted. proxies (Dict[str, str], optional) —
A dictionary of proxy servers to use by protocol or endpoint, for example, {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request. local_files_only (bool, optional, defaults to False) —
Whether to only load local model weights and configuration files or not. If set to True, the model
won’t be downloaded from the Hub. token (str or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True, the token generated from
diffusers-cli login (stored in ~/.huggingface) is used. 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
allowed by Git. subfolder (str, optional, defaults to "") —
The subfolder location of a model file within a larger model repository on the Hub or locally. mirror (str, optional) —
Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
information. Load Textual Inversion embeddings into the text encoder of StableDiffusionPipeline (both 🤗 Diffusers and
Automatic1111 formats are supported). Example: To load a Textual Inversion embedding vector in 🤗 Diffusers format: Copied from diffusers import StableDiffusionPipeline
import torch
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
pipe.load_textual_inversion("sd-concepts-library/cat-toy")
prompt = "A <cat-toy> backpack"
image = pipe(prompt, num_inference_steps=50).images[0]
image.save("cat-backpack.png") To load a Textual Inversion embedding vector in Automatic1111 format, make sure to download the vector first
(for example from civitAI) and then load the vector locally: Copied from diffusers import StableDiffusionPipeline
import torch
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
pipe.load_textual_inversion("./charturnerv2.pt", token="charturnerv2")
prompt = "charturnerv2, multiple views of the same character in the same outfit, a character turnaround of a woman wearing a black jacket and red shirt, best quality, intricate details."
image = pipe(prompt, num_inference_steps=50).images[0]
image.save("character.png") maybe_convert_prompt < source > ( prompt: Union tokenizer: PreTrainedTokenizer ) → str or list of str Parameters prompt (str or list of str) —
The prompt or prompts to guide the image generation. tokenizer (PreTrainedTokenizer) —
The tokenizer responsible for encoding the prompt into input tokens. Returns
str or list of str
The converted prompt
Processes prompts that include a special token corresponding to a multi-vector textual inversion embedding to
be replaced with multiple special tokens each corresponding to one of the vectors. If the prompt has no textual
inversion token or if the textual inversion token is a single vector, the input prompt is returned. unload_textual_inversion < source > ( tokens: Union = None ) Unload Textual Inversion embeddings from the text encoder of StableDiffusionPipeline Example: Copied from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained("runwayml/stable-diffusion-v1-5")
# Example 1
pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork")
pipeline.load_textual_inversion("sd-concepts-library/moeb-style")
# Remove all token embeddings
pipeline.unload_textual_inversion()
# Example 2
pipeline.load_textual_inversion("sd-concepts-library/moeb-style")
pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork")
# Remove just one token
pipeline.unload_textual_inversion("<moe-bius>")
How to contribute to Diffusers 🧨 We ❤️ contributions from the open-source community! Everyone is welcome, and all types of participation –not just code– are valued and appreciated. Answering questions, helping others, reaching out, and improving the documentation are all immensely valuable to the community, so don’t b...
the core library. In the following, we give an overview of different ways to contribute, ranked by difficulty in ascending order. All of them are valuable to the community. Asking and answering questions on the Diffusers discussion forum or on Discord. Opening new issues on the GitHub Issues tab. Answering issues on th...