Buckets:
| import"../chunks/DsnmJJEf.js";import{i as ae,h as oe,H as l,a as s,D as o,E as te,s as ne}from"../chunks/BLbO27j4.js";import{p as ie,o as pe,s as e,f as re,a as L,b as de,c as t,d as D,n as a,r as n}from"../chunks/jDjavuwI.js";const ce='{"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}';var me=D('<meta name="hf:doc:metadata"/>'),he=D(`<p></p> <!> <p>FLUX 3 Image Klein is a 5.6B image generation model from Black Forest Labs: a single transformer (<a href="/docs/diffusers/pr_15078/en/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a>) generates images from a text prompt, alone or together with one or more reference images. Text conditioning comes from Qwen3-VL, and images use the FLUX.2 packed autoencoder (<code>AutoencoderKLFlux2</code>).</p> <p>FLUX 3 Image Klein ships as a <a href="../../modular_diffusers/overview">modular pipeline</a>. Get started with a text-to-image generation:</p> <!> <p><code>prompt</code> is the only required input: the pipeline carries the recommended sampling settings (50 steps, guidance scale 3.5, scheduler shift 6.93) and generates 1024 x 1024 images by default. It takes one prompt per call; use <code>num_images_per_prompt</code> for several images of the same prompt.</p> <p>As you can see in the example above, loading and running differ a little from a <code>DiffusionPipeline</code>. Loading is lazy: <a href="/docs/diffusers/pr_15078/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> only builds the pipeline, and you call <a href="/docs/diffusers/pr_15078/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> to load the weights. A call returns the pipeline state, and you ask for what you need with <code>output</code>: <code>output="images"</code> here, or <code>output=["images", "prompt"]</code> to also get the caption the prompt upsampler wrote.</p> <blockquote class="tip"><p>If you’re working with <code>ModularPipeline</code> for the first time, read the <a href="../../modular_diffusers/quickstart">quickstart</a>, and <a href="../../modular_diffusers/coming_from_diffusion_pipeline">Coming from DiffusionPipeline</a> if you know the standard pipelines. Besides loading and outputs, a few other things differ: <a href="#guidance-scale">guidance</a>, <a href="#per-step-callbacks">callbacks</a> and <a href="#memory">offloading</a>.</p></blockquote> <!> <p>Prompting matters: FLUX 3 Image Klein takes full scene captions that describe the subject, composition, lighting, and atmosphere, not short prompts; a request sent as typed gives generic output. That is why the pipeline runs the prompt upsampler first on every request, text-to-image and editing alike. It is a separate 9B model from 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>) that expands <code>prompt</code> into such a caption before the text encoder, and a short prompt is all it takes.</p> <p>The prompt upsampler turns a short request, together with the reference images when editing, into the full scene caption the model takes: medium and style, scene, lighting and camera, each subject with its colors, materials and position in the frame. One model covers text-to-image, editing with reference images and layout with boxes. The caption it wrote comes back as the <code>prompt</code> output. In the example above, ask for it alongside the images to see what the image model received:</p> <!> <!> <p>The full caption runs to about 240 words; <code>max_new_tokens</code> caps its length (3584 by default).</p> <p>You can print the step’s <code>doc</code> to see what it takes and what it writes:</p> <!> <!> <p>Like other blocks in the pipeline, the <code>prompt_upsampler</code> block also runs on its own. The recommended way is to pop it out of the blocks: the popped block becomes a standalone upsampler, and the remaining blocks become a pipeline that takes the expanded caption as <code>prompt</code>:</p> <!> <p>This way it can be served as a separate stage, on its own GPU or behind its own endpoint, and a UI can show the caption it wrote and let the user edit it before generating. Any other LLM can take the upsampler’s place, with the same system prompts: give it <code>system_prompts["t2i"]</code> from the upsampler repository (or <code>"i2i"</code>, with the references first in the user message) as the system prompt and the request as the user message, and pass the caption it returns as <code>prompt</code> to <code>pipe</code>.</p> <!> <p>Pass one or more reference images with <code>image</code>. Every reference keeps its own resolution (center-cropped to the 16-pixel grid; references above 16 megapixels are downscaled first), and the generation size defaults to one megapixel at the first reference’s aspect ratio. The prompt the image model takes is the <em>target</em> image as a complete caption of the reference with the edit folded in, not a one-line instruction; the upsampler sees the references too and writes it from your instruction: what to keep, what to change.</p> <!> <p>With several references, refer to them as the first image, the second image, … in the order they are passed to <code>image</code>; the caption names them <code><ref_image_0></code>, <code><ref_image_1></code>, … for the image model:</p> <!> <p>Pass <code>height</code> and/or <code>width</code> to override the derived size.</p> <!> <p>To place content explicitly, pass <code>boxes</code>: for each element an <code>id</code>, a short <code>desc</code>, and a <code>bbox</code> of <code>[y_min, x_min, y_max, x_max]</code> in 0-1 (origin top-left), so it is independent of the output size. The upsampler writes the caption around them, citing each element as <code><id></code>, and appends the table of boxes, yours kept exactly:</p> <!> <p>When editing, a box names its source with <code>from</code>: <code>"target"</code> with a <code>tgt_bbox</code> adds a new element there, <code>"ref_image_0"</code> with a <code>src_bbox</code> and a <code>tgt_bbox</code> moves an element of that reference (equal boxes keep it in place):</p> <!> <p>The caption the image model reads has the elements tagged <code><id></code> in the text and the table appended as JSON, with the boxes on a 0-1000 canvas; print the <code>prompt</code> output to see it. A caption written in that form by hand goes to the pipeline without the step, as in <a href="#prompt-upsampling">Prompt upsampling</a>.</p> <!> <p>The pipeline applies classifier-free guidance through its <code>guider</code> component and does not take a <code>guidance_scale</code> argument at call time. The default guider is <a href="/docs/diffusers/pr_15078/en/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance">ClassifierFreeGuidance</a> with <code>guidance_scale=3.5</code>, the recommended setting for both workflows. To change it, create an updated copy of the guider:</p> <!> <p>See the <a href="../../using-diffusers/guiders">guiders guide</a> to switch to a different guidance method.</p> <!> <p>The step-distilled checkpoint generates in 16 steps without classifier-free guidance. Its transformer is a flow map: at every step it is told the current timestep and the one the step jumps to. It loads like the base model (the repo’s <code>modular_model_index.json</code> resolves to <a href="/docs/diffusers/pr_15078/en/api/pipelines/flux3#diffusers.Flux3DistilledModularPipeline">Flux3DistilledModularPipeline</a> and <a href="/docs/diffusers/pr_15078/en/api/pipelines/flux3#diffusers.Flux3DistilledAutoBlocks">Flux3DistilledAutoBlocks</a>); the pipeline has no <code>guider</code> and does not take <code>negative_prompt</code>:</p> <!> <p>It serves the same two workflows as the base model. <code>num_inference_steps</code> defaults to 16; the model is trained for 4 to 16 steps.</p> <!> <p>A <code>generator</code> fixes the noise the pipeline draws (see <a href="../../using-diffusers/reusing_seeds">Reproducibility</a>). To reuse noise drawn elsewhere, pass it as <code>latents</code> with shape <code>(batch_size, 128, height // 16, width // 16)</code>. For example, the <a href="https://github.com/black-forest-labs/flux-3" rel="nofollow">BFL implementation</a> draws its noise as image tokens on the CPU and casts it to bf16; this reproduces its sample for a given seed:</p> <!> <!> <p>The pipeline serves two workflows, <code>text2image</code> and <code>image_conditioned</code>; the one that runs is picked by the inputs (<code>image</code> selects image-to-image). <a href="/docs/diffusers/pr_15078/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> can also build a pipeline for one workflow with the <code>workflow</code> argument, which then only expects and loads the components that workflow needs:</p> <!> <!> <p>To use an existing callback function, insert a block into the denoising loop. The <a href="../../using-diffusers/callback#modular-pipelines">callbacks guide</a> has a simple example with the <code>CallbackOnStepEnd</code> block and the <code>walk_denoise_loops</code> helper:</p> <!> <p>To stop early, raise from the callback; there is no <code>interrupt</code> flag.</p> <!> <p>Loading everything in bf16 takes about 39 GB of weights: the transformer is 5.5B parameters, the Qwen3-VL-4B text encoder 4B and the <a href="#prompt-upsampling">prompt upsampler</a> 9B (about 19 GB on its own), with the image VAE in fp32. A pipeline built without the upsampler step (see there) loads about 20 GB. For GPUs with less memory, enable component offloading; the manager moves components between the CPU and the GPU as each step needs them, the upsampler included:</p> <!> <!> <p><a href="/docs/diffusers/pr_15078/en/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a> loads the transformer straight from a Black Forest Labs model package with <a href="/docs/diffusers/pr_15078/en/api/loaders/single_file#diffusers.loaders.FromOriginalModelMixin.from_single_file">from_single_file()</a>. The package <code>config.json</code> is not read; pass the diffusers config with <code>config</code> and <code>subfolder</code>.</p> <!> <p>Load the other components by name first: <a href="/docs/diffusers/pr_15078/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> without <code>names</code> would also load the transformer from the pipeline repo.</p> <p>Loading the FP8r and NVFP4 single-file checkpoints are also supported. Both load through the same call with a <a href="/docs/diffusers/pr_15078/en/api/quantization#diffusers.BFLQuantizationConfig">BFLQuantizationConfig</a>. See the <a href="../../quantization/bfl">BFL quantization guide</a> for the kernel requirements of each scheme.</p> <!> <p>When loading the step-distilled checkpoints, we need their | |
| configs (<code>flow_map=True</code>):</p> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A ModularPipeline for FLUX.3.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Auto blocks that perform text-to-image and image-to-image generation using FLUX.3. <code>prompt</code> goes through the prompt | |
| upsampler first; pop the <code>prompt_upsampler</code> step to encode it as given.</p> <p>Supported workflows:</p> <ul><li><code>text2image</code>: requires <code>prompt</code></li> <li><code>image_conditioned</code>: requires <code>prompt</code>, <code>image</code></li></ul> <p>Components: | |
| prompt_upsampler (<code>Qwen3_5ForConditionalGeneration</code>): The prompt upsampler. prompt_upsampler_processor | |
| (<code>AutoProcessor</code>): Its processor. 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>Inputs: | |
| prompt (<code>str</code>): | |
| The edit instruction to expand into the full caption (one per call). | |
| image (<code>Image | list</code>, <em>optional</em>): | |
| The reference image(s) of the edit, at most 10; the same ones the pipeline receives. | |
| boxes (<code>list</code>, <em>optional</em>): | |
| Layout boxes, each {‘id’, ‘desc’, ‘from’, ‘src_bbox’, ‘tgt_bbox’} with the boxes as [y_min, x_min, y_max, | |
| x_max] in 0-1: ‘from’: ‘target’ with <code>tgt_bbox</code> adds an element there, ‘from’: ‘ref_image_0’, … with <code>src_bbox</code> and <code>tgt_bbox</code> moves one from a reference image. | |
| max_new_tokens (<code>int</code>, <em>optional</em>, defaults to 3584): | |
| The most tokens the upsampler may generate for the caption. | |
| negative_prompt (<code>str</code>, <em>optional</em>): | |
| The prompt not to guide the generation | |
| max_sequence_length (<code>int</code>, <em>optional</em>, defaults to 8192): | |
| Maximum number of prompt tokens; longer prompts are truncated. | |
| text_encoder_out_layers (<code>tuple</code>, <em>optional</em>, defaults to (4, 8, 12, 16, 20, 24, 28, 32)): | |
| Indices of the text-encoder hidden layers whose states are stacked to form the text embeddings | |
| num_images_per_prompt (<code>int</code>, <em>optional</em>, defaults to 1): | |
| The number of images to generate per prompt. | |
| image_cond_latents (<code>list</code>, <em>optional</em>): | |
| Normalized packed latents of the reference images, one tensor of shape (B, C, height_i//16, width_i//16) | |
| per image | |
| height (<code>int</code>, <em>optional</em>, defaults to None or 1024, depending on the workflow): | |
| The height in pixels of the generated image; defaults to the first reference image’s aspect ratio at the | |
| default area | |
| width (<code>int</code>, <em>optional</em>, defaults to None or 1024, depending on the workflow): | |
| The width in pixels of the generated image; defaults to the first reference image’s aspect ratio at the | |
| default area | |
| latents (<code>Tensor</code>): | |
| Pre-generated noisy latents for image generation. | |
| generator (<code>Generator</code>, <em>optional</em>): | |
| Torch generator for deterministic generation. | |
| num_inference_steps (<code>int</code>): | |
| The number of denoising steps. | |
| timesteps (<code>Tensor</code>): | |
| Timesteps for the denoising process. (overrides <code>num_inference_steps</code> when provided) | |
| sigmas (<code>list</code>, <em>optional</em>): | |
| Custom sigmas for the denoising process. (overrides <code>num_inference_steps</code> when provided) | |
| *<em>denoiser_input_fields (<code>None</code>,</em>optional<em>): | |
| conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc. | |
| attention_kwargs (<code>dict</code>,</em>optional<em>): | |
| Additional kwargs for attention processors. | |
| output_type (<code>str</code>,</em>optional*, defaults to pil): | |
| Output format: ‘pil’, ‘np’, ‘pt’.</p> <p>Outputs: | |
| images (<code>list</code>): | |
| Generated images. | |
| latents (<code>Tensor</code>): | |
| Denoised latents.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Auto blocks that perform text-to-image and image-to-image generation using the step-distilled FLUX.3 model (16 | |
| steps, no classifier-free guidance). <code>prompt</code> goes through the prompt upsampler first; pop the <code>prompt_upsampler</code> step to encode it as given.</p> <p>Supported workflows:</p> <ul><li><code>text2image</code>: requires <code>prompt</code></li> <li><code>image_conditioned</code>: requires <code>prompt</code>, <code>image</code></li></ul> <p>Components: | |
| prompt_upsampler (<code>Qwen3_5ForConditionalGeneration</code>): The prompt upsampler. prompt_upsampler_processor | |
| (<code>AutoProcessor</code>): Its processor. 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>Inputs: | |
| prompt (<code>str</code>): | |
| The edit instruction to expand into the full caption (one per call). | |
| image (<code>Image | list</code>, <em>optional</em>): | |
| The reference image(s) of the edit, at most 10; the same ones the pipeline receives. | |
| boxes (<code>list</code>, <em>optional</em>): | |
| Layout boxes, each {‘id’, ‘desc’, ‘from’, ‘src_bbox’, ‘tgt_bbox’} with the boxes as [y_min, x_min, y_max, | |
| x_max] in 0-1: ‘from’: ‘target’ with <code>tgt_bbox</code> adds an element there, ‘from’: ‘ref_image_0’, … with <code>src_bbox</code> and <code>tgt_bbox</code> moves one from a reference image. | |
| max_new_tokens (<code>int</code>, <em>optional</em>, defaults to 3584): | |
| The most tokens the upsampler may generate for the caption. | |
| max_sequence_length (<code>int</code>, <em>optional</em>, defaults to 8192): | |
| Maximum number of prompt tokens; longer prompts are truncated. | |
| text_encoder_out_layers (<code>tuple</code>, <em>optional</em>, defaults to (4, 8, 12, 16, 20, 24, 28, 32)): | |
| Indices of the text-encoder hidden layers whose states are stacked to form the text embeddings | |
| num_images_per_prompt (<code>int</code>, <em>optional</em>, defaults to 1): | |
| The number of images to generate per prompt. | |
| image_cond_latents (<code>list</code>, <em>optional</em>): | |
| Normalized packed latents of the reference images, one tensor of shape (B, C, height_i//16, width_i//16) | |
| per image | |
| height (<code>int</code>, <em>optional</em>, defaults to None or 1024, depending on the workflow): | |
| The height in pixels of the generated image; defaults to the first reference image’s aspect ratio at the | |
| default area | |
| width (<code>int</code>, <em>optional</em>, defaults to None or 1024, depending on the workflow): | |
| The width in pixels of the generated image; defaults to the first reference image’s aspect ratio at the | |
| default area | |
| latents (<code>Tensor</code>): | |
| Pre-generated noisy latents for image generation. | |
| generator (<code>Generator</code>, <em>optional</em>): | |
| Torch generator for deterministic generation. | |
| num_inference_steps (<code>int</code>): | |
| The number of denoising steps. | |
| timesteps (<code>Tensor</code>): | |
| Timesteps for the denoising process. (overrides <code>num_inference_steps</code> when provided) | |
| sigmas (<code>list</code>, <em>optional</em>): | |
| Custom sigmas for the denoising process. (overrides <code>num_inference_steps</code> when provided) | |
| *<em>denoiser_input_fields (<code>None</code>,</em>optional<em>): | |
| conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc. | |
| output_type (<code>str</code>,</em>optional*, defaults to pil): | |
| Output format: ‘pil’, ‘np’, ‘pt’.</p> <p>Outputs: | |
| images (<code>list</code>): | |
| Generated images. | |
| latents (<code>Tensor</code>): | |
| Denoised latents.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A ModularPipeline for the step-distilled FLUX.3 model (16 steps, no classifier-free guidance).</p></div> <!> <p></p>`,1);function ge(P,K){ie(K,!1),pe(()=>{new URLSearchParams(window.location.search).get("fw")}),ae();var c=he();oe("hchutw",S=>{var H=me();ne(H,"content",ce),L(S,H)});var m=e(re(c),2);l(m,{title:"FLUX 3 Image Klein",local:"flux-3-image-klein",headingTag:"h1"});var h=e(m,6);s(h,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwTW9kdWxhclBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyME1vZHVsYXJQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4tYmFzZSUyMiklMEFwaXBlLmxvYWRfY29tcG9uZW50cyhkdHlwZSUzRCU3QiUyMnZhZSUyMiUzQSUyMHRvcmNoLmZsb2F0MzIlMkMlMjAlMjJkZWZhdWx0JTIyJTNBJTIwdG9yY2guYmZsb2F0MTYlN0QpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0QlMjJBJTIwcmVkJTIwZm94JTIwaW4lMjBhJTIwc25vdy1jb3ZlcmVkJTIwZm9yZXN0JTIwY2xlYXJpbmclMjBhdCUyMGdvbGRlbiUyMGhvdXIlMjIlMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0R0b3JjaC5HZW5lcmF0b3IoKS5tYW51YWxfc2VlZCgwKSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dCUzRCUyMmltYWdlcyUyMiUyQyUwQSklNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJmb3gucG5nJTIyKQ==",highlighted:`<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>)`,lang:"python",wrap:!1});var u=e(h,8);l(u,{title:"Prompt upsampling",local:"prompt-upsampling",headingTag:"h2"});var M=e(u,6);s(M,{code:"b3V0JTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0QlMjJBJTIwcmVkJTIwZm94JTIwaW4lMjBhJTIwc25vdy1jb3ZlcmVkJTIwZm9yZXN0JTIwY2xlYXJpbmclMjBhdCUyMGdvbGRlbiUyMGhvdXIlMjIlMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0R0b3JjaC5HZW5lcmF0b3IoKS5tYW51YWxfc2VlZCgwKSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dCUzRCU1QiUyMmltYWdlcyUyMiUyQyUyMCUyMnByb21wdCUyMiU1RCUyQyUwQSklMEFwcmludChvdXQlNUIlMjJwcm9tcHQlMjIlNUQp",highlighted:`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>])`,lang:"python",wrap:!1});var y=e(M,2);s(y,{code:"RnVsbC1jb2xvciUyMG91dGRvb3IlMjB3aWxkbGlmZSUyMHBob3RvZ3JhcGglMjB0YWtlbiUyMGZyb20lMjBhJTIwbG93JTIwZXllLWxldmVsJTIwcGVyc3BlY3RpdmUlMjBpbiUyMGElMjBzbm93LWNvdmVyZWQlMjBmb3Jlc3QlMjBjbGVhcmluZyUyMGF0JTIwZ29sZGVuJTIwaG91ci4lMjBJbiUyMHRoZSUyMGNlbnRlciUyMGZvcmVncm91bmQlMkMlMjBhJTIwcmVkJTIwZm94JTIwc3RhbmRzJTIwaW4lMjBwcm9maWxlJTIwZmFjaW5nJTIwbGVmdCUyQyUyMGl0cyUyMGJvZHklMjB0dXJuZWQlMjB0b3dhcmQlMjB0aGUlMjB2aWV3ZXIlMjBhbmQlMjBpdHMlMjBoZWFkJTIwcmFpc2VkJTIwYXMlMjBpdCUyMGxvb2tzJTIwYWNyb3NzJTIwdGhlJTIwY2xlYXJpbmcuJTIwVGhlJTIwZm94JTIwaGFzJTIwZGVuc2UlMjBydXN0LXJlZCUyMHdpbnRlciUyMGZ1ciUyQyUyMGElMjB3aGl0ZSUyMHRocm9hdCUyMGFuZCUyMGNoZXN0JTJDJTIwYmxhY2slMjBsb3dlciUyMGxlZ3MlMkMlMjBwb2ludGVkJTIwZWFycyUyMHdpdGglMjBkYXJrJTIwdGlwcyUyQyUyMGFuZCUyMGElMjBsb25nJTIwYnVzaHklMjB0YWlsJTIwZW5kaW5nJTIwaW4lMjB3aGl0ZS4lMjAuLi4=",highlighted:'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. ...',lang:"",wrap:!1});var g=e(y,6);s(g,{code:"cHJpbnQocGlwZS5ibG9ja3Muc3ViX2Jsb2NrcyU1QiUyMnByb21wdF91cHNhbXBsZXIlMjIlNUQuZG9jKQ==",highlighted:'<span class="hljs-built_in">print</span>(pipe.blocks.sub_blocks[<span class="hljs-string">"prompt_upsampler"</span>].doc)',lang:"python",wrap:!1});var b=e(g,2);s(b,{code:"JTIwJTIwSW5wdXRzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwcHJvbXB0JTIwKCU2MHN0ciU2MCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBUaGUlMjBlZGl0JTIwaW5zdHJ1Y3Rpb24lMjB0byUyMGV4cGFuZCUyMGludG8lMjB0aGUlMjBmdWxsJTIwY2FwdGlvbiUyMChvbmUlMjBwZXIlMjBjYWxsKS4lMEElMjAlMjAlMjAlMjAlMjAlMjBpbWFnZSUyMCglNjBJbWFnZSUyMCU3QyUyMGxpc3QlNjAlMkMlMjAqb3B0aW9uYWwqKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMFRoZSUyMHJlZmVyZW5jZSUyMGltYWdlKHMpJTIwb2YlMjB0aGUlMjBlZGl0JTJDJTIwYXQlMjBtb3N0JTIwMTAlM0IlMjB0aGUlMjBzYW1lJTIwb25lcyUyMHRoZSUyMHBpcGVsaW5lJTIwcmVjZWl2ZXMuJTBBJTIwJTIwJTIwJTIwJTIwJTIwYm94ZXMlMjAoJTYwbGlzdCU2MCUyQyUyMCpvcHRpb25hbCopJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwTGF5b3V0JTIwYm94ZXMlMkMlMjBlYWNoJTIwJTdCJ2lkJyUyQyUyMCdkZXNjJyUyQyUyMCdmcm9tJyUyQyUyMCdzcmNfYmJveCclMkMlMjAndGd0X2Jib3gnJTdEJTIwd2l0aCUyMHRoZSUyMGJveGVzJTIwYXMlMjAlNUJ5X21pbiUyQyUyMHhfbWluJTJDJTIweV9tYXglMkMlMjB4X21heCU1RCUyMGluJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMC0xJTNBJTIwLi4uJTBBJTIwJTIwJTIwJTIwJTIwJTIwbWF4X25ld190b2tlbnMlMjAoJTYwaW50JTYwJTJDJTIwKm9wdGlvbmFsKiUyQyUyMGRlZmF1bHRzJTIwdG8lMjAzNTg0KSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMFRoZSUyMG1vc3QlMjB0b2tlbnMlMjB0aGUlMjB1cHNhbXBsZXIlMjBtYXklMjBnZW5lcmF0ZSUyMGZvciUyMHRoZSUyMGNhcHRpb24uJTBBJTBBJTIwJTIwT3V0cHV0cyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMHByb21wdCUyMCglNjBzdHIlNjApJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwVGhlJTIwZnVsbCUyMGNhcHRpb24lMkMlMjByZXBsYWNpbmclMjB0aGUlMjByZXF1ZXN0Lg==",highlighted:` <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.`,lang:"",wrap:!1});var f=e(b,4);s(f,{code:"YmxvY2tzJTIwJTNEJTIwTW9kdWxhclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbi1iYXNlJTIyKS5ibG9ja3MlMEFwdXBfYmxvY2slMjAlM0QlMjBibG9ja3Muc3ViX2Jsb2Nrcy5wb3AoJTIycHJvbXB0X3Vwc2FtcGxlciUyMiklMEElMEFwdXAlMjAlM0QlMjBwdXBfYmxvY2suaW5pdF9waXBlbGluZSglMjJibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbi1iYXNlJTIyKSUwQXB1cC5sb2FkX2NvbXBvbmVudHMoZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiklMEFwdXAudG8oJTIyY3VkYSUyMiklMEFjYXB0aW9uJTIwJTNEJTIwcHVwKHByb21wdCUzRCUyMkElMjByZWQlMjBmb3glMjBpbiUyMGElMjBzbm93LWNvdmVyZWQlMjBmb3Jlc3QlMjBjbGVhcmluZyUyMGF0JTIwZ29sZGVuJTIwaG91ciUyMiUyQyUyMG91dHB1dCUzRCUyMnByb21wdCUyMiklMEElMEFwaXBlJTIwJTNEJTIwYmxvY2tzLmluaXRfcGlwZWxpbmUoJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4tYmFzZSUyMiklMEFwaXBlLmxvYWRfY29tcG9uZW50cyhkdHlwZSUzRCU3QiUyMnZhZSUyMiUzQSUyMHRvcmNoLmZsb2F0MzIlMkMlMjAlMjJkZWZhdWx0JTIyJTNBJTIwdG9yY2guYmZsb2F0MTYlN0QpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlM0RjYXB0aW9uJTJDJTIwZ2VuZXJhdG9yJTNEdG9yY2guR2VuZXJhdG9yKCkubWFudWFsX3NlZWQoMCklMkMlMjBvdXRwdXQlM0QlMjJpbWFnZXMlMjIpJTVCMCU1RA==",highlighted:`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>]`,lang:"python",wrap:!1});var J=e(f,4);l(J,{title:"Image-to-image",local:"image-to-image",headingTag:"h2"});var w=e(J,4);s(w,{code:"bmlnaHQlMjAlM0QlMjBwaXBlKCUwQSUyMCUyMCUyMCUyMHByb21wdCUzRCUyMnRoZSUyMHNhbWUlMjBzY2VuZSUyMGF0JTIwbmlnaHQlMjB1bmRlciUyMGElMjBmdWxsJTIwbW9vbiUyMiUyQyUwQSUyMCUyMCUyMCUyMGltYWdlJTNEaW1hZ2UlMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0R0b3JjaC5HZW5lcmF0b3IoKS5tYW51YWxfc2VlZCgwKSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dCUzRCU1QiUyMmltYWdlcyUyMiUyQyUyMCUyMnByb21wdCUyMiU1RCUyQyUwQSk=",highlighted:`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>], | |
| )`,lang:"python",wrap:!1});var j=e(w,4);s(j,{code:"Y29tYmluZWQlMjAlM0QlMjBwaXBlKCUwQSUyMCUyMCUyMCUyMHByb21wdCUzRCUyMnRoZSUyMGZveCUyMGZyb20lMjB0aGUlMjBmaXJzdCUyMGltYWdlJTIwc2l0dGluZyUyMG9uJTIwdGhlJTIwd29vZGVuJTIwYmVuY2glMjBmcm9tJTIwdGhlJTIwc2Vjb25kJTIwaW1hZ2UlMjIlMkMlMEElMjAlMjAlMjAlMjBpbWFnZSUzRCU1QmltYWdlJTJDJTIwYmVuY2glNUQlMkMlMEElMjAlMjAlMjAlMjBoZWlnaHQlM0Q3NjglMkMlMEElMjAlMjAlMjAlMjB3aWR0aCUzRDEzNjAlMkMlMEElMjAlMjAlMjAlMjBvdXRwdXQlM0QlMjJpbWFnZXMlMjIlMkMlMEEpJTVCMCU1RA==",highlighted:`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>]`,lang:"python",wrap:!1});var T=e(j,4);l(T,{title:"Layout control",local:"layout-control",headingTag:"h2"});var U=e(T,4);s(U,{code:"Ym94ZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMjJpZCUyMiUzQSUyMCUyMmJhbGxvb25fMSUyMiUyQyUyMCUyMmRlc2MlMjIlM0ElMjAlMjJhJTIwcmVkJTIwYW5kJTIweWVsbG93JTIwc3RyaXBlZCUyMGhvdC1haXIlMjBiYWxsb29uJTIyJTJDJTIwJTIyYmJveCUyMiUzQSUyMCU1QjAuMDglMkMlMjAwLjA2JTJDJTIwMC40OCUyQyUyMDAuMzglNUQlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMjJpZCUyMiUzQSUyMCUyMmJhbGxvb25fMiUyMiUyQyUyMCUyMmRlc2MlMjIlM0ElMjAlMjJhJTIwc21hbGwlMjBibHVlJTIwaG90LWFpciUyMGJhbGxvb24lMjIlMkMlMjAlMjJiYm94JTIyJTNBJTIwJTVCMC4yMCUyQyUyMDAuNjIlMkMlMjAwLjQyJTJDJTIwMC44MCU1RCU3RCUyQyUwQSU1RCUwQW91dCUyMCUzRCUyMHBpcGUocHJvbXB0JTNEJTIyaG90LWFpciUyMGJhbGxvb25zJTIwb3ZlciUyMGElMjBncmVlbiUyMHZhbGxleSUyMGF0JTIwc3VucmlzZSUyMiUyQyUyMGJveGVzJTNEYm94ZXMlMkMlMjBvdXRwdXQlM0QlNUIlMjJpbWFnZXMlMjIlMkMlMjAlMjJwcm9tcHQlMjIlNUQp",highlighted:`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>])`,lang:"python",wrap:!1});var I=e(U,4);s(I,{code:"Ym94ZXMlMjAlM0QlMjAlNUIlN0IlMjJpZCUyMiUzQSUyMCUyMmNhY3R1cyUyMiUyQyUyMCUyMmRlc2MlMjIlM0ElMjAlMjJhJTIwc21hbGwlMjBwb3R0ZWQlMjBjYWN0dXMlMjIlMkMlMjAlMjJmcm9tJTIyJTNBJTIwJTIydGFyZ2V0JTIyJTJDJTIwJTIyc3JjX2Jib3glMjIlM0ElMjBOb25lJTJDJTIwJTIydGd0X2Jib3glMjIlM0ElMjAlNUIwLjU1JTJDJTIwMC42MiUyQyUyMDAuODUlMkMlMjAwLjg1JTVEJTdEJTVEJTBBb3V0JTIwJTNEJTIwcGlwZShwcm9tcHQlM0QlMjJhZGQlMjBhJTIwc21hbGwlMjBwb3R0ZWQlMjBjYWN0dXMlMjBpbiUyMHRoZSUyMG1hcmtlZCUyMHNwb3QlMjIlMkMlMjBpbWFnZSUzRG11ZyUyQyUyMGJveGVzJTNEYm94ZXMlMkMlMjBvdXRwdXQlM0QlNUIlMjJpbWFnZXMlMjIlMkMlMjAlMjJwcm9tcHQlMjIlNUQpJTBBJTBBYm94ZXMlMjAlM0QlMjAlNUIlN0IlMjJpZCUyMiUzQSUyMCUyMmtuaWdodCUyMiUyQyUyMCUyMmRlc2MlMjIlM0ElMjAlMjJ0aGUlMjBrbmlnaHQlMjBmaWd1cmUlMjIlMkMlMjAlMjJmcm9tJTIyJTNBJTIwJTIycmVmX2ltYWdlXzAlMjIlMkMlMjAlMjJzcmNfYmJveCUyMiUzQSUyMCU1QjAuNTAlMkMlMjAwLjE1JTJDJTIwMC44NSUyQyUyMDAuMzUlNUQlMkMlMjAlMjJ0Z3RfYmJveCUyMiUzQSUyMCU1QjAuMTklMkMlMjAwLjA2JTJDJTIwMC41NCUyQyUyMDAuMjYlNUQlN0QlNUQlMEFvdXQlMjAlM0QlMjBwaXBlKHByb21wdCUzRCUyMm1vdmUlMjB0aGUlMjBrbmlnaHQlMjB1cCUyMGFuZCUyMHRvJTIwdGhlJTIwbGVmdCUyQyUyMGtlZXAlMjB0aGUlMjByZXN0JTIwdW5jaGFuZ2VkJTIyJTJDJTIwaW1hZ2UlM0RrbmlnaHQlMkMlMjBib3hlcyUzRGJveGVzJTJDJTIwb3V0cHV0JTNEJTVCJTIyaW1hZ2VzJTIyJTJDJTIwJTIycHJvbXB0JTIyJTVEKQ==",highlighted:`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>])`,lang:"python",wrap:!1});var Z=e(I,4);l(Z,{title:"Guidance scale",local:"guidance-scale",headingTag:"h2"});var k=e(Z,4);s(k,{code:"cGlwZS5ndWlkZXIlMjAlM0QlMjBwaXBlLmd1aWRlci5uZXcoZ3VpZGFuY2Vfc2NhbGUlM0Q1LjAp",highlighted:'pipe.guider = pipe.guider.new(guidance_scale=<span class="hljs-number">5.0</span>)',lang:"python",wrap:!1});var B=e(k,4);l(B,{title:"Step-distilled model",local:"step-distilled-model",headingTag:"h2"});var _=e(B,4);s(_,{code:"cGlwZSUyMCUzRCUyME1vZHVsYXJQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4lMjIpJTBBcGlwZS5sb2FkX2NvbXBvbmVudHMoZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiklMEFwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCUzRHByb21wdCUyQyUyMGdlbmVyYXRvciUzRHRvcmNoLkdlbmVyYXRvcigpLm1hbnVhbF9zZWVkKDApJTJDJTIwb3V0cHV0JTNEJTIyaW1hZ2VzJTIyKSU1QjAlNUQ=",highlighted:`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>]`,lang:"python",wrap:!1});var x=e(_,4);l(x,{title:"Reproducible generation",local:"reproducible-generation",headingTag:"h2"});var G=e(x,4);s(G,{code:"aGVpZ2h0JTJDJTIwd2lkdGglMjAlM0QlMjAxMDI0JTJDJTIwMTAyNCUwQWglMkMlMjB3JTIwJTNEJTIwaGVpZ2h0JTIwJTJGJTJGJTIwMTYlMkMlMjB3aWR0aCUyMCUyRiUyRiUyMDE2JTBBJTBBbm9pc2UlMjAlM0QlMjB0b3JjaC5yYW5kbigoaCUyMColMjB3JTJDJTIwMTI4KSUyQyUyMGdlbmVyYXRvciUzRHRvcmNoLkdlbmVyYXRvcigpLm1hbnVhbF9zZWVkKDApKS50byh0b3JjaC5iZmxvYXQxNiklMEFsYXRlbnRzJTIwJTNEJTIwbm9pc2UuVC5yZXNoYXBlKDElMkMlMjAxMjglMkMlMjBoJTJDJTIwdyklMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTNEcHJvbXB0JTJDJTIwbGF0ZW50cyUzRGxhdGVudHMlMkMlMjBoZWlnaHQlM0RoZWlnaHQlMkMlMjB3aWR0aCUzRHdpZHRoJTJDJTIwb3V0cHV0JTNEJTIyaW1hZ2VzJTIyKSU1QjAlNUQ=",highlighted:`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>]`,lang:"python",wrap:!1});var W=e(G,2);l(W,{title:"Workflows",local:"workflows",headingTag:"h2"});var v=e(W,4);s(v,{code:"ZnJvbSUyMGRpZmZ1c2Vycy5tb2R1bGFyX3BpcGVsaW5lcyUyMGltcG9ydCUyMEZsdXgzQXV0b0Jsb2NrcyUwQSUwQXByaW50KEZsdXgzQXV0b0Jsb2NrcygpLmF2YWlsYWJsZV93b3JrZmxvd3MpJTBBJTIzJTIwJTVCJTIydGV4dDJpbWFnZSUyMiUyQyUyMCUyMmltYWdlX2NvbmRpdGlvbmVkJTIyJTVEJTBBJTBBdDJpJTIwJTNEJTIwTW9kdWxhclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbi1iYXNlJTIyJTJDJTIwd29ya2Zsb3clM0QlMjJ0ZXh0MmltYWdlJTIyKSUwQXByaW50KHQyaS5ibG9ja3MuZG9jKQ==",highlighted:`<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)`,lang:"python",wrap:!1});var C=e(v,2);l(C,{title:"Per-step callbacks",local:"per-step-callbacks",headingTag:"h2"});var Q=e(C,4);s(Q,{code:"YmxvY2tzJTIwJTNEJTIwRmx1eDNBdXRvQmxvY2tzKCklMjAlMjAlMjMlMjBvciUyMEZsdXgzRGlzdGlsbGVkQXV0b0Jsb2NrcyUwQWZvciUyMGxvb3AlMjBpbiUyMHdhbGtfZGVub2lzZV9sb29wcyhibG9ja3MpJTNBJTBBJTIwJTIwJTIwJTIwbG9vcC5zdWJfYmxvY2tzJTVCJTIyY2FsbGJhY2slMjIlNUQlMjAlM0QlMjBDYWxsYmFja09uU3RlcEVuZCgpJTBBcGlwZSUyMCUzRCUyMGJsb2Nrcy5pbml0X3BpcGVsaW5lKCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGZmx1eC0zLWltYWdlLWtsZWluLWJhc2UlMjIpJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCUzRGNhcHRpb24lMkMlMjBjYWxsYmFja19vbl9zdGVwX2VuZCUzRG15X2NhbGxiYWNrJTJDJTIwb3V0cHV0JTNEJTIyaW1hZ2VzJTIyKSU1QjAlNUQ=",highlighted:`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>]`,lang:"python",wrap:!1});var N=e(Q,4);l(N,{title:"Memory",local:"memory",headingTag:"h2"});var F=e(N,4);s(F,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvbXBvbmVudHNNYW5hZ2VyJTJDJTIwTW9kdWxhclBpcGVsaW5lJTBBJTBBbWFuYWdlciUyMCUzRCUyMENvbXBvbmVudHNNYW5hZ2VyKCklMEFwaXBlJTIwJTNEJTIwTW9kdWxhclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbi1iYXNlJTIyJTJDJTIwY29tcG9uZW50c19tYW5hZ2VyJTNEbWFuYWdlciklMEFwaXBlLmxvYWRfY29tcG9uZW50cyhkdHlwZSUzRCU3QiUyMnZhZSUyMiUzQSUyMHRvcmNoLmZsb2F0MzIlMkMlMjAlMjJkZWZhdWx0JTIyJTNBJTIwdG9yY2guYmZsb2F0MTYlN0QpJTBBbWFuYWdlci5lbmFibGVfYXV0b19jcHVfb2ZmbG9hZChkZXZpY2UlM0QlMjJjdWRhJTIyKQ==",highlighted:`<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>)`,lang:"python",wrap:!1});var Y=e(F,2);l(Y,{title:"Single-file loading",local:"single-file-loading",headingTag:"h2"});var q=e(Y,4);s(q,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eDNUcmFuc2Zvcm1lcjJETW9kZWwlMkMlMjBNb2R1bGFyUGlwZWxpbmUlMEElMEF0cmFuc2Zvcm1lciUyMCUzRCUyMEZsdXgzVHJhbnNmb3JtZXIyRE1vZGVsLmZyb21fc2luZ2xlX2ZpbGUoJTBBJTIwJTIwJTIwJTIwJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmJsYWNrLWZvcmVzdC1sYWJzJTJGZmx1eC0zLWltYWdlLWtsZWluLWJhc2UlMkZibG9iJTJGbWFpbiUyRm1vZGVsLnNhZmV0ZW5zb3JzJTIyJTJDJTBBJTIwJTIwJTIwJTIwY29uZmlnJTNEJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4tYmFzZSUyMiUyQyUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTBBJTIwJTIwJTIwJTIwZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSklMEElMEFwaXBlJTIwJTNEJTIwTW9kdWxhclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbi1iYXNlJTIyKSUwQXBpcGUubG9hZF9jb21wb25lbnRzKGR0eXBlJTNEJTdCJTIydmFlJTIyJTNBJTIwdG9yY2guZmxvYXQzMiUyQyUyMCUyMmRlZmF1bHQlMjIlM0ElMjB0b3JjaC5iZmxvYXQxNiU3RCklMEFwaXBlLnVwZGF0ZV9jb21wb25lbnRzKHRyYW5zZm9ybWVyJTNEdHJhbnNmb3JtZXIpJTBBcGlwZS50byglMjJjdWRhJTIyKQ==",highlighted:`<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>)`,lang:"python",wrap:!1});var X=e(q,6);s(X,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEJGTFF1YW50aXphdGlvbkNvbmZpZyUwQSUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwRmx1eDNUcmFuc2Zvcm1lcjJETW9kZWwuZnJvbV9zaW5nbGVfZmlsZSglMEElMjAlMjAlMjAlMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4tYmFzZSUyRmJsb2IlMkZtYWluJTJGdmFyaWFudHMlMkZudmZwNCUyRm1vZGVsLnNhZmV0ZW5zb3JzJTIyJTJDJTBBJTIwJTIwJTIwJTIwY29uZmlnJTNEJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4tYmFzZSUyMiUyQyUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTBBJTIwJTIwJTIwJTIwcXVhbnRpemF0aW9uX2NvbmZpZyUzREJGTFF1YW50aXphdGlvbkNvbmZpZyhjb21wdXRlX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTJDJTBBJTIwJTIwJTIwJTIwZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSk=",highlighted:`<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, | |
| )`,lang:"python",wrap:!1});var R=e(X,4);s(R,{code:"dHJhbnNmb3JtZXIlMjAlM0QlMjBGbHV4M1RyYW5zZm9ybWVyMkRNb2RlbC5mcm9tX3NpbmdsZV9maWxlKCUwQSUyMCUyMCUyMCUyMCUyMmh0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbiUyRmJsb2IlMkZtYWluJTJGdmFyaWFudHMlMkZudmZwNCUyRm1vZGVsLnNhZmV0ZW5zb3JzJTIyJTJDJTBBJTIwJTIwJTIwJTIwY29uZmlnJTNEJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZmbHV4LTMtaW1hZ2Uta2xlaW4lMjIlMkMlMEElMjAlMjAlMjAlMjBzdWJmb2xkZXIlM0QlMjJ0cmFuc2Zvcm1lciUyMiUyQyUwQSUyMCUyMCUyMCUyMHF1YW50aXphdGlvbl9jb25maWclM0RCRkxRdWFudGl6YXRpb25Db25maWcoY29tcHV0ZV9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUyQyUwQSUyMCUyMCUyMCUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMEEp",highlighted:`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, | |
| )`,lang:"python",wrap:!1});var V=e(R,2);l(V,{title:"Flux3ModularPipeline",local:"diffusers.Flux3ModularPipeline",headingTag:"h2"});var i=e(V,2),O=t(i);o(O,{name:"class diffusers.Flux3ModularPipeline",anchor:"diffusers.Flux3ModularPipeline",source:"https://github.com/huggingface/diffusers/blob/vr_15078/src/diffusers/modular_pipelines/flux3/modular_pipeline.py#L24",parameters:[{name:"blocks",val:": diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None"},{name:"pretrained_model_name_or_path",val:": str | os.PathLike | None = None"},{name:"components_manager",val:": diffusers.modular_pipelines.components_manager.ComponentsManager | None = None"},{name:"collection",val:": str | None = None"},{name:"workflow",val:": str | None = None"},{name:"modular_config_dict",val:": dict[str, typing.Any] | None = None"},{name:"config_dict",val:": dict[str, typing.Any] | None = None"},{name:"**kwargs",val:""}]}),a(2),n(i);var A=e(i,2);l(A,{title:"Flux3AutoBlocks",local:"diffusers.Flux3AutoBlocks",headingTag:"h2"});var p=e(A,2),$=t(p);o($,{name:"class diffusers.Flux3AutoBlocks",anchor:"diffusers.Flux3AutoBlocks",source:"https://github.com/huggingface/diffusers/blob/vr_15078/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3.py#L331",parameters:[]}),a(12),n(p);var z=e(p,2);l(z,{title:"Flux3DistilledAutoBlocks",local:"diffusers.Flux3DistilledAutoBlocks",headingTag:"h2"});var r=e(z,2),ee=t(r);o(ee,{name:"class diffusers.Flux3DistilledAutoBlocks",anchor:"diffusers.Flux3DistilledAutoBlocks",source:"https://github.com/huggingface/diffusers/blob/vr_15078/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3_distilled.py#L258",parameters:[]}),a(12),n(r);var E=e(r,2);l(E,{title:"Flux3DistilledModularPipeline",local:"diffusers.Flux3DistilledModularPipeline",headingTag:"h2"});var d=e(E,2),se=t(d);o(se,{name:"class diffusers.Flux3DistilledModularPipeline",anchor:"diffusers.Flux3DistilledModularPipeline",source:"https://github.com/huggingface/diffusers/blob/vr_15078/src/diffusers/modular_pipelines/flux3/modular_pipeline.py#L52",parameters:[{name:"blocks",val:": diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None"},{name:"pretrained_model_name_or_path",val:": str | os.PathLike | None = None"},{name:"components_manager",val:": diffusers.modular_pipelines.components_manager.ComponentsManager | None = None"},{name:"collection",val:": str | None = None"},{name:"workflow",val:": str | None = None"},{name:"modular_config_dict",val:": dict[str, typing.Any] | None = None"},{name:"config_dict",val:": dict[str, typing.Any] | None = None"},{name:"**kwargs",val:""}]}),a(2),n(d);var le=e(d,2);te(le,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/flux3.md"}),a(2),L(P,c),de()}export{ge as component}; | |
Xet Storage Details
- Size:
- 51.5 kB
- Xet hash:
- 4fe165166fa5ac5283668f1ddbb6d6edbc06ea6e1d7680090df6d09efcc9bfec
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.