text stringlengths 0 5.54k |
|---|
The frequency at which the callback function is called. If not specified, the callback is called at |
every step. cross_attention_kwargs (dict, optional) — |
A kwargs dictionary that if specified is passed along to the AttentionProcessor as defined in |
self.processor. 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. Returns |
StableDiffusionPipelineOutput or tuple |
If return_dict is True, StableDiffusionPipelineOutput is returned, |
otherwise a tuple is returned where the first element is a list with the generated images and the |
second element is a list of bools indicating whether the corresponding generated image contains |
“not-safe-for-work” (nsfw) content. |
The call function to the pipeline for generation. Copied >>> import PIL |
>>> import requests |
>>> import torch |
>>> from io import BytesIO |
>>> from diffusers import StableDiffusionDiffEditPipeline |
>>> def download_image(url): |
... response = requests.get(url) |
... return PIL.Image.open(BytesIO(response.content)).convert("RGB") |
>>> img_url = "https://github.com/Xiang-cd/DiffEdit-stable-diffusion/raw/main/assets/origin.png" |
>>> init_image = download_image(img_url).resize((768, 768)) |
>>> pipe = StableDiffusionDiffEditPipeline.from_pretrained( |
... "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16 |
... ) |
>>> pipe = pipe.to("cuda") |
>>> pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) |
>>> pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config) |
>>> pipeline.enable_model_cpu_offload() |
>>> mask_prompt = "A bowl of fruits" |
>>> prompt = "A bowl of pears" |
>>> mask_image = pipe.generate_mask(image=init_image, source_prompt=prompt, target_prompt=mask_prompt) |
>>> image_latents = pipe.invert(image=init_image, prompt=mask_prompt).latents |
>>> image = pipe(prompt=prompt, mask_image=mask_image, image_latents=image_latents).images[0] 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. disable_vae_tiling < source > ( ) Disable tiled VAE decoding. If enable_vae_tiling was previously enabled, this method will go back to |
computing decoding 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. enable_vae_tiling < source > ( ) Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to |
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow |
processing larger images. encode_prompt < source > ( prompt device num_images_per_prompt do_classifier_free_guidance negative_prompt = None prompt_embeds: Optional = None negative_prompt_embeds: Optional = None lora_scale: Optional = None clip_skip: Optional = None ) Parameters prompt (str or List[str], optional... |
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. |
VQModel The VQ-VAE model was introduced in Neural Discrete Representation Learning by Aaron van den Oord, Oriol Vinyals and Koray Kavukcuoglu. The model is used in 🤗 Diffusers to decode latent representations into images. Unlike AutoencoderKL, the VQModel works in a quantized latent space. The abstract from the paper ... |
Tuple of downsample block types. up_block_types (Tuple[str], optional, defaults to ("UpDecoderBlock2D",)) — |
Tuple of upsample block types. block_out_channels (Tuple[int], optional, defaults to (64,)) — |
Tuple of block output channels. layers_per_block (int, optional, defaults to 1) — Number of layers per block. act_fn (str, optional, defaults to "silu") — The activation function to use. latent_channels (int, optional, defaults to 3) — Number of channels in the latent space. sample_size (int, optional, defaults... |
The component-wise standard deviation of the trained latent space computed using the first batch of the |
training set. This is used to scale the latent space to have unit variance when training the diffusion |
model. The latents are scaled with the formula z = z * scaling_factor before being passed to the |
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 Image |
Synthesis with Latent Diffusion Models paper. norm_type (str, optional, defaults to "group") — |
Type of normalization layer to use. Can be one of "group" or "spatial". A VQ-VAE model for decoding latent representations. This model inherits from ModelMixin. Check the superclass documentation for it’s generic methods implemented |
for all models (such as downloading or saving). forward < source > ( sample: FloatTensor return_dict: bool = True ) → VQEncoderOutput or tuple Parameters sample (torch.FloatTensor) — Input sample. return_dict (bool, optional, defaults to True) — |
Whether or not to return a models.vq_model.VQEncoderOutput instead of a plain tuple. Returns |
VQEncoderOutput or tuple |
If return_dict is True, a VQEncoderOutput is returned, otherwise a plain tuple |
is returned. |
The VQModel forward method. VQEncoderOutput class diffusers.models.vq_model.VQEncoderOutput < source > ( latents: FloatTensor ) Parameters latents (torch.FloatTensor of shape (batch_size, num_channels, height, width)) — |
The encoded output sample from the last layer of the model. Output of VQModel encoding method. |
Stable Diffusion XL This script is experimental, and it’s easy to overfit and run into issues like catastrophic forgetting. Try exploring different hyperparameters to get the best results on your dataset. Stable Diffusion XL (SDXL) is a larger and more powerful iteration of the Stable Diffusion model, capable of produc... |
cd diffusers |
pip install . Then navigate to the example folder containing the training script and install the required dependencies for the script you’re using: Copied cd examples/text_to_image |
pip install -r requirements_sdxl.txt 🤗 Accelerate is a library for helping you train on multiple GPUs/TPUs or with mixed-precision. It’ll automatically configure your training setup based on your hardware and environment. Take a look at the 🤗 Accelerate Quick tour to learn more. Initialize an 🤗 Accelerate environmen... |
write_basic_config() Lastly, if you want to train a model on your own dataset, take a look at the Create a dataset for training guide to learn how to create a dataset that works with the training script. Script parameters The following sections highlight parts of the training script that are important for understandin... |
--mixed_precision="bf16" Most of the parameters are identical to the parameters in the Text-to-image training guide, so you’ll focus on the parameters that are relevant to training SDXL in this guide. --pretrained_vae_model_name_or_path: path to a pretrained VAE; the SDXL VAE is known to suffer from numerical instabi... |
--snr_gamma=5.0 Training script The training script is also similar to the Text-to-image training guide, but it’s been modified to support SDXL training. This guide will focus on the code that is unique to the SDXL training script. It starts by creating functions to tokenize the prompts to calculate the prompt embed... |
args.pretrained_model_name_or_path, subfolder="tokenizer", revision=args.revision, use_fast=False |
) |
tokenizer_two = AutoTokenizer.from_pretrained( |
args.pretrained_model_name_or_path, subfolder="tokenizer_2", revision=args.revision, use_fast=False |
) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.