text
stringlengths
0
5.54k
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. encode_prompt < source > ( prompt device num_images_per_prompt do_classifier_free_guidance negative_prompt = None prompt_embeds: Optional = None negative_prom...
prompt to be encoded
device — (torch.device):
torch device num_images_per_prompt (int) —
number of images that should be generated per prompt do_classifier_free_guidance (bool) —
whether to use classifier free guidance or not 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). 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) —
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, e.g. prompt
weighting. If not provided, negative_prompt_embeds will be generated from negative_prompt input
argument. lora_scale (float, optional) —
A LoRA scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded. clip_skip (int, optional) —
Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
the output of the pre-final layer will be used for computing the prompt embeddings. Encodes the prompt into text encoder hidden states. StableDiffusionPipelineOutput class diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput < source > ( images: Union nsfw_content_detected: Optional ) Parameters ...
List of denoised PIL images of length batch_size or NumPy array of shape (batch_size, height, width, num_channels). nsfw_content_detected (List[bool]) —
List indicating whether the corresponding generated image contains “not-safe-for-work” (nsfw) content or
None if safety checking could not be performed. Output class for Stable Diffusion pipelines.
DPMSolverSinglestepScheduler DPMSolverSinglestepScheduler is a single step scheduler from DPM-Solver: A Fast ODE Solver for Diffusion Probabilistic Model Sampling in Around 10 Steps and DPM-Solver++: Fast Solver for Guided Sampling of Diffusion Probabilistic Models by Cheng Lu, Yuhao Zhou, Fan Bao, Jianfei Chen, Chongx...
samples, and it can generate quite good samples even in 10 steps. The original implementation can be found at LuChengTHU/dpm-solver. Tips It is recommended to set solver_order to 2 for guide sampling, and solver_order=3 for unconditional sampling. Dynamic thresholding from Imagen is supported, and for pixel-space
diffusion models, you can set both algorithm_type="dpmsolver++" and thresholding=True to use dynamic
thresholding. This thresholding method is unsuitable for latent-space diffusion models such as
Stable Diffusion. DPMSolverSinglestepScheduler class diffusers.DPMSolverSinglestepScheduler < source > ( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: Optional = None solver_order: int = 2 prediction_type: str = 'epsilon' thresholding: ...
The number of diffusion steps to train the model. beta_start (float, defaults to 0.0001) —
The starting beta value of inference. beta_end (float, defaults to 0.02) —
The final beta value. beta_schedule (str, defaults to "linear") —
The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
linear, scaled_linear, or squaredcos_cap_v2. trained_betas (np.ndarray, optional) —
Pass an array of betas directly to the constructor to bypass beta_start and beta_end. solver_order (int, defaults to 2) —
The DPMSolver order which can be 1 or 2 or 3. It is recommended to use solver_order=2 for guided
sampling, and solver_order=3 for unconditional sampling. prediction_type (str, defaults to epsilon, optional) —
Prediction type of the scheduler function; can be epsilon (predicts the noise of the diffusion process),
sample (directly predicts the noisy sample) or v_prediction` (see section 2.4 of Imagen
Video paper). thresholding (bool, defaults to False) —
Whether to use the “dynamic thresholding” method. This is unsuitable for latent-space diffusion models such
as Stable Diffusion. dynamic_thresholding_ratio (float, defaults to 0.995) —
The ratio for the dynamic thresholding method. Valid only when thresholding=True. sample_max_value (float, defaults to 1.0) —
The threshold value for dynamic thresholding. Valid only when thresholding=True and
algorithm_type="dpmsolver++". algorithm_type (str, defaults to dpmsolver++) —
Algorithm type for the solver; can be dpmsolver or dpmsolver++. The
dpmsolver type implements the algorithms in the DPMSolver
paper, and the dpmsolver++ type implements the algorithms in the
DPMSolver++ paper. It is recommended to use dpmsolver++ or
sde-dpmsolver++ with solver_order=2 for guided sampling like in Stable Diffusion. solver_type (str, defaults to midpoint) —
Solver type for the second-order solver; can be midpoint or heun. The solver type slightly affects the
sample quality, especially for a small number of steps. It is recommended to use midpoint solvers. lower_order_final (bool, defaults to True) —
Whether to use lower-order solvers in the final steps. Only valid for < 15 inference steps. This can
stabilize the sampling of DPMSolver for steps < 15, especially for steps <= 10. use_karras_sigmas (bool, optional, defaults to False) —
Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If True,
the sigmas are determined according to a sequence of noise levels {σi}. final_sigmas_type (str, optional, defaults to "zero") —
The final sigma value for the noise schedule during the sampling process. If "sigma_min", the final sigma
is the same as the last sigma in the training schedule. If zero, the final sigma is set to 0. lambda_min_clipped (float, defaults to -inf) —
Clipping threshold for the minimum value of lambda(t) for numerical stability. This is critical for the
cosine (squaredcos_cap_v2) noise schedule. variance_type (str, optional) —
Set to “learned” or “learned_range” for diffusion models that predict variance. If set, the model’s output
contains the predicted Gaussian variance. DPMSolverSinglestepScheduler is a fast dedicated high-order solver for diffusion ODEs. This model inherits from SchedulerMixin and ConfigMixin. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving. convert_model_output < source > ( model_output: FloatTensor *args sample: FloatTensor = None **kwargs ) → torch.FloatTensor Parameters model_output (torch.FloatTensor) —
The direct output from the learned diffusion model. sample (torch.FloatTensor) —
A current instance of a sample created by the diffusion process. Returns
torch.FloatTensor
The converted model output.
Convert the model output to the corresponding type the DPMSolver/DPMSolver++ algorithm needs. DPM-Solver is
designed to discretize an integral of the noise prediction model, and DPM-Solver++ is designed to discretize an
integral of the data prediction model. The algorithm and model type are decoupled. You can use either DPMSolver or DPMSolver++ for both noise
prediction and data prediction models. dpm_solver_first_order_update < source > ( model_output: FloatTensor *args sample: FloatTensor = None **kwargs ) → torch.FloatTensor Parameters model_output (torch.FloatTensor) —