diff --git a/docs/source/en/advanced_inference/outpaint.md b/docs/source/en/advanced_inference/outpaint.md index 0613543f2aa2..bcc969ebe17f 100644 --- a/docs/source/en/advanced_inference/outpaint.md +++ b/docs/source/en/advanced_inference/outpaint.md @@ -117,7 +117,7 @@ controlnets = [ "diffusers/controlnet-zoe-depth-sdxl-1.0", dtype=torch.float16 ), ] -vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16).to("cuda") +vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" pipeline = StableDiffusionXLControlNetPipeline.from_pretrained( "SG161222/RealVisXL_V4.0", dtype=torch.float16, variant="fp16", controlnet=controlnets, vae=vae ).to("cuda") @@ -176,7 +176,7 @@ pipeline = StableDiffusionXLInpaintPipeline.from_pretrained( dtype=torch.float16, variant="fp16", vae=vae, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Prepare a mask for the final outpainted image. To create a more natural transition between the original image and the outpainted background, blur the mask to help it blend better. diff --git a/docs/source/en/api/models/allegro_transformer3d.md b/docs/source/en/api/models/allegro_transformer3d.md index 48dd886b24eb..d64aada626a6 100644 --- a/docs/source/en/api/models/allegro_transformer3d.md +++ b/docs/source/en/api/models/allegro_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AllegroTransformer3DModel -transformer = AllegroTransformer3DModel.from_pretrained("rhymes-ai/Allegro", subfolder="transformer", dtype=torch.bfloat16).to("cuda") +transformer = AllegroTransformer3DModel.from_pretrained("rhymes-ai/Allegro", subfolder="transformer", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" ``` ## AllegroTransformer3DModel diff --git a/docs/source/en/api/models/asymmetricautoencoderkl.md b/docs/source/en/api/models/asymmetricautoencoderkl.md index 0c7fbd38fb54..c7312ebf0562 100644 --- a/docs/source/en/api/models/asymmetricautoencoderkl.md +++ b/docs/source/en/api/models/asymmetricautoencoderkl.md @@ -41,7 +41,7 @@ mask_image = load_image(mask_url).resize((512, 512)) pipe = StableDiffusionInpaintPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-inpainting") pipe.vae = AsymmetricAutoencoderKL.from_pretrained("cross-attention/asymmetric-autoencoder-kl-x-1-5") -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe(prompt=prompt, image=original_image, mask_image=mask_image).images[0] make_image_grid([original_image, mask_image, image], rows=1, cols=3) diff --git a/docs/source/en/api/models/autoencoder_dc.md b/docs/source/en/api/models/autoencoder_dc.md index aff90cf7b596..92fe114e798e 100644 --- a/docs/source/en/api/models/autoencoder_dc.md +++ b/docs/source/en/api/models/autoencoder_dc.md @@ -36,7 +36,7 @@ Load a model in Diffusers format with [`~ModelMixin.from_pretrained`]. ```python from diffusers import AutoencoderDC -ae = AutoencoderDC.from_pretrained("mit-han-lab/dc-ae-f32c32-sana-1.0-diffusers", dtype=torch.float32).to("cuda") +ae = AutoencoderDC.from_pretrained("mit-han-lab/dc-ae-f32c32-sana-1.0-diffusers", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu" ``` ## Load a model in Diffusers via `from_single_file` diff --git a/docs/source/en/api/models/autoencoder_rae.md b/docs/source/en/api/models/autoencoder_rae.md index a8c00dd4fde2..75d4e5d2c91f 100644 --- a/docs/source/en/api/models/autoencoder_rae.md +++ b/docs/source/en/api/models/autoencoder_rae.md @@ -34,7 +34,7 @@ from diffusers import AutoencoderRAE model = AutoencoderRAE.from_pretrained( "nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08" -).to("cuda").eval() +).to("cuda").eval() # or "mps", "xpu", "cpu" ``` ## Encoding and decoding a real image @@ -47,7 +47,7 @@ from torchvision.transforms.functional import to_tensor, to_pil_image model = AutoencoderRAE.from_pretrained( "nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08" -).to("cuda").eval() +).to("cuda").eval() # or "mps", "xpu", "cpu" image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = image.convert("RGB").resize((224, 224)) @@ -68,7 +68,7 @@ Some pretrained checkpoints include per-channel `latents_mean` and `latents_std` ```python model = AutoencoderRAE.from_pretrained( "nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08" -).to("cuda").eval() +).to("cuda").eval() # or "mps", "xpu", "cpu" # Latent normalization is handled automatically inside encode/decode # when the checkpoint config includes latents_mean/latents_std. diff --git a/docs/source/en/api/models/autoencoder_tiny.md b/docs/source/en/api/models/autoencoder_tiny.md index 120c0273a3d0..e3f56eafe9e8 100644 --- a/docs/source/en/api/models/autoencoder_tiny.md +++ b/docs/source/en/api/models/autoencoder_tiny.md @@ -24,7 +24,7 @@ pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-2-1-base", dtype=torch.float16 ) pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", dtype=torch.float16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "slice of delicious New York-style berry cheesecake" image = pipe(prompt, num_inference_steps=25).images[0] @@ -41,7 +41,7 @@ pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 ) pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", dtype=torch.float16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "slice of delicious New York-style berry cheesecake" image = pipe(prompt, num_inference_steps=25).images[0] diff --git a/docs/source/en/api/models/autoencoderkl_allegro.md b/docs/source/en/api/models/autoencoderkl_allegro.md index 2f5220231026..a000d4593033 100644 --- a/docs/source/en/api/models/autoencoderkl_allegro.md +++ b/docs/source/en/api/models/autoencoderkl_allegro.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLAllegro -vae = AutoencoderKLAllegro.from_pretrained("rhymes-ai/Allegro", subfolder="vae", dtype=torch.float32).to("cuda") +vae = AutoencoderKLAllegro.from_pretrained("rhymes-ai/Allegro", subfolder="vae", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLAllegro diff --git a/docs/source/en/api/models/autoencoderkl_audio_ltx_2.md b/docs/source/en/api/models/autoencoderkl_audio_ltx_2.md index b3c4ea88175a..465fdfc3bea9 100644 --- a/docs/source/en/api/models/autoencoderkl_audio_ltx_2.md +++ b/docs/source/en/api/models/autoencoderkl_audio_ltx_2.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLLTX2Audio -vae = AutoencoderKLLTX2Audio.from_pretrained("Lightricks/LTX-2", subfolder="vae", dtype=torch.float32).to("cuda") +vae = AutoencoderKLLTX2Audio.from_pretrained("Lightricks/LTX-2", subfolder="vae", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLLTX2Audio diff --git a/docs/source/en/api/models/autoencoderkl_cogvideox.md b/docs/source/en/api/models/autoencoderkl_cogvideox.md index 184739fc7157..9d2e13758da9 100644 --- a/docs/source/en/api/models/autoencoderkl_cogvideox.md +++ b/docs/source/en/api/models/autoencoderkl_cogvideox.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLCogVideoX -vae = AutoencoderKLCogVideoX.from_pretrained("THUDM/CogVideoX-2b", subfolder="vae", dtype=torch.float16).to("cuda") +vae = AutoencoderKLCogVideoX.from_pretrained("THUDM/CogVideoX-2b", subfolder="vae", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLCogVideoX diff --git a/docs/source/en/api/models/autoencoderkl_ltx_2.md b/docs/source/en/api/models/autoencoderkl_ltx_2.md index 4fc08e9f471a..24fd089f48bb 100644 --- a/docs/source/en/api/models/autoencoderkl_ltx_2.md +++ b/docs/source/en/api/models/autoencoderkl_ltx_2.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLLTX2Video -vae = AutoencoderKLLTX2Video.from_pretrained("Lightricks/LTX-2", subfolder="vae", dtype=torch.float32).to("cuda") +vae = AutoencoderKLLTX2Video.from_pretrained("Lightricks/LTX-2", subfolder="vae", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLLTX2Video diff --git a/docs/source/en/api/models/autoencoderkl_ltx_video.md b/docs/source/en/api/models/autoencoderkl_ltx_video.md index 541d15ee32e4..704c445e5b29 100644 --- a/docs/source/en/api/models/autoencoderkl_ltx_video.md +++ b/docs/source/en/api/models/autoencoderkl_ltx_video.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLLTXVideo -vae = AutoencoderKLLTXVideo.from_pretrained("Lightricks/LTX-Video", subfolder="vae", dtype=torch.float32).to("cuda") +vae = AutoencoderKLLTXVideo.from_pretrained("Lightricks/LTX-Video", subfolder="vae", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLLTXVideo diff --git a/docs/source/en/api/models/autoencoderkl_magvit.md b/docs/source/en/api/models/autoencoderkl_magvit.md index 762578eadb6f..fd537cb86017 100644 --- a/docs/source/en/api/models/autoencoderkl_magvit.md +++ b/docs/source/en/api/models/autoencoderkl_magvit.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLMagvit -vae = AutoencoderKLMagvit.from_pretrained("alibaba-pai/EasyAnimateV5.1-12b-zh", subfolder="vae", dtype=torch.float16).to("cuda") +vae = AutoencoderKLMagvit.from_pretrained("alibaba-pai/EasyAnimateV5.1-12b-zh", subfolder="vae", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLMagvit diff --git a/docs/source/en/api/models/autoencoderkl_minimax_h3.md b/docs/source/en/api/models/autoencoderkl_minimax_h3.md index 97220ee8c04c..1df2aa27241e 100644 --- a/docs/source/en/api/models/autoencoderkl_minimax_h3.md +++ b/docs/source/en/api/models/autoencoderkl_minimax_h3.md @@ -27,7 +27,7 @@ from diffusers import AutoencoderKLMiniMaxH3 vae = AutoencoderKLMiniMaxH3.from_pretrained( "MiniMaxAI/MiniMax-H3", subfolder="vae", dtype=torch.float32 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLMiniMaxH3 diff --git a/docs/source/en/api/models/autoencoderkl_minimax_h3_audio.md b/docs/source/en/api/models/autoencoderkl_minimax_h3_audio.md index ab78da3f5e32..92582b2cb0e6 100644 --- a/docs/source/en/api/models/autoencoderkl_minimax_h3_audio.md +++ b/docs/source/en/api/models/autoencoderkl_minimax_h3_audio.md @@ -25,7 +25,7 @@ from diffusers import AutoencoderKLMiniMaxH3Audio audio_vae = AutoencoderKLMiniMaxH3Audio.from_pretrained( "MiniMaxAI/MiniMax-H3", subfolder="audio_vae", dtype=torch.float32 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLMiniMaxH3Audio diff --git a/docs/source/en/api/models/autoencoderkl_mochi.md b/docs/source/en/api/models/autoencoderkl_mochi.md index 746b1b84c30b..3fc4137a29a4 100644 --- a/docs/source/en/api/models/autoencoderkl_mochi.md +++ b/docs/source/en/api/models/autoencoderkl_mochi.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import AutoencoderKLMochi -vae = AutoencoderKLMochi.from_pretrained("genmo/mochi-1-preview", subfolder="vae", dtype=torch.float32).to("cuda") +vae = AutoencoderKLMochi.from_pretrained("genmo/mochi-1-preview", subfolder="vae", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu" ``` ## AutoencoderKLMochi diff --git a/docs/source/en/api/models/cogvideox_transformer3d.md b/docs/source/en/api/models/cogvideox_transformer3d.md index 1b09ba3d5ebc..f85f2929c682 100644 --- a/docs/source/en/api/models/cogvideox_transformer3d.md +++ b/docs/source/en/api/models/cogvideox_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import CogVideoXTransformer3DModel -transformer = CogVideoXTransformer3DModel.from_pretrained("THUDM/CogVideoX-2b", subfolder="transformer", dtype=torch.float16).to("cuda") +transformer = CogVideoXTransformer3DModel.from_pretrained("THUDM/CogVideoX-2b", subfolder="transformer", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" ``` ## CogVideoXTransformer3DModel diff --git a/docs/source/en/api/models/cogview3plus_transformer2d.md b/docs/source/en/api/models/cogview3plus_transformer2d.md index 2135926cc9cb..f6721c4ca4b0 100644 --- a/docs/source/en/api/models/cogview3plus_transformer2d.md +++ b/docs/source/en/api/models/cogview3plus_transformer2d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import CogView3PlusTransformer2DModel -transformer = CogView3PlusTransformer2DModel.from_pretrained("THUDM/CogView3Plus-3b", subfolder="transformer", dtype=torch.bfloat16).to("cuda") +transformer = CogView3PlusTransformer2DModel.from_pretrained("THUDM/CogView3Plus-3b", subfolder="transformer", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" ``` ## CogView3PlusTransformer2DModel diff --git a/docs/source/en/api/models/cogview4_transformer2d.md b/docs/source/en/api/models/cogview4_transformer2d.md index ed7b7abae8b2..d622df1673b0 100644 --- a/docs/source/en/api/models/cogview4_transformer2d.md +++ b/docs/source/en/api/models/cogview4_transformer2d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import CogView4Transformer2DModel -transformer = CogView4Transformer2DModel.from_pretrained("THUDM/CogView4-6B", subfolder="transformer", dtype=torch.bfloat16).to("cuda") +transformer = CogView4Transformer2DModel.from_pretrained("THUDM/CogView4-6B", subfolder="transformer", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" ``` ## CogView4Transformer2DModel diff --git a/docs/source/en/api/models/consisid_transformer3d.md b/docs/source/en/api/models/consisid_transformer3d.md index 98b49aee883c..5ed7491ecf35 100644 --- a/docs/source/en/api/models/consisid_transformer3d.md +++ b/docs/source/en/api/models/consisid_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import ConsisIDTransformer3DModel -transformer = ConsisIDTransformer3DModel.from_pretrained("BestWishYsh/ConsisID-preview", subfolder="transformer", dtype=torch.bfloat16).to("cuda") +transformer = ConsisIDTransformer3DModel.from_pretrained("BestWishYsh/ConsisID-preview", subfolder="transformer", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" ``` ## ConsisIDTransformer3DModel diff --git a/docs/source/en/api/models/controlnet.md b/docs/source/en/api/models/controlnet.md index 785ec6bbd0d3..73a90079303b 100644 --- a/docs/source/en/api/models/controlnet.md +++ b/docs/source/en/api/models/controlnet.md @@ -43,7 +43,7 @@ from diffusers import ControlNetModel, UNet2DConditionModel lora_id = "stabilityai/control-lora" lora_filename = "control-LoRAs-rank128/control-lora-canny-rank128.safetensors" -unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", dtype=torch.bfloat16).to("cuda") +unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" controlnet = ControlNetModel.from_unet(unet).to(device="cuda", dtype=torch.bfloat16) controlnet.load_lora_adapter(lora_id, weight_name=lora_filename, prefix=None, controlnet_config=controlnet.config) ``` diff --git a/docs/source/en/api/models/easyanimate_transformer3d.md b/docs/source/en/api/models/easyanimate_transformer3d.md index 72311466076f..14d602e91d44 100644 --- a/docs/source/en/api/models/easyanimate_transformer3d.md +++ b/docs/source/en/api/models/easyanimate_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import EasyAnimateTransformer3DModel -transformer = EasyAnimateTransformer3DModel.from_pretrained("alibaba-pai/EasyAnimateV5.1-12b-zh", subfolder="transformer", dtype=torch.float16).to("cuda") +transformer = EasyAnimateTransformer3DModel.from_pretrained("alibaba-pai/EasyAnimateV5.1-12b-zh", subfolder="transformer", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" ``` ## EasyAnimateTransformer3DModel diff --git a/docs/source/en/api/models/ltx2_diffusion_decoder.md b/docs/source/en/api/models/ltx2_diffusion_decoder.md index 8c12fb5c25ba..9a4059166267 100644 --- a/docs/source/en/api/models/ltx2_diffusion_decoder.md +++ b/docs/source/en/api/models/ltx2_diffusion_decoder.md @@ -23,7 +23,7 @@ pipeline's `vae`: run any LTX-2 pipeline with `output_type="latent"`, then decod import torch from diffusers import LTX2Pipeline, LTX2VideoDiffusionDecodePipeline, LTX2VideoDiffusionDecoderModel -pipe = LTX2Pipeline.from_pretrained("Lightricks/LTX-2.5-Diffusers", dtype=torch.bfloat16).to("cuda") +pipe = LTX2Pipeline.from_pretrained("Lightricks/LTX-2.5-Diffusers", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" latents = pipe(prompt="a potter shaping a clay vase", output_type="latent").frames decoder = LTX2VideoDiffusionDecoderModel.from_pretrained( diff --git a/docs/source/en/api/models/ltx2_video_transformer3d.md b/docs/source/en/api/models/ltx2_video_transformer3d.md index 279564360d6a..f3f54902c12f 100644 --- a/docs/source/en/api/models/ltx2_video_transformer3d.md +++ b/docs/source/en/api/models/ltx2_video_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import LTX2VideoTransformer3DModel -transformer = LTX2VideoTransformer3DModel.from_pretrained("Lightricks/LTX-2", subfolder="transformer", dtype=torch.bfloat16).to("cuda") +transformer = LTX2VideoTransformer3DModel.from_pretrained("Lightricks/LTX-2", subfolder="transformer", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" ``` ## LTX2VideoTransformer3DModel diff --git a/docs/source/en/api/models/ltx_video_transformer3d.md b/docs/source/en/api/models/ltx_video_transformer3d.md index d04b12c9090c..7b5d0911f2c9 100644 --- a/docs/source/en/api/models/ltx_video_transformer3d.md +++ b/docs/source/en/api/models/ltx_video_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import LTXVideoTransformer3DModel -transformer = LTXVideoTransformer3DModel.from_pretrained("Lightricks/LTX-Video", subfolder="transformer", dtype=torch.bfloat16).to("cuda") +transformer = LTXVideoTransformer3DModel.from_pretrained("Lightricks/LTX-Video", subfolder="transformer", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" ``` ## LTXVideoTransformer3DModel diff --git a/docs/source/en/api/models/minimax_h3_transformer3d.md b/docs/source/en/api/models/minimax_h3_transformer3d.md index 423e8fdc5837..3e4d45e5cdf6 100644 --- a/docs/source/en/api/models/minimax_h3_transformer3d.md +++ b/docs/source/en/api/models/minimax_h3_transformer3d.md @@ -27,7 +27,7 @@ from diffusers import MiniMaxH3Transformer3DModel transformer = MiniMaxH3Transformer3DModel.from_pretrained( "MiniMaxAI/MiniMax-H3", subfolder="transformer", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` The checkpoint is mixed precision: the two input patch projections, the timestep MLP and the two output heads are float32 while the block stack is bfloat16. `from_pretrained` keeps that layout through `_keep_in_fp32_modules`, so pass `dtype=torch.bfloat16` and let it place the float32 modules rather than casting the model with `.to(torch.bfloat16)` afterwards. diff --git a/docs/source/en/api/models/mochi_transformer3d.md b/docs/source/en/api/models/mochi_transformer3d.md index 2329d3bedb77..770156504ba1 100644 --- a/docs/source/en/api/models/mochi_transformer3d.md +++ b/docs/source/en/api/models/mochi_transformer3d.md @@ -18,7 +18,7 @@ The model can be loaded with the following code snippet. ```python from diffusers import MochiTransformer3DModel -transformer = MochiTransformer3DModel.from_pretrained("genmo/mochi-1-preview", subfolder="transformer", dtype=torch.float16).to("cuda") +transformer = MochiTransformer3DModel.from_pretrained("genmo/mochi-1-preview", subfolder="transformer", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" ``` ## MochiTransformer3DModel diff --git a/docs/source/en/api/pipelines/ace_step.md b/docs/source/en/api/pipelines/ace_step.md index ca1047092e0e..c9ac9d9b2fa1 100644 --- a/docs/source/en/api/pipelines/ace_step.md +++ b/docs/source/en/api/pipelines/ace_step.md @@ -55,7 +55,7 @@ import soundfile as sf from diffusers import AceStepPipeline pipe = AceStepPipeline.from_pretrained("ACE-Step/acestep-v15-xl-turbo-diffusers", dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" audio = pipe( prompt="A beautiful piano piece with soft melodies and gentle rhythm", diff --git a/docs/source/en/api/pipelines/anima.md b/docs/source/en/api/pipelines/anima.md index 5ac544f3caaa..a8324e4f1138 100644 --- a/docs/source/en/api/pipelines/anima.md +++ b/docs/source/en/api/pipelines/anima.md @@ -22,7 +22,7 @@ from diffusers import ModularPipeline pipe = ModularPipeline.from_pretrained("circlestone-labs/Anima-Base-v1.0-Diffusers") pipe.load_components(dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe(prompt="masterpiece, best quality, 1girl, solo, city lights").images[0] ``` diff --git a/docs/source/en/api/pipelines/animatediff.md b/docs/source/en/api/pipelines/animatediff.md index c11efd650341..11bb60f5aa44 100644 --- a/docs/source/en/api/pipelines/animatediff.md +++ b/docs/source/en/api/pipelines/animatediff.md @@ -131,7 +131,7 @@ pipe: AnimateDiffControlNetPipeline = AnimateDiffControlNetPipeline.from_pretrai motion_adapter=motion_adapter, controlnet=controlnet, vae=vae, -).to(device="cuda", dtype=torch.float16) +).to(device="cuda", dtype=torch.float16) # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config, beta_schedule="linear") pipe.load_lora_weights("wangfuyun/AnimateLCM", weight_name="AnimateLCM_sd15_t2v_lora.safetensors", adapter_name="lcm-lora") pipe.set_adapters(["lcm-lora"], [0.8]) @@ -211,7 +211,7 @@ motion_adapter_id = "guoyww/animatediff-motion-adapter-v1-5-3" controlnet_id = "guoyww/animatediff-sparsectrl-scribble" lora_adapter_id = "guoyww/animatediff-motion-lora-v1-5-3" vae_id = "stabilityai/sd-vae-ft-mse" -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" motion_adapter = MotionAdapter.from_pretrained(motion_adapter_id, dtype=torch.float16).to(device) controlnet = SparseControlNetModel.from_pretrained(controlnet_id, dtype=torch.float16).to(device) @@ -307,7 +307,7 @@ motion_adapter_id = "guoyww/animatediff-motion-adapter-v1-5-3" controlnet_id = "guoyww/animatediff-sparsectrl-rgb" lora_adapter_id = "guoyww/animatediff-motion-lora-v1-5-3" vae_id = "stabilityai/sd-vae-ft-mse" -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" motion_adapter = MotionAdapter.from_pretrained(motion_adapter_id, dtype=torch.float16).to(device) controlnet = SparseControlNetModel.from_pretrained(controlnet_id, dtype=torch.float16).to(device) @@ -392,7 +392,7 @@ pipe = AnimateDiffSDXLPipeline.from_pretrained( scheduler=scheduler, dtype=torch.float16, variant="fp16", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # enable memory savings pipe.vae.enable_slicing() @@ -549,7 +549,7 @@ pipe = AnimateDiffVideoToVideoControlNetPipeline.from_pretrained( motion_adapter=motion_adapter, controlnet=controlnet, vae=vae, -).to(device="cuda", dtype=torch.float16) +).to(device="cuda", dtype=torch.float16) # or "mps", "xpu", "cpu" # Enable LCM to speed up inference pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config, beta_schedule="linear") @@ -761,7 +761,7 @@ from diffusers.utils import export_to_gif adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2") model_id = "SG161222/Realistic_Vision_V5.1_noVAE" -pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, dtype=torch.float16).to("cuda") +pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = DDIMScheduler.from_pretrained( model_id, subfolder="scheduler", @@ -951,7 +951,7 @@ pipe.set_adapters(["lcm_lora"], [0.8]) # Enable FreeNoise for long prompt generation pipe.enable_free_noise(context_length=16, context_stride=4) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Can be a single prompt, or a dictionary with frame timesteps prompt = { diff --git a/docs/source/en/api/pipelines/anyflow.md b/docs/source/en/api/pipelines/anyflow.md index 7667f8fc1ffa..1c3f7463d1cd 100644 --- a/docs/source/en/api/pipelines/anyflow.md +++ b/docs/source/en/api/pipelines/anyflow.md @@ -49,7 +49,7 @@ from diffusers.utils import export_to_video pipe = AnyFlowPipeline.from_pretrained( "nvidia/AnyFlow-Wan2.1-T2V-1.3B-Diffusers", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = ( "An astronaut runs smoothly and appears almost weightless on the lunar surface, " @@ -85,7 +85,7 @@ from diffusers.utils import export_to_video pipe = AnyFlowFARPipeline.from_pretrained( "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = ( "An astronaut runs smoothly and appears almost weightless on the lunar surface, " @@ -106,7 +106,7 @@ from diffusers.utils import export_to_video, load_image pipe = AnyFlowFARPipeline.from_pretrained( "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # Example conditioning image from the AnyFlow repo. first_frame = load_image( @@ -140,7 +140,7 @@ from diffusers.utils import export_to_video, load_video pipe = AnyFlowFARPipeline.from_pretrained( "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # Example conditioning clip from the AnyFlow repo — take the first 9 frames (3 latent frames at VAE temporal stride 4). context_frames = load_video( diff --git a/docs/source/en/api/pipelines/chronoedit.md b/docs/source/en/api/pipelines/chronoedit.md index 2305b5799d5e..572292c14291 100644 --- a/docs/source/en/api/pipelines/chronoedit.md +++ b/docs/source/en/api/pipelines/chronoedit.md @@ -50,7 +50,7 @@ image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encod vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) transformer = ChronoEditTransformer3DModel.from_pretrained(model_id, subfolder="transformer", dtype=torch.bfloat16) pipe = ChronoEditPipeline.from_pretrained(model_id, image_encoder=image_encoder, transformer=transformer, vae=vae, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image( "https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png" @@ -117,7 +117,7 @@ pipe = ChronoEditPipeline.from_pretrained(model_id, image_encoder=image_encoder, pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers", weight_name="lora/chronoedit_distill_lora.safetensors", adapter_name="distill") pipe.fuse_lora(adapter_names=["distill"], lora_scale=1.0) pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image( "https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png" @@ -169,7 +169,7 @@ pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers-Paint-Brush-Lora", weigh pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers", weight_name="lora/chronoedit_distill_lora.safetensors", adapter_name="distill") pipe.fuse_lora(adapter_names=["paintbrush", "distill"], lora_scale=1.0) pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image( "https://raw.githubusercontent.com/nv-tlabs/ChronoEdit/refs/heads/main/assets/images/input_paintbrush.png" diff --git a/docs/source/en/api/pipelines/cogvideox.md b/docs/source/en/api/pipelines/cogvideox.md index 09c7405bf0aa..d8010d5bd525 100644 --- a/docs/source/en/api/pipelines/cogvideox.md +++ b/docs/source/en/api/pipelines/cogvideox.md @@ -68,7 +68,7 @@ pipeline = CogVideoXPipeline.from_pretrained( quantization_config=pipeline_quant_config, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" # model-offloading pipeline.enable_model_cpu_offload() @@ -103,7 +103,7 @@ from diffusers.utils import export_to_video pipeline = CogVideoXPipeline.from_pretrained( "THUDM/CogVideoX-2b", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # torch.compile pipeline.transformer.to(memory_format=torch.channels_last) @@ -146,7 +146,7 @@ export_to_video(video, "output.mp4", fps=8) "THUDM/CogVideoX-5b", dtype=torch.bfloat16 ) - pipeline.to("cuda") + pipeline.to("cuda") # or "mps", "xpu", "cpu" # load LoRA weights pipeline.load_lora_weights("finetrainers/CogVideoX-1.5-crush-smol-v0", adapter_name="crush-lora") diff --git a/docs/source/en/api/pipelines/consisid.md b/docs/source/en/api/pipelines/consisid.md index aa28517c37c2..b8c1d9d88fb3 100644 --- a/docs/source/en/api/pipelines/consisid.md +++ b/docs/source/en/api/pipelines/consisid.md @@ -64,7 +64,7 @@ from huggingface_hub import snapshot_download snapshot_download(repo_id="BestWishYsh/ConsisID-preview", local_dir="BestWishYsh/ConsisID-preview") # Load face helper model to preprocess input face image -face_helper_1, face_helper_2, face_clip_model, face_main_model, eva_transform_mean, eva_transform_std = prepare_face_models("BestWishYsh/ConsisID-preview", device="cuda", dtype=torch.bfloat16) +face_helper_1, face_helper_2, face_clip_model, face_main_model, eva_transform_mean, eva_transform_std = prepare_face_models("BestWishYsh/ConsisID-preview", device="cuda", dtype=torch.bfloat16) # or "mps", "xpu", "cpu" # Load consisid base model pipe = ConsisIDPipeline.from_pretrained("BestWishYsh/ConsisID-preview", dtype=torch.bfloat16) diff --git a/docs/source/en/api/pipelines/consistency_models.md b/docs/source/en/api/pipelines/consistency_models.md index e09f6fc5bc5d..a9e45726e328 100644 --- a/docs/source/en/api/pipelines/consistency_models.md +++ b/docs/source/en/api/pipelines/consistency_models.md @@ -30,7 +30,7 @@ For an additional speed-up, use `torch.compile` to generate multiple images in < import torch from diffusers import ConsistencyModelPipeline - device = "cuda" + device = "cuda" # or "mps", "xpu", "cpu" # Load the cd_bedroom256_lpips checkpoint. model_id_or_path = "openai/diffusers-cd_bedroom256_lpips" pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, dtype=torch.float16) diff --git a/docs/source/en/api/pipelines/control_flux_inpaint.md b/docs/source/en/api/pipelines/control_flux_inpaint.md index a0105c3a941b..1b9f098acea1 100644 --- a/docs/source/en/api/pipelines/control_flux_inpaint.md +++ b/docs/source/en/api/pipelines/control_flux_inpaint.md @@ -55,7 +55,7 @@ pipe.transformer = transformer pipe.text_encoder_2 = text_encoder_2 pipe.enable_model_cpu_offload() # --------------------------------------------------------------- -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "a blue robot singing opera with human-like expressions" image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png") diff --git a/docs/source/en/api/pipelines/cosmos.md b/docs/source/en/api/pipelines/cosmos.md index 9e43cad4f12c..0f9447add6fb 100644 --- a/docs/source/en/api/pipelines/cosmos.md +++ b/docs/source/en/api/pipelines/cosmos.md @@ -32,7 +32,7 @@ model_id = "nvidia/Cosmos-Predict2.5-2B" pipe = Cosmos2_5_PredictBasePipeline.from_pretrained( model_id, revision="diffusers/base/post-trained", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow advance of traffic through the frosty city corridor." negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality." diff --git a/docs/source/en/api/pipelines/cosmos3.md b/docs/source/en/api/pipelines/cosmos3.md index 28a045807d17..ae8de9ca66c8 100644 --- a/docs/source/en/api/pipelines/cosmos3.md +++ b/docs/source/en/api/pipelines/cosmos3.md @@ -100,7 +100,7 @@ json_prompt = json.load(open("assets/example_t2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -135,7 +135,7 @@ json_prompt = json.load(open("assets/example_t2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -174,7 +174,7 @@ from diffusers import Cosmos3OmniPipeline json_prompt = json.load(open("assets/example_t2i_prompt.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) result = pipe(prompt=json.dumps(json_prompt), num_frames=1, height=720, width=1280) @@ -193,7 +193,7 @@ from diffusers import Cosmos3OmniPipeline json_prompt = json.load(open("assets/example_t2i_prompt.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) result = pipe(prompt=json.dumps(json_prompt), num_frames=1, height=720, width=1280) @@ -221,7 +221,7 @@ json_prompt = json.load(open("assets/example_i2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt_i2v.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) image = load_image( @@ -255,7 +255,7 @@ json_prompt = json.load(open("assets/example_i2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt_i2v.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) image = load_image( @@ -299,7 +299,7 @@ json_prompt = json.load(open("assets/example_v2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt_i2v.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -341,7 +341,7 @@ json_prompt = json.load(open("assets/example_v2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt_i2v.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -390,7 +390,7 @@ json_prompt = json.load(open("assets/example_v2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt_i2v.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -437,7 +437,7 @@ json_prompt = json.load(open("assets/example_v2v_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt_i2v.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -492,7 +492,7 @@ json_prompt = json.load(open("assets/example_t2v_sound_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) result = pipe( @@ -528,7 +528,7 @@ json_prompt = json.load(open("assets/example_t2v_sound_prompt.json")) negative_prompt = json.load(open("assets/negative_prompt.json")) pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) result = pipe( @@ -575,7 +575,7 @@ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepSchedu from diffusers.utils import export_to_video, load_video pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -622,7 +622,7 @@ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepSchedu from diffusers.utils import export_to_video, load_video pipe = Cosmos3OmniPipeline.from_pretrained( - "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" + "nvidia/Cosmos3-Super", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False @@ -821,7 +821,7 @@ from diffusers import Cosmos3OmniPipeline pipe = Cosmos3OmniPipeline.from_pretrained( "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" enable_safety_checker=False, ) ``` @@ -845,7 +845,7 @@ To supply a custom checker (e.g., a no-op subclass for fast tests), pass it as ` pipe = Cosmos3OmniPipeline.from_pretrained( "nvidia/Cosmos3-Nano", dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" safety_checker=MyCustomSafetyChecker(), ) ``` @@ -919,7 +919,7 @@ from diffusers.utils import encode_video, export_to_video, load_image, load_vide pipe = Cosmos3OmniModularPipeline.from_pretrained("nvidia/Cosmos3-Nano", dtype=torch.bfloat16) pipe.load_components(dtype=torch.bfloat16) pipe.enable_safety_checker() -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False ) @@ -1082,7 +1082,7 @@ from diffusers.utils import export_to_video, load_video pipe = Cosmos3OmniModularPipeline.from_pretrained("nvidia/Cosmos3-Nano", dtype=torch.bfloat16) pipe.load_components(dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = UniPCMultistepScheduler.from_config( pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False ) @@ -1133,7 +1133,7 @@ json_prompt = json.load(open("assets/example_t2i_prompt.json")) repo = "nvidia/Cosmos3-Super-Text2Image-4Step" pipe = Cosmos3DistilledModularPipeline.from_pretrained(repo, dtype=torch.bfloat16) pipe.load_components(dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # text-to-image (distilled) videos = pipe( diff --git a/docs/source/en/api/pipelines/deepfloyd_if.md b/docs/source/en/api/pipelines/deepfloyd_if.md index c6e336385352..b6f5c1edc05d 100644 --- a/docs/source/en/api/pipelines/deepfloyd_if.md +++ b/docs/source/en/api/pipelines/deepfloyd_if.md @@ -317,7 +317,7 @@ The simplest optimization to run IF faster is to move all model components to th ```py pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" ``` You can also run the diffusion process for a shorter number of timesteps. @@ -342,7 +342,7 @@ A smaller number will vary the image less but run faster. ```py pipe = IFImg2ImgPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe(image=image, prompt="", strength=0.3).images ``` @@ -355,7 +355,7 @@ from diffusers import DiffusionPipeline import torch pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", dtype=torch.float16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" pipe.text_encoder = torch.compile(pipe.text_encoder, mode="reduce-overhead", fullgraph=True) pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) diff --git a/docs/source/en/api/pipelines/dreamlite.md b/docs/source/en/api/pipelines/dreamlite.md index 37cb298e17dc..3384b939df64 100644 --- a/docs/source/en/api/pipelines/dreamlite.md +++ b/docs/source/en/api/pipelines/dreamlite.md @@ -45,7 +45,7 @@ import torch from diffusers import DreamLitePipeline pipe = DreamLitePipeline.from_pretrained("carlofkl/DreamLite-base", revision="diffusers", dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a dog running on the grass", @@ -69,7 +69,7 @@ from diffusers import DreamLitePipeline from diffusers.utils import load_image pipe = DreamLitePipeline.from_pretrained("carlofkl/DreamLite-base", revision="diffusers", dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" source = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") @@ -95,7 +95,7 @@ import torch from diffusers import DreamLiteMobilePipeline pipe = DreamLiteMobilePipeline.from_pretrained("carlofkl/DreamLite-mobile", revision="diffusers", dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a dog running on the grass", @@ -115,7 +115,7 @@ from diffusers import DreamLiteMobilePipeline from diffusers.utils import load_image pipe = DreamLiteMobilePipeline.from_pretrained("carlofkl/DreamLite-mobile", revision="diffusers", dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" source = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") diff --git a/docs/source/en/api/pipelines/ernie_image.md b/docs/source/en/api/pipelines/ernie_image.md index 02fe166fab87..64cb3caae10c 100644 --- a/docs/source/en/api/pipelines/ernie_image.md +++ b/docs/source/en/api/pipelines/ernie_image.md @@ -45,7 +45,7 @@ from diffusers import ErnieImagePipeline from diffusers.utils import load_image pipe = ErnieImagePipeline.from_pretrained("baidu/ERNIE-Image", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # If you are running low on GPU VRAM, you can enable offloading pipe.enable_model_cpu_offload() @@ -68,7 +68,7 @@ from diffusers import ErnieImagePipeline from diffusers.utils import load_image pipe = ErnieImagePipeline.from_pretrained("baidu/ERNIE-Image-Turbo", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # If you are running low on GPU VRAM, you can enable offloading pipe.enable_model_cpu_offload() diff --git a/docs/source/en/api/pipelines/flux.md b/docs/source/en/api/pipelines/flux.md index 9e5c1df7a373..e7c222079e3a 100644 --- a/docs/source/en/api/pipelines/flux.md +++ b/docs/source/en/api/pipelines/flux.md @@ -104,7 +104,7 @@ image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolv mask = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/cup_mask.png") repo_id = "black-forest-labs/FLUX.1-Fill-dev" -pipe = FluxFillPipeline.from_pretrained(repo_id, dtype=torch.bfloat16).to("cuda") +pipe = FluxFillPipeline.from_pretrained(repo_id, dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a white paper cup", @@ -129,7 +129,7 @@ from controlnet_aux import CannyDetector from diffusers import FluxControlPipeline from diffusers.utils import load_image -pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-Canny-dev", dtype=torch.bfloat16).to("cuda") +pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-Canny-dev", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png") @@ -157,7 +157,7 @@ from controlnet_aux import CannyDetector from diffusers import FluxControlPipeline from diffusers.utils import load_image -pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16).to("cuda") +pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" pipe.load_lora_weights("black-forest-labs/FLUX.1-Canny-dev-lora") prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." @@ -188,7 +188,7 @@ from diffusers import FluxControlPipeline, FluxTransformer2DModel from diffusers.utils import load_image from image_gen_aux import DepthPreprocessor -pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-Depth-dev", dtype=torch.bfloat16).to("cuda") +pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-Depth-dev", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png") @@ -217,7 +217,7 @@ from diffusers import FluxControlPipeline, FluxTransformer2DModel from diffusers.utils import load_image from image_gen_aux import DepthPreprocessor -pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16).to("cuda") +pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" pipe.load_lora_weights("black-forest-labs/FLUX.1-Depth-dev-lora") prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." @@ -248,7 +248,7 @@ image.save("output.png") import torch from diffusers import FluxPriorReduxPipeline, FluxPipeline from diffusers.utils import load_image -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" dtype = torch.bfloat16 @@ -285,7 +285,7 @@ from diffusers.utils import load_image pipe = FluxKontextPipeline.from_pretrained( "black-forest-labs/FLUX.1-Kontext-dev", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yarn-art-pikachu.png").convert("RGB") prompt = "Make Pikachu hold a sign that says 'Black Forest Labs is awesome', yarn art style, detailed, vibrant colors" @@ -338,7 +338,7 @@ mask = load_image(mask_url) pipe = FluxKontextInpaintPipeline.from_pretrained( "black-forest-labs/FLUX.1-Kontext-dev", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe(prompt=prompt, image=source, mask_image=mask, strength=1.0).images[0] image.save("kontext_inpainting_normal.png") @@ -354,7 +354,7 @@ from diffusers.utils import load_image pipe = FluxKontextInpaintPipeline.from_pretrained( "black-forest-labs/FLUX.1-Kontext-dev", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "Replace this ball" img_url = "https://images.pexels.com/photos/39362/the-ball-stadion-football-the-pitch-39362.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" @@ -429,7 +429,7 @@ from diffusers.utils import load_image pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flux_ip_adapter_input.jpg").resize((1024, 1024)) diff --git a/docs/source/en/api/pipelines/glm_image.md b/docs/source/en/api/pipelines/glm_image.md index 8f4d1ab3b50d..e6e4b58623df 100644 --- a/docs/source/en/api/pipelines/glm_image.md +++ b/docs/source/en/api/pipelines/glm_image.md @@ -52,7 +52,7 @@ image = pipe( width=36 * 32, num_inference_steps=30, guidance_scale=1.5, - generator=torch.Generator(device="cuda").manual_seed(42), + generator=torch.Generator(device="cuda").manual_seed(42), # or "mps", "xpu", "cpu" ).images[0] image.save("output_t2i.png") @@ -76,7 +76,7 @@ image = pipe( width=32 * 32, num_inference_steps=30, guidance_scale=1.5, - generator=torch.Generator(device="cuda").manual_seed(42), + generator=torch.Generator(device="cuda").manual_seed(42), # or "mps", "xpu", "cpu" ).images[0] image.save("output_i2i.png") diff --git a/docs/source/en/api/pipelines/helios.md b/docs/source/en/api/pipelines/helios.md index b01fe88f4845..24aaa6eb5e31 100644 --- a/docs/source/en/api/pipelines/helios.md +++ b/docs/source/en/api/pipelines/helios.md @@ -110,7 +110,7 @@ pipeline = HeliosPipeline.from_pretrained( vae=vae, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" # attention backend # pipeline.transformer.set_attention_backend("flash") @@ -170,7 +170,7 @@ pipeline = HeliosPipeline.from_pretrained( vae=vae, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" negative_prompt = """ Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, @@ -265,7 +265,7 @@ pipeline = HeliosPyramidPipeline.from_pretrained( vae=vae, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" negative_prompt = """ Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, @@ -366,7 +366,7 @@ pipeline = HeliosPyramidPipeline.from_pretrained( vae=vae, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" negative_prompt = """ Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, diff --git a/docs/source/en/api/pipelines/hunyuandit.md b/docs/source/en/api/pipelines/hunyuandit.md index b0abcb3506a3..8d056bc61f7c 100644 --- a/docs/source/en/api/pipelines/hunyuandit.md +++ b/docs/source/en/api/pipelines/hunyuandit.md @@ -50,7 +50,7 @@ import torch pipeline = HunyuanDiTPipeline.from_pretrained( "Tencent-Hunyuan/HunyuanDiT-Diffusers", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Then change the memory layout of the pipelines `transformer` and `vae` components to `torch.channels-last`: diff --git a/docs/source/en/api/pipelines/hunyuanimage21.md b/docs/source/en/api/pipelines/hunyuanimage21.md index 84dcf1c4b87d..9cc82af75e3b 100644 --- a/docs/source/en/api/pipelines/hunyuanimage21.md +++ b/docs/source/en/api/pipelines/hunyuanimage21.md @@ -40,7 +40,7 @@ pipe = HunyuanImagePipeline.from_pretrained( "hunyuanvideo-community/HunyuanImage-2.1-Diffusers", dtype=torch.bfloat16 ) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" ``` You can inspect the `guider` object: @@ -85,7 +85,7 @@ pipe = HunyuanImagePipeline.from_pretrained( "hunyuanvideo-community/HunyuanImage-2.1-Diffusers", dtype=torch.bfloat16 ) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" # Update the guider configuration pipe.guider = pipe.guider.new(guidance_scale=5.0) @@ -114,7 +114,7 @@ use `distilled_guidance_scale` with the guidance-distilled checkpoint, import torch from diffusers import HunyuanImagePipeline pipe = HunyuanImagePipeline.from_pretrained("hunyuanvideo-community/HunyuanImage-2.1-Distilled-Diffusers", dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = ( "A cute, cartoon-style anthropomorphic penguin plush toy with fluffy fur, standing in a painting studio, " diff --git a/docs/source/en/api/pipelines/ideogram4.md b/docs/source/en/api/pipelines/ideogram4.md index d9f3e341b169..10df62cf5c7a 100644 --- a/docs/source/en/api/pipelines/ideogram4.md +++ b/docs/source/en/api/pipelines/ideogram4.md @@ -32,7 +32,7 @@ import torch from diffusers import Ideogram4Pipeline pipe = Ideogram4Pipeline.from_pretrained("ideogram-ai/ideogram-v4", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A photo of a cat holding a sign that says hello world" # The defaults are the recommended settings for best quality. @@ -57,7 +57,7 @@ import torch from diffusers import Ideogram4Pipeline pipe = Ideogram4Pipeline.from_pretrained("ideogram-ai/ideogram-4-nf4", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Expand the prompt into a structured JSON caption with Ideogram's hosted magic-prompt API. response = requests.post( @@ -89,7 +89,7 @@ prompt_enhancer_head = Ideogram4PromptEnhancerHead.from_pretrained( pipe = Ideogram4Pipeline.from_pretrained( "ideogram-ai/ideogram-4-nf4", prompt_enhancer_head=prompt_enhancer_head, dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A photo of a cat holding a sign that says hello world" image = pipe( diff --git a/docs/source/en/api/pipelines/joyimage_edit.md b/docs/source/en/api/pipelines/joyimage_edit.md index dc30aeedf6e1..48eacfb7fd70 100644 --- a/docs/source/en/api/pipelines/joyimage_edit.md +++ b/docs/source/en/api/pipelines/joyimage_edit.md @@ -28,7 +28,7 @@ from diffusers.utils import load_image pipeline = JoyImageEditPipeline.from_pretrained( "jdopensource/JoyAI-Image-Edit-Diffusers", dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg") prompt = "Add wings to the astronaut." diff --git a/docs/source/en/api/pipelines/joyimage_edit_plus.md b/docs/source/en/api/pipelines/joyimage_edit_plus.md index c16856fd191c..4729f5f8d369 100644 --- a/docs/source/en/api/pipelines/joyimage_edit_plus.md +++ b/docs/source/en/api/pipelines/joyimage_edit_plus.md @@ -28,7 +28,7 @@ from diffusers import JoyImageEditPlusPipeline pipeline = JoyImageEditPlusPipeline.from_pretrained( "jdopensource/JoyAI-Image-Edit-Plus-Diffusers", dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" images = [ Image.open("reference_0.png").convert("RGB"), diff --git a/docs/source/en/api/pipelines/kandinsky.md b/docs/source/en/api/pipelines/kandinsky.md index 05c3db13bfde..a1965eb3cb72 100644 --- a/docs/source/en/api/pipelines/kandinsky.md +++ b/docs/source/en/api/pipelines/kandinsky.md @@ -48,7 +48,7 @@ To use the Kandinsky models for any task, you always start by setting up the pri from diffusers import KandinskyPriorPipeline, KandinskyPipeline import torch -prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16).to("cuda") +prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", dtype=torch.float16).to("cuda") prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting" @@ -74,7 +74,7 @@ image from diffusers import KandinskyV22PriorPipeline, KandinskyV22Pipeline import torch -prior_pipeline = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16).to("cuda") +prior_pipeline = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyV22Pipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", dtype=torch.float16).to("cuda") prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting" @@ -165,7 +165,7 @@ For image-to-image, pass the initial image and text prompt to condition the imag import torch from diffusers import KandinskyImg2ImgPipeline, KandinskyPriorPipeline -prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyImg2ImgPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", dtype=torch.float16, use_safetensors=True).to("cuda") ``` @@ -176,7 +176,7 @@ pipeline = KandinskyImg2ImgPipeline.from_pretrained("kandinsky-community/kandins import torch from diffusers import KandinskyV22Img2ImgPipeline, KandinskyPriorPipeline -prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyV22Img2ImgPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", dtype=torch.float16, use_safetensors=True).to("cuda") ``` @@ -341,7 +341,7 @@ import torch import numpy as np from PIL import Image -prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyInpaintPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-inpaint", dtype=torch.float16, use_safetensors=True).to("cuda") ``` @@ -355,7 +355,7 @@ import torch import numpy as np from PIL import Image -prior_pipeline = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyV22InpaintPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder-inpaint", dtype=torch.float16, use_safetensors=True).to("cuda") ``` @@ -474,7 +474,7 @@ from diffusers import KandinskyPriorPipeline, KandinskyPipeline from diffusers.utils import load_image, make_image_grid import torch -prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" img_1 = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png") img_2 = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/starry_night.jpeg") make_image_grid([img_1.resize((512,512)), img_2.resize((512,512))], rows=1, cols=2) @@ -488,7 +488,7 @@ from diffusers import KandinskyV22PriorPipeline, KandinskyV22Pipeline from diffusers.utils import load_image, make_image_grid import torch -prior_pipeline = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" img_1 = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png") img_2 = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/starry_night.jpeg") make_image_grid([img_1.resize((512,512)), img_2.resize((512,512))], rows=1, cols=2) @@ -525,7 +525,7 @@ Call the `interpolate` function to generate the embeddings, and then pass them t prompt = "" prior_out = prior_pipeline.interpolate(images_texts, weights) -pipeline = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", dtype=torch.float16, use_safetensors=True).to("cuda") +pipeline = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" image = pipeline(prompt, **prior_out, height=768, width=768).images[0] image @@ -543,7 +543,7 @@ image prompt = "" prior_out = prior_pipeline.interpolate(images_texts, weights) -pipeline = KandinskyV22Pipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", dtype=torch.float16, use_safetensors=True).to("cuda") +pipeline = KandinskyV22Pipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" image = pipeline(prompt, **prior_out, height=768, width=768).images[0] image @@ -596,7 +596,7 @@ def make_hint(image, depth_estimator): return hint depth_estimator = pipeline("depth-estimation") -hint = make_hint(img, depth_estimator).unsqueeze(0).half().to("cuda") +hint = make_hint(img, depth_estimator).unsqueeze(0).half().to("cuda") # or "mps", "xpu", "cpu" ``` ### Text-to-image [[controlnet-text-to-image]] @@ -608,7 +608,7 @@ from diffusers import KandinskyV22PriorPipeline, KandinskyV22ControlnetPipeline prior_pipeline = KandinskyV22PriorPipeline.from_pretrained( "kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyV22ControlnetPipeline.from_pretrained( "kandinsky-community/kandinsky-2-2-controlnet-depth", dtype=torch.float16 @@ -621,7 +621,7 @@ Generate the image embeddings from a prompt and negative prompt: prompt = "A robot, 4k photo" negative_prior_prompt = "lowres, text, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature" -generator = torch.Generator(device="cuda").manual_seed(43) +generator = torch.Generator(device="cuda").manual_seed(43) # or "mps", "xpu", "cpu" image_emb, zero_image_emb = prior_pipeline( prompt=prompt, negative_prompt=negative_prior_prompt, generator=generator @@ -670,7 +670,7 @@ def make_hint(image, depth_estimator): return hint depth_estimator = pipeline("depth-estimation") -hint = make_hint(img, depth_estimator).unsqueeze(0).half().to("cuda") +hint = make_hint(img, depth_estimator).unsqueeze(0).half().to("cuda") # or "mps", "xpu", "cpu" ``` Load the prior pipeline and the [`KandinskyV22ControlnetImg2ImgPipeline`]: @@ -678,7 +678,7 @@ Load the prior pipeline and the [`KandinskyV22ControlnetImg2ImgPipeline`]: ```py prior_pipeline = KandinskyV22PriorEmb2EmbPipeline.from_pretrained( "kandinsky-community/kandinsky-2-2-prior", dtype=torch.float16, use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline = KandinskyV22ControlnetImg2ImgPipeline.from_pretrained( "kandinsky-community/kandinsky-2-2-controlnet-depth", dtype=torch.float16 @@ -691,7 +691,7 @@ Pass a text prompt and the initial image to the prior pipeline to generate the i prompt = "A robot, 4k photo" negative_prior_prompt = "lowres, text, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature" -generator = torch.Generator(device="cuda").manual_seed(43) +generator = torch.Generator(device="cuda").manual_seed(43) # or "mps", "xpu", "cpu" img_emb = prior_pipeline(prompt=prompt, image=img, strength=0.85, generator=generator) negative_emb = prior_pipeline(prompt=negative_prior_prompt, image=img, strength=1, generator=generator) @@ -754,7 +754,7 @@ from diffusers import DDPMScheduler from diffusers import DiffusionPipeline scheduler = DDPMScheduler.from_pretrained("kandinsky-community/kandinsky-2-1", subfolder="ddpm_scheduler") -pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", scheduler=scheduler, dtype=torch.float16, use_safetensors=True).to("cuda") +pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", scheduler=scheduler, dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" ``` ## KandinskyPriorPipeline diff --git a/docs/source/en/api/pipelines/kandinsky5_image.md b/docs/source/en/api/pipelines/kandinsky5_image.md index 1125e1594b03..8d4e8fe39128 100644 --- a/docs/source/en/api/pipelines/kandinsky5_image.md +++ b/docs/source/en/api/pipelines/kandinsky5_image.md @@ -47,7 +47,7 @@ from diffusers import Kandinsky5T2IPipeline # Load the pipeline model_id = "kandinskylab/Kandinsky-5.0-T2I-Lite-sft-Diffusers" pipe = Kandinsky5T2IPipeline.from_pretrained(model_id) -_ = pipe.to(device='cuda',dtype=torch.bfloat16) +_ = pipe.to(device='cuda',dtype=torch.bfloat16) # or "mps", "xpu", "cpu" # Generate image prompt = "A fluffy, expressive cat wearing a bright red hat with a soft, slightly textured fabric. The hat should look cozy and well-fitted on the cat’s head. On the front of the hat, add clean, bold white text that reads “SWEET”, clearly visible and neatly centered. Ensure the overall lighting highlights the hat’s color and the cat’s fur details." @@ -72,7 +72,7 @@ from diffusers.utils import load_image model_id = "kandinskylab/Kandinsky-5.0-I2I-Lite-sft-Diffusers" pipe = Kandinsky5I2IPipeline.from_pretrained(model_id) -_ = pipe.to(device='cuda',dtype=torch.bfloat16) +_ = pipe.to(device='cuda',dtype=torch.bfloat16) # or "mps", "xpu", "cpu" pipe.enable_model_cpu_offload() # <--- Enable CPU offloading for single GPU inference # Edit the input image diff --git a/docs/source/en/api/pipelines/kandinsky5_video.md b/docs/source/en/api/pipelines/kandinsky5_video.md index db942cbdfc02..46876051778f 100644 --- a/docs/source/en/api/pipelines/kandinsky5_video.md +++ b/docs/source/en/api/pipelines/kandinsky5_video.md @@ -64,7 +64,7 @@ from diffusers.utils import export_to_video model_id = "kandinskylab/Kandinsky-5.0-T2V-Pro-sft-5s-Diffusers" pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" pipeline.transformer.set_attention_backend("flex") # <--- Set attention backend to Flex pipeline.enable_model_cpu_offload() # <--- Enable cpu offloading for single GPU inference pipeline.transformer.compile(mode="max-autotune-no-cudagraphs", dynamic=True) # <--- Compile with max-autotune-no-cudagraphs @@ -95,7 +95,7 @@ from diffusers.utils import export_to_video # Load the pipeline model_id = "kandinskylab/Kandinsky-5.0-T2V-Lite-sft-5s-Diffusers" pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" # Generate video prompt = "A cat and a dog baking a cake together in a kitchen." @@ -122,7 +122,7 @@ pipe = Kandinsky5T2VPipeline.from_pretrained( "kandinskylab/Kandinsky-5.0-T2V-Lite-sft-10s-Diffusers", dtype=torch.bfloat16 ) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" pipe.transformer.set_attention_backend( "flex" @@ -154,7 +154,7 @@ export_to_video(output, "output.mp4", fps=24, quality=9) ```python model_id = "kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-5s-Diffusers" pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" output = pipe( prompt="A beautiful sunset over mountains", @@ -177,7 +177,7 @@ from diffusers.utils import export_to_video model_id = "kandinskylab/Kandinsky-5.0-I2V-Pro-sft-5s-Diffusers" pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" pipeline.transformer.set_attention_backend("flex") # <--- Set attention backend to Flex pipeline.enable_model_cpu_offload() # <--- Enable cpu offloading for single GPU inference pipeline.transformer.compile(mode="max-autotune-no-cudagraphs", dynamic=True) # <--- Compile with max-autotune-no-cudagraphs diff --git a/docs/source/en/api/pipelines/kolors.md b/docs/source/en/api/pipelines/kolors.md index c5e97ca955a1..1e3eb7cf424f 100644 --- a/docs/source/en/api/pipelines/kolors.md +++ b/docs/source/en/api/pipelines/kolors.md @@ -33,7 +33,7 @@ import torch from diffusers import DPMSolverMultistepScheduler, KolorsPipeline pipe = KolorsPipeline.from_pretrained("Kwai-Kolors/Kolors-diffusers", dtype=torch.float16, variant="fp16") -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True) image = pipe( diff --git a/docs/source/en/api/pipelines/krea2.md b/docs/source/en/api/pipelines/krea2.md index b6e6fd5998c3..4c7107425d86 100644 --- a/docs/source/en/api/pipelines/krea2.md +++ b/docs/source/en/api/pipelines/krea2.md @@ -36,7 +36,7 @@ from diffusers import Krea2Pipeline # Load from a local directory produced by the Krea 2 conversion (no hub repo yet). pipe = Krea2Pipeline.from_pretrained("krea/Krea-2-Raw", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "a fox in the snow" image = pipe( @@ -57,7 +57,7 @@ import torch from diffusers import Krea2Pipeline pipe = Krea2Pipeline.from_pretrained("krea/Krea-2-Turbo", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( "a fox in the snow", @@ -93,7 +93,7 @@ from diffusers import ClassifierFreeGuidance, ModularPipeline pipe = ModularPipeline.from_pretrained("krea/Krea-2-Raw") pipe.load_components(dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( @@ -117,7 +117,7 @@ from diffusers import ModularPipeline pipe = ModularPipeline.from_pretrained("krea/Krea-2-Turbo") pipe.load_components(dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a fox in the snow", diff --git a/docs/source/en/api/pipelines/latent_consistency_models.md b/docs/source/en/api/pipelines/latent_consistency_models.md index 28ef207ff4b6..41e413bfd445 100644 --- a/docs/source/en/api/pipelines/latent_consistency_models.md +++ b/docs/source/en/api/pipelines/latent_consistency_models.md @@ -52,7 +52,7 @@ unet = UNet2DConditionModel.from_pretrained( ) pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", unet=unet, dtype=torch.float16, variant="fp16", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k" @@ -86,7 +86,7 @@ pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl") @@ -131,7 +131,7 @@ pipe = AutoPipelineForImage2Image.from_pretrained( unet=unet, dtype=torch.float16, variant="fp16", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png") @@ -176,7 +176,7 @@ pipe = AutoPipelineForImage2Image.from_pretrained( "Lykon/dreamshaper-7", dtype=torch.float16, variant="fp16", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) @@ -224,7 +224,7 @@ pipe = AutoPipelineForInpainting.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-inpainting", dtype=torch.float16, variant="fp16", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) @@ -281,7 +281,7 @@ unet = UNet2DConditionModel.from_pretrained( ) pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", unet=unet, dtype=torch.float16, variant="fp16", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("TheLastBen/Papercut_SDXL", weight_name="papercut.safetensors", adapter_name="papercut") @@ -310,7 +310,7 @@ pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) @@ -375,7 +375,7 @@ pipe = StableDiffusionControlNetPipeline.from_pretrained( controlnet=controlnet, dtype=torch.float16, safety_checker=None, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) generator = torch.manual_seed(0) @@ -430,7 +430,7 @@ pipe = StableDiffusionControlNetPipeline.from_pretrained( dtype=torch.float16, safety_checker=None, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) @@ -491,7 +491,7 @@ image = image[:, :, None] image = np.concatenate([image, image, image], axis=2) canny_image = Image.fromarray(image).resize((1024, 1216)) -adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", dtype=torch.float16, variant="fp16").to("cuda") +adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", dtype=torch.float16, variant="fp16").to("cuda") # or "mps", "xpu", "cpu" unet = UNet2DConditionModel.from_pretrained( "latent-consistency/lcm-sdxl", @@ -557,7 +557,7 @@ image = image[:, :, None] image = np.concatenate([image, image, image], axis=2) canny_image = Image.fromarray(image).resize((1024, 1024)) -adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", dtype=torch.float16, variant="fp16").to("cuda") +adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", dtype=torch.float16, variant="fp16").to("cuda") # or "mps", "xpu", "cpu" pipe = StableDiffusionXLAdapterPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", @@ -608,7 +608,7 @@ adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5" pipe = AnimateDiffPipeline.from_pretrained( "frankjoshua/toonyou_beta6", motion_adapter=adapter, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # set scheduler pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) diff --git a/docs/source/en/api/pipelines/latte.md b/docs/source/en/api/pipelines/latte.md index 8faa5bf1b839..627fbe82b99d 100644 --- a/docs/source/en/api/pipelines/latte.md +++ b/docs/source/en/api/pipelines/latte.md @@ -41,7 +41,7 @@ from diffusers import LattePipeline pipeline = LattePipeline.from_pretrained( "maxin-cn/Latte-1", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Then change the memory layout of the pipelines `transformer` and `vae` components to `torch.channels-last`: diff --git a/docs/source/en/api/pipelines/longcat_audio_dit.md b/docs/source/en/api/pipelines/longcat_audio_dit.md index ce692d034aec..d776a7597105 100644 --- a/docs/source/en/api/pipelines/longcat_audio_dit.md +++ b/docs/source/en/api/pipelines/longcat_audio_dit.md @@ -29,7 +29,7 @@ pipeline = LongCatAudioDiTPipeline.from_pretrained( "ruixiangma/LongCat-AudioDiT-1B-Diffusers", dtype=torch.float16, ) -pipeline = pipeline.to("cuda") +pipeline = pipeline.to("cuda") # or "mps", "xpu", "cpu" prompt = "A calm ocean wave ambience with soft wind in the background." audio = pipeline( diff --git a/docs/source/en/api/pipelines/longcat_image.md b/docs/source/en/api/pipelines/longcat_image.md index 30c5a76866e0..0724c743983a 100644 --- a/docs/source/en/api/pipelines/longcat_image.md +++ b/docs/source/en/api/pipelines/longcat_image.md @@ -39,7 +39,7 @@ from diffusers import LongCatImagePipeline weight_dtype = torch.bfloat16 pipe = LongCatImagePipeline.from_pretrained("meituan-longcat/LongCat-Image", dtype=torch.bfloat16 ) -pipe.to('cuda') +pipe.to('cuda') # or "mps", "xpu", "cpu" # pipe.enable_model_cpu_offload() prompt = '一个年轻的亚裔女性,身穿黄色针织衫,搭配白色项链。她的双手放在膝盖上,表情恬静。背景是一堵粗糙的砖墙,午后的阳光温暖地洒在她身上,营造出一种宁静而温馨的氛围。镜头采用中距离视角,突出她的神态和服饰的细节。光线柔和地打在她的脸上,强调她的五官和饰品的质感,增加画面的层次感与亲和力。整个画面构图简洁,砖墙的纹理与阳光的光影效果相得益彰,突显出人物的优雅与从容。' diff --git a/docs/source/en/api/pipelines/ltx2.md b/docs/source/en/api/pipelines/ltx2.md index e73689b4af52..59b43a3af78e 100644 --- a/docs/source/en/api/pipelines/ltx2.md +++ b/docs/source/en/api/pipelines/ltx2.md @@ -129,7 +129,7 @@ from diffusers.pipelines.ltx2.latent_upsampler import LTX2LatentUpsamplerModel from diffusers.pipelines.ltx2.utils import DISTILLED_SIGMA_VALUES, STAGE_2_DISTILLED_SIGMA_VALUES from diffusers.utils import encode_video -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -209,7 +209,7 @@ from diffusers.pipelines.ltx2.utils import DISTILLED_SIGMA_VALUES, STAGE_2_DISTI from diffusers.utils import encode_video from diffusers.utils import load_image -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -299,7 +299,7 @@ from diffusers.utils import encode_video from diffusers.pipelines.ltx2.utils import DEFAULT_NEGATIVE_PROMPT from diffusers.utils import load_image, load_video -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -374,7 +374,7 @@ from diffusers.utils import encode_video from diffusers.pipelines.ltx2.utils import DEFAULT_NEGATIVE_PROMPT from diffusers.utils import load_image -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -446,7 +446,7 @@ from diffusers import LTX2Pipeline from diffusers.utils import encode_video from diffusers.pipelines.ltx2.utils import DEFAULT_NEGATIVE_PROMPT, T2V_DEFAULT_SYSTEM_PROMPT -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -520,7 +520,7 @@ from diffusers import LTX2Pipeline from diffusers.utils import encode_video from diffusers.pipelines.ltx2.utils import DISTILLED_SIGMA_VALUES -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -573,7 +573,7 @@ from diffusers.pipelines.ltx2.latent_upsampler import LTX2LatentUpsamplerModel from diffusers.pipelines.ltx2.utils import DISTILLED_SIGMA_VALUES, STAGE_2_DISTILLED_SIGMA_VALUES from diffusers.utils import encode_video -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 1536 height = 1024 num_frames = 121 @@ -693,7 +693,7 @@ from diffusers.models.autoencoders.ltx2_diffusion_decoder import LTX2VideoVaeNei from diffusers.pipelines.ltx2.utils import DISTILLED_SIGMA_VALUES from diffusers.utils import encode_video -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" frame_rate = 24.0 generator = torch.Generator(device).manual_seed(42) model_path = "Lightricks/LTX-2.5-Diffusers" @@ -766,7 +766,7 @@ import torch from diffusers import FlowMatchEulerDiscreteScheduler, LTX2Pipeline, LTX2VideoTransformer3DModel from diffusers.pipelines.ltx2.utils import DEFAULT_NEGATIVE_PROMPT -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" model_path = "Lightricks/LTX-2.5-Diffusers" # Passing `transformer=` keeps `from_pretrained` from fetching the distilled folder as well. @@ -819,7 +819,7 @@ from diffusers import LTX2Pipeline from diffusers.utils import encode_video from diffusers.pipelines.ltx2.utils import DISTILLED_SIGMA_VALUES -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" width = 768 height = 512 random_seed = 42 @@ -926,7 +926,7 @@ from diffusers.models.autoencoders.ltx2_diffusion_decoder import LTX2VideoVaeNei from diffusers.pipelines.ltx2.utils import DEFAULT_NEGATIVE_PROMPT from diffusers.utils import encode_video -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" frame_rate = 24.0 random_seed = 42 generator = torch.Generator(device).manual_seed(random_seed) @@ -981,7 +981,7 @@ from diffusers.models.autoencoders.ltx2_diffusion_decoder import LTX2VideoVaeNei from diffusers.pipelines.ltx2.utils import DEFAULT_NEGATIVE_PROMPT from diffusers.utils import encode_video, load_image -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" frame_rate = 24.0 random_seed = 42 generator = torch.Generator(device).manual_seed(random_seed) diff --git a/docs/source/en/api/pipelines/ltx_video.md b/docs/source/en/api/pipelines/ltx_video.md index 75abcf916d3a..b7726d8f0c0b 100644 --- a/docs/source/en/api/pipelines/ltx_video.md +++ b/docs/source/en/api/pipelines/ltx_video.md @@ -151,7 +151,7 @@ export_to_video(video, "output.mp4", fps=24) pipeline = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.7-dev", dtype=torch.bfloat16) pipeline_upsample = LTXLatentUpsamplePipeline.from_pretrained("Lightricks/ltxv-spatial-upscaler-0.9.7", vae=pipeline.vae, dtype=torch.bfloat16) - pipeline.to("cuda") + pipeline.to("cuda") # or "mps", "xpu", "cpu" pipe_upsample.to("cuda") pipeline.vae.enable_tiling() @@ -249,7 +249,7 @@ export_to_video(video, "output.mp4", fps=24) pipeline = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.7-distilled", dtype=torch.bfloat16) pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained("Lightricks/ltxv-spatial-upscaler-0.9.7", vae=pipeline.vae, dtype=torch.bfloat16) - pipeline.to("cuda") + pipeline.to("cuda") # or "mps", "xpu", "cpu" pipe_upsample.to("cuda") pipeline.vae.enable_tiling() @@ -341,7 +341,7 @@ export_to_video(video, "output.mp4", fps=24) # TODO: Update the checkpoint here once updated in LTX org upsampler = LTXLatentUpsamplerModel.from_pretrained("a-r-r-o-w/LTX-0.9.8-Latent-Upsampler", dtype=torch.bfloat16) pipe_upsample = LTXLatentUpsamplePipeline(vae=pipeline.vae, latent_upsampler=upsampler).to(torch.bfloat16) - pipeline.to("cuda") + pipeline.to("cuda") # or "mps", "xpu", "cpu" pipe_upsample.to("cuda") pipeline.vae.enable_tiling() diff --git a/docs/source/en/api/pipelines/lumina.md b/docs/source/en/api/pipelines/lumina.md index 150bc4ea7b94..762c32f645c6 100644 --- a/docs/source/en/api/pipelines/lumina.md +++ b/docs/source/en/api/pipelines/lumina.md @@ -60,7 +60,7 @@ import torch pipeline = LuminaPipeline.from_pretrained( "Alpha-VLLM/Lumina-Next-SFT-diffusers", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Then change the memory layout of the pipelines `transformer` and `vae` components to `torch.channels-last`: diff --git a/docs/source/en/api/pipelines/marigold.md b/docs/source/en/api/pipelines/marigold.md index 984c3832d150..d5a1c6bd2675 100644 --- a/docs/source/en/api/pipelines/marigold.md +++ b/docs/source/en/api/pipelines/marigold.md @@ -118,7 +118,7 @@ import torch pipe = diffusers.MarigoldDepthPipeline.from_pretrained( "prs-eth/marigold-depth-v1-1", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") @@ -165,7 +165,7 @@ import torch pipe = diffusers.MarigoldNormalsPipeline.from_pretrained( "prs-eth/marigold-normals-v1-1", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") @@ -215,7 +215,7 @@ import torch pipe = diffusers.MarigoldIntrinsicsPipeline.from_pretrained( "prs-eth/marigold-iid-appearance-v1-1", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") @@ -235,7 +235,7 @@ import torch pipe = diffusers.MarigoldIntrinsicsPipeline.from_pretrained( "prs-eth/marigold-iid-lighting-v1-1", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") @@ -284,7 +284,7 @@ steps to the minimum: pipe = diffusers.MarigoldDepthPipeline.from_pretrained( "prs-eth/marigold-depth-v1-1", variant="fp16", dtype=torch.float16 - ).to("cuda") + ).to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") @@ -307,7 +307,7 @@ Note that using a lightweight VAE may slightly reduce the visual quality of the pipe = diffusers.MarigoldDepthPipeline.from_pretrained( "prs-eth/marigold-depth-v1-1", variant="fp16", dtype=torch.float16 - ).to("cuda") + ).to("cuda") # or "mps", "xpu", "cpu" + pipe.vae = diffusers.AutoencoderTiny.from_pretrained( + "madebyollin/taesd", dtype=torch.float16 @@ -329,7 +329,7 @@ Speeding them up can be achieved by using a more efficient attention processor: pipe = diffusers.MarigoldDepthPipeline.from_pretrained( "prs-eth/marigold-depth-v1-1", variant="fp16", dtype=torch.float16 - ).to("cuda") + ).to("cuda") # or "mps", "xpu", "cpu" + pipe.vae.set_attn_processor(AttnProcessor2_0()) + pipe.unet.set_attn_processor(AttnProcessor2_0()) @@ -351,7 +351,7 @@ the same pipeline instance is called repeatedly, such as within a loop. pipe = diffusers.MarigoldDepthPipeline.from_pretrained( "prs-eth/marigold-depth-v1-1", variant="fp16", dtype=torch.float16 - ).to("cuda") + ).to("cuda") # or "mps", "xpu", "cpu" pipe.vae.set_attn_processor(AttnProcessor2_0()) pipe.unet.set_attn_processor(AttnProcessor2_0()) @@ -376,7 +376,7 @@ The effect of ensembling is particularly well-seen with surface normals: ```diff import diffusers - pipe = diffusers.MarigoldNormalsPipeline.from_pretrained("prs-eth/marigold-normals-v1-1").to("cuda") + pipe = diffusers.MarigoldNormalsPipeline.from_pretrained("prs-eth/marigold-normals-v1-1").to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") @@ -437,7 +437,7 @@ from diffusers.models.attention_processor import AttnProcessor2_0 from PIL import Image from tqdm import tqdm -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" path_in = "https://huggingface.co/spaces/prs-eth/marigold-lcm/resolve/c7adb5427947d2680944f898cd91d386bf0d4924/files/video/obama.mp4" path_out = "obama_depth.gif" @@ -506,7 +506,7 @@ The snippet below demonstrates how to load an image, compute depth, and pass it import torch import diffusers -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" generator = torch.Generator(device=device).manual_seed(2024) image = diffusers.utils.load_image( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_depth_source.png" @@ -574,7 +574,7 @@ Maximizing `batch_size` will deliver maximum device utilization. import diffusers import torch -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" seed = 2024 generator = torch.Generator(device=device).manual_seed(seed) @@ -607,7 +607,7 @@ import torch pipe = diffusers.MarigoldDepthPipeline.from_pretrained( "prs-eth/marigold-depth-v1-1", variant="fp16", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg") diff --git a/docs/source/en/api/pipelines/minimax_h3.md b/docs/source/en/api/pipelines/minimax_h3.md index 4c1b5d4b49c0..52e586624878 100644 --- a/docs/source/en/api/pipelines/minimax_h3.md +++ b/docs/source/en/api/pipelines/minimax_h3.md @@ -89,7 +89,7 @@ from diffusers import ComponentsManager, ModularPipeline manager = ComponentsManager() pipe = ModularPipeline.from_pretrained("MiniMaxAI/MiniMax-H3", components_manager=manager) pipe.load_components(workflow="t2va", dtype=torch.bfloat16) -manager.enable_auto_cpu_offload(device="cuda", memory_reserve_margin="12GB") +manager.enable_auto_cpu_offload(device="cuda", memory_reserve_margin="12GB") # or "mps", "xpu", "cpu" pipe.transformer.set_attention_backend("_flash_3_hub") # Hopper, roughly 3x faster; kernels fetched from the Hub ``` @@ -134,7 +134,7 @@ pipe.text_encoder.requires_grad_(False) offload = dict(onload_device=torch.device("cuda"), offload_device=torch.device("cpu"), use_stream=True) pipe.transformer.enable_group_offload(offload_type="block_level", num_blocks_per_group=1, **offload) apply_group_offloading(pipe.text_encoder.model, offload_type="leaf_level", **offload) -pipe.vae.to("cuda") +pipe.vae.to("cuda") # or "mps", "xpu", "cpu" pipe.audio_vae.to("cuda") ``` @@ -185,7 +185,7 @@ from diffusers.utils.export_utils import encode_video # 61.7GB of transformer and 62.1GB of conditioner do not sit on one accelerator, so the components are # registered in a manager that moves each one on and off as the blocks reach it. See [Memory](#memory). manager = ComponentsManager() -manager.enable_auto_cpu_offload(device="cuda") +manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu" pipe = ModularPipeline.from_pretrained("MiniMaxAI/MiniMax-H3", components_manager=manager) pipe.load_components(workflow="fl2va", dtype=torch.bfloat16) @@ -248,7 +248,7 @@ from diffusers.utils.export_utils import encode_video # `ref2va` is a workflow of the one MiniMax-H3 pipeline; selecting it loads only the `transformer_ref/` # checkpoint partition, and the manager moves each component on and off the accelerator in turn. manager = ComponentsManager() -manager.enable_auto_cpu_offload(device="cuda") +manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu" pipe = ModularPipeline.from_pretrained("MiniMaxAI/MiniMax-H3", workflow="ref2va", components_manager=manager) pipe.load_components(dtype=torch.bfloat16) @@ -301,7 +301,7 @@ from diffusers import ComponentsManager, ModularPipeline from diffusers.modular_pipelines.minimax_h3 import MiniMaxH3VideoReference manager = ComponentsManager() -manager.enable_auto_cpu_offload(device="cuda") +manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu" # The full pipeline holds every workflow and picks one per call from the inputs. Loading without a # `workflow=` brings both transformer partitions in one call, so the `ref2va` request that follows the diff --git a/docs/source/en/api/pipelines/minimax_music3.md b/docs/source/en/api/pipelines/minimax_music3.md index 7645d71a8861..f5b4321fd496 100644 --- a/docs/source/en/api/pipelines/minimax_music3.md +++ b/docs/source/en/api/pipelines/minimax_music3.md @@ -31,7 +31,7 @@ from diffusers import ModularPipeline pipe = ModularPipeline.from_pretrained("MiniMaxAI/MiniMax-Music3") pipe.load_components(dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" lyrics = """[verse] Morning light filtering through the pine @@ -70,7 +70,7 @@ from diffusers import ComponentsManager, ModularPipeline from diffusers.hooks.group_offloading import apply_group_offloading manager = ComponentsManager() -manager.enable_auto_cpu_offload(device="cuda") +manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu" pipe = ModularPipeline.from_pretrained("MiniMaxAI/MiniMax-Music3", components_manager=manager) pipe.load_components(dtype=torch.bfloat16) diff --git a/docs/source/en/api/pipelines/mochi.md b/docs/source/en/api/pipelines/mochi.md index 29f83620d72f..e9ec83039606 100644 --- a/docs/source/en/api/pipelines/mochi.md +++ b/docs/source/en/api/pipelines/mochi.md @@ -217,7 +217,7 @@ with torch.autocast(device_type="cuda", dtype=torch.bfloat16, cache_enabled=Fals num_inference_steps=50, guidance_scale=4.5, num_videos_per_prompt=1, - generator=torch.Generator(device="cuda").manual_seed(0), + generator=torch.Generator(device="cuda").manual_seed(0), # or "mps", "xpu", "cpu" max_sequence_length=256, output_type="pil", ).frames[0] @@ -257,7 +257,7 @@ with torch.autocast(device_type="cuda", dtype=torch.bfloat16, cache_enabled=Fals num_inference_steps=50, guidance_scale=4.5, num_videos_per_prompt=1, - generator=torch.Generator(device="cuda").manual_seed(0), + generator=torch.Generator(device="cuda").manual_seed(0), # or "mps", "xpu", "cpu" max_sequence_length=256, output_type="pil", ).frames[0] diff --git a/docs/source/en/api/pipelines/motif_video.md b/docs/source/en/api/pipelines/motif_video.md index a9343240c472..dd47d881e3fa 100644 --- a/docs/source/en/api/pipelines/motif_video.md +++ b/docs/source/en/api/pipelines/motif_video.md @@ -24,7 +24,7 @@ pipe = MotifVideoPipeline.from_pretrained( "Motif-Technologies/Motif-Video-2B", dtype=torch.bfloat16, ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A woman with long brown hair and light skin smiles at another woman with long blonde hair." negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted" @@ -54,7 +54,7 @@ pipe = MotifVideoImage2VideoPipeline.from_pretrained( "Motif-Technologies/Motif-Video-2B", dtype=torch.bfloat16, ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image("input_image.png") prompt = "A cinematic scene with vivid colors." diff --git a/docs/source/en/api/pipelines/omnigen.md b/docs/source/en/api/pipelines/omnigen.md index 074dbd64931f..2f1718d5b712 100644 --- a/docs/source/en/api/pipelines/omnigen.md +++ b/docs/source/en/api/pipelines/omnigen.md @@ -50,7 +50,7 @@ pipe = OmniGenPipeline.from_pretrained( "Shitao/OmniGen-v1-diffusers", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "Realistic photo. A young woman sits on a sofa, holding a book and facing the camera. She wears delicate silver hoop earrings adorned with tiny, sparkling diamonds that catch the light, with her long chestnut hair cascading over her shoulders. Her eyes are focused and gentle, framed by long, dark lashes. She is dressed in a cozy cream sweater, which complements her warm, inviting smile. Behind her, there is a table with a cup of water in a sleek, minimalist blue mug. The background is a serene indoor setting with soft natural light filtering through a window, adorned with tasteful art and flowers, creating a cozy and peaceful ambiance. 4K, HD." image = pipe( @@ -82,7 +82,7 @@ pipe = OmniGenPipeline.from_pretrained( "Shitao/OmniGen-v1-diffusers", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt="<|image_1|> Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola." input_images=[load_image("https://raw.githubusercontent.com/VectorSpaceLab/OmniGen/main/imgs/docs_img/t2i_woman_with_book.png")] @@ -141,7 +141,7 @@ pipe = OmniGenPipeline.from_pretrained( "Shitao/OmniGen-v1-diffusers", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt="Detect the skeleton of human in this image: <|image_1|>" input_images=[load_image("https://raw.githubusercontent.com/VectorSpaceLab/OmniGen/main/imgs/docs_img/edit.png")] @@ -195,7 +195,7 @@ pipe = OmniGenPipeline.from_pretrained( "Shitao/OmniGen-v1-diffusers", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt="Following the pose of this image <|image_1|>, generate a new photo: A young boy is sitting on a sofa in the library, holding a book. His hair is neatly combed, and a faint smile plays on his lips, with a few freckles scattered across his cheeks. The library is quiet, with rows of shelves filled with books stretching out behind him." input_images=[load_image("https://raw.githubusercontent.com/VectorSpaceLab/OmniGen/main/imgs/docs_img/edit.png")] @@ -231,7 +231,7 @@ pipe = OmniGenPipeline.from_pretrained( "Shitao/OmniGen-v1-diffusers", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt="A man and a woman are sitting at a classroom desk. The man is the man with yellow hair in <|image_1|>. The woman is the woman on the left of <|image_2|>" input_image_1 = load_image("https://raw.githubusercontent.com/VectorSpaceLab/OmniGen/main/imgs/docs_img/3.png") @@ -273,7 +273,7 @@ pipe = OmniGenPipeline.from_pretrained( "Shitao/OmniGen-v1-diffusers", dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt="A woman is walking down the street, wearing a white long-sleeve blouse with lace details on the sleeves, paired with a blue pleated skirt. The woman is <|image_1|>. The long-sleeve blouse and a pleated skirt are <|image_2|>." input_image_1 = load_image("https://raw.githubusercontent.com/VectorSpaceLab/OmniGen/main/imgs/docs_img/emma.jpeg") diff --git a/docs/source/en/api/pipelines/pag.md b/docs/source/en/api/pipelines/pag.md index 055feee8cebe..4be5ffb34f50 100644 --- a/docs/source/en/api/pipelines/pag.md +++ b/docs/source/en/api/pipelines/pag.md @@ -293,7 +293,7 @@ pipeline = AutoPipelineForText2Image.from_pretrained( image_encoder=image_encoder, enable_pag=True, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter-plus_sdxl_vit-h.bin") diff --git a/docs/source/en/api/pipelines/pixart.md b/docs/source/en/api/pipelines/pixart.md index 5007f3385529..bdd66efd9f7c 100644 --- a/docs/source/en/api/pipelines/pixart.md +++ b/docs/source/en/api/pipelines/pixart.md @@ -93,7 +93,7 @@ pipe = PixArtAlphaPipeline.from_pretrained( "PixArt-alpha/PixArt-XL-2-1024-MS", text_encoder=None, dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" latents = pipe( negative_prompt=None, diff --git a/docs/source/en/api/pipelines/pixart_sigma.md b/docs/source/en/api/pipelines/pixart_sigma.md index 4fc43190a5ab..270999149d2e 100644 --- a/docs/source/en/api/pipelines/pixart_sigma.md +++ b/docs/source/en/api/pipelines/pixart_sigma.md @@ -97,7 +97,7 @@ pipe = PixArtSigmaPipeline.from_pretrained( "PixArt-alpha/PixArt-Sigma-XL-2-1024-MS", text_encoder=None, dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" latents = pipe( negative_prompt=None, diff --git a/docs/source/en/api/pipelines/prx.md b/docs/source/en/api/pipelines/prx.md index 90a4eae0d123..a71afc7ee67c 100644 --- a/docs/source/en/api/pipelines/prx.md +++ b/docs/source/en/api/pipelines/prx.md @@ -44,7 +44,7 @@ from diffusers.pipelines.prx import PRXPipeline # Load pipeline - VAE and text encoder will be loaded from HuggingFace pipe = PRXPipeline.from_pretrained("Photoroom/prx-512-t2i-sft", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A front-facing portrait of a lion the golden savanna at sunset." image = pipe(prompt, num_inference_steps=28, guidance_scale=5.0).images[0] @@ -101,7 +101,7 @@ pipe = PRXPipeline( tokenizer=tokenizer, vae=vae ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" ``` diff --git a/docs/source/en/api/pipelines/prx_pixel.md b/docs/source/en/api/pipelines/prx_pixel.md index 3bb5d38d72f1..2bb7c855a54a 100644 --- a/docs/source/en/api/pipelines/prx_pixel.md +++ b/docs/source/en/api/pipelines/prx_pixel.md @@ -34,7 +34,7 @@ import torch from diffusers import PRXPixelPipeline pipe = PRXPixelPipeline.from_pretrained("Photoroom/prxpixel-t2i", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A front-facing portrait of a lion in the golden savanna at sunset." image = pipe(prompt, num_inference_steps=28, guidance_scale=5.0).images[0] diff --git a/docs/source/en/api/pipelines/qwenimage.md b/docs/source/en/api/pipelines/qwenimage.md index d0b78ae2658e..d66cd78b0554 100644 --- a/docs/source/en/api/pipelines/qwenimage.md +++ b/docs/source/en/api/pipelines/qwenimage.md @@ -67,7 +67,7 @@ scheduler_config = { scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config) pipe = DiffusionPipeline.from_pretrained( ckpt_id, scheduler=scheduler, dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.load_lora_weights( "lightx2v/Qwen-Image-Lightning", weight_name="Qwen-Image-Lightning-8steps-V1.0.safetensors" ) @@ -103,7 +103,7 @@ from diffusers.utils import load_image pipe = QwenImageEditPlusPipeline.from_pretrained( "Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image_1 = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/grumpy.jpg") image_2 = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peng.png") @@ -124,7 +124,7 @@ Using `torch.compile` on the transformer provides ~2.4x speedup (A100 80GB: 4.70 import torch from diffusers import QwenImagePipeline -pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", dtype=torch.bfloat16).to("cuda") +pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" pipe.transformer = torch.compile(pipe.transformer) # First call triggers compilation (~7s overhead) diff --git a/docs/source/en/api/pipelines/sana_sprint.md b/docs/source/en/api/pipelines/sana_sprint.md index 8cf29df9c294..f712703f8b40 100644 --- a/docs/source/en/api/pipelines/sana_sprint.md +++ b/docs/source/en/api/pipelines/sana_sprint.md @@ -98,7 +98,7 @@ image = load_image( pipe = SanaSprintImg2ImgPipeline.from_pretrained( "Efficient-Large-Model/Sana_Sprint_1.6B_1024px_diffusers", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a cute pink bear", diff --git a/docs/source/en/api/pipelines/sana_video.md b/docs/source/en/api/pipelines/sana_video.md index f710736787d1..009db80c917a 100644 --- a/docs/source/en/api/pipelines/sana_video.md +++ b/docs/source/en/api/pipelines/sana_video.md @@ -52,7 +52,7 @@ pipe = SanaVideoPipeline.from_pretrained( ) pipe.text_encoder.to(torch.bfloat16) pipe.vae.to(torch.float32) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window." negative_prompt = "A chaotic sequence with misshapen, deformed limbs in heavy motion blur, sudden disappearance, jump cuts, jerky movements, rapid shot changes, frames out of sync, inconsistent character shapes, temporal artifacts, jitter, and ghosting effects, creating a disorienting visual experience." @@ -87,7 +87,7 @@ pipe = SanaImageToVideoPipeline.from_pretrained( pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config(pipe.scheduler.config, flow_shift=8.0) pipe.vae.to(torch.float32) pipe.text_encoder.to(torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image("https://raw.githubusercontent.com/NVlabs/Sana/refs/heads/main/asset/samples/i2v-1.png") prompt = "A woman stands against a stunning sunset backdrop, her long, wavy brown hair gently blowing in the breeze. She wears a sleeveless, light-colored blouse with a deep V-neckline, which accentuates her graceful posture. The warm hues of the setting sun cast a golden glow across her face and hair, creating a serene and ethereal atmosphere. The background features a blurred landscape with soft, rolling hills and scattered clouds, adding depth to the scene. The camera remains steady, capturing the tranquil moment from a medium close-up angle." diff --git a/docs/source/en/api/pipelines/shap_e.md b/docs/source/en/api/pipelines/shap_e.md index 1ff5d3d5034b..c683a53da7ba 100644 --- a/docs/source/en/api/pipelines/shap_e.md +++ b/docs/source/en/api/pipelines/shap_e.md @@ -79,7 +79,7 @@ To generate a 3D object from another image, use the [`ShapEImg2ImgPipeline`]. Yo from diffusers import DiffusionPipeline import torch -prior_pipeline = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") +prior_pipeline = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" pipeline = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", dtype=torch.float16, use_safetensors=True).to("cuda") prompt = "A cheeseburger, white background" @@ -101,7 +101,7 @@ from PIL import Image from diffusers import ShapEImg2ImgPipeline from diffusers.utils import export_to_gif -pipe = ShapEImg2ImgPipeline.from_pretrained("openai/shap-e-img2img", dtype=torch.float16, variant="fp16").to("cuda") +pipe = ShapEImg2ImgPipeline.from_pretrained("openai/shap-e-img2img", dtype=torch.float16, variant="fp16").to("cuda") # or "mps", "xpu", "cpu" guidance_scale = 3.0 image = Image.open("burger.png").resize((256, 256)) diff --git a/docs/source/en/api/pipelines/skyreels_v2.md b/docs/source/en/api/pipelines/skyreels_v2.md index d05b1689ede2..dc65d76d5c56 100644 --- a/docs/source/en/api/pipelines/skyreels_v2.md +++ b/docs/source/en/api/pipelines/skyreels_v2.md @@ -179,7 +179,7 @@ pipeline = SkyReelsV2DiffusionForcingPipeline.from_pretrained( vae=vae, dtype=torch.bfloat16, ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" flow_shift = 8.0 # 8.0 for T2V, 5.0 for I2V pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift) @@ -223,7 +223,7 @@ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.fl pipeline = SkyReelsV2DiffusionForcingImageToVideoPipeline.from_pretrained( model_id, vae=vae, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" flow_shift = 5.0 # 8.0 for T2V, 5.0 for I2V pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift) @@ -286,7 +286,7 @@ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.fl pipeline = SkyReelsV2DiffusionForcingVideoToVideoPipeline.from_pretrained( model_id, vae=vae, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" flow_shift = 5.0 # 8.0 for T2V, 5.0 for I2V pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift) diff --git a/docs/source/en/api/pipelines/stable_audio_3.md b/docs/source/en/api/pipelines/stable_audio_3.md index e950e510efcb..358de2df5a25 100644 --- a/docs/source/en/api/pipelines/stable_audio_3.md +++ b/docs/source/en/api/pipelines/stable_audio_3.md @@ -62,7 +62,7 @@ import soundfile as sf from diffusers import StableAudio3Pipeline pipe = StableAudio3Pipeline.from_pretrained("/tmp/sa3-diffusers-euler", torch_dtype=torch.float32) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator("cuda").manual_seed(0) audio = pipe( diff --git a/docs/source/en/api/pipelines/stable_diffusion/sdxl_turbo.md b/docs/source/en/api/pipelines/stable_diffusion/sdxl_turbo.md index c42faf122bc1..70a6fc6c1a17 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/sdxl_turbo.md +++ b/docs/source/en/api/pipelines/stable_diffusion/sdxl_turbo.md @@ -45,7 +45,7 @@ from diffusers import AutoPipelineForText2Image import torch pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", dtype=torch.float16, variant="fp16") -pipeline = pipeline.to("cuda") +pipeline = pipeline.to("cuda") # or "mps", "xpu", "cpu" ``` You can also use the [`~StableDiffusionXLPipeline.from_single_file`] method to load a model checkpoint stored in a single file format (`.ckpt` or `.safetensors`) from the Hub or locally. For this loading method, you need to set `timestep_spacing="trailing"` (feel free to experiment with the other scheduler config values to get better results): @@ -57,7 +57,7 @@ import torch pipeline = StableDiffusionXLPipeline.from_single_file( "https://huggingface.co/stabilityai/sdxl-turbo/blob/main/sd_xl_turbo_1.0_fp16.safetensors", dtype=torch.float16, variant="fp16") -pipeline = pipeline.to("cuda") +pipeline = pipeline.to("cuda") # or "mps", "xpu", "cpu" pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config, timestep_spacing="trailing") ``` @@ -73,7 +73,7 @@ from diffusers import AutoPipelineForText2Image import torch pipeline_text2image = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", dtype=torch.float16, variant="fp16") -pipeline_text2image = pipeline_text2image.to("cuda") +pipeline_text2image = pipeline_text2image.to("cuda") # or "mps", "xpu", "cpu" prompt = "A cinematic shot of a baby racoon wearing an intricate italian priest robe." @@ -96,7 +96,7 @@ from diffusers import AutoPipelineForImage2Image from diffusers.utils import load_image, make_image_grid # use from_pipe to avoid consuming additional memory when loading a checkpoint -pipeline_image2image = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cuda") +pipeline_image2image = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cuda") # or "mps", "xpu", "cpu" init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") init_image = init_image.resize((512, 512)) diff --git a/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_2.md b/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_2.md index 590f8ef09275..c7e43e3e5092 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_2.md +++ b/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_2.md @@ -48,7 +48,7 @@ repo_id = "stabilityai/stable-diffusion-2-base" pipe = DiffusionPipeline.from_pretrained(repo_id, dtype=torch.float16, variant="fp16") pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "High quality photo of an astronaut riding a horse in space" image = pipe(prompt, num_inference_steps=25).images[0] @@ -72,7 +72,7 @@ repo_id = "stabilityai/stable-diffusion-2-inpainting" pipe = DiffusionPipeline.from_pretrained(repo_id, dtype=torch.float16, variant="fp16") pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "Face of a yellow cat, high resolution, sitting on a park bench" image = pipe(prompt=prompt, image=init_image, mask_image=mask_image, num_inference_steps=25).images[0] @@ -89,7 +89,7 @@ import torch # load model and scheduler model_id = "stabilityai/stable-diffusion-x4-upscaler" pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, dtype=torch.float16) -pipeline = pipeline.to("cuda") +pipeline = pipeline.to("cuda") # or "mps", "xpu", "cpu" # let's download an image url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png" @@ -110,7 +110,7 @@ from diffusers.utils import load_image, make_image_grid pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( "stabilityai/stable-diffusion-2-depth", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" url = "http://images.cocodataset.org/val2017/000000039769.jpg" diff --git a/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_3.md b/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_3.md index c2c62716b182..7cefd48a7be2 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_3.md +++ b/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_3.md @@ -42,7 +42,7 @@ import torch from diffusers import StableDiffusion3Pipeline pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", dtype=torch.float16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a photo of a cat holding a sign that says hello world", @@ -88,7 +88,7 @@ feature_extractor = SiglipImageProcessor.from_pretrained( image_encoder = SiglipVisionModel.from_pretrained( image_encoder_id, dtype=torch.float16 -).to( "cuda") +).to( "cuda") # or "mps", "xpu", "cpu" pipe = StableDiffusion3Pipeline.from_pretrained( "stabilityai/stable-diffusion-3.5-large", @@ -166,7 +166,7 @@ pipe = StableDiffusion3Pipeline.from_pretrained( tokenizer_3=None, dtype=torch.float16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = pipe( prompt="a photo of a cat holding a sign that says hello world", @@ -246,7 +246,7 @@ torch._inductor.config.coordinate_descent_check_all_directions = True pipe = StableDiffusion3Pipeline.from_pretrained( "stabilityai/stable-diffusion-3-medium-diffusers", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipe.set_progress_bar_config(disable=True) pipe.transformer.to(memory_format=torch.channels_last) @@ -359,7 +359,7 @@ pipe = StableDiffusion3Pipeline.from_pretrained( "stabilityai/stable-diffusion-3-medium-diffusers", dtype=torch.float16 ) pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd3", dtype=torch.float16) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "slice of delicious New York-style berry cheesecake" image = pipe(prompt, num_inference_steps=25).images[0] diff --git a/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_xl.md b/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_xl.md index dbb609d6f664..55dd32f0c5ca 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_xl.md +++ b/docs/source/en/api/pipelines/stable_diffusion/stable_diffusion_xl.md @@ -60,7 +60,7 @@ import torch pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-refiner-1.0", dtype=torch.float16, use_safetensors=True, variant="fp16" @@ -76,7 +76,7 @@ import torch pipeline = StableDiffusionXLPipeline.from_single_file( "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" refiner = StableDiffusionXLImg2ImgPipeline.from_single_file( "https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/sd_xl_refiner_1.0.safetensors", dtype=torch.float16 @@ -93,7 +93,7 @@ import torch pipeline_text2image = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipeline_text2image(prompt=prompt).images[0] @@ -113,7 +113,7 @@ from diffusers import AutoPipelineForImage2Image from diffusers.utils import load_image, make_image_grid # use from_pipe to avoid consuming additional memory when loading a checkpoint -pipeline = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cuda") +pipeline = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cuda") # or "mps", "xpu", "cpu" url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png" init_image = load_image(url) @@ -135,7 +135,7 @@ from diffusers import AutoPipelineForInpainting from diffusers.utils import load_image, make_image_grid # use from_pipe to avoid consuming additional memory when loading a checkpoint -pipeline = AutoPipelineForInpainting.from_pipe(pipeline_text2image).to("cuda") +pipeline = AutoPipelineForInpainting.from_pipe(pipeline_text2image).to("cuda") # or "mps", "xpu", "cpu" img_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png" mask_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-inpaint-mask.png" @@ -171,7 +171,7 @@ import torch base = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" refiner = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-refiner-1.0", @@ -228,7 +228,7 @@ import torch base = StableDiffusionXLInpaintPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" refiner = StableDiffusionXLInpaintPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-refiner-1.0", @@ -281,7 +281,7 @@ import torch base = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" refiner = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-refiner-1.0", @@ -346,7 +346,7 @@ import torch pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe( @@ -371,7 +371,7 @@ import torch pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipeline(prompt=prompt, crops_coords_top_left=(256, 0)).images[0] @@ -390,7 +390,7 @@ import torch pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe( @@ -412,7 +412,7 @@ import torch pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16", use_safetensors=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # prompt is passed to OAI CLIP-ViT/L-14 prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" @@ -435,7 +435,7 @@ SDXL is a large model, and you may need to optimize memory to get it to run on y 1. Offload the model to the CPU with [`~StableDiffusionXLPipeline.enable_model_cpu_offload`] for out-of-memory errors: ```diff -- base.to("cuda") +- base.to("cuda") # or "mps", "xpu", "cpu" - refiner.to("cuda") + base.enable_model_cpu_offload() + refiner.enable_model_cpu_offload() diff --git a/docs/source/en/api/pipelines/stable_diffusion/svd.md b/docs/source/en/api/pipelines/stable_diffusion/svd.md index 97392adc3bad..a615b736bfa9 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/svd.md +++ b/docs/source/en/api/pipelines/stable_diffusion/svd.md @@ -70,7 +70,7 @@ You can gain a 20-25% speedup at the expense of slightly increased memory by [co ```diff - pipe.enable_model_cpu_offload() -+ pipe.to("cuda") ++ pipe.to("cuda") # or "mps", "xpu", "cpu" + pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) ``` diff --git a/docs/source/en/api/pipelines/stable_unclip.md b/docs/source/en/api/pipelines/stable_unclip.md index 61161f825a59..2975d2aaf7fc 100644 --- a/docs/source/en/api/pipelines/stable_unclip.md +++ b/docs/source/en/api/pipelines/stable_unclip.md @@ -59,7 +59,7 @@ pipe = StableUnCLIPPipeline.from_pretrained( prior_scheduler=prior_scheduler, ) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" wave_prompt = "dramatic wave, the Oceans roar, Strong wave spiral across the oceans as the waves unfurl into roaring crests; perfect wave form; perfect wave shape; dramatic wave shape; wave shape unbelievable; wave; wave shape spectacular" image = pipe(prompt=wave_prompt).images[0] @@ -78,7 +78,7 @@ import torch pipe = StableUnCLIPImg2ImgPipeline.from_pretrained( "stabilityai/stable-diffusion-2-1-unclip", dtype=torch.float16, variation="fp16" ) -pipe = pipe.to("cuda") +pipe = pipe.to("cuda") # or "mps", "xpu", "cpu" url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/tarsila_do_amaral.png" init_image = load_image(url) diff --git a/docs/source/en/api/pipelines/visualcloze.md b/docs/source/en/api/pipelines/visualcloze.md index 83b6930094cb..4e1f02ea9d25 100644 --- a/docs/source/en/api/pipelines/visualcloze.md +++ b/docs/source/en/api/pipelines/visualcloze.md @@ -70,7 +70,7 @@ from diffusers import VisualClozePipeline from diffusers.utils import load_image pipe = VisualClozePipeline.from_pretrained("VisualCloze/VisualClozePipeline-384", resolution=384, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Load in-context images (make sure the paths are correct and accessible) image_paths = [ @@ -122,7 +122,7 @@ from diffusers import VisualClozePipeline from diffusers.utils import load_image pipe = VisualClozePipeline.from_pretrained("VisualCloze/VisualClozePipeline-384", resolution=384, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Load in-context images (make sure the paths are correct and accessible) image_paths = [ @@ -172,7 +172,7 @@ from diffusers import VisualClozePipeline from diffusers.utils import load_image pipe = VisualClozePipeline.from_pretrained("VisualCloze/VisualClozePipeline-384", resolution=384, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Load in-context images (make sure the paths are correct and accessible) image_paths = [ @@ -231,7 +231,7 @@ from PIL import Image pipe = VisualClozeGenerationPipeline.from_pretrained( "VisualCloze/VisualClozePipeline-384", resolution=384, dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image_paths = [ # in-context examples diff --git a/docs/source/en/api/pipelines/wan.md b/docs/source/en/api/pipelines/wan.md index f3c0376d4db5..757b44026a22 100644 --- a/docs/source/en/api/pipelines/wan.md +++ b/docs/source/en/api/pipelines/wan.md @@ -93,7 +93,7 @@ pipeline = WanPipeline.from_pretrained( text_encoder=text_encoder, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" prompt = """ The camera rushes from far to near in a low-angle shot, @@ -142,7 +142,7 @@ pipeline = WanPipeline.from_pretrained( text_encoder=text_encoder, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" # torch.compile pipeline.transformer.to(memory_format=torch.channels_last) @@ -197,7 +197,7 @@ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.fl pipe = WanImageToVideoPipeline.from_pretrained( model_id, vae=vae, image_encoder=image_encoder, dtype=torch.bfloat16 ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" first_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png") last_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png") @@ -294,7 +294,7 @@ from diffusers.utils import export_to_video, load_image, load_video model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers" vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Load character image and preprocessed videos image = load_image("path/to/character.jpg") @@ -343,7 +343,7 @@ from diffusers.utils import export_to_video, load_image, load_video model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers" vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Load all required inputs for replacement mode image = load_image("path/to/new_character.jpg") @@ -396,7 +396,7 @@ from diffusers.utils import export_to_video, load_image, load_video model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers" vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" image = load_image("path/to/character.jpg") pose_video = load_video("path/to/pose_video.mp4") @@ -472,7 +472,7 @@ export_to_video(output, "animated_advanced.mp4", fps=30) pipeline.scheduler = UniPCMultistepScheduler.from_config( pipeline.scheduler.config, flow_shift=5.0 ) - pipeline.to("cuda") + pipeline.to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights("benjamin-paine/steamboat-willie-1.3b", adapter_name="steamboat-willie") pipeline.set_adapters("steamboat-willie") diff --git a/docs/source/en/api/pipelines/wan_animate_2.md b/docs/source/en/api/pipelines/wan_animate_2.md index 6d55a4d5de25..430e284dddf4 100644 --- a/docs/source/en/api/pipelines/wan_animate_2.md +++ b/docs/source/en/api/pipelines/wan_animate_2.md @@ -35,7 +35,7 @@ pipe.transformer.enable_group_offload( offload_type="block_level", use_stream=True, ) -pipe.text_encoder.to("cuda") +pipe.text_encoder.to("cuda") # or "mps", "xpu", "cpu" pipe.image_encoder.to("cuda") pipe.vae.to("cuda") pipe.transformer.compile_repeated_blocks(fullgraph=False) diff --git a/docs/source/en/api/pipelines/z_image.md b/docs/source/en/api/pipelines/z_image.md index ea7f010b51d6..b35dbc40001d 100644 --- a/docs/source/en/api/pipelines/z_image.md +++ b/docs/source/en/api/pipelines/z_image.md @@ -36,7 +36,7 @@ from diffusers import ZImageImg2ImgPipeline from diffusers.utils import load_image pipe = ZImageImg2ImgPipeline.from_pretrained("Tongyi-MAI/Z-Image-Turbo", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" init_image = load_image(url).resize((1024, 1024)) @@ -65,7 +65,7 @@ from diffusers import ZImageInpaintPipeline from diffusers.utils import load_image pipe = ZImageInpaintPipeline.from_pretrained("Tongyi-MAI/Z-Image-Turbo", dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" init_image = load_image(url).resize((1024, 1024)) diff --git a/docs/source/en/api/schedulers/ddim.md b/docs/source/en/api/schedulers/ddim.md index 99ab1a9ac02b..67496cf97f71 100644 --- a/docs/source/en/api/schedulers/ddim.md +++ b/docs/source/en/api/schedulers/ddim.md @@ -65,7 +65,7 @@ pipe = DiffusionPipeline.from_pretrained("ptx0/pseudo-journey-v2", dtype=torch.f pipe.scheduler = DDIMScheduler.from_config( pipe.scheduler.config, rescale_betas_zero_snr=True, timestep_spacing="trailing" ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k" image = pipe(prompt, guidance_rescale=0.7).images[0] diff --git a/docs/source/en/hybrid_inference/overview.md b/docs/source/en/hybrid_inference/overview.md index b7ebcb206850..41f18a72ec1e 100644 --- a/docs/source/en/hybrid_inference/overview.md +++ b/docs/source/en/hybrid_inference/overview.md @@ -42,7 +42,7 @@ pipeline = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-schnell", dtype=torch.float16, vae=None, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) init_image = load_image( @@ -74,7 +74,7 @@ pipeline = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-schnell", dtype=torch.bfloat16, vae=None, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ @@ -109,7 +109,7 @@ transformer = HunyuanVideoTransformer3DModel.from_pretrained( "hunyuanvideo-community/HunyuanVideo", subfolder="transformer", dtype=torch.bfloat16 ) pipeline = HunyuanVideoPipeline.from_pretrained( - model_id, transformer=transformer, vae=None, dtype=torch.float16, device_map="cuda" + model_id, transformer=transformer, vae=None, dtype=torch.float16, device_map="cuda" # or "mps", "xpu", "cpu" ) latent = pipeline( @@ -178,7 +178,7 @@ pipeline = StableDiffusionXLPipeline.from_pretrained( "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, vae=None, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.unet = pipeline.unet.to(memory_format=torch.channels_last) diff --git a/docs/source/en/installation.md b/docs/source/en/installation.md index 5a8da1e91853..c4eb0e0f0d76 100644 --- a/docs/source/en/installation.md +++ b/docs/source/en/installation.md @@ -77,6 +77,23 @@ uv pip install git+https://github.com/huggingface/diffusers +## Devices + +Diffusers runs on any accelerator supported by PyTorch. The examples throughout the docs use `"cuda"` because it is the most common setup, but nothing is CUDA-specific. Swap in the device string for your hardware, such as `"xpu"` for Intel GPUs, `"mps"` for Apple silicon, or `"cpu"`. + +```py +device = "cuda" # or "mps", "xpu", "cpu" +pipeline.to(device) +``` + +To pick the device at runtime instead of hardcoding it, use [torch.accelerator](https://docs.pytorch.org/docs/stable/accelerator.html). + +```py +import torch + +device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu" +``` + ## Editable install An editable install is recommended for development workflows or if you're using the `main` version of the source code. A special link is created between the cloned repository and the Python library paths. This avoids reinstalling a package after every change. diff --git a/docs/source/en/modular_diffusers/components_manager.md b/docs/source/en/modular_diffusers/components_manager.md index d4138e552093..418f84bedb2c 100644 --- a/docs/source/en/modular_diffusers/components_manager.md +++ b/docs/source/en/modular_diffusers/components_manager.md @@ -87,7 +87,7 @@ The table shows models (with device, dtype, and memory info) separately from oth The [`~ComponentsManager.enable_auto_cpu_offload`] method is a global offloading strategy that works across all models regardless of which pipeline is using them. Once enabled, you don't need to worry about device placement if you add or remove components. ```py -manager.enable_auto_cpu_offload(device="cuda") +manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu" ``` All models begin on the CPU and [`ComponentsManager`] moves them to the appropriate device right before they're needed, and moves other models back to the CPU when GPU memory is low. diff --git a/docs/source/en/modular_diffusers/custom_blocks.md b/docs/source/en/modular_diffusers/custom_blocks.md index f5e957a08530..fbc05b16d77e 100644 --- a/docs/source/en/modular_diffusers/custom_blocks.md +++ b/docs/source/en/modular_diffusers/custom_blocks.md @@ -239,7 +239,7 @@ Use the block to generate a mask: ```python image_annotator.load_components(dtype=torch.bfloat16) -image_annotator.to("cuda") +image_annotator.to("cuda") # or "mps", "xpu", "cpu" image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg") image = image.resize((1024, 1024)) @@ -269,7 +269,7 @@ inpaint_blocks.sub_blocks.insert("image_annotator", annotator_block, 0) # Initialize the combined pipeline pipe = inpaint_blocks.init_pipeline() -pipe.load_components(dtype=torch.float16, device="cuda") +pipe.load_components(dtype=torch.float16, device="cuda") # or "mps", "xpu", "cpu" # Now the pipeline automatically generates masks from prompts output = pipe( diff --git a/docs/source/en/modular_diffusers/modular_pipeline.md b/docs/source/en/modular_diffusers/modular_pipeline.md index 68177c7e7fb8..5d521349cae4 100644 --- a/docs/source/en/modular_diffusers/modular_pipeline.md +++ b/docs/source/en/modular_diffusers/modular_pipeline.md @@ -31,7 +31,7 @@ from diffusers import ModularPipeline pipeline = ModularPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0") pipeline.load_components(dtype=torch.float16) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" image = pipeline(prompt="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k").images[0] image.save("modular_t2i_out.png") @@ -47,7 +47,7 @@ from diffusers.utils import load_image pipeline = ModularPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0") pipeline.load_components(dtype=torch.float16) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png" init_image = load_image(url) @@ -66,7 +66,7 @@ from diffusers.utils import load_image pipeline = ModularPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0") pipeline.load_components(dtype=torch.float16) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" img_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png" mask_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-inpaint-mask.png" @@ -360,7 +360,7 @@ Since blocks are composable, you can take a pipeline apart and reconstruct it in from diffusers import ModularPipeline, ComponentsManager import torch -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" dtype = torch.bfloat16 repo_id = "black-forest-labs/FLUX.2-klein-4B" diff --git a/docs/source/en/optimization/attention_backends.md b/docs/source/en/optimization/attention_backends.md index 08df0e75a952..7602ddda1134 100644 --- a/docs/source/en/optimization/attention_backends.md +++ b/docs/source/en/optimization/attention_backends.md @@ -42,7 +42,7 @@ import torch from diffusers import QwenImagePipeline pipeline = QwenImagePipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.transformer.set_attention_backend("_flash_3_hub") @@ -68,7 +68,7 @@ import torch from diffusers import QwenImagePipeline pipeline = QwenImagePipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California @@ -115,7 +115,7 @@ The checks are run now before every attention operation. ```py import torch -query = torch.randn(1, 10, 8, 64, dtype=torch.bfloat16, device="cuda") +query = torch.randn(1, 10, 8, 64, dtype=torch.bfloat16, device="cuda") # or "mps", "xpu", "cpu" key = torch.randn(1, 10, 8, 64, dtype=torch.bfloat16, device="cuda") value = torch.randn(1, 10, 8, 64, dtype=torch.bfloat16, device="cuda") diff --git a/docs/source/en/optimization/cache.md b/docs/source/en/optimization/cache.md index 04f23758b88b..079f073b73f0 100644 --- a/docs/source/en/optimization/cache.md +++ b/docs/source/en/optimization/cache.md @@ -31,7 +31,7 @@ import torch from diffusers import CogVideoXPipeline, PyramidAttentionBroadcastConfig pipeline = CogVideoXPipeline.from_pretrained("THUDM/CogVideoX-5b", dtype=torch.bfloat16) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" config = PyramidAttentionBroadcastConfig( spatial_attention_block_skip_range=2, @@ -54,7 +54,7 @@ import torch from diffusers import CogVideoXPipeline, FasterCacheConfig pipe line= CogVideoXPipeline.from_pretrained("THUDM/CogVideoX-5b", dtype=torch.bfloat16) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" config = FasterCacheConfig( spatial_attention_block_skip_range=2, @@ -101,7 +101,7 @@ from diffusers import FluxPipeline, TaylorSeerCacheConfig pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" config = TaylorSeerCacheConfig( cache_interval=5, @@ -130,7 +130,7 @@ from diffusers import FluxPipeline, MagCacheConfig pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-schnell", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # 1. Calibration Step # Run full inference to measure model behavior. diff --git a/docs/source/en/optimization/cache_dit.md b/docs/source/en/optimization/cache_dit.md index 52ae2cb9ad47..9c3edb23fdf7 100644 --- a/docs/source/en/optimization/cache_dit.md +++ b/docs/source/en/optimization/cache_dit.md @@ -178,7 +178,7 @@ from diffusers import FluxPipeline pipe_or_adapter = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # Default options, F8B0, 8 warmup steps, and unlimited cached # steps for good balance between performance and precision diff --git a/docs/source/en/optimization/deepcache.md b/docs/source/en/optimization/deepcache.md index c3b99ae44bed..2514867a504f 100644 --- a/docs/source/en/optimization/deepcache.md +++ b/docs/source/en/optimization/deepcache.md @@ -23,7 +23,7 @@ Then load and enable the [`DeepCacheSDHelper`](https://github.com/horseee/DeepCa ```diff import torch from diffusers import StableDiffusionPipeline - pipe = StableDiffusionPipeline.from_pretrained('stable-diffusion-v1-5/stable-diffusion-v1-5', dtype=torch.float16).to("cuda") + pipe = StableDiffusionPipeline.from_pretrained('stable-diffusion-v1-5/stable-diffusion-v1-5', dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" + from DeepCache import DeepCacheSDHelper + helper = DeepCacheSDHelper(pipe=pipe) diff --git a/docs/source/en/optimization/fp16.md b/docs/source/en/optimization/fp16.md index ecf0ba90ff45..e51cd7437cbf 100644 --- a/docs/source/en/optimization/fp16.md +++ b/docs/source/en/optimization/fp16.md @@ -33,7 +33,7 @@ from diffusers import StableDiffusionXLPipeline pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" pipeline(prompt, num_inference_steps=30).images[0] @@ -50,7 +50,7 @@ from diffusers import StableDiffusionXLPipeline pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" pipeline(prompt, num_inference_steps=30).images[0] @@ -71,7 +71,7 @@ torch.backends.cuda.matmul.allow_tf32 = True pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" pipeline(prompt, num_inference_steps=30).images[0] @@ -98,7 +98,7 @@ from diffusers import StableDiffusionXLPipeline pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" @@ -132,7 +132,7 @@ Changing the memory layout to [channels_last](./memory#torchchannels_last) also ```py pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.unet.to(memory_format=torch.channels_last) pipeline.vae.to(memory_format=torch.channels_last) pipeline.unet = torch.compile( @@ -187,7 +187,7 @@ from diffusers import StableDiffusionXLPipeline pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # compile only the repeated transformer layers inside the UNet pipeline.unet.compile_repeated_blocks(fullgraph=True) @@ -213,7 +213,7 @@ from accelerate.utils import compile_regions pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.unet = compile_regions(pipeline.unet, mode="reduce-overhead", fullgraph=True) ``` @@ -295,7 +295,7 @@ Filter out some linear layers in the UNet and VAE which don't benefit from dynam ```py pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" apply_dynamic_quant(pipeline.unet, dynamic_quant_filter_fn) apply_dynamic_quant(pipeline.vae, dynamic_quant_filter_fn) diff --git a/docs/source/en/optimization/memory.md b/docs/source/en/optimization/memory.md index 950d05b81e69..a68628946015 100644 --- a/docs/source/en/optimization/memory.md +++ b/docs/source/en/optimization/memory.md @@ -55,7 +55,7 @@ pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", unet=unet, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` ### Device placement @@ -182,7 +182,7 @@ from diffusers import AutoModel, StableDiffusionXLPipeline pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.vae.enable_slicing() pipeline(["An astronaut riding a horse on Mars"]*32).images[0] print(f"Max memory reserved: {torch.cuda.max_memory_allocated() / 1024**3:.2f} GB") @@ -204,7 +204,7 @@ from diffusers.utils import load_image pipeline = AutoPipelineForImage2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.vae.enable_tiling() init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-sdxl-init.png") @@ -431,7 +431,7 @@ transformer.enable_layerwise_casting(storage_dtype=torch.float8_e4m3fn, compute_ pipeline = CogVideoXPipeline.from_pretrained("THUDM/CogVideoX-5b", transformer=transformer, dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = ( "A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. " "The panda's fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other " diff --git a/docs/source/en/optimization/para_attn.md b/docs/source/en/optimization/para_attn.md index d7f257008173..3222787f08a1 100644 --- a/docs/source/en/optimization/para_attn.md +++ b/docs/source/en/optimization/para_attn.md @@ -46,7 +46,7 @@ from diffusers import FluxPipeline pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" from para_attn.first_block_cache.diffusers_adapters import apply_cache_on_pipe @@ -98,7 +98,7 @@ pipe = HunyuanVideoPipeline.from_pretrained( transformer=transformer, dtype=torch.float16, revision="refs/pr/18", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" from para_attn.first_block_cache.diffusers_adapters import apply_cache_on_pipe @@ -172,7 +172,7 @@ from diffusers import FluxPipeline pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" from para_attn.first_block_cache.diffusers_adapters import apply_cache_on_pipe @@ -232,7 +232,7 @@ pipe = HunyuanVideoPipeline.from_pretrained( transformer=transformer, dtype=torch.float16, revision="refs/pr/18", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" from para_attn.first_block_cache.diffusers_adapters import apply_cache_on_pipe @@ -304,7 +304,7 @@ torch.cuda.set_device(dist.get_rank()) pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" from para_attn.context_parallel import init_context_parallel_mesh from para_attn.context_parallel.diffusers_adapters import parallelize_pipe @@ -398,7 +398,7 @@ pipe = HunyuanVideoPipeline.from_pretrained( transformer=transformer, dtype=torch.float16, revision="refs/pr/18", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" from para_attn.context_parallel import init_context_parallel_mesh from para_attn.context_parallel.diffusers_adapters import parallelize_pipe diff --git a/docs/source/en/optimization/pruna.md b/docs/source/en/optimization/pruna.md index 694abee03e42..dfb42cb441e1 100644 --- a/docs/source/en/optimization/pruna.md +++ b/docs/source/en/optimization/pruna.md @@ -59,7 +59,7 @@ from pruna import PrunaModel, SmashConfig, smash pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # define the configuration smash_config = SmashConfig() diff --git a/docs/source/en/optimization/speed-memory-optims.md b/docs/source/en/optimization/speed-memory-optims.md index 63b552a81faa..21dd5b6ea1db 100644 --- a/docs/source/en/optimization/speed-memory-optims.md +++ b/docs/source/en/optimization/speed-memory-optims.md @@ -62,7 +62,7 @@ pipeline = DiffusionPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # compile pipeline.transformer.to(memory_format=torch.channels_last) @@ -103,7 +103,7 @@ pipeline = DiffusionPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # model CPU offloading pipeline.enable_model_cpu_offload() @@ -148,7 +148,7 @@ pipeline = DiffusionPipeline.from_pretrained( "Wan-AI/Wan2.1-T2V-14B-Diffusers", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # group offloading onload_device = torch.device("cuda") diff --git a/docs/source/en/optimization/tgate.md b/docs/source/en/optimization/tgate.md index 9962e956cd56..57e18090c03d 100644 --- a/docs/source/en/optimization/tgate.md +++ b/docs/source/en/optimization/tgate.md @@ -42,7 +42,7 @@ pipe = TgatePixArtLoader( pipe, gate_step=gate_step, num_inference_steps=inference_step, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe.tgate( "An alpaca made of colorful building blocks, cyberpunk.", @@ -75,7 +75,7 @@ pipe = TgateSDXLLoader( pipe, gate_step=gate_step, num_inference_steps=inference_step, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe.tgate( "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k.", @@ -108,7 +108,7 @@ pipe = TgateSDXLDeepCacheLoader( pipe, cache_interval=3, cache_branch_id=0, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe.tgate( "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k.", @@ -148,7 +148,7 @@ pipe = TgateSDXLLoader( gate_step=gate_step, num_inference_steps=inference_step, lcm=True -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe.tgate( "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k.", diff --git a/docs/source/en/optimization/tome.md b/docs/source/en/optimization/tome.md index 74dbf7e6c961..833bd69058a9 100644 --- a/docs/source/en/optimization/tome.md +++ b/docs/source/en/optimization/tome.md @@ -29,7 +29,7 @@ You can use ToMe from the [`tomesd`](https://github.com/dbolya/tomesd) library w pipeline = StableDiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, use_safetensors=True, - ).to("cuda") + ).to("cuda") # or "mps", "xpu", "cpu" + tomesd.apply_patch(pipeline, ratio=0.5) image = pipeline("a photo of an astronaut riding a horse on mars").images[0] diff --git a/docs/source/en/optimization/xdit.md b/docs/source/en/optimization/xdit.md index 1c66b34da69c..d0f14749c0d1 100644 --- a/docs/source/en/optimization/xdit.md +++ b/docs/source/en/optimization/xdit.md @@ -50,7 +50,7 @@ Here's an example of using xDiT to accelerate inference of a Diffusers model. prompt=input_config.prompt, num_inference_steps=input_config.num_inference_steps, output_type=input_config.output_type, - generator=torch.Generator(device="cuda").manual_seed(input_config.seed), + generator=torch.Generator(device="cuda").manual_seed(input_config.seed), # or "mps", "xpu", "cpu" ) + if input_config.output_type == "pil": diff --git a/docs/source/en/quantization/autoround.md b/docs/source/en/quantization/autoround.md index 6dc4c514141c..91021970df2d 100644 --- a/docs/source/en/quantization/autoround.md +++ b/docs/source/en/quantization/autoround.md @@ -43,7 +43,7 @@ pipe = DiffusionPipeline.from_pretrained( "INCModel/Z-Image-W4A16-AutoRound", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" ) image = pipe("a cat holding a sign that says hello").images[0] @@ -64,7 +64,7 @@ transformer = ZImageTransformer2DModel.from_pretrained( subfolder="transformer", quantization_config=quantization_config, dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" ) pipe = ZImagePipeline.from_pretrained( @@ -96,7 +96,7 @@ pipe = DiffusionPipeline.from_pretrained( "INCModel/Z-Image-W4A16-AutoRound", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" ) pipe.transformer = torch.compile(pipe.transformer, mode="default", fullgraph=False) @@ -172,7 +172,7 @@ model_id = "INCModel/Z-Image-W4A16-AutoRound" pipe = ZImagePipeline.from_pretrained( model_id, dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" ) image = pipe("a cat holding a sign that says hello").images[0] diff --git a/docs/source/en/quantization/modelopt.md b/docs/source/en/quantization/modelopt.md index d6eae0bef4c7..af8458d5f779 100644 --- a/docs/source/en/quantization/modelopt.md +++ b/docs/source/en/quantization/modelopt.md @@ -42,7 +42,7 @@ pipe = SanaPipeline.from_pretrained( transformer=transformer, dtype=dtype, ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" print(f"Pipeline memory usage: {torch.cuda.max_memory_reserved() / 1024**3:.3f} GB") @@ -132,7 +132,7 @@ pipe = SanaPipeline.from_pretrained( transformer=transformer, dtype=torch.bfloat16, ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A cat holding a sign that says hello world" image = pipe( prompt, num_inference_steps=50, guidance_scale=4.5, max_sequence_length=512 diff --git a/docs/source/en/quantization/nunchaku.md b/docs/source/en/quantization/nunchaku.md index 825eecdae810..d6a07591b6fe 100644 --- a/docs/source/en/quantization/nunchaku.md +++ b/docs/source/en/quantization/nunchaku.md @@ -42,7 +42,7 @@ model_id = "rootonchair/ERNIE-Image-Turbo-nunchaku-lite-nvfp4" pipe = DiffusionPipeline.from_pretrained( model_id, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "A modern red armchair in a quiet studio, soft window light, realistic product photography" image = pipe( diff --git a/docs/source/en/quantization/overview.md b/docs/source/en/quantization/overview.md index ccde85d725d9..9ff0de9a4785 100644 --- a/docs/source/en/quantization/overview.md +++ b/docs/source/en/quantization/overview.md @@ -59,7 +59,7 @@ pipe = DiffusionPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe("photo of a cute dog").images[0] ``` @@ -120,7 +120,7 @@ pipe = DiffusionPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe("photo of a cute dog").images[0] ``` @@ -136,7 +136,7 @@ from diffusers import DiffusionPipeline pipe = DiffusionPipeline.from_pretrained( "rootonchair/ERNIE-Image-Turbo-nunchaku-lite-nvfp4", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` The following backends support loading prequantized checkpoints out of the box. diff --git a/docs/source/en/quantization/quanto.md b/docs/source/en/quantization/quanto.md index d41b238961d4..1dd4c05e1cbe 100644 --- a/docs/source/en/quantization/quanto.md +++ b/docs/source/en/quantization/quanto.md @@ -42,7 +42,7 @@ transformer = FluxTransformer2DModel.from_pretrained( ) pipe = FluxPipeline.from_pretrained(model_id, transformer=transformer, dtype=dtype) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A cat holding a sign that says hello world" image = pipe( @@ -131,7 +131,7 @@ transformer = torch.compile(transformer, mode="max-autotune", fullgraph=True) pipe = FluxPipeline.from_pretrained( model_id, transformer=transformer, dtype=dtype ) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" images = pipe("A cat holding a sign that says hello").images[0] images.save("flux-quanto-compile.png") ``` diff --git a/docs/source/en/quantization/sdnq.md b/docs/source/en/quantization/sdnq.md index 40fb23eba773..f4b337ac93b3 100644 --- a/docs/source/en/quantization/sdnq.md +++ b/docs/source/en/quantization/sdnq.md @@ -30,7 +30,7 @@ from diffusers import DiffusionPipeline pipe = DiffusionPipeline.from_pretrained( "Disty0/Z-Image-Turbo-SDNQ-uint4-svd-r32", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipe("a cat holding a sign that says hello").images[0] image.save("output.png") @@ -54,7 +54,7 @@ pipe = DiffusionPipeline.from_pretrained( "Tongyi-MAI/Z-Image-Turbo", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Or quantize a single model component directly. @@ -92,7 +92,7 @@ from sdnq.loader import apply_sdnq_options_to_model pipe = DiffusionPipeline.from_pretrained( "Disty0/Z-Image-Turbo-SDNQ-uint4-svd-r32", dtype=torch.bfloat16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()): pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True) diff --git a/docs/source/en/quantization/torchao.md b/docs/source/en/quantization/torchao.md index d642d839c0a6..2baf7e64d8fe 100644 --- a/docs/source/en/quantization/torchao.md +++ b/docs/source/en/quantization/torchao.md @@ -35,7 +35,7 @@ pipeline = DiffusionPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -47,7 +47,7 @@ pipeline = DiffusionPipeline.from_pretrained( quantization_config=pipeline_quant_config, torch_dtype=torch.bfloat16, ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" ``` Without `device_map`, Diffusers quantizes the layers on the CPU. This is slower, but avoids the temporary GPU-memory spike during quantization. To reduce GPU memory usage further, use [`~DiffusionPipeline.enable_model_cpu_offload`] instead. You can also quantize additional components, such as the text encoder. @@ -68,7 +68,7 @@ pipeline = DiffusionPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", quantization_config=pipeline_quant_config, dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.transformer.compile(transformer, mode="max-autotune", fullgraph=True) @@ -124,7 +124,7 @@ from diffusers import FluxPipeline, AutoModel transformer = AutoModel.from_pretrained("/path/to/flux_int8wo", dtype=torch.bfloat16, use_safetensors=False) pipe = FluxPipeline.from_pretrained("black-forest-labs/Flux.1-Dev", transformer=transformer, dtype=torch.bfloat16) -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "A cat holding a sign that says hello world" image = pipe(prompt, num_inference_steps=30, guidance_scale=7.0).images[0] diff --git a/docs/source/en/quicktour.md b/docs/source/en/quicktour.md index 341608852300..92f1d95001ed 100644 --- a/docs/source/en/quicktour.md +++ b/docs/source/en/quicktour.md @@ -53,7 +53,7 @@ import torch from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ @@ -83,7 +83,7 @@ pipeline = DiffusionPipeline.from_pretrained( "Wan-AI/Wan2.2-T2V-A14B-Diffusers", vae=vae dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ @@ -110,7 +110,7 @@ import torch from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.load_lora_weights( "flymy-ai/qwen-image-realism-lora", @@ -147,7 +147,7 @@ pipeline = DiffusionPipeline.from_pretrained( "Qwen/Qwen-Image", dtype=torch.bfloat16, quantization_config=quant_config, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ @@ -189,7 +189,7 @@ pipeline = DiffusionPipeline.from_pretrained( "Qwen/Qwen-Image", dtype=torch.bfloat16, quantization_config=quant_config, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.enable_model_cpu_offload() @@ -216,7 +216,7 @@ import torch from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.transformer.compile_repeated_blocks( diff --git a/docs/source/en/stable_diffusion.md b/docs/source/en/stable_diffusion.md index 876526105fc7..fd368f5b1654 100644 --- a/docs/source/en/stable_diffusion.md +++ b/docs/source/en/stable_diffusion.md @@ -31,7 +31,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.enable_model_cpu_offload() @@ -93,7 +93,7 @@ Many modern diffusion models deliver high-quality images out-of-the-box. However pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ @@ -115,7 +115,7 @@ Many modern diffusion models deliver high-quality images out-of-the-box. However pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler = HeunDiscreteScheduler.from_config(pipeline.scheduler.config) diff --git a/docs/source/en/training/cogvideox.md b/docs/source/en/training/cogvideox.md index 7de41be0aa95..2a67b83ebd90 100644 --- a/docs/source/en/training/cogvideox.md +++ b/docs/source/en/training/cogvideox.md @@ -235,7 +235,7 @@ from diffusers.utils import export_to_video pipe = CogVideoXPipeline.from_pretrained("THUDM/CogVideoX-2b", dtype=torch.float16) # pipe.load_lora_weights("/path/to/lora/weights", adapter_name="cogvideox-lora") # Or, pipe.load_lora_weights("my-awesome-hf-username/my-awesome-lora-name", adapter_name="cogvideox-lora") # If loading from the HF Hub -pipe.to("cuda") +pipe.to("cuda") # or "mps", "xpu", "cpu" # Assuming lora_alpha=32 and rank=64 for training. If different, set accordingly pipe.set_adapters(["cogvideox-lora"], [32 / 64]) diff --git a/docs/source/en/training/controlnet.md b/docs/source/en/training/controlnet.md index eeb1ecdd0d46..f52ba33f242f 100644 --- a/docs/source/en/training/controlnet.md +++ b/docs/source/en/training/controlnet.md @@ -255,7 +255,7 @@ import torch controlnet = ControlNetModel.from_pretrained("path/to/controlnet", dtype=torch.float16) pipeline = StableDiffusionControlNetPipeline.from_pretrained( "path/to/base/model", controlnet=controlnet, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" control_image = load_image("./conditioning_image_1.png") prompt = "pale golden rod circle with old lace background" diff --git a/docs/source/en/training/custom_diffusion.md b/docs/source/en/training/custom_diffusion.md index 0e7a439c461a..4c802cb08b02 100644 --- a/docs/source/en/training/custom_diffusion.md +++ b/docs/source/en/training/custom_diffusion.md @@ -306,7 +306,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "CompVis/stable-diffusion-v1-4", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.unet.load_attn_procs("path-to-save-model", weight_name="pytorch_custom_diffusion_weights.bin") pipeline.load_textual_inversion("path-to-save-model", weight_name=".bin") @@ -329,7 +329,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "CompVis/stable-diffusion-v1-4", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" model_id = "sayakpaul/custom-diffusion-cat-wooden-pot" pipeline.unet.load_attn_procs(model_id, weight_name="pytorch_custom_diffusion_weights.bin") pipeline.load_textual_inversion(model_id, weight_name=".bin") diff --git a/docs/source/en/training/distributed_inference.md b/docs/source/en/training/distributed_inference.md index 856572c2ff08..a731844412fe 100644 --- a/docs/source/en/training/distributed_inference.md +++ b/docs/source/en/training/distributed_inference.md @@ -215,7 +215,7 @@ import torch from diffusers import AutoencoderKL from diffusers.image_processor import VaeImageProcessor -vae = AutoencoderKL.from_pretrained(ckpt_id, subfolder="vae", dtype=torch.bfloat16).to("cuda") +vae = AutoencoderKL.from_pretrained(ckpt_id, subfolder="vae", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1) image_processor = VaeImageProcessor(vae_scale_factor=vae_scale_factor) diff --git a/docs/source/en/training/dreambooth.md b/docs/source/en/training/dreambooth.md index ddcc92c2059d..a28cf17ac837 100644 --- a/docs/source/en/training/dreambooth.md +++ b/docs/source/en/training/dreambooth.md @@ -335,7 +335,7 @@ Once training is complete, you can use your newly trained model for inference! from diffusers import DiffusionPipeline import torch -pipeline = DiffusionPipeline.from_pretrained("path_to_saved_model", dtype=torch.float16, use_safetensors=True).to("cuda") +pipeline = DiffusionPipeline.from_pretrained("path_to_saved_model", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" image = pipeline("A photo of sks dog in a bucket", num_inference_steps=50, guidance_scale=7.5).images[0] image.save("dog-bucket.png") ``` diff --git a/docs/source/en/training/instructpix2pix.md b/docs/source/en/training/instructpix2pix.md index 28e72ad3c3c8..550c53bf8ced 100644 --- a/docs/source/en/training/instructpix2pix.md +++ b/docs/source/en/training/instructpix2pix.md @@ -208,7 +208,7 @@ import torch from diffusers import StableDiffusionInstructPix2PixPipeline from diffusers.utils import load_image -pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained("your_cool_model", dtype=torch.float16).to("cuda") +pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained("your_cool_model", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator("cuda").manual_seed(0) image = load_image("https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/test_pix2pix_4.png") diff --git a/docs/source/en/training/lcm_distill.md b/docs/source/en/training/lcm_distill.md index 414551d1f2ef..cfe7d7e2fdce 100644 --- a/docs/source/en/training/lcm_distill.md +++ b/docs/source/en/training/lcm_distill.md @@ -222,7 +222,7 @@ unet = UNet2DConditionModel.from_pretrained("your-username/your-model", dtype=to pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", unet=unet, dtype=torch.float16, variant="fp16") pipeline.scheduler = LCMScheduler.from_config(pipe.scheduler.config) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" prompt = "sushi rolls in the form of panda heads, sushi platter" diff --git a/docs/source/en/training/lora.md b/docs/source/en/training/lora.md index 9503d94464f4..d2049ab56b0c 100644 --- a/docs/source/en/training/lora.md +++ b/docs/source/en/training/lora.md @@ -189,7 +189,7 @@ Once training has been completed, you can use your model for inference: from diffusers import AutoPipelineForText2Image import torch -pipeline = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to("cuda") +pipeline = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights("path/to/lora/model", weight_name="pytorch_lora_weights.safetensors") image = pipeline("A naruto with blue eyes").images[0] ``` diff --git a/docs/source/en/training/sdxl.md b/docs/source/en/training/sdxl.md index 5da04e06fda7..cdbea957e2b2 100644 --- a/docs/source/en/training/sdxl.md +++ b/docs/source/en/training/sdxl.md @@ -212,7 +212,7 @@ After you've finished training, you can use your newly trained SDXL model for in from diffusers import DiffusionPipeline import torch -pipeline = DiffusionPipeline.from_pretrained("path/to/your/model", dtype=torch.float16).to("cuda") +pipeline = DiffusionPipeline.from_pretrained("path/to/your/model", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" prompt = "A naruto with green eyes and red legs." image = pipeline(prompt, num_inference_steps=30, guidance_scale=7.5).images[0] diff --git a/docs/source/en/training/text2image.md b/docs/source/en/training/text2image.md index 688747ee714e..33df598ea16b 100644 --- a/docs/source/en/training/text2image.md +++ b/docs/source/en/training/text2image.md @@ -168,7 +168,7 @@ Once training is complete, you can use your newly trained model for inference: from diffusers import StableDiffusionPipeline import torch -pipeline = StableDiffusionPipeline.from_pretrained("path/to/saved_model", dtype=torch.float16, use_safetensors=True).to("cuda") +pipeline = StableDiffusionPipeline.from_pretrained("path/to/saved_model", dtype=torch.float16, use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" image = pipeline(prompt="yoda").images[0] image.save("yoda-naruto.png") diff --git a/docs/source/en/training/text_inversion.md b/docs/source/en/training/text_inversion.md index d06f0d35faf2..913230d4463e 100644 --- a/docs/source/en/training/text_inversion.md +++ b/docs/source/en/training/text_inversion.md @@ -193,7 +193,7 @@ After training is complete, you can use your newly trained model for inference l from diffusers import StableDiffusionPipeline import torch -pipeline = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to("cuda") +pipeline = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_textual_inversion("sd-concepts-library/cat-toy") image = pipeline("A train", num_inference_steps=50).images[0] image.save("cat-train.png") diff --git a/docs/source/en/training/unconditional_training.md b/docs/source/en/training/unconditional_training.md index ab3bdd6416f3..2427b2e5da40 100644 --- a/docs/source/en/training/unconditional_training.md +++ b/docs/source/en/training/unconditional_training.md @@ -193,6 +193,6 @@ The training script creates and saves a checkpoint file in your repository. Now from diffusers import DiffusionPipeline import torch -pipeline = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128").to("cuda") +pipeline = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128").to("cuda") # or "mps", "xpu", "cpu" image = pipeline().images[0] ``` diff --git a/docs/source/en/tutorials/autopipeline.md b/docs/source/en/tutorials/autopipeline.md index 22d9e0ffe011..d3f829aa6ae4 100644 --- a/docs/source/en/tutorials/autopipeline.md +++ b/docs/source/en/tutorials/autopipeline.md @@ -23,7 +23,7 @@ import torch from diffusers import AutoPipelineForImage2Image pipeline = AutoPipelineForImage2Image.from_pretrained( - "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda", + "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda", # or "mps", "xpu", "cpu" ) print(pipeline) "StableDiffusionXLImg2ImgPipeline { @@ -39,7 +39,7 @@ import torch from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( - "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda", + "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda", # or "mps", "xpu", "cpu" ) print(pipeline) "StableDiffusionXLPipeline { diff --git a/docs/source/en/tutorials/using_peft_for_inference.md b/docs/source/en/tutorials/using_peft_for_inference.md index 39df8fc06872..0139fb1779dd 100644 --- a/docs/source/en/tutorials/using_peft_for_inference.md +++ b/docs/source/en/tutorials/using_peft_for_inference.md @@ -26,7 +26,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/super-cereal-sdxl-lora", weight_name="cereal_box_sdxl_v1.safetensors", @@ -90,7 +90,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.unet.load_lora_adapter( "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", @@ -113,7 +113,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", @@ -155,7 +155,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/super-cereal-sdxl-lora", weight_name="cereal_box_sdxl_v1.safetensors", @@ -179,7 +179,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/super-cereal-sdxl-lora", weight_name="cereal_box_sdxl_v1.safetensors", @@ -215,7 +215,7 @@ from diffusers import FluxPipeline pipeline = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipelne.load_lora_weights("alvarobartt/ghibli-characters-flux-lora", "lora") @@ -255,7 +255,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", @@ -293,7 +293,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # 1. enable_lora_hotswap pipeline.enable_lora_hotswap(target_rank=max_rank) pipeline.load_lora_weights( @@ -350,7 +350,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", @@ -397,7 +397,7 @@ unet = AutoModel.from_pretrained( use_safetensors=True, variant="fp16", subfolder="unet", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Load a pipeline, pass the UNet to it, and load a LoRA. @@ -408,7 +408,7 @@ pipeline = DiffusionPipeline.from_pretrained( variant="fp16", dtype=torch.float16, unet=unet -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", @@ -468,7 +468,7 @@ base_unet = AutoModel.from_pretrained( use_safetensors=True, variant="fp16", subfolder="unet", -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" model = PeftModel.from_pretrained( base_unet, @@ -503,7 +503,7 @@ pipeline = DiffusionPipeline.from_pretrained( unet=model, variant="fp16", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline("A bowl of ramen shaped like a cute kawaii bear, by Feng Zikai").images[0] ``` @@ -522,7 +522,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", @@ -568,7 +568,7 @@ The fused pipeline can now be quickly loaded for inference without requiring eac ```py pipeline = DiffusionPipeline.from_pretrained( "username/fused-ikea-feng", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline("A bowl of ramen shaped like a cute kawaii bear, by Feng Zikai").images[0] ``` @@ -597,7 +597,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights( "ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", @@ -623,7 +623,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.unet.load_lora_adapter( "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", diff --git a/docs/source/en/using-diffusers/automodel.md b/docs/source/en/using-diffusers/automodel.md index ddae567d4153..38d30539973e 100644 --- a/docs/source/en/using-diffusers/automodel.md +++ b/docs/source/en/using-diffusers/automodel.md @@ -21,7 +21,7 @@ import torch from diffusers import AutoModel, DiffusionPipeline transformer = AutoModel.from_pretrained( - "Qwen/Qwen-Image", subfolder="transformer", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", subfolder="transformer", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) text_encoder = AutoModel.from_pretrained( @@ -59,7 +59,7 @@ import torch from diffusers import AutoModel transformer = AutoModel.from_pretrained( - "custom/custom-transformer-model", trust_remote_code=True, dtype=torch.bfloat16, device_map="cuda" + "custom/custom-transformer-model", trust_remote_code=True, dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -82,7 +82,7 @@ import torch from diffusers import AutoModel transformer = AutoModel.from_pretrained( - "Overworld/Waypoint-1-Small", subfolder="transformer", trust_remote_code=True, dtype=torch.bfloat16, device_map="cuda" + "Overworld/Waypoint-1-Small", subfolder="transformer", trust_remote_code=True, dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) ``` diff --git a/docs/source/en/using-diffusers/batched_inference.md b/docs/source/en/using-diffusers/batched_inference.md index a6be304a421e..27646be0f9e6 100644 --- a/docs/source/en/using-diffusers/batched_inference.md +++ b/docs/source/en/using-diffusers/batched_inference.md @@ -26,7 +26,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) prompts = [ @@ -66,7 +66,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) prompt=""" @@ -130,7 +130,7 @@ Enable reproducible batch generation by passing a list of [Generator’s](https: Use a list comprehension to iterate over the batch size specified in `range()` to create a unique `Generator` object for each image in the batch. Don't multiply the `Generator` by the batch size because that only creates one `Generator` object that is used sequentially for each image in the batch. ```py -generator = [torch.Generator(device="cuda").manual_seed(0)] * 3 +generator = [torch.Generator(device="cuda").manual_seed(0)] * 3 # or "mps", "xpu", "cpu" ``` Pass the `generator` to the pipeline. @@ -145,7 +145,7 @@ pipeline = DiffusionPipeline.from_pretrained( device_map="cuda" ) -generator = [torch.Generator(device="cuda").manual_seed(i) for i in range(3)] +generator = [torch.Generator(device="cuda").manual_seed(i) for i in range(3)] # or "mps", "xpu", "cpu" prompts = [ "Cinematic shot of a cozy coffee shop interior, warm pastel light streaming through a window where a cat rests. Shallow depth of field, glowing cups in soft focus, dreamy lofi-inspired mood, nostalgic tones, framed like a quiet film scene.", "Polaroid-style photograph of a cozy coffee shop interior, bathed in warm pastel light. A cat sits on the windowsill near steaming mugs. Soft, slightly faded tones and dreamy blur evoke nostalgia, a lofi mood, and the intimate, imperfect charm of instant film.", diff --git a/docs/source/en/using-diffusers/callback.md b/docs/source/en/using-diffusers/callback.md index 3847b376cc49..37cd8bb55de2 100644 --- a/docs/source/en/using-diffusers/callback.md +++ b/docs/source/en/using-diffusers/callback.md @@ -37,7 +37,7 @@ callback = SDXLCFGCutoffCallback(cutoff_step_ratio=0.4) pipeline = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config, use_karras_sigmas=True) @@ -124,7 +124,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) image = pipeline( diff --git a/docs/source/en/using-diffusers/conditional_image_generation.md b/docs/source/en/using-diffusers/conditional_image_generation.md index cdc1f3d7132d..fe1602567db9 100644 --- a/docs/source/en/using-diffusers/conditional_image_generation.md +++ b/docs/source/en/using-diffusers/conditional_image_generation.md @@ -31,7 +31,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` 2. Pass a prompt to the pipeline to generate an image: @@ -61,7 +61,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator("cuda").manual_seed(31) image = pipeline("Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", generator=generator).images[0] image @@ -77,7 +77,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator("cuda").manual_seed(31) image = pipeline("Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", generator=generator).images[0] image @@ -95,7 +95,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "kandinsky-community/kandinsky-2-2-decoder", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator("cuda").manual_seed(31) image = pipeline("Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", generator=generator).images[0] image @@ -114,7 +114,7 @@ import torch controlnet = ControlNetModel.from_pretrained( "lllyasviel/control_v11p_sd15_openpose", dtype=torch.float16, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pose_image = load_image("https://huggingface.co/lllyasviel/control_v11p_sd15_openpose/resolve/main/images/control.png") ``` @@ -123,7 +123,7 @@ Pass the `controlnet` to the [`AutoPipelineForText2Image`], and provide the prom ```py pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", controlnet=controlnet, dtype=torch.float16, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator("cuda").manual_seed(31) image = pipeline("Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", image=pose_image, generator=generator).images[0] image @@ -162,7 +162,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, variant="fp16" -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipeline( "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", height=768, width=512 ).images[0] @@ -186,7 +186,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipeline( "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", guidance_scale=3.5 ).images[0] @@ -218,7 +218,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipeline( prompt="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", negative_prompt="ugly, deformed, disfigured, poor details, bad anatomy", @@ -249,7 +249,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" generator = torch.Generator(device="cuda").manual_seed(30) image = pipeline( "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", @@ -277,7 +277,7 @@ import torch pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image = pipeline( prompt_embeds=prompt_embeds, # generated from Compel negative_prompt_embeds=negative_prompt_embeds, # generated from Compel @@ -300,7 +300,7 @@ PyTorch 2.0 also supports a more memory-efficient attention mechanism called [*s from diffusers import AutoPipelineForText2Image import torch -pipeline = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, variant="fp16").to("cuda") +pipeline = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, variant="fp16").to("cuda") # or "mps", "xpu", "cpu" pipeline.unet = torch.compile(pipeline.unet, mode="reduce-overhead", fullgraph=True) ``` diff --git a/docs/source/en/using-diffusers/controlnet.md b/docs/source/en/using-diffusers/controlnet.md index 4bf068def57e..5163bc4fb088 100644 --- a/docs/source/en/using-diffusers/controlnet.md +++ b/docs/source/en/using-diffusers/controlnet.md @@ -59,7 +59,7 @@ controlnet = FluxControlNetModel.from_pretrained( ) pipeline = FluxControlNetPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", controlnet=controlnet, dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = """ A photorealistic overhead image of a cat reclining sideways in a flamingo pool floatie holding a margarita. @@ -105,7 +105,7 @@ from diffusers import ControlNetModel, StableDiffusionXLControlNetImg2ImgPipelin from diffusers.utils import load_image -depth_estimator = DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas").to("cuda") +depth_estimator = DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas").to("cuda") # or "mps", "xpu", "cpu" feature_extractor = DPTImageProcessor.from_pretrained("Intel/dpt-hybrid-midas") def get_depth_map(image): @@ -143,7 +143,7 @@ pipeline = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained( controlnet=controlnet, vae=vae, dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = """ A photorealistic overhead image of a cat reclining sideways in a flamingo pool floatie holding a margarita. @@ -273,7 +273,7 @@ controlnets = [ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16) pipeline = StableDiffusionXLControlNetPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnets, vae=vae, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = """ a relaxed rabbit sitting on a striped towel next to a pool with a tropical drink nearby, @@ -324,7 +324,7 @@ pipeline = StableDiffusionXLControlNetPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" canny_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/canny-cat.png") pipeline( diff --git a/docs/source/en/using-diffusers/create_a_server.md b/docs/source/en/using-diffusers/create_a_server.md index 8ad0ed3cbe6a..8be1102f14b1 100644 --- a/docs/source/en/using-diffusers/create_a_server.md +++ b/docs/source/en/using-diffusers/create_a_server.md @@ -39,7 +39,7 @@ async def generate_image(image_input: TextToImageInput): loop = asyncio.get_event_loop() scheduler = shared_pipeline.pipeline.scheduler.from_config(shared_pipeline.pipeline.scheduler.config) pipeline = StableDiffusion3Pipeline.from_pipe(shared_pipeline.pipeline, scheduler=scheduler) - generator = torch.Generator(device="cuda") + generator = torch.Generator(device="cuda") # or "mps", "xpu", "cpu" generator.manual_seed(random.randint(0, 10000000)) output = await loop.run_in_executor(None, lambda: pipeline(image_input.prompt, generator = generator)) logger.info(f"output: {output}") diff --git a/docs/source/en/using-diffusers/custom_pipeline_overview.md b/docs/source/en/using-diffusers/custom_pipeline_overview.md index 0d960e69747c..0bc002c83dc6 100644 --- a/docs/source/en/using-diffusers/custom_pipeline_overview.md +++ b/docs/source/en/using-diffusers/custom_pipeline_overview.md @@ -39,7 +39,7 @@ pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-3-medium-diffusers", custom_pipeline="pipeline_stable_diffusion_3_instruct_pix2pix", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -54,7 +54,7 @@ pipeline = DiffusionPipeline.from_pretrained( custom_pipeline="pipeline_stable_diffusion_3_instruct_pix2pix", custom_revision="main" dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -73,7 +73,7 @@ There are a few ways to load a community pipeline. "stabilityai/stable-diffusion-3-medium-diffusers", custom_pipeline="path/to/pipeline_directory", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -83,7 +83,7 @@ There are a few ways to load a community pipeline. import torch from diffusers import DiffusionPipeline - pipeline_sd = DiffusionPipeline.from_pretrained("emilianJR/CyberRealistic_V3", dtype=torch.float16, device_map="cuda") + pipeline_sd = DiffusionPipeline.from_pretrained("emilianJR/CyberRealistic_V3", dtype=torch.float16, device_map="cuda") # or "mps", "xpu", "cpu" pipeline_lpw = DiffusionPipeline.from_pipe( pipeline_sd, custom_pipeline="lpw_stable_diffusion", device_map="cuda" ) @@ -135,7 +135,7 @@ pipeline = TextToVideoIFPipeline( tokenizer=tokenizer, scheduler=scheduler, feature_extractor=feature_extractor, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" dtype=torch.float16 ) ``` diff --git a/docs/source/en/using-diffusers/depth2img.md b/docs/source/en/using-diffusers/depth2img.md index ae7bbf162ac9..64fbed399d9d 100644 --- a/docs/source/en/using-diffusers/depth2img.md +++ b/docs/source/en/using-diffusers/depth2img.md @@ -27,7 +27,7 @@ pipeline = StableDiffusionDepth2ImgPipeline.from_pretrained( "stabilityai/stable-diffusion-2-depth", dtype=torch.float16, use_safetensors=True, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Now pass your prompt to the pipeline. You can also pass a `negative_prompt` to prevent certain words from guiding how an image is generated: diff --git a/docs/source/en/using-diffusers/dreambooth.md b/docs/source/en/using-diffusers/dreambooth.md index 14c4550d9c76..13940b8d1e98 100644 --- a/docs/source/en/using-diffusers/dreambooth.md +++ b/docs/source/en/using-diffusers/dreambooth.md @@ -25,7 +25,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "sd-dreambooth-library/herge-style", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = "A cute sks herge_style brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration" pipeline(prompt).images[0] ``` diff --git a/docs/source/en/using-diffusers/image_quality.md b/docs/source/en/using-diffusers/image_quality.md index 65b51d858f4d..8cbf11ea5388 100644 --- a/docs/source/en/using-diffusers/image_quality.md +++ b/docs/source/en/using-diffusers/image_quality.md @@ -25,7 +25,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, safety_checker=None -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.enable_freeu(s1=0.9, s2=0.2, b1=1.5, b2=1.6) generator = torch.Generator(device="cpu").manual_seed(33) prompt = "" @@ -53,7 +53,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-2-1", dtype=torch.float16, safety_checker=None -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.enable_freeu(s1=0.9, s2=0.2, b1=1.4, b2=1.6) generator = torch.Generator(device="cpu").manual_seed(80) prompt = "A squirrel eating a burger" @@ -81,7 +81,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.enable_freeu(s1=0.9, s2=0.2, b1=1.3, b2=1.4) generator = torch.Generator(device="cpu").manual_seed(13) prompt = "A squirrel eating a burger" @@ -110,7 +110,7 @@ from diffusers.utils import export_to_video pipeline = DiffusionPipeline.from_pretrained( "damo-vilab/text-to-video-ms-1.7b", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # values come from https://github.com/lyn-rgb/FreeU_Diffusers#video-pipelines pipeline.enable_freeu(b1=1.2, b2=1.4, s1=0.9, s2=0.2) prompt = "Confident teddy bear surfer rides the wave in the tropics" diff --git a/docs/source/en/using-diffusers/inpaint.md b/docs/source/en/using-diffusers/inpaint.md index 02b257e09cd6..b0fb51bcdb89 100644 --- a/docs/source/en/using-diffusers/inpaint.md +++ b/docs/source/en/using-diffusers/inpaint.md @@ -92,7 +92,7 @@ from diffusers import AutoPipelineForInpainting from diffusers.utils import load_image from PIL import Image -pipeline = AutoPipelineForInpainting.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to('cuda') +pipeline = AutoPipelineForInpainting.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to('cuda') # or "mps", "xpu", "cpu" mask = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/seashore_mask.png") blurred_mask = pipeline.mask_processor.blur(mask, blur_factor=33) @@ -356,7 +356,7 @@ import torch from diffusers import AutoPipelineForInpainting from diffusers.utils import load_image, make_image_grid -device = "cuda" +device = "cuda" # or "mps", "xpu", "cpu" pipeline = AutoPipelineForInpainting.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-inpainting", dtype=torch.float16, @@ -516,7 +516,7 @@ from diffusers import AutoPipelineForInpainting from diffusers.utils import load_image from PIL import Image -generator = torch.Generator(device='cuda').manual_seed(0) +generator = torch.Generator(device='cuda').manual_seed(0) # or "mps", "xpu", "cpu" pipeline = AutoPipelineForInpainting.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to('cuda') base = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/seashore.png") diff --git a/docs/source/en/using-diffusers/ip_adapter.md b/docs/source/en/using-diffusers/ip_adapter.md index 7535b6762f2a..47c8cb0af860 100644 --- a/docs/source/en/using-diffusers/ip_adapter.md +++ b/docs/source/en/using-diffusers/ip_adapter.md @@ -29,7 +29,7 @@ from diffusers.utils import load_image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter", subfolder="sdxl_models", @@ -73,7 +73,7 @@ from diffusers.utils import load_image pipeline = AutoPipelineForImage2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter", subfolder="sdxl_models", @@ -117,7 +117,7 @@ from diffusers.utils import load_image pipeline = AutoPipelineForImage2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter", subfolder="sdxl_models", @@ -230,7 +230,7 @@ pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", image_encoder=image_encoder, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter", @@ -249,7 +249,7 @@ from transformers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter-FaceID", @@ -273,7 +273,7 @@ pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", image_encoder=image_encoder, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter-FaceID", @@ -296,7 +296,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForImage2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" image_embeds = pipeline.prepare_ip_adapter_image_embeds( ip_adapter_image=image, @@ -347,7 +347,7 @@ from diffusers.utils import load_image pipeline = AutoPipelineForImage2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" mask1 = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_mask_mask1.png") mask2 = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_mask_mask2.png") @@ -435,7 +435,7 @@ from diffusers.utils import load_image pipeline = StableDiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) pipeline.load_ip_adapter( "h94/IP-Adapter", @@ -480,7 +480,7 @@ from insightface.app import FaceAnalysis pipeline = StableDiffusionPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) pipeline.load_ip_adapter( "h94/IP-Adapter-FaceID", @@ -673,7 +673,7 @@ pipeline = StableDiffusionControlNetPipeline.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", controlnet=controlnet, dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter", subfolder="models", @@ -721,7 +721,7 @@ from diffusers.utils import load_image pipeline = AutoPipelineForText2Image.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_ip_adapter( "h94/IP-Adapter", subfolder="sdxl_models", diff --git a/docs/source/en/using-diffusers/loading.md b/docs/source/en/using-diffusers/loading.md index b26ebfbdc3b2..b98e7e25b2d0 100644 --- a/docs/source/en/using-diffusers/loading.md +++ b/docs/source/en/using-diffusers/loading.md @@ -29,7 +29,7 @@ import torch from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -48,7 +48,7 @@ import torch from diffusers import QwenImagePipeline pipeline = QwenImagePipeline.from_pretrained( - "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" + "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -72,7 +72,7 @@ import torch from diffusers import QwenImagePipeline pipeline = QwenImagePipeline.from_pretrained( - "path/to/your/cache", dtype=torch.bfloat16, device_map="cuda" + "path/to/your/cache", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -128,7 +128,7 @@ max_memory = {0: "16GB", 1: "16GB"} pipeline = DiffusionPipeline.from_pretrained( "Qwen/Qwen-Image", dtype=torch.bfloat16, - device_map="cuda", + device_map="cuda", # or "mps", "xpu", "cpu" ) ``` @@ -161,7 +161,7 @@ from diffusers import DiffusionPipeline os.environ["HF_ENABLE_PARALLEL_LOADING"] = "YES" pipeline = DiffusionPipeline.from_pretrained( - "Wan-AI/Wan2.2-I2V-A14B-Diffusers", dtype=torch.bfloat16, device_map="cuda" + "Wan-AI/Wan2.2-I2V-A14B-Diffusers", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -183,7 +183,7 @@ pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", vae=vae, dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -203,7 +203,7 @@ import torch from diffusers import AutoPipelineForText2Image pipeline_sdxl = AutoPipelineForText2Image.from_pretrained( - "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, device_map="cuda" + "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California diff --git a/docs/source/en/using-diffusers/other-formats.md b/docs/source/en/using-diffusers/other-formats.md index 835836848b96..a4a7620d587b 100644 --- a/docs/source/en/using-diffusers/other-formats.md +++ b/docs/source/en/using-diffusers/other-formats.md @@ -46,7 +46,7 @@ from diffusers import StableDiffusionXLPipeline pipeline = StableDiffusionXLPipeline.from_single_file( "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -63,7 +63,7 @@ pipeline = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", transformer=transformer, dtype=torch.bfloat16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) ``` @@ -175,7 +175,7 @@ from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", torch.dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline = DiffusionPipeline.from_single_file( @@ -194,7 +194,7 @@ from diffusers import FluxPipeline pipeline = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights("linoyts/yarn_art_Flux_LoRA") pipeline.save_lora_weights( text_encoder_lora_adapter_metadata={"r": 8, "lora_alpha": 8}, diff --git a/docs/source/en/using-diffusers/reusing_seeds.md b/docs/source/en/using-diffusers/reusing_seeds.md index f703070428dd..c1b7a10392b3 100644 --- a/docs/source/en/using-diffusers/reusing_seeds.md +++ b/docs/source/en/using-diffusers/reusing_seeds.md @@ -35,7 +35,7 @@ import torch import numpy as np from diffusers import DDIMPipeline -ddim = DDIMPipeline.from_pretrained("google/ddpm-cifar10-32", device_map="cuda") +ddim = DDIMPipeline.from_pretrained("google/ddpm-cifar10-32", device_map="cuda") # or "mps", "xpu", "cpu" generator = torch.manual_seed(0) image = ddim(num_inference_steps=2, output_type="np", generator=generator).images print(np.abs(image).sum()) diff --git a/docs/source/en/using-diffusers/schedulers.md b/docs/source/en/using-diffusers/schedulers.md index aa4acde8254e..a17d9e5bfeaf 100644 --- a/docs/source/en/using-diffusers/schedulers.md +++ b/docs/source/en/using-diffusers/schedulers.md @@ -29,7 +29,7 @@ import torch from diffusers import DiffusionPipeline pipeline = DiffusionPipeline.from_pretrained( - "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, device_map="cuda" + "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler ``` @@ -46,7 +46,7 @@ pipeline = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", scheduler=dpm, dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler ``` @@ -74,7 +74,7 @@ print(sampling_schedule) pipeline = DiffusionPipeline.from_pretrained( "SG161222/RealVisXL_V4.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler = DPMSolverMultistepScheduler.from_config( pipeline.scheduler.config, algorithm_type="sde-dpmsolver++" @@ -118,7 +118,7 @@ To fix this, a model must be trained with `v_prediction`. If a model is trained ```py from diffusers import DiffusionPipeline, DDIMScheduler -pipeline = DiffusionPipeline.from_pretrained("ptx0/pseudo-journey-v2", device_map="cuda") +pipeline = DiffusionPipeline.from_pretrained("ptx0/pseudo-journey-v2", device_map="cuda") # or "mps", "xpu", "cpu" pipeline.scheduler = DDIMScheduler.from_config( pipeline.scheduler.config, rescale_betas_zero_snr=True, timestep_spacing="trailing" @@ -168,7 +168,7 @@ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler pipeline = DiffusionPipeline.from_pretrained( "SG161222/RealVisXL_V4.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler = DPMSolverMultistepScheduler.from_config( pipeline.scheduler.config, timestep_spacing="trailing" @@ -210,7 +210,7 @@ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler pipeline = DiffusionPipeline.from_pretrained( "SG161222/RealVisXL_V4.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler = DPMSolverMultistepScheduler.from_config( pipeline.scheduler.config, algorithm_type="sde-dpmsolver++" @@ -238,7 +238,7 @@ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler pipeline = DiffusionPipeline.from_pretrained( "SG161222/RealVisXL_V4.0", dtype=torch.float16, - device_map="cuda" + device_map="cuda" # or "mps", "xpu", "cpu" ) pipeline.scheduler = DPMSolverMultistepScheduler.from_config( pipeline.scheduler.config, diff --git a/docs/source/en/using-diffusers/t2i_adapter.md b/docs/source/en/using-diffusers/t2i_adapter.md index 4c397ea017d3..c72400034e49 100644 --- a/docs/source/en/using-diffusers/t2i_adapter.md +++ b/docs/source/en/using-diffusers/t2i_adapter.md @@ -58,7 +58,7 @@ pipeline = StableDiffusionXLAdapterPipeline.from_pretrained( adapter=t2i_adapter, vae=vae, dtype=torch.float16, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = """ A photorealistic overhead image of a cat reclining sideways in a flamingo pool floatie holding a margarita. @@ -130,7 +130,7 @@ pipeline = StableDiffusionXLAdapterPipeline.from_pretrained( dtype=torch.float16, vae=vae, adapter=adapters, -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline( prompt, diff --git a/docs/source/en/using-diffusers/text-img2vid.md b/docs/source/en/using-diffusers/text-img2vid.md index 0c846a383ee3..8a7ab648d694 100644 --- a/docs/source/en/using-diffusers/text-img2vid.md +++ b/docs/source/en/using-diffusers/text-img2vid.md @@ -57,7 +57,7 @@ pipeline = WanPipeline.from_pretrained( text_encoder=text_encoder, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" prompt = """ The camera rushes from far to near in a low-angle shot, @@ -187,7 +187,7 @@ from diffusers.utils import export_to_video pipeline = LTXPipeline.from_pretrained( "Lightricks/LTX-Video", dtype=torch.bfloat16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = """ A woman with long brown hair and light skin smiles at another woman with long blonde hair. The woman @@ -222,7 +222,7 @@ from diffusers.utils import export_to_video pipeline = CogVideoXPipeline.from_pretrained( "THUDM/CogVideoX-2b", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" prompt = """ A detailed wooden toy ship with intricately carved masts and sails is seen gliding smoothly over @@ -261,7 +261,7 @@ pipeline = WanPipeline.from_pretrained( pipeline.scheduler = UniPCMultistepScheduler.from_config( pipeline.scheduler.config, flow_shift=5.0 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights("benjamin-paine/steamboat-willie-14b", adapter_name="steamboat-willie") pipeline.set_adapters("steamboat-willie") @@ -330,7 +330,7 @@ pipeline = WanPipeline.from_pretrained( text_encoder=text_encoder, dtype=torch.bfloat16 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" prompt = """ The camera rushes from far to near in a low-angle shot, @@ -385,7 +385,7 @@ pipeline = WanPipeline.from_pretrained( pipeline.scheduler = UniPCMultistepScheduler.from_config( pipeline.scheduler.config, flow_shift=5.0 ) -pipeline.to("cuda") +pipeline.to("cuda") # or "mps", "xpu", "cpu" pipeline.load_lora_weights("benjamin-paine/steamboat-willie-14b", adapter_name="steamboat-willie") pipeline.set_adapters("steamboat-willie") @@ -423,7 +423,7 @@ from diffusers.utils import export_to_video pipeline = CogVideoXPipeline.from_pretrained( "THUDM/CogVideoX-2b", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" # torch.compile pipeline.transformer.to(memory_format=torch.channels_last) diff --git a/docs/source/en/using-diffusers/textual_inversion_inference.md b/docs/source/en/using-diffusers/textual_inversion_inference.md index 21105e1d4012..f2883d87b605 100644 --- a/docs/source/en/using-diffusers/textual_inversion_inference.md +++ b/docs/source/en/using-diffusers/textual_inversion_inference.md @@ -23,7 +23,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" ``` Load the word embeddings with [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] and include the unique token in the prompt to activate its generation. @@ -49,7 +49,7 @@ from diffusers import AutoPipelineForText2Image pipeline = AutoPipelineForText2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16 -).to("cuda") +).to("cuda") # or "mps", "xpu", "cpu" pipeline.load_textual_inversion( "EvilEngine/easynegative", weight_name="easynegative.safetensors", diff --git a/docs/source/en/using-diffusers/unconditional_image_generation.md b/docs/source/en/using-diffusers/unconditional_image_generation.md index 0add5bab6707..e64e7949bd2b 100644 --- a/docs/source/en/using-diffusers/unconditional_image_generation.md +++ b/docs/source/en/using-diffusers/unconditional_image_generation.md @@ -21,7 +21,7 @@ To get started, use the [`DiffusionPipeline`] to load the [anton-l/ddpm-butterfl ```py from diffusers import DiffusionPipeline -generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128").to("cuda") +generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128").to("cuda") # or "mps", "xpu", "cpu" image = generator().images[0] image ``` diff --git a/docs/source/en/using-diffusers/weighted_prompts.md b/docs/source/en/using-diffusers/weighted_prompts.md index 11d667180392..927ba9214df4 100644 --- a/docs/source/en/using-diffusers/weighted_prompts.md +++ b/docs/source/en/using-diffusers/weighted_prompts.md @@ -79,7 +79,7 @@ from diffusers import DiffusionPipeline from sd_embed.embedding_funcs import get_weighted_text_embeddings_sdxl pipeline = DiffusionPipeline.from_pretrained( - "Lykon/dreamshaper-xl-1-0", dtype=torch.bfloat16, device_map="cuda" + "Lykon/dreamshaper-xl-1-0", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" ) prompt = """ diff --git a/docs/source/en/using-diffusers/write_own_pipeline.md b/docs/source/en/using-diffusers/write_own_pipeline.md index e34727b5da25..06b25235dbca 100644 --- a/docs/source/en/using-diffusers/write_own_pipeline.md +++ b/docs/source/en/using-diffusers/write_own_pipeline.md @@ -25,7 +25,7 @@ A pipeline is a quick and easy way to run a model for inference, requiring no mo ```py >>> from diffusers import DDPMPipeline ->>> ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda") +>>> ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" >>> image = ddpm(num_inference_steps=25).images[0] >>> image ``` @@ -46,7 +46,7 @@ To recreate the pipeline with the model and scheduler separately, let's write ou >>> from diffusers import DDPMScheduler, UNet2DModel >>> scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256") ->>> model = UNet2DModel.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda") +>>> model = UNet2DModel.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda") # or "mps", "xpu", "cpu" ``` 2. Set the number of timesteps to run the denoising process for: @@ -71,7 +71,7 @@ tensor([980, 960, 940, 920, 900, 880, 860, 840, 820, 800, 780, 760, 740, 720, >>> import torch >>> sample_size = model.config.sample_size ->>> noise = torch.randn((1, 3, sample_size, sample_size), device="cuda") +>>> noise = torch.randn((1, 3, sample_size, sample_size), device="cuda") # or "mps", "xpu", "cpu" ``` 5. Now write a loop to iterate over the timesteps. At each timestep, the model does a [`UNet2DModel.forward`] pass and returns the noisy residual. The scheduler's [`~DDPMScheduler.step`] method takes the noisy residual, timestep, and input and it predicts the image at the previous timestep. This output becomes the next input to the model in the denoising loop, and it'll repeat until it reaches the end of the `timesteps` array. @@ -142,7 +142,7 @@ Instead of the default [`PNDMScheduler`], exchange it for the [`UniPCMultistepSc To speed up inference, move the models to a GPU since, unlike the scheduler, they have trainable weights: ```py ->>> torch_device = "cuda" +>>> torch_device = "cuda" # or "mps", "xpu", "cpu" >>> vae.to(torch_device) >>> text_encoder.to(torch_device) >>> unet.to(torch_device)