Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"FLUX 3 Image Klein","local":"flux-3-image-klein","sections":[{"title":"Mẫu hóa lại prompt","local":"prompt-upsampling","sections":[],"depth":2},{"title":"Ảnh sang ảnh","local":"image-to-image","sections":[],"depth":2},{"title":"Kiểm soát bố cục","local":"layout-control","sections":[],"depth":2},{"title":"Thang độ dẫn","local":"guidance-scale","sections":[],"depth":2},{"title":"Mô hình được chưng cất theo bước","local":"step-distilled-model","sections":[],"depth":2},{"title":"Tạo ra có thể tái lập","local":"reproducible-generation","sections":[],"depth":2},{"title":"Quy trình làm việc","local":"workflows","sections":[],"depth":2},{"title":"Callback theo từng bước","local":"per-step-callbacks","sections":[],"depth":2},{"title":"Bộ nhớ","local":"memory","sections":[],"depth":2},{"title":"Tải tệp đơn","local":"single-file-loading","sections":[],"depth":2},{"title":"Flux3ModularPipeline","local":"diffusers.Flux3ModularPipeline","sections":[],"depth":2},{"title":"Flux3AutoBlocks","local":"diffusers.Flux3AutoBlocks","sections":[],"depth":2},{"title":"Flux3DistilledAutoBlocks","local":"diffusers.Flux3DistilledAutoBlocks","sections":[],"depth":2},{"title":"Flux3DistilledModularPipeline","local":"diffusers.Flux3DistilledModularPipeline","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/yxSHiGDF.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CPfOwUO_.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/BYe-f74j.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/D32hXVzh.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DqpuBF3n.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Dyp9xKq8.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/8.AKHyGgGH.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Dk44y1gU.js" rel="modulepreload"> | |
| <!--hchutw--><meta name="hf:doc:metadata" content="{"title":"FLUX 3 Image Klein","local":"flux-3-image-klein","sections":[{"title":"Prompt upsampling","local":"prompt-upsampling","sections":[],"depth":2},{"title":"Image-to-image","local":"image-to-image","sections":[],"depth":2},{"title":"Layout control","local":"layout-control","sections":[],"depth":2},{"title":"Guidance scale","local":"guidance-scale","sections":[],"depth":2},{"title":"Step-distilled model","local":"step-distilled-model","sections":[],"depth":2},{"title":"Reproducible generation","local":"reproducible-generation","sections":[],"depth":2},{"title":"Workflows","local":"workflows","sections":[],"depth":2},{"title":"Per-step callbacks","local":"per-step-callbacks","sections":[],"depth":2},{"title":"Memory","local":"memory","sections":[],"depth":2},{"title":"Single-file loading","local":"single-file-loading","sections":[],"depth":2},{"title":"Flux3ModularPipeline","local":"diffusers.Flux3ModularPipeline","sections":[],"depth":2},{"title":"Flux3AutoBlocks","local":"diffusers.Flux3AutoBlocks","sections":[],"depth":2},{"title":"Flux3DistilledAutoBlocks","local":"diffusers.Flux3DistilledAutoBlocks","sections":[],"depth":2},{"title":"Flux3DistilledModularPipeline","local":"diffusers.Flux3DistilledModularPipeline","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <!--[0--><h1 class="relative group"><a id="flux-3-image-klein" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#flux-3-image-klein"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->FLUX 3 Image Klein<!----></span></h1><!--]--><!----> <p>FLUX 3 Image Klein là mô hình tạo ảnh 5.6B từ Black Forest Labs: một transformer duy nhất (<a href="/docs/diffusers/main/vi/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a>) tạo ảnh từ một prompt văn bản, hoạt động độc lập hoặc cùng với một hoặc nhiều ảnh tham chiếu. Điều kiện văn bản đến từ Qwen3-VL, và ảnh sử dụng autoencoder đóng gói FLUX.2 (<code>AutoencoderKLFlux2</code>).</p> <p>FLUX 3 Image Klein được phát hành dưới dạng <a href="../../modular_diffusers/overview">pipeline module hóa</a>. Bắt đầu với việc tạo ảnh từ văn bản:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline | |
| pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>) | |
| pipe.load_components(dtype={<span class="hljs-string">"vae"</span>: torch.float32, <span class="hljs-string">"default"</span>: torch.bfloat16}) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| image = pipe( | |
| prompt=<span class="hljs-string">"A red fox in a snow-covered forest clearing at golden hour"</span>, | |
| generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), | |
| output=<span class="hljs-string">"images"</span>, | |
| )[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"fox.png"</span>)<!----></pre></div><!----> <p><code>prompt</code> là đầu vào bắt buộc duy nhất: pipeline mang theo các cài đặt lấy mẫu được khuyến nghị (50 bước, guidance scale 3.5, scheduler shift 6.93) và mặc định tạo ảnh kích thước 1024 x 1024. Mỗi lần gọi chỉ nhận một prompt; dùng <code>num_images_per_prompt</code> để tạo nhiều ảnh từ cùng một prompt.</p> <p>Như bạn có thể thấy trong ví dụ ở trên, việc tải và chạy hơi khác so với <code>DiffusionPipeline</code>. Việc tải là theo kiểu lười (lazy): <a href="/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> chỉ xây dựng pipeline, và bạn gọi <a href="/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> để tải trọng số. Một lời gọi sẽ trả về trạng thái của pipeline, và bạn yêu cầu những gì cần thiết bằng <code>output</code>: ở đây là <code>output="images"</code>, hoặc <code>output=["images", "prompt"]</code> để cũng nhận được chú thích mà prompt upsampler đã viết.</p> <blockquote class="tip"><p>Nếu bạn làm việc với <code>ModularPipeline</code> lần đầu tiên, hãy đọc <a href="../../modular_diffusers/quickstart">quickstart</a>, và <a href="../../modular_diffusers/coming_from_diffusion_pipeline">Coming from DiffusionPipeline</a> nếu bạn đã quen thuộc với các pipeline chuẩn. Ngoài việc tải và đầu ra, một số điểm khác biệt khác là: <a href="#guidance-scale">guidance</a>, <a href="#per-step-callbacks">callbacks</a> và <a href="#memory">offloading</a>.</p></blockquote> <!--[1--><h2 class="relative group"><a id="prompt-upsampling" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#prompt-upsampling"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Mẫu hóa lại prompt<!----></span></h2><!--]--><!----> <p>Việc tạo prompt rất quan trọng: FLUX 3 Image Klein nhận các mô tả cảnh hoàn chỉnh, trong đó nêu rõ chủ thể, bố cục, ánh sáng và bầu không khí, chứ không phải các <code>prompt</code> ngắn; một yêu cầu được gửi đúng như cách gõ sẽ cho ra kết quả chung chung. Đó là lý do pipeline chạy bộ mở rộng prompt trước tiên cho mọi yêu cầu, dù là tạo ảnh từ văn bản hay chỉnh sửa. Đây là một mô hình 9B riêng biệt từ Black Forest Labs (<a href="https://huggingface.co/black-forest-labs/flux-3-image-klein-pup" rel="nofollow">black-forest-labs/flux-3-image-klein-pup</a>) có nhiệm vụ mở rộng <code>prompt</code> thành một mô tả như vậy trước khi đưa vào bộ mã hóa văn bản, và chỉ cần một <code>prompt</code> ngắn là đủ.</p> <p>Upsampler prompt biến một yêu cầu ngắn, cùng với các hình ảnh tham chiếu khi chỉnh sửa, thành mô tả cảnh hoàn chỉnh mà mô hình sử dụng: medium và style, cảnh, ánh sáng và camera, mỗi chủ thể cùng màu sắc, vật liệu và vị trí của nó trong khung hình. Một mô hình bao phủ text-to-image, chỉnh sửa với hình ảnh tham chiếu và layout với các hộp. Mô tả mà nó viết được trả về dưới dạng đầu ra <code>prompt</code>. Trong ví dụ trên, hãy yêu cầu nó cùng với các hình ảnh để xem mô hình hình ảnh đã nhận được gì:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->out = pipe( | |
| prompt=<span class="hljs-string">"A red fox in a snow-covered forest clearing at golden hour"</span>, | |
| generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), | |
| output=[<span class="hljs-string">"images"</span>, <span class="hljs-string">"prompt"</span>], | |
| ) | |
| <span class="hljs-built_in">print</span>(out[<span class="hljs-string">"prompt"</span>])<!----></pre></div><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!---->Full-color outdoor wildlife photograph taken <span class="hljs-built_in">from</span> <span class="hljs-keyword">a</span> low eye-level perspective <span class="hljs-keyword">in</span> <span class="hljs-keyword">a</span> snow-covered forest clearing <span class="hljs-keyword">at</span> golden hour. In <span class="hljs-keyword">the</span> center foreground, <span class="hljs-keyword">a</span> red fox stands <span class="hljs-keyword">in</span> profile facing left, its body turned toward <span class="hljs-keyword">the</span> viewer <span class="hljs-keyword">and</span> its head raised <span class="hljs-keyword">as</span> <span class="hljs-keyword">it</span> looks across <span class="hljs-keyword">the</span> clearing. The fox has dense rust-red winter fur, <span class="hljs-keyword">a</span> white throat <span class="hljs-keyword">and</span> chest, <span class="hljs-keyword">black</span> <span class="hljs-built_in">lower</span> legs, pointed ears <span class="hljs-keyword">with</span> dark tips, <span class="hljs-keyword">and</span> <span class="hljs-keyword">a</span> <span class="hljs-keyword">long</span> bushy tail ending <span class="hljs-keyword">in</span> white. ...<!----></pre></div><!----> <p>Đoạn chú thích đầy đủ dài khoảng 240 từ; <code>max_new_tokens</code> giới hạn độ dài của nó (mặc định là 3584).</p> <p>Bạn có thể in <code>doc</code> của bước để xem nó nhận những gì và ghi ra những gì:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-built_in">print</span>(pipe.blocks.sub_blocks[<span class="hljs-string">"prompt_upsampler"</span>].doc)<!----></pre></div><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!----> <span class="hljs-symbol">Inputs</span>: | |
| prompt (<span class="hljs-string">`str`</span>): | |
| <span class="hljs-symbol">The</span> edit instruction to expand into the full caption (one per call). | |
| image (<span class="hljs-string">`Image | list`</span>, *optional*): | |
| <span class="hljs-symbol">The</span> reference image(s) of the edit, at most <span class="hljs-number">10</span>; the same ones the pipeline receives. | |
| boxes (<span class="hljs-string">`list`</span>, *optional*): | |
| <span class="hljs-symbol">Layout</span> boxes, each {<span class="hljs-string">'id'</span>, <span class="hljs-string">'desc'</span>, <span class="hljs-string">'from'</span>, <span class="hljs-string">'src_bbox'</span>, <span class="hljs-string">'tgt_bbox'</span>} with the boxes as [y_min, x_min, y_max, x_max] in | |
| <span class="hljs-number">0</span><span class="hljs-number">-1</span>: ... | |
| max_new_tokens (<span class="hljs-string">`int`</span>, *optional*, defaults to <span class="hljs-number">3584</span>): | |
| <span class="hljs-symbol">The</span> most tokens the upsampler may generate for the caption. | |
| <span class="hljs-symbol">Outputs</span>: | |
| prompt (<span class="hljs-string">`str`</span>): | |
| <span class="hljs-symbol">The</span> full caption, replacing the request.<!----></pre></div><!----> <p>Tương tự như các khối khác trong pipeline, khối <code>prompt_upsampler</code> cũng chạy độc lập. Cách được khuyến nghị là tách nó ra khỏi các khối: khối bị tách ra sẽ trở thành một upsampler độc lập, và các khối còn lại sẽ tạo thành một pipeline nhận caption đã mở rộng dưới dạng <code>prompt</code>:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->blocks = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>).blocks | |
| pup_block = blocks.sub_blocks.pop(<span class="hljs-string">"prompt_upsampler"</span>) | |
| pup = pup_block.init_pipeline(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>) | |
| pup.load_components(dtype=torch.bfloat16) | |
| pup.to(<span class="hljs-string">"cuda"</span>) | |
| caption = pup(prompt=<span class="hljs-string">"A red fox in a snow-covered forest clearing at golden hour"</span>, output=<span class="hljs-string">"prompt"</span>) | |
| pipe = blocks.init_pipeline(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>) | |
| pipe.load_components(dtype={<span class="hljs-string">"vae"</span>: torch.float32, <span class="hljs-string">"default"</span>: torch.bfloat16}) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| image = pipe(prompt=caption, generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>Nhờ đó, nó có thể được triển khai như một giai đoạn riêng biệt, trên GPU riêng hoặc sau endpoint riêng, và giao diện người dùng có thể hiển thị chú thích mà nó đã viết, cho phép người dùng chỉnh sửa trước khi tạo ảnh. Bất kỳ LLM nào khác cũng có thể thay thế upsampler, với cùng các system prompt: hãy cung cấp <code>system_prompts["t2i"]</code> từ kho upsampler (hoặc <code>"i2i"</code>, với các tham chiếu đặt trước trong user message) làm system prompt và yêu cầu làm user message, sau đó truyền chú thích mà nó trả về dưới dạng <code>prompt</code> cho <code>pipe</code>.</p> <!--[1--><h2 class="relative group"><a id="image-to-image" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#image-to-image"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Ảnh sang ảnh<!----></span></h2><!--]--><!----> <p>Truyền một hoặc nhiều hình ảnh tham chiếu bằng <code>image</code>. Một tham chiếu đơn được giữ nguyên vẹn: nó chỉ bị giảm kích thước khi vượt quá 4 megapixel, được đệm lên lưới 16 pixel, và kích thước mặc định của quá trình tạo sẽ khớp với kích thước của nó, do đó kết quả chỉnh sửa sẽ có cùng kích thước với đầu vào. Nhiều tham chiếu sẽ mỗi cái được điều chỉnh dưới 1 megapixel và cắt theo lưới, và kích thước mặc định của quá trình tạo sẽ lấy theo kích thước của tham chiếu đầu tiên. Giá trị <code>height</code>/<code>width</code> cụ thể sẽ ghi đè lên mặc định. Hãy mô tả hình ảnh <em>mục tiêu</em> như một chú thích hoàn chỉnh của hình tham chiếu với phần chỉnh sửa của bạn được tích hợp vào, thay vì một dòng hướng dẫn ngắn, hoặc để <a href="#prompt-upsampling">prompt upsampler</a> viết ra từ hướng dẫn và các hình tham chiếu:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->night = pipe( | |
| prompt=<span class="hljs-string">"the same scene at night under a full moon"</span>, | |
| image=image, | |
| generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), | |
| output=[<span class="hljs-string">"images"</span>, <span class="hljs-string">"prompt"</span>], | |
| )<!----></pre></div><!----> <p>Với một số tham chiếu, hãy gọi chúng là hình ảnh đầu tiên, hình ảnh thứ hai, … theo thứ tự chúng được truyền vào <code>image</code>; chú thích gọi chúng là <code><ref_image_0></code>, <code><ref_image_1></code>, … đối với mô hình hình ảnh:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->combined = pipe( | |
| prompt=<span class="hljs-string">"the fox from the first image sitting on the wooden bench from the second image"</span>, | |
| image=[image, bench], | |
| height=<span class="hljs-number">768</span>, | |
| width=<span class="hljs-number">1360</span>, | |
| output=<span class="hljs-string">"images"</span>, | |
| )[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>Truyền <code>height</code> và/hoặc <code>width</code> để ghi đè kích thước đã suy ra.</p> <!--[1--><h2 class="relative group"><a id="layout-control" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#layout-control"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Kiểm soát bố cục<!----></span></h2><!--]--><!----> <p>Để đặt nội dung một cách rõ ràng, hãy truyền <code>boxes</code>: cho mỗi phần tử một <code>id</code>, một <code>desc</code> ngắn, và một <code>bbox</code> dạng <code>[y_min, x_min, y_max, x_max]</code> trong khoảng 0-1 (gốc ở góc trên bên trái), để nó độc lập với kích thước đầu ra. Bộ tăng độ phân giải sẽ viết chú thích xung quanh chúng, trích dẫn mỗi phần tử dưới dạng <code><id></code>, và thêm bảng các hộp, giữ nguyên chính xác hộp của bạn:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->boxes = [ | |
| {<span class="hljs-string">"id"</span>: <span class="hljs-string">"balloon_1"</span>, <span class="hljs-string">"desc"</span>: <span class="hljs-string">"a red and yellow striped hot-air balloon"</span>, <span class="hljs-string">"bbox"</span>: [<span class="hljs-number">0.08</span>, <span class="hljs-number">0.06</span>, <span class="hljs-number">0.48</span>, <span class="hljs-number">0.38</span>]}, | |
| {<span class="hljs-string">"id"</span>: <span class="hljs-string">"balloon_2"</span>, <span class="hljs-string">"desc"</span>: <span class="hljs-string">"a small blue hot-air balloon"</span>, <span class="hljs-string">"bbox"</span>: [<span class="hljs-number">0.20</span>, <span class="hljs-number">0.62</span>, <span class="hljs-number">0.42</span>, <span class="hljs-number">0.80</span>]}, | |
| ] | |
| out = pipe(prompt=<span class="hljs-string">"hot-air balloons over a green valley at sunrise"</span>, boxes=boxes, output=[<span class="hljs-string">"images"</span>, <span class="hljs-string">"prompt"</span>])<!----></pre></div><!----> <p>Khi chỉnh sửa, một hộp chỉ định nguồn của nó bằng <code>from</code>: <code>"target"</code> kèm <code>tgt_bbox</code> sẽ thêm một phần tử mới tại đó, <code>"ref_image_0"</code> kèm <code>src_bbox</code> và <code>tgt_bbox</code> sẽ di chuyển một phần tử của ảnh tham chiếu đó (các hộp bằng nhau sẽ giữ nguyên vị trí):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->boxes = [{<span class="hljs-string">"id"</span>: <span class="hljs-string">"cactus"</span>, <span class="hljs-string">"desc"</span>: <span class="hljs-string">"a small potted cactus"</span>, <span class="hljs-string">"from"</span>: <span class="hljs-string">"target"</span>, <span class="hljs-string">"src_bbox"</span>: <span class="hljs-literal">None</span>, <span class="hljs-string">"tgt_bbox"</span>: [<span class="hljs-number">0.55</span>, <span class="hljs-number">0.62</span>, <span class="hljs-number">0.85</span>, <span class="hljs-number">0.85</span>]}] | |
| out = pipe(prompt=<span class="hljs-string">"add a small potted cactus in the marked spot"</span>, image=mug, boxes=boxes, output=[<span class="hljs-string">"images"</span>, <span class="hljs-string">"prompt"</span>]) | |
| boxes = [{<span class="hljs-string">"id"</span>: <span class="hljs-string">"knight"</span>, <span class="hljs-string">"desc"</span>: <span class="hljs-string">"the knight figure"</span>, <span class="hljs-string">"from"</span>: <span class="hljs-string">"ref_image_0"</span>, <span class="hljs-string">"src_bbox"</span>: [<span class="hljs-number">0.50</span>, <span class="hljs-number">0.15</span>, <span class="hljs-number">0.85</span>, <span class="hljs-number">0.35</span>], <span class="hljs-string">"tgt_bbox"</span>: [<span class="hljs-number">0.19</span>, <span class="hljs-number">0.06</span>, <span class="hljs-number">0.54</span>, <span class="hljs-number">0.26</span>]}] | |
| out = pipe(prompt=<span class="hljs-string">"move the knight up and to the left, keep the rest unchanged"</span>, image=knight, boxes=boxes, output=[<span class="hljs-string">"images"</span>, <span class="hljs-string">"prompt"</span>])<!----></pre></div><!----> <p>Caption mà mô hình ảnh đọc có các phần tử được gắn thẻ <code><id></code> trong văn bản và bảng được nối thêm dưới dạng JSON, với các hộp trên canvas 0-1000; in ra kết quả <code>prompt</code> để xem. Một caption được viết theo dạng đó bằng tay sẽ được đưa vào pipeline mà không cần bước này, như trong <a href="#prompt-upsampling">Prompt upsampling</a>.</p> <!--[1--><h2 class="relative group"><a id="guidance-scale" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#guidance-scale"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Thang độ dẫn<!----></span></h2><!--]--><!----> <p>Pipeline áp dụng classifier-free guidance thông qua thành phần <code>guider</code> và không nhận đối số <code>guidance_scale</code> tại thời điểm gọi. Guider mặc định là <a href="/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance">ClassifierFreeGuidance</a> với <code>guidance_scale=3.5</code>, cài đặt được khuyến nghị cho cả hai workflow. Để thay đổi, hãy tạo một bản sao cập nhật của guider:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->pipe.guider = pipe.guider.new(guidance_scale=<span class="hljs-number">5.0</span>)<!----></pre></div><!----> <p>Xem <a href="../../using-diffusers/guiders">hướng dẫn cho guider</a> để chuyển sang phương pháp guidance khác.</p> <!--[1--><h2 class="relative group"><a id="step-distilled-model" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#step-distilled-model"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Mô hình được chưng cất theo bước<!----></span></h2><!--]--><!----> <p>Checkpoint được chưng cất theo bước tạo ra kết quả trong 16 bước mà không cần classifier-free guidance. Transformer của nó là một flow map: ở mỗi bước, nó được cung cấp timestep hiện tại và timestep mà bước đó nhảy tới. Nó được nạp giống như mô hình cơ sở (tệp <code>modular_model_index.json</code> trong kho chỉ đến <a href="/docs/diffusers/main/vi/api/pipelines/flux3#diffusers.Flux3DistilledModularPipeline">Flux3DistilledModularPipeline</a> và <a href="/docs/diffusers/main/vi/api/pipelines/flux3#diffusers.Flux3DistilledAutoBlocks">Flux3DistilledAutoBlocks</a>); pipeline không có <code>guider</code> và không nhận <code>negative_prompt</code>:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/flux-3-image-klein"</span>) | |
| pipe.load_components(dtype=torch.bfloat16) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| image = pipe(prompt=prompt, generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>Nó phục vụ cùng hai luồng công việc như mô hình cơ sở. <code>num_inference_steps</code> mặc định là 16; mô hình được huấn luyện trong 4 đến 16 bước.</p> <!--[1--><h2 class="relative group"><a id="reproducible-generation" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#reproducible-generation"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Tạo ra có thể tái lập<!----></span></h2><!--]--><!----> <p>Một <code>generator</code> cố định nhiễu mà pipeline lấy (xem <a href="../../using-diffusers/reusing_seeds">Tính tái lập</a>). Để tái sử dụng nhiễu đã lấy ở nơi khác, hãy truyền nó dưới dạng <code>latents</code> với hình dạng <code>(batch_size, 128, height // 16, width // 16)</code>. Ví dụ, <a href="https://github.com/black-forest-labs/flux-3-image-klein" rel="nofollow">cách triển khai của BFL</a> lấy nhiễu dưới dạng các token ảnh trên CPU và chuyển đổi nó sang bf16; điều này tái lập mẫu của nó cho một seed nhất định:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->height, width = <span class="hljs-number">1024</span>, <span class="hljs-number">1024</span> | |
| h, w = height // <span class="hljs-number">16</span>, width // <span class="hljs-number">16</span> | |
| noise = torch.randn((h * w, <span class="hljs-number">128</span>), generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>)).to(torch.bfloat16) | |
| latents = noise.T.reshape(<span class="hljs-number">1</span>, <span class="hljs-number">128</span>, h, w) | |
| image = pipe(prompt=prompt, latents=latents, height=height, width=width, output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="workflows" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#workflows"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Quy trình làm việc<!----></span></h2><!--]--><!----> <p>Pipeline phục vụ hai luồng công việc, <code>text2image</code> và <code>image_conditioned</code>; luồng được thực thi sẽ được chọn dựa trên các đầu vào (<code>image</code> chọn image-to-image). <a href="/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> cũng có thể xây dựng pipeline cho một luồng công việc bằng tham số <code>workflow</code>, khi đó pipeline chỉ kỳ vọng và tải các thành phần mà luồng công việc đó cần:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> Flux3AutoBlocks | |
| <span class="hljs-built_in">print</span>(Flux3AutoBlocks().available_workflows) | |
| <span class="hljs-comment"># ["text2image", "image_conditioned"]</span> | |
| t2i = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>, workflow=<span class="hljs-string">"text2image"</span>) | |
| <span class="hljs-built_in">print</span>(t2i.blocks.doc)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="per-step-callbacks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#per-step-callbacks"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Callback theo từng bước<!----></span></h2><!--]--><!----> <p>Để sử dụng một hàm callback có sẵn, hãy chèn một khối vào vòng lặp khử nhiễu. <a href="../../using-diffusers/callback#modular-pipelines">hướng dẫn về callback</a> có một ví dụ đơn giản với khối <code>CallbackOnStepEnd</code> và hàm trợ giúp <code>walk_denoise_loops</code>:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->blocks = Flux3AutoBlocks() <span class="hljs-comment"># or Flux3DistilledAutoBlocks</span> | |
| <span class="hljs-keyword">for</span> loop <span class="hljs-keyword">in</span> walk_denoise_loops(blocks): | |
| loop.sub_blocks[<span class="hljs-string">"callback"</span>] = CallbackOnStepEnd() | |
| pipe = blocks.init_pipeline(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>) | |
| image = pipe(prompt=caption, callback_on_step_end=my_callback, output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>Để dừng sớm, hãy raise từ callback; không có cờ <code>interrupt</code>.</p> <!--[1--><h2 class="relative group"><a id="memory" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#memory"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Bộ nhớ<!----></span></h2><!--]--><!----> <p>Việc nạp toàn bộ ở bf16 tiêu tốn khoảng 39 GB trọng số: transformer có 5,5B tham số, text encoder Qwen3-VL-4B có 4B và <a href="#prompt-upsampling">prompt upsampler</a> có 9B (khoảng 19 GB riêng), với image VAE ở fp32. Một pipeline được xây dựng không có bước upsampler (xem ở đó) nạp khoảng 20 GB. Đối với GPU có bộ nhớ ít hơn, hãy bật component offloading; trình quản lý sẽ di chuyển các component giữa CPU và GPU khi mỗi bước cần đến, bao gồm cả upsampler:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentsManager, ModularPipeline | |
| manager = ComponentsManager() | |
| pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>, components_manager=manager) | |
| pipe.load_components(dtype={<span class="hljs-string">"vae"</span>: torch.float32, <span class="hljs-string">"default"</span>: torch.bfloat16}) | |
| manager.enable_auto_cpu_offload(device=<span class="hljs-string">"cuda"</span>)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="single-file-loading" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#single-file-loading"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Tải tệp đơn<!----></span></h2><!--]--><!----> <p><a href="/docs/diffusers/main/vi/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a> nạp transformer trực tiếp từ gói mô hình của Black Forest Labs bằng <a href="/docs/diffusers/main/vi/api/loaders/single_file#diffusers.loaders.FromOriginalModelMixin.from_single_file">from_single_file()</a>. Gói <code>config.json</code> không được đọc; hãy truyền cấu hình diffusers bằng <code>config</code> và <code>subfolder</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Flux3Transformer2DModel, ModularPipeline | |
| transformer = Flux3Transformer2DModel.from_single_file( | |
| <span class="hljs-string">"https://huggingface.co/black-forest-labs/flux-3-image-klein-base/blob/main/model.safetensors"</span>, | |
| config=<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>, | |
| subfolder=<span class="hljs-string">"transformer"</span>, | |
| dtype=torch.bfloat16, | |
| ) | |
| pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>) | |
| pipe.load_components(dtype={<span class="hljs-string">"vae"</span>: torch.float32, <span class="hljs-string">"default"</span>: torch.bfloat16}) | |
| pipe.update_components(transformer=transformer) | |
| pipe.to(<span class="hljs-string">"cuda"</span>)<!----></pre></div><!----> <p>Tải các thành phần khác theo tên trước: <a href="/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> không có <code>names</code> cũng sẽ tải transformer từ kho pipeline.</p> <p>Việc nạp các checkpoint đơn tệp FP8r và NVFP4 cũng được hỗ trợ. Cả hai đều được nạp thông qua cùng một lệnh gọi với <a href="/docs/diffusers/main/vi/api/quantization#diffusers.BFLQuantizationConfig">BFLQuantizationConfig</a>. Xem <a href="../../quantization/bfl">hướng dẫn lượng tử hóa BFL</a> để biết yêu cầu về kernel của từng phương án.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> BFLQuantizationConfig | |
| transformer = Flux3Transformer2DModel.from_single_file( | |
| <span class="hljs-string">"https://huggingface.co/black-forest-labs/flux-3-image-klein-base/blob/main/variants/nvfp4/model.safetensors"</span>, | |
| config=<span class="hljs-string">"black-forest-labs/flux-3-image-klein-base"</span>, | |
| subfolder=<span class="hljs-string">"transformer"</span>, | |
| quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16), | |
| dtype=torch.bfloat16, | |
| )<!----></pre></div><!----> <p>Khi nạp các checkpoint đã chưng cất theo bước, chúng ta cần cấu hình của chúng (<code>flow_map=True</code>):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!---->transformer = Flux3Transformer2DModel.from_single_file( | |
| <span class="hljs-string">"https://huggingface.co/black-forest-labs/flux-3-image-klein/blob/main/variants/nvfp4/model.safetensors"</span>, | |
| config=<span class="hljs-string">"black-forest-labs/flux-3-image-klein"</span>, | |
| subfolder=<span class="hljs-string">"transformer"</span>, | |
| quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16), | |
| dtype=torch.bfloat16, | |
| )<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3ModularPipeline" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#diffusers.Flux3ModularPipeline"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Flux3ModularPipeline<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3ModularPipeline"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">lớp</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3ModularPipeline</span></span></h3><!----> <a id="diffusers.Flux3ModularPipeline" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3ModularPipeline"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_pipeline.py#L24" target="_blank"><span><</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">blocks<span class="opacity-60">: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">pretrained_model_name_or_path<span class="opacity-60">: str | os.PathLike | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">components_manager<span class="opacity-60">: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">collection<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">workflow<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">modular_config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">**kwargs<span class="opacity-60"></span></span></span><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>Một ModularPipeline cho FLUX.3.</p></div> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3AutoBlocks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#diffusers.Flux3AutoBlocks"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Flux3AutoBlocks<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3AutoBlocks"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">lớp</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3AutoBlocks</span></span></h3><!----> <a id="diffusers.Flux3AutoBlocks" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3AutoBlocks"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3.py#L339" target="_blank"><span><</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>Auto blocks thực hiện tạo ảnh từ văn bản và tạo ảnh từ ảnh bằng FLUX.3. <code>prompt</code> sẽ đi qua prompt upsampler trước; hãy bỏ bước <code>prompt_upsampler</code> để mã hóa như đã cho.</p> <p>Các quy trình làm việc được hỗ trợ:</p> <ul><li><code>text2image</code>: yêu cầu <code>prompt</code></li> <li><code>image_conditioned</code>: yêu cầu <code>prompt</code>, <code>image</code></li></ul> <p>Các thành phần: | |
| prompt_upsampler (<code>Qwen3_5ForConditionalGeneration</code>): Bộ mở rộng prompt. prompt_upsampler_processor | |
| (<code>AutoProcessor</code>): Bộ xử lý của nó. text_encoder (<code>Qwen3VLForConditionalGeneration</code>) tokenizer | |
| (<code>AutoProcessor</code>) image_processor (<code>Flux3ImageProcessor</code>) vae (<code>AutoencoderKLFlux2</code>) transformer | |
| (<code>Flux3Transformer2DModel</code>) scheduler (<code>FlowMatchEulerDiscreteScheduler</code>) guider (<code>ClassifierFreeGuidance</code>)</p> <p>Đầu vào: | |
| prompt (<code>str</code>): | |
| Lệnh chỉnh sửa để mở rộng thành chú thích đầy đủ (một lệnh cho mỗi lần gọi). | |
| image (<code>Image | list</code>, <em>tùy chọn</em>): | |
| Hình ảnh tham chiếu của chỉnh sửa, tối đa 10; giống với những hình ảnh mà pipeline nhận được. | |
| boxes (<code>list</code>, <em>tùy chọn</em>): | |
| Các hộp bố cục, mỗi hộp có dạng {‘id’, ‘desc’, ‘from’, ‘src_bbox’, ‘tgt_bbox’} với các hộp là [y_min, x_min, y_max, | |
| x_max] trong khoảng 0-1: ‘from’: ‘target’ với <code>tgt_bbox</code> thêm một phần tử tại đó, ‘from’: ‘ref_image_0’, … với <code>src_bbox</code> và <code>tgt_bbox</code> di chuyển một phần tử từ hình ảnh tham chiếu. | |
| max_new_tokens (<code>int</code>, <em>tùy chọn</em>, mặc định là 3584): | |
| Số token tối đa mà upsampler có thể tạo ra cho chú thích. | |
| negative_prompt (<code>str</code>, <em>tùy chọn</em>): | |
| Prompt không dùng để định hướng quá trình tạo | |
| max_sequence_length (<code>int</code>, <em>tùy chọn</em>, mặc định là 8192): | |
| Số lượng token prompt tối đa; các prompt dài hơn sẽ bị cắt bớt. | |
| text_encoder_out_layers (<code>tuple</code>, <em>tùy chọn</em>, mặc định là (4, 8, 12, 16, 20, 24, 28, 32)): | |
| Chỉ số của các lớp ẩn của text-encoder mà trạng thái của chúng được xếp chồng để tạo thành text embeddings | |
| num_images_per_prompt (<code>int</code>, <em>tùy chọn</em>, mặc định là 1): | |
| Số lượng hình ảnh cần tạo cho mỗi prompt. | |
| image_cond_latents (<code>list</code>, <em>tùy chọn</em>): | |
| Các latents đã chuẩn hóa và đóng gói của các hình ảnh tham chiếu, một tensor có hình dạng (B, C, height_i//16, width_i//16) | |
| cho mỗi hình ảnh | |
| height (<code>int</code>, <em>tùy chọn</em>, mặc định là None hoặc 1024, tùy thuộc vào quy trình làm việc): | |
| Chiều cao tính bằng pixel của hình ảnh được tạo; mặc định là chiều cao của chính hình ảnh tham chiếu đầu tiên | |
| width (<code>int</code>, <em>tùy chọn</em>, mặc định là None hoặc 1024, tùy thuộc vào quy trình làm việc): | |
| Chiều rộng tính bằng pixel của hình ảnh được tạo; mặc định là chiều rộng của chính hình ảnh tham chiếu đầu tiên | |
| reference_crop (<code>list | NoneType</code>, <em>tùy chọn</em>): | |
| Đối với mỗi tham chiếu, hộp của tham chiếu bên trong canvas đã đệm hoặc None, từ bước tiền xử lý | |
| latents (<code>Tensor</code>): | |
| Các latents nhiễu đã tạo trước cho việc tạo hình ảnh. | |
| generator (<code>Generator</code>, <em>tùy chọn</em>): | |
| Torch generator cho việc tạo ra có tính xác định. | |
| num_inference_steps (<code>int</code>): | |
| Số bước khử nhiễu. | |
| timesteps (<code>Tensor</code>): | |
| Các bước thời gian cho quá trình khử nhiễu. (ghi đè <code>num_inference_steps</code> khi được cung cấp) | |
| sigmas (<code>list</code>, <em>tùy chọn</em>): | |
| Các sigmas tùy chỉnh cho quá trình khử nhiễu. (ghi đè <code>num_inference_steps</code> khi được cung cấp) | |
| *<em>denoiser_input_fields (<code>None</code>,</em>tùy chọn<em>): | |
| đầu vào của mô hình điều kiện cho denoiser: ví dụ prompt_embeds, negative_prompt_embeds, v.v. | |
| attention_kwargs (<code>dict</code>,</em>tùy chọn<em>): | |
| Các kwargs bổ sung cho các bộ xử lý attention. | |
| output_type (<code>str</code>,</em>tùy chọn*, mặc định là pil): | |
| Định dạng đầu ra: ‘pil’, ‘np’, ‘pt’.</p> <p>Đầu ra: | |
| images (<code>list</code>): | |
| Các hình ảnh được tạo ra. | |
| latents (<code>Tensor</code>): | |
| Các latents đã khử nhiễu.</p></div> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3DistilledAutoBlocks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#diffusers.Flux3DistilledAutoBlocks"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Flux3DistilledAutoBlocks<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3DistilledAutoBlocks"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">lớp</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3DistilledAutoBlocks</span></span></h3><!----> <a id="diffusers.Flux3DistilledAutoBlocks" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3DistilledAutoBlocks"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3_distilled.py#L258" target="_blank"><span><</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>Auto blocks thực hiện tạo ảnh từ văn bản và tạo ảnh từ ảnh bằng mô hình FLUX.3 đã được step-distilled (16 bước, không có classifier-free guidance). <code>prompt</code> sẽ đi qua prompt upsampler trước; hãy bỏ bước <code>prompt_upsampler</code> để mã hóa nó như đã cho.</p> <p>Các quy trình làm việc được hỗ trợ:</p> <ul><li><code>text2image</code>: yêu cầu <code>prompt</code></li> <li><code>image_conditioned</code>: yêu cầu <code>prompt</code>, <code>image</code></li></ul> <p>Các thành phần: | |
| prompt_upsampler (<code>Qwen3_5ForConditionalGeneration</code>): Bộ mở rộng prompt. prompt_upsampler_processor | |
| (<code>AutoProcessor</code>): Bộ xử lý của nó. text_encoder (<code>Qwen3VLForConditionalGeneration</code>) tokenizer | |
| (<code>AutoProcessor</code>) image_processor (<code>Flux3ImageProcessor</code>) vae (<code>AutoencoderKLFlux2</code>) transformer | |
| (<code>Flux3Transformer2DModel</code>) scheduler (<code>FlowMatchEulerDiscreteScheduler</code>)</p> <p>Đầu vào: | |
| prompt (<code>str</code>): | |
| Lệnh chỉnh sửa để mở rộng thành chú thích đầy đủ (một lệnh cho mỗi lần gọi). | |
| image (<code>Image | list</code>, <em>tùy chọn</em>): | |
| Hình ảnh tham chiếu của chỉnh sửa, tối đa 10; giống những hình ảnh mà pipeline nhận được. | |
| boxes (<code>list</code>, <em>tùy chọn</em>): | |
| Các hộp bố cục, mỗi hộp có dạng {‘id’, ‘desc’, ‘from’, ‘src_bbox’, ‘tgt_bbox’} với các hộp là [y_min, x_min, y_max, | |
| x_max] trong khoảng 0-1: ‘from’: ‘target’ với <code>tgt_bbox</code> thêm một phần tử tại đó, ‘from’: ‘ref_image_0’, … với <code>src_bbox</code> và <code>tgt_bbox</code> di chuyển một phần tử từ hình ảnh tham chiếu. | |
| max_new_tokens (<code>int</code>, <em>tùy chọn</em>, mặc định là 3584): | |
| Số token tối đa mà upsampler có thể tạo ra cho chú thích. | |
| max_sequence_length (<code>int</code>, <em>tùy chọn</em>, mặc định là 8192): | |
| Số lượng token prompt tối đa; các prompt dài hơn sẽ bị cắt bớt. | |
| text_encoder_out_layers (<code>tuple</code>, <em>tùy chọn</em>, mặc định là (4, 8, 12, 16, 20, 24, 28, 32)): | |
| Chỉ số của các lớp ẩn của text-encoder mà trạng thái của chúng được xếp chồng để tạo thành text embeddings | |
| num_images_per_prompt (<code>int</code>, <em>tùy chọn</em>, mặc định là 1): | |
| Số lượng hình ảnh cần tạo cho mỗi prompt. | |
| image_cond_latents (<code>list</code>, <em>tùy chọn</em>): | |
| Các latents đã chuẩn hóa và đóng gói của các hình ảnh tham chiếu, một tensor có hình dạng (B, C, height_i//16, width_i//16) | |
| cho mỗi hình ảnh | |
| height (<code>int</code>, <em>tùy chọn</em>, mặc định là None hoặc 1024, tùy thuộc vào quy trình làm việc): | |
| Chiều cao tính bằng pixel của hình ảnh được tạo; mặc định là chiều cao của chính hình ảnh tham chiếu đầu tiên | |
| width (<code>int</code>, <em>tùy chọn</em>, mặc định là None hoặc 1024, tùy thuộc vào quy trình làm việc): | |
| Chiều rộng tính bằng pixel của hình ảnh được tạo; mặc định là chiều rộng của chính hình ảnh tham chiếu đầu tiên | |
| reference_crop (<code>list | NoneType</code>, <em>tùy chọn</em>): | |
| Đối với mỗi tham chiếu, hộp của tham chiếu bên trong canvas đã đệm hoặc None, từ bước tiền xử lý | |
| latents (<code>Tensor</code>): | |
| Các latents nhiễu đã tạo trước cho việc tạo hình ảnh. | |
| generator (<code>Generator</code>, <em>tùy chọn</em>): | |
| Torch generator cho việc tạo ra có tính xác định. | |
| num_inference_steps (<code>int</code>): | |
| Số bước khử nhiễu. | |
| timesteps (<code>Tensor</code>): | |
| Các bước thời gian cho quá trình khử nhiễu. (ghi đè <code>num_inference_steps</code> khi được cung cấp) | |
| sigmas (<code>list</code>, <em>tùy chọn</em>): | |
| Các sigmas tùy chỉnh cho quá trình khử nhiễu. (ghi đè <code>num_inference_steps</code> khi được cung cấp) | |
| *<em>denoiser_input_fields (<code>None</code>,</em>tùy chọn<em>): | |
| đầu vào của mô hình điều kiện cho denoiser: ví dụ prompt_embeds, negative_prompt_embeds, v.v. | |
| output_type (<code>str</code>,</em>tùy chọn*, mặc định là pil): | |
| Định dạng đầu ra: ‘pil’, ‘np’, ‘pt’.</p> <p>Đầu ra: | |
| images (<code>list</code>): | |
| Các hình ảnh được tạo ra. | |
| latents (<code>Tensor</code>): | |
| Các latents đã khử nhiễu.</p></div> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3DistilledModularPipeline" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#diffusers.Flux3DistilledModularPipeline"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Flux3DistilledModularPipeline<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3DistilledModularPipeline"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">lớp</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3DistilledModularPipeline</span></span></h3><!----> <a id="diffusers.Flux3DistilledModularPipeline" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3DistilledModularPipeline"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_pipeline.py#L52" target="_blank"><span><</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">blocks<span class="opacity-60">: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">pretrained_model_name_or_path<span class="opacity-60">: str | os.PathLike | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">components_manager<span class="opacity-60">: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">collection<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">workflow<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">modular_config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">**kwargs<span class="opacity-60"></span></span></span><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>Mô hình FLUX.3 có bước chưng cất (16 bước, không có hướng dẫn không phân loại) với ModularPipeline.</p></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/flux3.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_gxjg5b = { | |
| base: "/docs/diffusers/main/en", | |
| assets: "/docs/diffusers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js"), | |
| import("/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 8], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 100 kB
- Xet hash:
- c85684afb1ea6d333a85b0d420660ce23a816c5544938f92825778c29956a37c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.