Buckets:
| import"../chunks/DsnmJJEf.js";import{i as $,h as ee,C as oe,H as n,a as r,D as o,E as te,s as ae}from"../chunks/BtE7mKSK.js";import{p as ne,o as se,s as e,f as W,a as b,b as re,c as t,d as y,r as a,n as s}from"../chunks/jDjavuwI.js";import{E as ie}from"../chunks/SrSJA0zO.js";const le='{"title":"Krea 2","local":"krea-2","sections":[{"title":"Text-to-image","local":"text-to-image","sections":[],"depth":2},{"title":"Krea2Pipeline","local":"diffusers.Krea2Pipeline","sections":[],"depth":2},{"title":"Krea2PipelineOutput","local":"diffusers.pipelines.krea2.Krea2PipelineOutput","sections":[],"depth":2},{"title":"Modular","local":"modular","sections":[],"depth":2},{"title":"Krea2ModularPipeline","local":"diffusers.Krea2ModularPipeline","sections":[],"depth":2},{"title":"Krea2AutoBlocks","local":"diffusers.Krea2AutoBlocks","sections":[],"depth":2},{"title":"Krea2TurboModularPipeline","local":"diffusers.Krea2TurboModularPipeline","sections":[],"depth":2},{"title":"Krea2TurboAutoBlocks","local":"diffusers.Krea2TurboAutoBlocks","sections":[],"depth":2}],"depth":1}';var de=y('<meta name="hf:doc:metadata"/>'),ce=y("<p>Examples:</p> <!>",1),pe=y(`<p></p> <!> <!> <p>Krea 2 (K2) is a flow-matching text-to-image model built around a single-stream MMDiT with grouped-query attention. A | |
| Qwen3-VL text encoder provides the conditioning: instead of the last hidden state, hidden states from twelve decoder | |
| layers are tapped per token and fused inside the transformer by a small text-fusion stage. Images are decoded with the | |
| Qwen-Image VAE.</p> <p>Two checkpoints are released, sharing the same architecture but with different recommended sampler settings:</p> <ul><li><strong>Base (midtrain)</strong> — use the full sampler with classifier-free guidance: <code>num_inference_steps=28</code>, <code>guidance_scale=4.5</code>.</li> <li><strong>TDM (distilled)</strong> — distilled for few-step sampling, run with <code>num_inference_steps=8</code> and guidance disabled | |
| (<code>guidance_scale=0.0</code>).</li></ul> <p><code>guidance_scale</code> follows the Krea 2 convention: the velocity is computed as <code>cond + guidance_scale * (cond - uncond)</code> and guidance is enabled whenever <code>guidance_scale > 0</code> (this equals the usual CFG formulation with scale <code>1 + guidance_scale</code>).</p> <!> <!> <p>We additionally provide an example for using Krea2 Turbo :</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>The Krea 2 pipeline for text-to-image generation.</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>Function invoked when calling the pipeline for generation.</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"><!></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>Tokenize <code>prompt</code> into the fixed-length Krea 2 layout and tap the selected encoder hidden states.</p> <p>Returns a <code>(hidden_states, attention_mask)</code> tuple of shapes <code>(batch_size, text_seq_len, num_text_layers, text_hidden_dim)</code> and <code>(batch_size, text_seq_len)</code> (bool).</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>Build the <code>(text_seq_len + grid_height * grid_width, 3)</code> rotary coordinates for the combined sequence: | |
| text tokens sit at the origin, image tokens carry their <code>(0, h, w)</code> latent-grid coordinates.</p></div></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>Output class for the Krea 2 pipeline.</p></div> <!> <p>Krea 2 is also available as a <a href="../../modular_diffusers/overview">modular pipeline</a>. Classifier-free guidance is | |
| configured through the <code>guider</code> component rather than a <code>guidance_scale</code> call argument. Krea 2 uses cond-anchored CFG, | |
| which is <a href="/docs/diffusers/pr_14340/en/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance">ClassifierFreeGuidance</a> with <code>use_original_formulation=True</code>.</p> <!> <p>We additionally provide an example for using Krea2 Turbo. The distilled checkpoint maps to its own set of blocks | |
| (<a href="/docs/diffusers/pr_14340/en/api/pipelines/krea2#diffusers.Krea2TurboAutoBlocks">Krea2TurboAutoBlocks</a>): it runs guidance-free (no <code>guider</code>), takes no negative prompt, and samples in a few steps. <code>ModularPipeline.from_pretrained</code> picks the turbo blocks automatically from the checkpoint’s <code>is_distilled</code> config, so | |
| no guidance configuration is needed:</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 Krea 2.</p> <blockquote class="warning"><p>> This is an experimental feature!</p></blockquote></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 Modular pipeline for text-to-image generation using Krea 2: encode text -> core denoise (symmetric CFG) -> | |
| decode.</p> <p>Supported workflows:</p> <ul><li><code>text2image</code>: requires <code>prompt</code></li></ul> <p>Components: | |
| text_encoder (<code>Qwen3VLModel</code>): The Qwen3-VL text encoder. tokenizer (<code>AutoTokenizer</code>): The tokenizer paired | |
| with the text encoder. guider (<code>ClassifierFreeGuidance</code>) transformer (<code>Krea2Transformer2DModel</code>) scheduler | |
| (<code>FlowMatchEulerDiscreteScheduler</code>) vae (<code>AutoencoderKLQwenImage</code>) image_processor (<code>VaeImageProcessor</code>)</p> <p>Inputs: | |
| prompt (<code>str</code>): | |
| The prompt or prompts to guide image generation. | |
| negative_prompt (<code>str</code>, <em>optional</em>): | |
| The negative prompt(s) for CFG. | |
| max_sequence_length (<code>int</code>, <em>optional</em>, defaults to 512): | |
| Maximum sequence length for prompt encoding. | |
| num_images_per_prompt (<code>int</code>, <em>optional</em>, defaults to 1): | |
| The number of images to generate per prompt. | |
| latents (<code>Tensor</code>, <em>optional</em>): | |
| Pre-generated noisy latents for image generation. | |
| height (<code>int</code>, <em>optional</em>, defaults to 1024): | |
| The height in pixels of the generated image. | |
| width (<code>int</code>, <em>optional</em>, defaults to 1024): | |
| The width in pixels of the generated image. | |
| generator (<code>Generator</code>, <em>optional</em>): | |
| Torch generator for deterministic generation. | |
| num_inference_steps (<code>int</code>, <em>optional</em>, defaults to 28): | |
| The number of denoising steps. | |
| sigmas (<code>list</code>, <em>optional</em>): | |
| Custom sigma schedule (defaults to a linear ramp). | |
| attention_kwargs (<code>dict</code>, <em>optional</em>): | |
| Additional kwargs for attention processors. | |
| output_type (<code>str</code>, <em>optional</em>, defaults to pil): | |
| Output format: ‘pil’, ‘np’, ‘pt’.</p> <p>Outputs: | |
| images (<code>list</code>): | |
| Generated images.</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 distilled Krea 2 turbo (TDM) checkpoint. It runs without classifier-free guidance, so it | |
| takes no negative prompt and has no guider.</p> <blockquote class="warning"><p>> This is an experimental feature!</p></blockquote></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 Modular pipeline for text-to-image generation using the distilled Krea 2 turbo checkpoint: encode text -> core | |
| denoise (guidance-free) -> decode.</p> <p>Supported workflows:</p> <ul><li><code>text2image</code>: requires <code>prompt</code></li></ul> <p>Components: | |
| text_encoder (<code>Qwen3VLModel</code>): The Qwen3-VL text encoder. tokenizer (<code>AutoTokenizer</code>): The tokenizer paired | |
| with the text encoder. transformer (<code>Krea2Transformer2DModel</code>) scheduler (<code>FlowMatchEulerDiscreteScheduler</code>) | |
| vae (<code>AutoencoderKLQwenImage</code>) image_processor (<code>VaeImageProcessor</code>)</p> <p>Inputs: | |
| prompt (<code>str</code>): | |
| The prompt or prompts to guide image generation. | |
| max_sequence_length (<code>int</code>, <em>optional</em>, defaults to 512): | |
| Maximum sequence length for prompt encoding. | |
| num_images_per_prompt (<code>int</code>, <em>optional</em>, defaults to 1): | |
| The number of images to generate per prompt. | |
| latents (<code>Tensor</code>, <em>optional</em>): | |
| Pre-generated noisy latents for image generation. | |
| height (<code>int</code>, <em>optional</em>, defaults to 1024): | |
| The height in pixels of the generated image. | |
| width (<code>int</code>, <em>optional</em>, defaults to 1024): | |
| The width in pixels of the generated image. | |
| generator (<code>Generator</code>, <em>optional</em>): | |
| Torch generator for deterministic generation. | |
| num_inference_steps (<code>int</code>, <em>optional</em>, defaults to 8): | |
| The number of denoising steps. | |
| sigmas (<code>list</code>, <em>optional</em>): | |
| Custom sigma schedule (defaults to a linear ramp). | |
| attention_kwargs (<code>dict</code>, <em>optional</em>): | |
| Additional kwargs for attention processors. | |
| output_type (<code>str</code>, <em>optional</em>, defaults to pil): | |
| Output format: ‘pil’, ‘np’, ‘pt’.</p> <p>Outputs: | |
| images (<code>list</code>): | |
| Generated images.</p></div> <!> <p></p>`,1);function _e(V,S){ne(S,!1),se(()=>{new URLSearchParams(window.location.search).get("fw")}),$();var M=pe();ee("1j2cvz3",i=>{var f=de();ae(f,"content",le),b(i,f)});var w=e(W(M),2);oe(w,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var T=e(w,2);n(T,{title:"Krea 2",local:"krea-2",headingTag:"h1"});var v=e(T,10);n(v,{title:"Text-to-image",local:"text-to-image",headingTag:"h2"});var J=e(v,2);r(J,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwS3JlYTJQaXBlbGluZSUwQSUwQSUyMyUyMExvYWQlMjBmcm9tJTIwYSUyMGxvY2FsJTIwZGlyZWN0b3J5JTIwcHJvZHVjZWQlMjBieSUyMHRoZSUyMEtyZWElMjAyJTIwY29udmVyc2lvbiUyMChubyUyMGh1YiUyMHJlcG8lMjB5ZXQpLiUwQXBpcGUlMjAlM0QlMjBLcmVhMlBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJrcmVhJTJGS3JlYS0yLVJhdyUyMiUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMmElMjBmb3glMjBpbiUyMHRoZSUyMHNub3clMjIlMEFpbWFnZSUyMCUzRCUyMHBpcGUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwaGVpZ2h0JTNEMTAyNCUyQyUwQSUyMCUyMCUyMCUyMHdpZHRoJTNEMTAyNCUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyOCUyQyUwQSUyMCUyMCUyMCUyMGd1aWRhbmNlX3NjYWxlJTNENC41JTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEdG9yY2guR2VuZXJhdG9yKCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKDApJTJDJTBBKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJrcmVhMi5wbmclMjIp",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Krea2Pipeline | |
| <span class="hljs-comment"># Load from a local directory produced by the Krea 2 conversion (no hub repo yet).</span> | |
| pipe = Krea2Pipeline.from_pretrained(<span class="hljs-string">"krea/Krea-2-Raw"</span>, dtype=torch.bfloat16) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| prompt = <span class="hljs-string">"a fox in the snow"</span> | |
| image = pipe( | |
| prompt, | |
| height=<span class="hljs-number">1024</span>, | |
| width=<span class="hljs-number">1024</span>, | |
| num_inference_steps=<span class="hljs-number">28</span>, | |
| guidance_scale=<span class="hljs-number">4.5</span>, | |
| generator=torch.Generator(<span class="hljs-string">"cuda"</span>).manual_seed(<span class="hljs-number">0</span>), | |
| ).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"krea2.png"</span>)`,lang:"python",wrap:!1});var k=e(J,4);r(k,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwS3JlYTJQaXBlbGluZSUwQSUwQXBpcGUlMjAlM0QlMjBLcmVhMlBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJrcmVhJTJGS3JlYS0yLVR1cmJvJTIyJTJDJTIwZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiklMEFwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKCUwQSUyMCUyMCUyMCUyMCUyMmElMjBmb3glMjBpbiUyMHRoZSUyMHNub3clMjIlMkMlMEElMjAlMjAlMjAlMjBoZWlnaHQlM0QxMDI0JTJDJTBBJTIwJTIwJTIwJTIwd2lkdGglM0QxMDI0JTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDglMkMlMEElMjAlMjAlMjAlMjBndWlkYW5jZV9zY2FsZSUzRDAuMCUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRHRvcmNoLkdlbmVyYXRvciglMjJjdWRhJTIyKS5tYW51YWxfc2VlZCgwKSUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIya3JlYTJfdHVyYm8ucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Krea2Pipeline | |
| pipe = Krea2Pipeline.from_pretrained(<span class="hljs-string">"krea/Krea-2-Turbo"</span>, dtype=torch.bfloat16) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| image = pipe( | |
| <span class="hljs-string">"a fox in the snow"</span>, | |
| height=<span class="hljs-number">1024</span>, | |
| width=<span class="hljs-number">1024</span>, | |
| num_inference_steps=<span class="hljs-number">8</span>, | |
| guidance_scale=<span class="hljs-number">0.0</span>, | |
| generator=torch.Generator(<span class="hljs-string">"cuda"</span>).manual_seed(<span class="hljs-number">0</span>), | |
| ).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"krea2_turbo.png"</span>)`,lang:"python",wrap:!1});var U=e(k,2);n(U,{title:"Krea2Pipeline",local:"diffusers.Krea2Pipeline",headingTag:"h2"});var l=e(U,2),j=t(l);o(j,{name:"class diffusers.Krea2Pipeline",anchor:"diffusers.Krea2Pipeline",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/pipelines/krea2/pipeline_krea2.py#L134",parameters:[{name:"scheduler",val:": FlowMatchEulerDiscreteScheduler"},{name:"vae",val:": AutoencoderKLQwenImage"},{name:"text_encoder",val:": Qwen3VLModel"},{name:"tokenizer",val:": AutoTokenizer"},{name:"transformer",val:": Krea2Transformer2DModel"},{name:"text_encoder_select_layers",val:": tuple[int, ...] | list[int] | None = None"},{name:"is_distilled",val:": bool = False"},{name:"patch_size",val:": int = 2"}],parametersDescription:[{anchor:"diffusers.Krea2Pipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/pr_14340/en/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler">FlowMatchEulerDiscreteScheduler</a>) — | |
| Euler flow-matching scheduler. The Krea 2 sigma schedule is the resolution-aware exponential time shift, so | |
| the scheduler config is expected to set <code>use_dynamic_shifting=True</code> together with the Krea 2 shift | |
| parameters (<code>base_shift=0.5</code>, <code>max_shift=1.15</code>, <code>base_image_seq_len=256</code>, <code>max_image_seq_len=6400</code>).`,name:"scheduler"},{anchor:"diffusers.Krea2Pipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/pr_14340/en/api/models/autoencoderkl_qwenimage#diffusers.AutoencoderKLQwenImage">AutoencoderKLQwenImage</a>) — | |
| The Qwen-Image variational auto-encoder (f8, 16 latent channels) used to decode latents to images.`,name:"vae"},{anchor:"diffusers.Krea2Pipeline.text_encoder",description:`<strong>text_encoder</strong> (<a href="https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel" rel="nofollow">PreTrainedModel</a>) — | |
| A Qwen3-VL model (e.g. <code>Qwen3VLModel</code> of <code>Qwen/Qwen3-VL-4B-Instruct</code>). The pipeline consumes a stack of | |
| hidden states tapped from several decoder layers rather than the last hidden state.`,name:"text_encoder"},{anchor:"diffusers.Krea2Pipeline.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer" rel="nofollow">AutoTokenizer</a>) — | |
| The tokenizer paired with the text encoder.`,name:"tokenizer"},{anchor:"diffusers.Krea2Pipeline.transformer",description:`<strong>transformer</strong> (<a href="/docs/diffusers/pr_14340/en/api/models/krea2_transformer2d#diffusers.Krea2Transformer2DModel">Krea2Transformer2DModel</a>) — | |
| The Krea 2 single-stream MMDiT that predicts the flow-matching velocity.`,name:"transformer"},{anchor:"diffusers.Krea2Pipeline.text_encoder_select_layers",description:`<strong>text_encoder_select_layers</strong> (<code>tuple[int, ...]</code>, <em>optional</em>) — | |
| Indices into the text encoder’s <code>hidden_states</code> tuple (0 is the embedding output) whose states are stacked | |
| per token as the transformer’s text conditioning. Must have <code>transformer.config.num_text_layers</code> entries.`,name:"text_encoder_select_layers"},{anchor:"diffusers.Krea2Pipeline.is_distilled",description:`<strong>is_distilled</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether the transformer is the few-step distilled (TDM/turbo) checkpoint. When <code>True</code> a fixed timestep | |
| shift <code>mu=1.15</code> is used; otherwise <code>mu</code> is computed from the image resolution.`,name:"is_distilled"},{anchor:"diffusers.Krea2Pipeline.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 2) — | |
| Side length of the square patches the latents are packed into before entering the transformer. The | |
| effective pixel-to-token downsampling factor is <code>vae_scale_factor * patch_size</code>.`,name:"patch_size"}]});var d=e(j,4),x=t(d);o(x,{name:"__call__",anchor:"diffusers.Krea2Pipeline.__call__",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/pipelines/krea2/pipeline_krea2.py#L445",parameters:[{name:"prompt",val:": str | list[str] | None = None"},{name:"negative_prompt",val:": str | list[str] | None = None"},{name:"height",val:": int = 1024"},{name:"width",val:": int = 1024"},{name:"num_inference_steps",val:": int = 28"},{name:"sigmas",val:": list[float] | None = None"},{name:"guidance_scale",val:": float = 4.5"},{name:"num_images_per_prompt",val:": int = 1"},{name:"generator",val:": typing.Union[torch.Generator, list[torch.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.Tensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"prompt_embeds_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"negative_prompt_embeds_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"output_type",val:": str | None = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback_on_step_end",val:": typing.Optional[typing.Callable[[int, int, dict], NoneType]] = None"},{name:"callback_on_step_end_tensor_inputs",val:": list = ['latents']"},{name:"attention_kwargs",val:": dict[str, typing.Any] | None = None"},{name:"max_sequence_length",val:": int = 512"}],parametersDescription:[{anchor:"diffusers.Krea2Pipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>list[str]</code>, <em>optional</em>) — | |
| The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.`,name:"prompt"},{anchor:"diffusers.Krea2Pipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>list[str]</code>, <em>optional</em>) — | |
| The prompt or prompts not to guide the image generation. Ignored when <code>guidance_scale <= 0</code>; defaults | |
| to an empty prompt when guidance is enabled.`,name:"negative_prompt"},{anchor:"diffusers.Krea2Pipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, defaults to 1024) — | |
| The height in pixels of the generated image. Rounded up to a multiple of 16 if needed.`,name:"height"},{anchor:"diffusers.Krea2Pipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, defaults to 1024) — | |
| The width in pixels of the generated image. Rounded up to a multiple of 16 if needed.`,name:"width"},{anchor:"diffusers.Krea2Pipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, defaults to 28) — | |
| The number of denoising steps. Use 28 for the base (midtrain) checkpoint and 8 for the few-step | |
| distilled (TDM) checkpoint.`,name:"num_inference_steps"},{anchor:"diffusers.Krea2Pipeline.__call__.sigmas",description:`<strong>sigmas</strong> (<code>list[float]</code>, <em>optional</em>) — | |
| Custom sigmas for the scheduler. If not defined, the default <code>linspace(1.0, 1/num_inference_steps, num_inference_steps)</code> grid is used (the resolution-aware shift is applied inside the scheduler).`,name:"sigmas"},{anchor:"diffusers.Krea2Pipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, defaults to 4.5) — | |
| Classifier-free guidance scale, following the Krea 2 convention: the velocity is computed as <code>cond + guidance_scale * (cond - uncond)</code> and guidance is enabled whenever <code>guidance_scale > 0</code> (this equals | |
| the usual CFG formulation with scale <code>1 + guidance_scale</code>). Set to <code>0.0</code> to disable (e.g. for the TDM | |
| checkpoint).`,name:"guidance_scale"},{anchor:"diffusers.Krea2Pipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, defaults to 1) — | |
| The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.Krea2Pipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>list[torch.Generator]</code>, <em>optional</em>) — | |
| One or more <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a> to | |
| make generation deterministic.`,name:"generator"},{anchor:"diffusers.Krea2Pipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Pre-generated noisy latents in packed form <code>(batch_size, image_seq_len, in_channels)</code>, sampled from a | |
| Gaussian distribution, to be used as inputs for image generation.`,name:"latents"},{anchor:"diffusers.Krea2Pipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Pre-generated text embeddings of shape <code>(batch_size, text_seq_len, num_text_layers, text_hidden_dim)</code>. | |
| If not provided, embeddings are generated from <code>prompt</code>.`,name:"prompt_embeds"},{anchor:"diffusers.Krea2Pipeline.__call__.prompt_embeds_mask",description:`<strong>prompt_embeds_mask</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Boolean mask for <code>prompt_embeds</code>; required when <code>prompt_embeds</code> is passed.`,name:"prompt_embeds_mask"},{anchor:"diffusers.Krea2Pipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Pre-generated negative text embeddings; same layout as <code>prompt_embeds</code>.`,name:"negative_prompt_embeds"},{anchor:"diffusers.Krea2Pipeline.__call__.negative_prompt_embeds_mask",description:`<strong>negative_prompt_embeds_mask</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Boolean mask for <code>negative_prompt_embeds</code>; required when <code>negative_prompt_embeds</code> is passed.`,name:"negative_prompt_embeds_mask"},{anchor:"diffusers.Krea2Pipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>"pil"</code>) — | |
| The output format of the generated image. Choose between <code>"pil"</code>, <code>"np"</code>, <code>"pt"</code> or <code>"latent"</code>.`,name:"output_type"},{anchor:"diffusers.Krea2Pipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether or not to return a <a href="/docs/diffusers/pr_14340/en/api/pipelines/krea2#diffusers.pipelines.krea2.Krea2PipelineOutput">Krea2PipelineOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"diffusers.Krea2Pipeline.__call__.callback_on_step_end",description:`<strong>callback_on_step_end</strong> (<code>Callable</code>, <em>optional</em>) — | |
| A function that is called at the end of each denoising step with <code>callback_on_step_end(self, step, timestep, callback_kwargs)</code>.`,name:"callback_on_step_end"},{anchor:"diffusers.Krea2Pipeline.__call__.callback_on_step_end_tensor_inputs",description:`<strong>callback_on_step_end_tensor_inputs</strong> (<code>list[str]</code>, <em>optional</em>, defaults to <code>["latents"]</code>) — | |
| The list of tensor inputs for the <code>callback_on_step_end</code> function. Must be a subset of | |
| <code>._callback_tensor_inputs</code>.`,name:"callback_on_step_end_tensor_inputs"},{anchor:"diffusers.Krea2Pipeline.__call__.attention_kwargs",description:`<strong>attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) — | |
| A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined under | |
| <code>self.processor</code> in | |
| <a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py" rel="nofollow">diffusers.models.attention_processor</a>.`,name:"attention_kwargs"},{anchor:"diffusers.Krea2Pipeline.__call__.max_sequence_length",description:`<strong>max_sequence_length</strong> (<code>int</code>, defaults to 512) — | |
| Fixed text sequence length consumed by the transformer; prompts are padded or truncated to it.`,name:"max_sequence_length"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><a | |
| href="/docs/diffusers/pr_14340/en/api/pipelines/krea2#diffusers.pipelines.krea2.Krea2PipelineOutput" | |
| >Krea2PipelineOutput</a> if | |
| <code>return_dict</code> is True, otherwise a <code>tuple</code>, whose first element is a list with the generated images.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><a | |
| href="/docs/diffusers/pr_14340/en/api/pipelines/krea2#diffusers.pipelines.krea2.Krea2PipelineOutput" | |
| >Krea2PipelineOutput</a> or <code>tuple</code></p> | |
| `});var A=e(x,4);ie(A,{anchor:"diffusers.Krea2Pipeline.__call__.example",children:(i,f)=>{var q=ce(),O=e(W(q),2);r(O,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwS3JlYTJQaXBlbGluZSUwQSUwQSUyMyUyMExvYWQlMjBmcm9tJTIwYSUyMGxvY2FsJTIwZGlyZWN0b3J5JTIwcHJvZHVjZWQlMjBieSUyMHRoZSUyMEtyZWElMjAyJTIwY29udmVyc2lvbiUyMChubyUyMGh1YiUyMHJlcG8lMjB5ZXQpLiUwQXBpcGUlMjAlM0QlMjBLcmVhMlBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJwYXRoJTJGdG8lMkZrcmVhMi1kaWZmdXNlcnMlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEFwcm9tcHQlMjAlM0QlMjAlMjJhJTIwZm94JTIwaW4lMjB0aGUlMjBzbm93JTIyJTBBJTIzJTIwQmFzZSUyMChtaWR0cmFpbiklMjBjaGVja3BvaW50JTIwZGVmYXVsdHMuJTIwRm9yJTIwdGhlJTIwZmV3LXN0ZXAlMjBkaXN0aWxsZWQlMjAoVERNKSUyMGNoZWNrcG9pbnQlMjB1c2UlMEElMjMlMjAlNjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEOCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNEMC4wJTYwJTIwaW5zdGVhZC4lMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDI4JTJDJTIwZ3VpZGFuY2Vfc2NhbGUlM0Q0LjUpLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMmtyZWEyLnBuZyUyMik=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Krea2Pipeline | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Load from a local directory produced by the Krea 2 conversion (no hub repo yet).</span> | |
| <span class="hljs-meta">>>> </span>pipe = Krea2Pipeline.from_pretrained(<span class="hljs-string">"path/to/krea2-diffusers"</span>, torch_dtype=torch.bfloat16) | |
| <span class="hljs-meta">>>> </span>pipe.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>prompt = <span class="hljs-string">"a fox in the snow"</span> | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Base (midtrain) checkpoint defaults. For the few-step distilled (TDM) checkpoint use</span> | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># \`num_inference_steps=8, guidance_scale=0.0\` instead.</span> | |
| <span class="hljs-meta">>>> </span>image = pipe(prompt, num_inference_steps=<span class="hljs-number">28</span>, guidance_scale=<span class="hljs-number">4.5</span>).images[<span class="hljs-number">0</span>] | |
| <span class="hljs-meta">>>> </span>image.save(<span class="hljs-string">"krea2.png"</span>)`,lang:"py",wrap:!1}),b(i,q)},$$slots:{default:!0}}),a(d);var c=e(d,2),Y=t(c);o(Y,{name:"encode_prompt",anchor:"diffusers.Krea2Pipeline.encode_prompt",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/pipelines/krea2/pipeline_krea2.py#L263",parameters:[{name:"prompt",val:": str | list[str]"},{name:"device",val:": typing.Optional[torch.device] = None"},{name:"num_images_per_prompt",val:": int = 1"},{name:"prompt_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"prompt_embeds_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"max_sequence_length",val:": int = 512"}],parametersDescription:[{anchor:"diffusers.Krea2Pipeline.encode_prompt.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>list[str]</code>, <em>optional</em>) — | |
| prompt to be encoded`,name:"prompt"},{anchor:"diffusers.Krea2Pipeline.encode_prompt.device",description:`<strong>device</strong> — (<code>torch.device</code>): | |
| torch device`,name:"device"},{anchor:"diffusers.Krea2Pipeline.encode_prompt.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>) — | |
| number of images that should be generated per prompt`,name:"num_images_per_prompt"},{anchor:"diffusers.Krea2Pipeline.encode_prompt.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Pre-generated text embeddings of shape <code>(batch_size, text_seq_len, num_text_layers, text_hidden_dim)</code>. | |
| Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not provided, text embeddings will | |
| be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.Krea2Pipeline.encode_prompt.prompt_embeds_mask",description:`<strong>prompt_embeds_mask</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Pre-generated boolean mask marking valid text tokens, of shape <code>(batch_size, text_seq_len)</code>. Required | |
| when <code>prompt_embeds</code> is passed.`,name:"prompt_embeds_mask"},{anchor:"diffusers.Krea2Pipeline.encode_prompt.max_sequence_length",description:`<strong>max_sequence_length</strong> (<code>int</code>, defaults to 512) — | |
| Fixed text sequence length consumed by the transformer; prompts are padded or truncated to it.`,name:"max_sequence_length"}]}),a(c);var p=e(c,2),E=t(p);o(E,{name:"get_text_hidden_states",anchor:"diffusers.Krea2Pipeline.get_text_hidden_states",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/pipelines/krea2/pipeline_krea2.py#L214",parameters:[{name:"prompt",val:": str | list[str]"},{name:"max_sequence_length",val:": int = 512"},{name:"device",val:": typing.Optional[torch.device] = None"}]}),s(4),a(p);var K=e(p,2),z=t(K);o(z,{name:"prepare_position_ids",anchor:"diffusers.Krea2Pipeline.prepare_position_ids",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/pipelines/krea2/pipeline_krea2.py#L381",parameters:[{name:"text_seq_len",val:": int"},{name:"grid_height",val:": int"},{name:"grid_width",val:": int"},{name:"device",val:": device"}]}),s(2),a(K),a(l);var I=e(l,2);n(I,{title:"Krea2PipelineOutput",local:"diffusers.pipelines.krea2.Krea2PipelineOutput",headingTag:"h2"});var m=e(I,2),R=t(m);o(R,{name:"class diffusers.pipelines.krea2.Krea2PipelineOutput",anchor:"diffusers.pipelines.krea2.Krea2PipelineOutput",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/pipelines/krea2/pipeline_output.py#L24",parameters:[{name:"images",val:": list[PIL.Image.Image] | numpy.ndarray"}],parametersDescription:[{anchor:"diffusers.pipelines.krea2.Krea2PipelineOutput.images",description:`<strong>images</strong> (<code>list[PIL.Image.Image]</code> or <code>np.ndarray</code>) — | |
| List of denoised PIL images of length <code>batch_size</code> or numpy array of shape <code>(batch_size, height, width, num_channels)</code>.`,name:"images"}]}),s(2),a(m);var Z=e(m,2);n(Z,{title:"Modular",local:"modular",headingTag:"h2"});var B=e(Z,4);r(B,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ2xhc3NpZmllckZyZWVHdWlkYW5jZSUyQyUyME1vZHVsYXJQaXBlbGluZSUwQSUwQXBpcGUlMjAlM0QlMjBNb2R1bGFyUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMmtyZWElMkZLcmVhLTItUmF3JTIyKSUwQXBpcGUubG9hZF9jb21wb25lbnRzKGR0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0QlMjJhJTIwZm94JTIwaW4lMjB0aGUlMjBzbm93JTIyJTJDJTBBJTIwJTIwJTIwJTIwaGVpZ2h0JTNEMTAyNCUyQyUwQSUyMCUyMCUyMCUyMHdpZHRoJTNEMTAyNCUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyOCUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRHRvcmNoLkdlbmVyYXRvciglMjJjdWRhJTIyKS5tYW51YWxfc2VlZCgwKSUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIya3JlYTIucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ClassifierFreeGuidance, ModularPipeline | |
| pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"krea/Krea-2-Raw"</span>) | |
| pipe.load_components(dtype=torch.bfloat16) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| image = pipe( | |
| prompt=<span class="hljs-string">"a fox in the snow"</span>, | |
| height=<span class="hljs-number">1024</span>, | |
| width=<span class="hljs-number">1024</span>, | |
| num_inference_steps=<span class="hljs-number">28</span>, | |
| generator=torch.Generator(<span class="hljs-string">"cuda"</span>).manual_seed(<span class="hljs-number">0</span>), | |
| ).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"krea2.png"</span>)`,lang:"python",wrap:!1});var G=e(B,4);r(G,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwTW9kdWxhclBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyME1vZHVsYXJQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIya3JlYSUyRktyZWEtMi1UdXJibyUyMiklMEFwaXBlLmxvYWRfY29tcG9uZW50cyhkdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTNEJTIyYSUyMGZveCUyMGluJTIwdGhlJTIwc25vdyUyMiUyQyUwQSUyMCUyMCUyMCUyMGhlaWdodCUzRDEwMjQlMkMlMEElMjAlMjAlMjAlMjB3aWR0aCUzRDEwMjQlMkMlMEElMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEOCUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRHRvcmNoLkdlbmVyYXRvciglMjJjdWRhJTIyKS5tYW51YWxfc2VlZCgwKSUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIya3JlYTJfdHVyYm8ucG5nJTIyKQ==",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">"krea/Krea-2-Turbo"</span>) | |
| pipe.load_components(dtype=torch.bfloat16) | |
| pipe.to(<span class="hljs-string">"cuda"</span>) | |
| image = pipe( | |
| prompt=<span class="hljs-string">"a fox in the snow"</span>, | |
| height=<span class="hljs-number">1024</span>, | |
| width=<span class="hljs-number">1024</span>, | |
| num_inference_steps=<span class="hljs-number">8</span>, | |
| generator=torch.Generator(<span class="hljs-string">"cuda"</span>).manual_seed(<span class="hljs-number">0</span>), | |
| ).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"krea2_turbo.png"</span>)`,lang:"python",wrap:!1});var C=e(G,2);n(C,{title:"Krea2ModularPipeline",local:"diffusers.Krea2ModularPipeline",headingTag:"h2"});var u=e(C,2),L=t(u);o(L,{name:"class diffusers.Krea2ModularPipeline",anchor:"diffusers.Krea2ModularPipeline",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/modular_pipelines/krea2/modular_pipeline.py#L19",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:"modular_config_dict",val:": dict[str, typing.Any] | None = None"},{name:"config_dict",val:": dict[str, typing.Any] | None = None"},{name:"**kwargs",val:""}]}),s(4),a(u);var P=e(u,2);n(P,{title:"Krea2AutoBlocks",local:"diffusers.Krea2AutoBlocks",headingTag:"h2"});var h=e(P,2),X=t(h);o(X,{name:"class diffusers.Krea2AutoBlocks",anchor:"diffusers.Krea2AutoBlocks",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/modular_pipelines/krea2/modular_blocks_krea2.py#L105",parameters:[]}),s(12),a(h);var Q=e(h,2);n(Q,{title:"Krea2TurboModularPipeline",local:"diffusers.Krea2TurboModularPipeline",headingTag:"h2"});var g=e(Q,2),F=t(g);o(F,{name:"class diffusers.Krea2TurboModularPipeline",anchor:"diffusers.Krea2TurboModularPipeline",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/modular_pipelines/krea2/modular_pipeline.py#L55",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:"modular_config_dict",val:": dict[str, typing.Any] | None = None"},{name:"config_dict",val:": dict[str, typing.Any] | None = None"},{name:"**kwargs",val:""}]}),s(4),a(g);var N=e(g,2);n(N,{title:"Krea2TurboAutoBlocks",local:"diffusers.Krea2TurboAutoBlocks",headingTag:"h2"});var _=e(N,2),H=t(_);o(H,{name:"class diffusers.Krea2TurboAutoBlocks",anchor:"diffusers.Krea2TurboAutoBlocks",source:"https://github.com/huggingface/diffusers/blob/vr_14340/src/diffusers/modular_pipelines/krea2/modular_blocks_krea2_turbo.py#L101",parameters:[]}),s(12),a(_);var D=e(_,2);te(D,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/krea2.md"}),s(2),b(V,M),re()}export{_e as component}; | |
Xet Storage Details
- Size:
- 38.8 kB
- Xet hash:
- 971798c66fdb5fea9be38576bbae20475d19e553505b258b7cbd7e76f1709911
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.