text stringlengths 0 5.54k |
|---|
a tuple, the first element is a list with the generated images. |
The call function to the pipeline for generation. Examples: Copied >>> import torch |
>>> from diffusers import StableUnCLIPPipeline |
>>> pipe = StableUnCLIPPipeline.from_pretrained( |
... "fusing/stable-unclip-2-1-l", torch_dtype=torch.float16 |
... ) # TODO update model path |
>>> pipe = pipe.to("cuda") |
>>> prompt = "a photo of an astronaut riding a horse on mars" |
>>> images = pipe(prompt).images |
>>> images[0].save("astronaut_horse.png") enable_attention_slicing < source > ( slice_size: Union = 'auto' ) Parameters slice_size (str or int, optional, defaults to "auto") β |
When "auto", halves the input to the attention heads, so attention will be computed in two steps. If |
"max", maximum amount of memory will be saved by running only one slice at a time. If a number is |
provided, uses as many slices as attention_head_dim // slice_size. In this case, attention_head_dim |
must be a multiple of slice_size. Enable sliced attention computation. When this option is enabled, the attention module splits the input tensor |
in slices to compute attention in several steps. For more than one attention head, the computation is performed |
sequentially over each head. This is useful to save some memory in exchange for a small speed decrease. β οΈ Donβt enable attention slicing if youβre already using scaled_dot_product_attention (SDPA) from PyTorch |
2.0 or xFormers. These attention computations are already very memory efficient so you wonβt need to enable |
this function. If you enable attention slicing with SDPA or xFormers, it can lead to serious slow downs! Examples: Copied >>> import torch |
>>> from diffusers import StableDiffusionPipeline |
>>> pipe = StableDiffusionPipeline.from_pretrained( |
... "runwayml/stable-diffusion-v1-5", |
... torch_dtype=torch.float16, |
... use_safetensors=True, |
... ) |
>>> prompt = "a photo of an astronaut riding a horse on mars" |
>>> pipe.enable_attention_slicing() |
>>> image = pipe(prompt).images[0] disable_attention_slicing < source > ( ) Disable sliced attention computation. If enable_attention_slicing was previously called, attention is |
computed in one step. enable_vae_slicing < source > ( ) Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to |
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes. disable_vae_slicing < source > ( ) Disable sliced VAE decoding. If enable_vae_slicing was previously enabled, this method will go back to |
computing decoding in one step. enable_xformers_memory_efficient_attention < source > ( attention_op: Optional = None ) Parameters attention_op (Callable, optional) β |
Override the default None operator for use as op argument to the |
memory_efficient_attention() |
function of xFormers. Enable memory efficient attention from xFormers. When this |
option is enabled, you should observe lower GPU memory usage and a potential speed up during inference. Speed |
up during training is not guaranteed. β οΈ When memory efficient attention and sliced attention are both enabled, memory efficient attention takes |
precedent. Examples: Copied >>> import torch |
>>> from diffusers import DiffusionPipeline |
>>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp |
>>> pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16) |
>>> pipe = pipe.to("cuda") |
>>> pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp) |
>>> # Workaround for not accepting attention shape using VAE for Flash Attention |
>>> pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None) disable_xformers_memory_efficient_attention < source > ( ) Disable memory efficient attention from xFormers. encode_prompt < source > ( prompt device num_images_per_prompt do_classifier_free_guidance negative_prompt = None prompt_embeds: ... |
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. noise_image_embeddings < source > ( image_embeds: Tensor noise_level: int noise: Optional = None generator: Optional = None ) Add noise to the image embeddings. The amount of ... |
noise_level increases the variance in the final un-noised images. The noise is applied in two ways: A noise schedule is applied directly to the embeddings. A vector of sinusoidal time embeddings are appended to the output. In both cases, the amount of noise is controlled by the same noise_level. The embeddings are norm... |
Feature extractor for image pre-processing before being encoded. image_encoder (CLIPVisionModelWithProjection) β |
CLIP vision model for encoding images. image_normalizer (StableUnCLIPImageNormalizer) β |
Used to normalize the predicted image embeddings before the noise is applied and un-normalize the image |
embeddings after the noise has been applied. image_noising_scheduler (KarrasDiffusionSchedulers) β |
Noise schedule for adding noise to the predicted image embeddings. The amount of noise to add is determined |
by the noise_level. tokenizer (~transformers.CLIPTokenizer) β |
A [~transformers.CLIPTokenizer)]. text_encoder (CLIPTextModel) β |
Frozen CLIPTextModel text-encoder. unet (UNet2DConditionModel) β |
A UNet2DConditionModel to denoise the encoded image latents. scheduler (KarrasDiffusionSchedulers) β |
A scheduler to be used in combination with unet to denoise the encoded image latents. vae (AutoencoderKL) β |
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. Pipeline for text-guided image-to-image generation using stable unCLIP. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods |
implemented for all pipelines (downloading, saving, running on a particular device, etc.). The pipeline also inherits the following loading methods: load_textual_inversion() for loading textual inversion embeddings load_lora_weights() for loading LoRA weights save_lora_weights() for saving LoRA weights __call__ < sou... |
The prompt or prompts to guide the image generation. If not defined, either prompt_embeds will be |
used or prompt is initialized to "". image (torch.FloatTensor or PIL.Image.Image) β |
Image or tensor representing an image batch. The image is encoded to its CLIP embedding which the |
unet is conditioned on. The image is not encoded by the vae and then used as the latents in the |
denoising process like it is in the standard Stable Diffusion text-guided image variation process. 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 20) β |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the |
expense of slower inference. guidance_scale (float, optional, defaults to 10.0) β |
A higher guidance scale value encourages the model to generate images closely linked to the text |
prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1. negative_prompt (str or List[str], optional) β |
The prompt or prompts to guide what to not include in image generation. If not defined, you need to |
pass negative_prompt_embeds instead. Ignored when not using guidance (guidance_scale < 1). 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 (Ξ·) from the DDIM paper. Only applies |
to the DDIMScheduler, and is ignored in other schedulers. generator (torch.Generator or List[torch.Generator], optional) β |
A torch.Generator 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 is 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 (prompt weighting). If not |
provided, text embeddings are generated from the prompt input argument. negative_prompt_embeds (torch.FloatTensor, optional) β |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.