Buckets:
| # Mulai Cepat | |
| Diffusers adalah pustaka untuk pengembang dan peneliti yang menyediakan API inferensi yang mudah untuk menghasilkan gambar, video, dan audio, serta komponen dasar untuk mengimplementasikan alur kerja baru. | |
| Diffusers menyediakan banyak optimasi bawaan yang memungkinkan Anda memuat dan menjalankan model besar pada konfigurasi dengan memori terbatas atau mempercepat inferensi. | |
| Quickstart ini akan memberikan gambaran umum tentang Diffusers dan membantu Anda mulai menghasilkan gambar dengan cepat. | |
| > [!TIP] | |
| > Sebelum memulai, pastikan Anda memiliki [akun](https://huggingface.co/join) Hugging Face untuk menggunakan model bergerbang seperti [Flux](https://huggingface.co/black-forest-labs/FLUX.1-dev). Ingin membangun pipeline kustom? Lihat [Modular Diffusers quickstart](./modular_diffusers/quickstart) dan [overview](./modular_diffusers/overview). | |
| Ikuti panduan [Instalasi](./installation) untuk menginstal Diffusers jika belum terpasang. | |
| ## Prompt agen | |
| Tempelkan ini ke agen coding Anda untuk menyiapkan Diffusers untuk inferensi. | |
| ```text | |
| Help me get set up with Hugging Face Diffusers for inference. | |
| 1. Install Diffusers for my environment with `uv pip install "diffusers[torch]"`. | |
| 2. If I need gated Hub models, help me authenticate to the Hugging Face Hub. | |
| 3. Install Diffusers coding agent skills with `diffusers-cli skills add diffusers-cli`. Pass `--cursor`, `--claude`, or `--codex` if auto-detect fails. Optionally pass `--all` to install every skill in the registry. | |
| 4. Run a first text-to-image with DiffusionPipeline or `diffusers-cli run`, using a small or current Quickstart model and the right `device_map` for my machine. | |
| 5. Ask what I want next and point me at the matching docs. | |
| ``` | |
| ## DiffusionPipeline | |
| [DiffusionPipeline](/docs/diffusers/v0.43.0/id/api/pipelines/overview#diffusers.DiffusionPipeline) mengemas komponen-komponen model difusi (text encoder, scheduler, UNet atau DiT, dan VAE) ke dalam satu kelas untuk inferensi. Muat dengan [from_pretrained()](/docs/diffusers/v0.43.0/id/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained), lalu panggil pipeline-nya. | |
| Argumen pada `__call__()` seperti `num_inference_steps` mengubah kualitas dan kecepatan. Untuk detail pemuatan dan komponen yang dapat dicampur, lihat [Memuat pipeline](./using-diffusers/loading). Untuk mengganti scheduler, lihat [Schedulers](./using-diffusers/schedulers). | |
| Contoh di bawah ini menggunakan nilai argumen default. | |
| Gunakan `.images[0]` untuk mengakses output gambar yang dihasilkan. | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "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 | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """ | |
| pipeline(prompt).images[0] | |
| ``` | |
| Gunakan `.frames[0]` untuk mengakses output video yang dihasilkan dan [export_to_video()](/docs/diffusers/v0.43.0/id/api/utilities#diffusers.utils.export_to_video) untuk menyimpan video. | |
| ```py | |
| import torch | |
| from diffusers import AutoencoderKLWan, DiffusionPipeline | |
| from diffusers.utils import export_to_video | |
| vae = AutoencoderKLWan.from_pretrained( | |
| "Wan-AI/Wan2.2-T2V-A14B-Diffusers", | |
| subfolder="vae", | |
| dtype=torch.float32 | |
| ) | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "Wan-AI/Wan2.2-T2V-A14B-Diffusers", | |
| vae=vae, | |
| dtype=torch.bfloat16, | |
| device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| prompt = """ | |
| Cinematic video of a sleek cat lounging on a colorful inflatable in a crystal-clear turquoise pool in Palm Springs, | |
| sipping a salt-rimmed margarita through a straw. Golden-hour sunlight glows over mid-century modern homes and swaying palms. | |
| Shot in rich Sony a7S III: with moody, glamorous color grading, subtle lens flares, and soft vintage film grain. | |
| Ripples shimmer as a warm desert breeze stirs the water, blending luxury and playful charm in an epic, gorgeously composed frame. | |
| """ | |
| video = pipeline(prompt=prompt, num_frames=81, num_inference_steps=40).frames[0] | |
| export_to_video(video, "output.mp4", fps=16) | |
| ``` | |
| ## LoRA | |
| Adaptor [LoRA](./tutorials/using_peft_for_inference) menambahkan checkpoint gaya atau subjek kecil di atas pipeline dasar. Muat salah satunya dengan [load_lora_weights()](/docs/diffusers/v0.43.0/id/api/loaders/lora#diffusers.loaders.QwenImageLoraLoaderMixin.load_lora_weights). Beberapa LoRA memerlukan frasa pemicu. Periksa model card LoRA tersebut. | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.load_lora_weights( | |
| "threecrowco/VolkClipartQwen", | |
| weight_name="pytorch_lora_weights.safetensors", | |
| ) | |
| prompt = """ | |
| Volk clipart style drawing of a cat sipping a margarita in a pool in Palm Springs, California, flat colors, bold outlines, simple shapes | |
| """ | |
| pipeline(prompt).images[0] | |
| ``` | |
| ## Kuantisasi dan optimasi | |
| Model besar sering kali membutuhkan memori lebih sedikit atau kecepatan lebih tinggi. Gunakan [quantization](./quantization/overview) untuk memperkecil bobot di memori, dan [compile_repeated_blocks()](/docs/diffusers/v0.43.0/id/api/models/overview#diffusers.ModelMixin.compile_repeated_blocks) untuk mempercepat generate berikutnya. Untuk [model offloading](./optimization/memory#model-offloading) dan opsi lainnya, lihat [Optimize and scale](./stable_diffusion). | |
| Untuk menggunakan memori lebih sedikit, muat dalam 4-bit dengan bitsandbytes. | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| from diffusers.quantizers import PipelineQuantizationConfig | |
| quant_config = PipelineQuantizationConfig( | |
| quant_backend="bitsandbytes_4bit", | |
| quant_kwargs={"load_in_4bit": True, "bnb_4bit_quant_type": "nf4", "bnb_4bit_compute_dtype": torch.bfloat16}, | |
| components_to_quantize=["transformer", "text_encoder"], | |
| ) | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "Qwen/Qwen-Image", | |
| dtype=torch.bfloat16, | |
| quantization_config=quant_config, | |
| device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| prompt = """ | |
| cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """ | |
| pipeline(prompt).images[0] | |
| ``` | |
| Untuk mempercepat eksekusi berikutnya, kompilasi blok berulang pada transformer. Panggilan generate pertama setelah kompilasi merupakan cold start dan berjalan lambat. Panggilan generate berikutnya akan lebih cepat. | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.transformer.compile_repeated_blocks(fullgraph=True) | |
| prompt = """ | |
| cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """ | |
| pipeline(prompt).images[0] | |
| ``` | |
| ## Langkah selanjutnya | |
| - [Inferensi](./using-diffusers/loading) — pipeline, prompting, dan adapter | |
| - [Optimalkan dan skalakan](./stable_diffusion) — memori, kecepatan, kuantisasi, dan penyajian | |
| - [Modular Diffusers](./modular_diffusers/overview) — blok yang dapat dikomposisikan dan pipeline kustom | |
| - [Latih dan sesuaikan](./training/overview) — skrip pelatihan dan adapter | |
| - [CLI](./using-diffusers/cli) — menghasilkan dari baris perintah | |
Xet Storage Details
- Size:
- 7.55 kB
- Xet hash:
- da187b4e4fc96937be5707127541c89bd7463ecf2ac8653190755f13eafd74e9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.