source
stringclasses
273 values
url
stringlengths
47
172
file_type
stringclasses
1 value
chunk
stringlengths
1
512
chunk_id
stringlengths
5
9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl/#optimizations
.md
SDXL is a large model, and you may need to optimize memory to get it to run on your hardware. Here are some tips to save memory and speed up inference. 1. Offload the model to the CPU with [`~StableDiffusionXLPipeline.enable_model_cpu_offload`] for out-of-memory errors: ```diff - base.to("cuda") - refiner.to("cuda"...
58_13_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl/#optimizations
.md
+ refiner.enable_model_cpu_offload() ``` 2. Use `torch.compile` for ~20% speed-up (you need `torch>=2.0`): ```diff + base.unet = torch.compile(base.unet, mode="reduce-overhead", fullgraph=True) + refiner.unet = torch.compile(refiner.unet, mode="reduce-overhead", fullgraph=True) ``` 3. Enable [xFormers](../optimiz...
58_13_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl/#other-resources
.md
If you're interested in experimenting with a minimal version of the [`UNet2DConditionModel`] used in SDXL, take a look at the [minSDXL](https://github.com/cloneofsimo/minSDXL) implementation which is written in PyTorch and directly compatible with 🤗 Diffusers.
58_14_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
59_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
59_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#load-schedulers-and-models
.md
[[open-in-colab]] Diffusion pipelines are a collection of interchangeable schedulers and models that can be mixed and matched to tailor a pipeline to a specific use case. The scheduler encapsulates the entire denoising process such as the number of denoising steps and the algorithm for finding the denoised sample. A ...
59_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#load-schedulers-and-models
.md
This guide will show you how to load schedulers and models to customize a pipeline. You'll use the [stable-diffusion-v1-5/stable-diffusion-v1-5](https://hf.co/stable-diffusion-v1-5/stable-diffusion-v1-5) checkpoint throughout this guide, so let's load it first. ```py import torch from diffusers import DiffusionPipeli...
59_1_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#load-schedulers-and-models
.md
pipeline = DiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16, use_safetensors=True ).to("cuda") ``` You can see what scheduler this pipeline uses with the `pipeline.scheduler` attribute. ```py pipeline.scheduler PNDMScheduler { "_class_name": "PNDMScheduler"...
59_1_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#load-schedulers-and-models
.md
"beta_start": 0.00085, "clip_sample": false, "num_train_timesteps": 1000, "set_alpha_to_one": false, "skip_prk_steps": true, "steps_offset": 1, "timestep_spacing": "leading", "trained_betas": null } ```
59_1_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#load-a-scheduler
.md
Schedulers are defined by a configuration file that can be used by a variety of schedulers. Load a scheduler with the [`SchedulerMixin.from_pretrained`] method, and specify the `subfolder` parameter to load the configuration file into the correct subfolder of the pipeline repository. For example, to load the [`DDIMSc...
59_2_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#load-a-scheduler
.md
ddim = DDIMScheduler.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="scheduler") ``` Then you can pass the newly loaded scheduler to the pipeline. ```python pipeline = DiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", scheduler=ddim, torch_dtype=torch.float1...
59_2_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
Schedulers have their own unique strengths and weaknesses, making it difficult to quantitatively compare which scheduler works best for a pipeline. You typically have to make a trade-off between denoising speed and denoising quality. We recommend trying out different schedulers to find one that works best for your use ...
59_3_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
Let's compare the [`LMSDiscreteScheduler`], [`EulerDiscreteScheduler`], [`EulerAncestralDiscreteScheduler`], and the [`DPMSolverMultistepScheduler`] on the following prompt and seed. ```py import torch from diffusers import DiffusionPipeline
59_3_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
pipeline = DiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16, use_safetensors=True ).to("cuda")
59_3_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
prompt = "A photograph of an astronaut riding a horse on Mars, high resolution, high definition." generator = torch.Generator(device="cuda").manual_seed(8) ``` To change the pipelines scheduler, use the [`~ConfigMixin.from_config`] method to load a different scheduler's `pipeline.scheduler.config` into the pipeline. ...
59_3_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
[`LMSDiscreteScheduler`] typically generates higher quality images than the default scheduler. ```py from diffusers import LMSDiscreteScheduler
59_3_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
pipeline.scheduler = LMSDiscreteScheduler.from_config(pipeline.scheduler.config) image = pipeline(prompt, generator=generator).images[0] image ``` </hfoption> <hfoption id="EulerDiscreteScheduler"> [`EulerDiscreteScheduler`] can generate higher quality images in just 30 steps. ```py from diffusers import EulerDis...
59_3_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config) image = pipeline(prompt, generator=generator).images[0] image ``` </hfoption> <hfoption id="EulerAncestralDiscreteScheduler"> [`EulerAncestralDiscreteScheduler`] can generate higher quality images in just 30 steps. ```py from diffu...
59_3_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config) image = pipeline(prompt, generator=generator).images[0] image ``` </hfoption> <hfoption id="DPMSolverMultistepScheduler"> [`DPMSolverMultistepScheduler`] provides a balance between speed and quality and can generate higher q...
59_3_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config) image = pipeline(prompt, generator=generator).images[0] image ``` </hfoption> </hfoptions> <div class="flex gap-4"> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/diffuser...
59_3_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">LMSDiscreteScheduler</figcaption> </div> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/diffusers_docs/astronaut_euler_discrete.png" /> <figcaption class="mt-2 text-center text-sm text-gray-500">EulerDisc...
59_3_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
</div> </div> <div class="flex gap-4"> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/diffusers_docs/astronaut_euler_ancestral.png" /> <figcaption class="mt-2 text-center text-sm text-gray-500">EulerAncestralDiscreteScheduler</figcaption> </div> <div> <img class=...
59_3_10
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#compare-schedulers
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">DPMSolverMultistepScheduler</figcaption> </div> </div> Most images look very similar and are comparable in quality. Again, it often comes down to your specific use case so a good approach is to run multiple different schedulers and compare the results.
59_3_11
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#flax-schedulers
.md
To compare Flax schedulers, you need to additionally load the scheduler state into the model parameters. For example, let's change the default scheduler in [`FlaxStableDiffusionPipeline`] to use the super fast [`FlaxDPMSolverMultistepScheduler`]. > [!WARNING] > The [`FlaxLMSDiscreteScheduler`] and [`FlaxDDPMScheduler...
59_4_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#flax-schedulers
.md
```py import jax import numpy as np from flax.jax_utils import replicate from flax.training.common_utils import shard from diffusers import FlaxStableDiffusionPipeline, FlaxDPMSolverMultistepScheduler
59_4_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#flax-schedulers
.md
scheduler, scheduler_state = FlaxDPMSolverMultistepScheduler.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="scheduler" ) pipeline, params = FlaxStableDiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", scheduler=scheduler, variant="bf16", dtype=jax.numpy.bfloat1...
59_4_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#flax-schedulers
.md
scheduler=scheduler, variant="bf16", dtype=jax.numpy.bfloat16, ) params["scheduler"] = scheduler_state ``` Then you can take advantage of Flax's compatibility with TPUs to generate a number of images in parallel. You'll need to make a copy of the model parameters for each available device and then split the inputs ac...
59_4_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#flax-schedulers
.md
```py # Generate 1 image per parallel device (8 on TPUv2-8 or TPUv3-8) prompt = "A photograph of an astronaut riding a horse on Mars, high resolution, high definition." num_samples = jax.device_count() prompt_ids = pipeline.prepare_inputs([prompt] * num_samples)
59_4_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#flax-schedulers
.md
prng_seed = jax.random.PRNGKey(0) num_inference_steps = 25 # shard inputs and rng params = replicate(params) prng_seed = jax.random.split(prng_seed, jax.device_count()) prompt_ids = shard(prompt_ids) images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images images = pipeline.numpy_to_pil(...
59_4_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#models
.md
Models are loaded from the [`ModelMixin.from_pretrained`] method, which downloads and caches the latest version of the model weights and configurations. If the latest files are available in the local cache, [`~ModelMixin.from_pretrained`] reuses files in the cache instead of re-downloading them.
59_5_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#models
.md
Models can be loaded from a subfolder with the `subfolder` argument. For example, the model weights for [stable-diffusion-v1-5/stable-diffusion-v1-5](https://hf.co/stable-diffusion-v1-5/stable-diffusion-v1-5) are stored in the [unet](https://hf.co/stable-diffusion-v1-5/stable-diffusion-v1-5/tree/main/unet) subfolder. ...
59_5_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#models
.md
unet = UNet2DConditionModel.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="unet", use_safetensors=True) ``` They can also be directly loaded from a [repository](https://huggingface.co/google/ddpm-cifar10-32/tree/main). ```python from diffusers import UNet2DModel
59_5_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/schedulers.md
https://huggingface.co/docs/diffusers/en/using-diffusers/schedulers/#models
.md
unet = UNet2DModel.from_pretrained("google/ddpm-cifar10-32", use_safetensors=True) ``` To load and save model variants, specify the `variant` argument in [`ModelMixin.from_pretrained`] and [`ModelMixin.save_pretrained`]. ```python from diffusers import UNet2DConditionModel unet = UNet2DConditionModel.from_pretrain...
59_5_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
60_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
60_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#stable-diffusion-xl-turbo
.md
[[open-in-colab]] SDXL Turbo is an adversarial time-distilled [Stable Diffusion XL](https://huggingface.co/papers/2307.01952) (SDXL) model capable of running inference in as little as 1 step. This guide will show you how to use SDXL-Turbo for text-to-image and image-to-image. Before you begin, make sure you have ...
60_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#load-model-checkpoints
.md
Model weights may be stored in separate subfolders on the Hub or locally, in which case, you should use the [`~StableDiffusionXLPipeline.from_pretrained`] method: ```py from diffusers import AutoPipelineForText2Image import torch
60_2_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#load-model-checkpoints
.md
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16") pipeline = pipeline.to("cuda") ``` You can also use the [`~StableDiffusionXLPipeline.from_single_file`] method to load a model checkpoint stored in a single file format (`.ckpt` or `.safetensors`)...
60_2_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#load-model-checkpoints
.md
```py from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler import torch
60_2_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#load-model-checkpoints
.md
pipeline = StableDiffusionXLPipeline.from_single_file( "https://huggingface.co/stabilityai/sdxl-turbo/blob/main/sd_xl_turbo_1.0_fp16.safetensors", torch_dtype=torch.float16, variant="fp16") pipeline = pipeline.to("cuda") pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config, timeste...
60_2_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#text-to-image
.md
For text-to-image, pass a text prompt. By default, SDXL Turbo generates a 512x512 image, and that resolution gives the best results. You can try setting the `height` and `width` parameters to 768x768 or 1024x1024, but you should expect quality degradations when doing so. Make sure to set `guidance_scale` to 0.0 to di...
60_3_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#text-to-image
.md
Increasing the number of steps to 2, 3 or 4 should improve image quality. ```py from diffusers import AutoPipelineForText2Image import torch
60_3_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#text-to-image
.md
pipeline_text2image = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16") pipeline_text2image = pipeline_text2image.to("cuda") prompt = "A cinematic shot of a baby racoon wearing an intricate italian priest robe."
60_3_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#text-to-image
.md
prompt = "A cinematic shot of a baby racoon wearing an intricate italian priest robe." image = pipeline_text2image(prompt=prompt, guidance_scale=0.0, num_inference_steps=1).images[0] image ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/sd...
60_3_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#image-to-image
.md
For image-to-image generation, make sure that `num_inference_steps * strength` is larger or equal to 1. The image-to-image pipeline will run for `int(num_inference_steps * strength)` steps, e.g. `0.5 * 2.0 = 1` step in our example below. ```py from diffusers import AutoPipelineForImage2Image from diffusers.utils impo...
60_4_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#image-to-image
.md
# use from_pipe to avoid consuming additional memory when loading a checkpoint pipeline_image2image = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cuda") init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") init_image = init_image.r...
60_4_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#image-to-image
.md
prompt = "cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k" image = pipeline_image2image(prompt, image=init_image, strength=0.5, guidance_scale=0.0, num_inference_steps=2).images[0] make_image_grid([init_image, image], rows=1, cols=2) ``` <div class="flex justify-center"> ...
60_4_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#speed-up-sdxl-turbo-even-more
.md
- Compile the UNet if you are using PyTorch version 2.0 or higher. The first inference run will be very slow, but subsequent ones will be much faster. ```py pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) ``` - When using the default VAE, keep it in `float32` to avoid costly `dtype` con...
60_5_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/sdxl_turbo.md
https://huggingface.co/docs/diffusers/en/using-diffusers/sdxl_turbo/#speed-up-sdxl-turbo-even-more
.md
```py pipe.upcast_vae() ``` As an alternative, you can also use a [16-bit VAE](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix) created by community member [`@madebyollin`](https://huggingface.co/madebyollin) that does not need to be upcasted to `float32`.
60_5_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
61_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
61_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#latent-consistency-model
.md
[[open-in-colab]]
61_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#latent-consistency-model
.md
[Latent Consistency Models (LCMs)](https://hf.co/papers/2310.04378) enable fast high-quality image generation by directly predicting the reverse diffusion process in the latent rather than pixel space. In other words, LCMs try to predict the noiseless image from the noisy image in contrast to typical diffusion models t...
61_1_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#latent-consistency-model
.md
LCMs are distilled from pretrained models which requires ~32 hours of A100 compute. To speed this up, [LCM-LoRAs](https://hf.co/papers/2311.05556) train a [LoRA adapter](https://huggingface.co/docs/peft/conceptual_guides/adapter#low-rank-adaptation-lora) which have much fewer parameters to train compared to the full mo...
61_1_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#latent-consistency-model
.md
This guide will show you how to use LCMs and LCM-LoRAs for fast inference on tasks and how to use them with other adapters like ControlNet or T2I-Adapter. > [!TIP] > LCMs and LCM-LoRAs are available for Stable Diffusion v1.5, Stable Diffusion XL, and the SSD-1B model. You can find their checkpoints on the [Latent Con...
61_1_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
<hfoptions id="lcm-text2img"> <hfoption id="LCM"> To use LCMs, you need to load the LCM checkpoint for your supported model into [`UNet2DConditionModel`] and replace the scheduler with the [`LCMScheduler`]. Then you can use the pipeline as usual, and pass a text prompt to generate an image in just 4 steps. A couple...
61_2_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
A couple of notes to keep in mind when using LCMs are: * Typically, batch size is doubled inside the pipeline for classifier-free guidance. But LCM applies guidance with guidance embeddings and doesn't need to double the batch size, which leads to faster inference. The downside is that negative prompts don't work wit...
61_2_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
* The ideal range for `guidance_scale` is [3., 13.] because that is what the UNet was trained with. However, disabling `guidance_scale` with a value of 1.0 is also effective in most cases. ```python from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, LCMScheduler import torch
61_2_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
unet = UNet2DConditionModel.from_pretrained( "latent-consistency/lcm-sdxl", torch_dtype=torch.float16, variant="fp16", ) pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", unet=unet, torch_dtype=torch.float16, variant="fp16", ).to("cuda") pipe.scheduler = LCMScheduler.from_con...
61_2_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k" generator = torch.manual_seed(0) image = pipe( prompt=prompt, num_inference_steps=4, generator=generator, guidance_scale=8.0 ).images[0] image ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/docu...
61_2_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
</div> </hfoption> <hfoption id="LCM-LoRA"> To use LCM-LoRAs, you need to replace the scheduler with the [`LCMScheduler`] and load the LCM-LoRA weights with the [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] method. Then you can use the pipeline as usual, and pass a text prompt to generate an image i...
61_2_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
A couple of notes to keep in mind when using LCM-LoRAs are: * Typically, batch size is doubled inside the pipeline for classifier-free guidance. But LCM applies guidance with guidance embeddings and doesn't need to double the batch size, which leads to faster inference. The downside is that negative prompts don't wor...
61_2_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
* You could use guidance with LCM-LoRAs, but it is very sensitive to high `guidance_scale` values and can lead to artifacts in the generated image. The best values we've found are between [1.0, 2.0]. * Replace [stabilityai/stable-diffusion-xl-base-1.0](https://hf.co/stabilityai/stable-diffusion-xl-base-1.0) with any fi...
61_2_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
```py import torch from diffusers import DiffusionPipeline, LCMScheduler
61_2_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", variant="fp16", torch_dtype=torch.float16 ).to("cuda") pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
61_2_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#text-to-image
.md
prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k" generator = torch.manual_seed(42) image = pipe( prompt=prompt, num_inference_steps=4, generator=generator, guidance_scale=1.0 ).images[0] image ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/doc...
61_2_10
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
<hfoptions id="lcm-img2img"> <hfoption id="LCM"> To use LCMs for image-to-image, you need to load the LCM checkpoint for your supported model into [`UNet2DConditionModel`] and replace the scheduler with the [`LCMScheduler`]. Then you can use the pipeline as usual, and pass a text prompt and initial image to generate ...
61_3_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
```python import torch from diffusers import AutoPipelineForImage2Image, UNet2DConditionModel, LCMScheduler from diffusers.utils import load_image
61_3_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
unet = UNet2DConditionModel.from_pretrained( "SimianLuo/LCM_Dreamshaper_v7", subfolder="unet", torch_dtype=torch.float16, ) pipe = AutoPipelineForImage2Image.from_pretrained( "Lykon/dreamshaper-7", unet=unet, torch_dtype=torch.float16, variant="fp16", ).to("cuda") pipe.scheduler = LCMScheduler.from_config(pipe.schedul...
61_3_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png") prompt = "Astronauts in a jungle, cold color palette, muted colors, detailed, 8k" generator = torch.manual_seed(0) image = pipe( prompt, image=init_image, num_inference_steps=4, guidance_s...
61_3_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
guidance_scale=7.5, strength=0.5, generator=generator ).images[0] image ``` <div class="flex gap-4"> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png"/> <figcaption class="mt-2 text-center text-sm text-gray-500">initial image</...
61_3_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">generated image</figcaption> </div> </div> </hfoption> <hfoption id="LCM-LoRA"> To use LCM-LoRAs for image-to-image, you need to replace the scheduler with the [`LCMScheduler`] and load the LCM-LoRA weights with the [`~loaders.StableDiffusionLoraLoaderMixin...
61_3_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
> [!TIP] > Experiment with different values for `num_inference_steps`, `strength`, and `guidance_scale` to get the best results. ```py import torch from diffusers import AutoPipelineForImage2Image, LCMScheduler from diffusers.utils import make_image_grid, load_image
61_3_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
pipe = AutoPipelineForImage2Image.from_pretrained( "Lykon/dreamshaper-7", torch_dtype=torch.float16, variant="fp16", ).to("cuda") pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5") init_image = load_image("https://huggingface.co/datasets/hugg...
61_3_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
generator = torch.manual_seed(0) image = pipe( prompt, image=init_image, num_inference_steps=4, guidance_scale=1, strength=0.6, generator=generator ).images[0] image ``` <div class="flex gap-4"> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/...
61_3_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#image-to-image
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">initial image</figcaption> </div> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lcm-lora-img2img.png"/> <figcaption class="mt-2 text-center text-sm text-gray-500">generated image</figc...
61_3_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#inpainting
.md
To use LCM-LoRAs for inpainting, you need to replace the scheduler with the [`LCMScheduler`] and load the LCM-LoRA weights with the [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] method. Then you can use the pipeline as usual, and pass a text prompt, initial image, and mask image to generate an image in ...
61_4_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#inpainting
.md
pipe = AutoPipelineForInpainting.from_pretrained( "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16", ).to("cuda") pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")
61_4_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#inpainting
.md
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5") init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png") mask_image = load_image("https://huggingface.co/datasets/huggingf...
61_4_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#inpainting
.md
prompt = "concept art digital painting of an elven castle, inspired by lord of the rings, highly detailed, 8k" generator = torch.manual_seed(0) image = pipe( prompt=prompt, image=init_image, mask_image=mask_image, generator=generator, num_inference_steps=4, guidance_scale=4, ).images[0] image ``` <div class="flex gap...
61_4_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#inpainting
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">initial image</figcaption> </div> <div> <img class="rounded-xl" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lcm-lora-inpaint.png"/> <figcaption class="mt-2 text-center text-sm text-gray-500">generated image</figc...
61_4_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#adapters
.md
LCMs are compatible with adapters like LoRA, ControlNet, T2I-Adapter, and AnimateDiff. You can bring the speed of LCMs to these adapters to generate images in a certain style or condition the model on another input like a canny image.
61_5_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
[LoRA](../using-diffusers/loading_adapters#lora) adapters can be rapidly finetuned to learn a new style from just a few images and plugged into a pretrained model to generate images in that style. <hfoptions id="lcm-lora"> <hfoption id="LCM">
61_6_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
<hfoptions id="lcm-lora"> <hfoption id="LCM"> Load the LCM checkpoint for your supported model into [`UNet2DConditionModel`] and replace the scheduler with the [`LCMScheduler`]. Then you can use the [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] method to load the LoRA weights into the LCM and generate...
61_6_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
unet = UNet2DConditionModel.from_pretrained( "latent-consistency/lcm-sdxl", torch_dtype=torch.float16, variant="fp16", ) pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", unet=unet, torch_dtype=torch.float16, variant="fp16", ).to("cuda") pipe.scheduler = LCMScheduler.from_con...
61_6_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
prompt = "papercut, a cute fox" generator = torch.manual_seed(0) image = pipe( prompt=prompt, num_inference_steps=4, generator=generator, guidance_scale=8.0 ).images[0] image ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lcm/lcm...
61_6_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
</div> </hfoption> <hfoption id="LCM-LoRA"> Replace the scheduler with the [`LCMScheduler`]. Then you can use the [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] method to load the LCM-LoRA weights and the style LoRA you want to use. Combine both LoRA adapters with the [`~loaders.UNet2DConditionLoader...
61_6_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", variant="fp16", torch_dtype=torch.float16 ).to("cuda") pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl", adapter_name="lcm") pipe.load_lora_weights("TheLastBe...
61_6_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#lora
.md
pipe.set_adapters(["lcm", "papercut"], adapter_weights=[1.0, 0.8]) prompt = "papercut, a cute fox" generator = torch.manual_seed(0) image = pipe(prompt, num_inference_steps=4, guidance_scale=1, generator=generator).images[0] image ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggin...
61_6_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
[ControlNet](./controlnet) are adapters that can be trained on a variety of inputs like canny edge, pose estimation, or depth. The ControlNet can be inserted into the pipeline to provide additional conditioning and control to the model for more accurate generation. You can find additional ControlNet models trained on...
61_7_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
<hfoptions id="lcm-controlnet"> <hfoption id="LCM"> Load a ControlNet model trained on canny images and pass it to the [`ControlNetModel`]. Then you can load a LCM model into [`StableDiffusionControlNetPipeline`] and replace the scheduler with the [`LCMScheduler`]. Now pass the canny image to the pipeline and generat...
61_7_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
```python import torch import cv2 import numpy as np from PIL import Image
61_7_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, LCMScheduler from diffusers.utils import load_image, make_image_grid image = load_image( "https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_image_vermeer.png" ).resize((512, 512)) image = np.array(image) low_...
61_7_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
image = np.array(image) low_threshold = 100 high_threshold = 200 image = cv2.Canny(image, low_threshold, high_threshold) image = image[:, :, None] image = np.concatenate([image, image, image], axis=2) canny_image = Image.fromarray(image)
61_7_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16) pipe = StableDiffusionControlNetPipeline.from_pretrained( "SimianLuo/LCM_Dreamshaper_v7", controlnet=controlnet, torch_dtype=torch.float16, safety_checker=None, ).to("cuda") pipe.scheduler = LCMScheduler.from_confi...
61_7_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
generator = torch.manual_seed(0) image = pipe( "the mona lisa", image=canny_image, num_inference_steps=4, generator=generator, ).images[0] make_image_grid([canny_image, image], rows=1, cols=2) ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main...
61_7_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
</div> </hfoption> <hfoption id="LCM-LoRA"> Load a ControlNet model trained on canny images and pass it to the [`ControlNetModel`]. Then you can load a Stable Diffusion v1.5 model into [`StableDiffusionControlNetPipeline`] and replace the scheduler with the [`LCMScheduler`]. Use the [`~loaders.StableDiffusionLoraLo...
61_7_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
> [!TIP] > Experiment with different values for `num_inference_steps`, `controlnet_conditioning_scale`, `cross_attention_kwargs`, and `guidance_scale` to get the best results. ```py import torch import cv2 import numpy as np from PIL import Image
61_7_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, LCMScheduler from diffusers.utils import load_image image = load_image( "https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_image_vermeer.png" ).resize((512, 512)) image = np.array(image) low_threshold = 100 h...
61_7_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/inference_with_lcm.md
https://huggingface.co/docs/diffusers/en/using-diffusers/inference_with_lcm/#controlnet
.md
image = np.array(image) low_threshold = 100 high_threshold = 200 image = cv2.Canny(image, low_threshold, high_threshold) image = image[:, :, None] image = np.concatenate([image, image, image], axis=2) canny_image = Image.fromarray(image)
61_7_10