text
stringlengths
0
5.54k
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") load_lora_weights < source > ( pretrained_model_name_or_path_or_dict: Union adapter_name = None **kwargs ) Parameters pretrained_model_name_or_path_or_dict (str or os.PathLike or dict) —
See lora_state_dict(). kwargs (dict, optional) —
See lora_state_dict(). adapter_name (str, optional) —
Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
default_{i} where i is the total number of adapters being loaded. Load LoRA weights specified in pretrained_model_name_or_path_or_dict into self.unet and
self.text_encoder. All kwargs are forwarded to self.lora_state_dict. See lora_state_dict() for more details on how the state dict is loaded. See load_lora_into_unet() for more details on how the state dict is loaded into
self.unet. See load_lora_into_text_encoder() for more details on how the state dict is loaded
into self.text_encoder. save_lora_weights < source > ( save_directory: Union unet_lora_layers: Dict = None text_encoder_lora_layers: Dict = None transformer_lora_layers: Dict = None is_main_process: bool = True weight_name: str = None save_function: Callable = None safe_serialization: bool = True ) Parameters sa...
Directory to save LoRA parameters to. Will be created if it doesn’t exist. unet_lora_layers (Dict[str, torch.nn.Module] or Dict[str, torch.Tensor]) —
State dict of the LoRA layers corresponding to the unet. text_encoder_lora_layers (Dict[str, torch.nn.Module] or Dict[str, torch.Tensor]) —
State dict of the LoRA layers corresponding to the text_encoder. Must explicitly pass the text
encoder LoRA state dict because it comes from 🤗 Transformers. is_main_process (bool, optional, defaults to True) —
Whether the process calling this is the main process or not. Useful during distributed training and you
need to call this function on all processes. In this case, set is_main_process=True only on the main
process to avoid race conditions. save_function (Callable) —
The function to use to save the state dictionary. Useful during distributed training when you need to
replace torch.save with another method. Can be configured with the environment variable
DIFFUSERS_SAVE_MODE. safe_serialization (bool, optional, defaults to True) —
Whether to save the model using safetensors or the traditional PyTorch way with pickle. Save the LoRA parameters corresponding to the UNet and text encoder. disable_freeu < source > ( ) Disables the FreeU mechanism if enabled. enable_freeu < source > ( s1: float s2: float b1: float b2: float ) Parameters ...
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to
mitigate “oversmoothing effect” in the enhanced denoising process. s2 (float) —
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to
mitigate “oversmoothing effect” in the enhanced denoising process. b1 (float) — Scaling factor for stage 1 to amplify the contributions of backbone features. b2 (float) — Scaling factor for stage 2 to amplify the contributions of backbone features. Enables the FreeU mechanism as in https://arxiv.org/abs/2309.114...
that are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL. StableDiffusionXLInstructPix2PixPipeline class diffusers.StableDiffusionXLInstructPix2PixPipeline < source > ( vae: AutoencoderKL text_encoder: CLIPTextModel text_encoder_2: CLIPTextModelWithProjection token...
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. text_encoder (CLIPTextModel) —
Frozen text-encoder. Stable Diffusion XL uses the text portion of
CLIP, specifically
the clip-vit-large-patch14 variant. text_encoder_2 ( CLIPTextModelWithProjection) —
Second frozen text-encoder. Stable Diffusion XL uses the text and pool portion of
CLIP,
specifically the
laion/CLIP-ViT-bigG-14-laion2B-39B-b160k
variant. tokenizer (CLIPTokenizer) —
Tokenizer of class
CLIPTokenizer. tokenizer_2 (CLIPTokenizer) —
Second Tokenizer of class
CLIPTokenizer. unet (UNet2DConditionModel) — Conditional U-Net architecture to denoise the encoded image latents. scheduler (SchedulerMixin) —
A scheduler to be used in combination with unet to denoise the encoded image latents. Can be one of
DDIMScheduler, LMSDiscreteScheduler, or PNDMScheduler. requires_aesthetics_score (bool, optional, defaults to "False") —
Whether the unet requires a aesthetic_score condition to be passed during inference. Also see the config
of stabilityai/stable-diffusion-xl-refiner-1-0. force_zeros_for_empty_prompt (bool, optional, defaults to "True") —
Whether the negative prompt embeddings shall be forced to always be set to 0. Also see the config of
stabilityai/stable-diffusion-xl-base-1-0. add_watermarker (bool, optional) —
Whether to use the invisible_watermark library to
watermark output images. If not defined, it will default to True if the package is installed, otherwise no
watermarker will be used. Pipeline for pixel-level image editing by following text instructions. Based on Stable Diffusion XL. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.) The pipeline also inherits the following loading methods: load_textual_inversion() for loading textual inversion embeddings from_single_file() for loading .ckpt files load_lora_weights() for loading LoRA weigh...
The prompt or prompts to guide the image generation. If not defined, one has to pass prompt_embeds.
instead. prompt_2 (str or List[str], optional) —
The prompt or prompts to be sent to the tokenizer_2 and text_encoder_2. If not defined, prompt is
used in both text-encoders image (torch.FloatTensor or PIL.Image.Image or np.ndarray or List[torch.FloatTensor] or List[PIL.Image.Image] or List[np.ndarray]) —
The image(s) to modify with the pipeline. height (int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) —
The height in pixels of the generated image. width (int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) —
The width in pixels of the generated image. num_inference_steps (int, optional, defaults to 50) —
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference. denoising_end (float, optional) —
When specified, determines the fraction (between 0.0 and 1.0) of the total denoising process to be
completed before it is intentionally prematurely terminated. As a result, the returned sample will
still retain a substantial amount of noise as determined by the discrete timesteps selected by the
scheduler. The denoising_end parameter should ideally be utilized when this pipeline forms a part of a
“Mixture of Denoisers” multi-pipeline setup, as elaborated in Refining the Image
Output guidance_scale (float, optional, defaults to 5.0) —
Guidance scale as defined in Classifier-Free Diffusion Guidance.
guidance_scale is defined as w of equation 2. of Imagen
Paper. Guidance scale is enabled by setting guidance_scale > 1. Higher guidance scale encourages to generate images that are closely linked to the text prompt,
usually at the expense of lower image quality. image_guidance_scale (float, optional, defaults to 1.5) —
Image guidance scale is to push the generated image towards the inital image image. Image guidance
scale is enabled by setting image_guidance_scale > 1. Higher image guidance scale encourages to
generate images that are closely linked to the source image image, usually at the expense of lower
image quality. This pipeline requires a value of at least 1. negative_prompt (str or List[str], optional) —
The prompt or prompts not to guide the image generation. If not defined, one has to pass
negative_prompt_embeds instead. Ignored when not using guidance (i.e., ignored if guidance_scale is
less than 1). negative_prompt_2 (str or List[str], optional) —
The prompt or prompts not to guide the image generation to be sent to tokenizer_2 and
text_encoder_2. If not defined, negative_prompt is used in both text-encoders. num_images_per_prompt (int, optional, defaults to 1) —
The number of images to generate per prompt. eta (float, optional, defaults to 0.0) —
Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
schedulers.DDIMScheduler, will be ignored for others. generator (torch.Generator or List[torch.Generator], optional) —
One or a list of torch generator(s)
to make generation deterministic. latents (torch.FloatTensor, optional) —
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random generator. prompt_embeds (torch.FloatTensor, optional) —
Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not
provided, text embeddings will be generated from prompt input argument. negative_prompt_embeds (torch.FloatTensor, optional) —