import{s as $e,n as Pe,o as Ee}from"../chunks/scheduler.8c3d61f6.js";import{S as Ce,i as Qe,g as l,s as n,r as u,A as Le,h as a,f as o,c as s,j as N,u as h,x as c,k as G,y as d,a as i,v as _,d as b,t as v,w as T}from"../chunks/index.589a98e8.js";import{D as fe}from"../chunks/Docstring.27406313.js";import{C as De}from"../chunks/CodeBlock.36627b28.js";import{H as ue,E as Re}from"../chunks/EditOnGithub.e5a8d9cb.js";function Je(he){let m,q,S,Y,w,H,M,_e='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/kolors/kolors_header_collage.png"/>',V,x,be='Kolors is a large-scale text-to-image generation model based on latent diffusion, developed by <a href="kwai-kolors@kuaishou.com">the Kuaishou Kolors team</a>. Trained on billions of text-image pairs, Kolors exhibits significant advantages over both open-source and closed-source models in visual quality, complex semantic accuracy, and text rendering for both Chinese and English characters. Furthermore, Kolors supports both Chinese and English inputs, demonstrating strong performance in understanding and generating Chinese-specific content. For more details, please refer to this <a href="https://github.com/Kwai-Kolors/Kolors/blob/master/imgs/Kolors_paper.pdf" rel="nofollow">technical report</a>.',B,y,ve="The abstract from the technical report is:",A,U,Te='<em>We present Kolors, a latent diffusion model for text-to-image synthesis, characterized by its profound understanding of both English and Chinese, as well as an impressive degree of photorealism. There are three key insights contributing to the development of Kolors. Firstly, unlike large language model T5 used in Imagen and Stable Diffusion 3, Kolors is built upon the General Language Model (GLM), which enhances its comprehension capabilities in both English and Chinese. Moreover, we employ a multimodal large language model to recaption the extensive training dataset for fine-grained text understanding. These strategies significantly improve Kolors’ ability to comprehend intricate semantics, particularly those involving multiple entities, and enable its advanced text rendering capabilities. Secondly, we divide the training of Kolors into two phases: the concept learning phase with broad knowledge and the quality improvement phase with specifically curated high-aesthetic data. Furthermore, we investigate the critical role of the noise schedule and introduce a novel schedule to optimize high-resolution image generation. These strategies collectively enhance the visual appeal of the generated high-resolution images. Lastly, we propose a category-balanced benchmark KolorsPrompts, which serves as a guide for the training and evaluation of Kolors. Consequently, even when employing the commonly used U-Net backbone, Kolors has demonstrated remarkable performance in human evaluations, surpassing the existing open-source models and achieving Midjourney-v6 level performance, especially in terms of visual appeal. We will release the code and weights of Kolors at <a href="https://github.com/Kwai-Kolors/Kolors" rel="nofollow">https://github.com/Kwai-Kolors/Kolors</a>, and hope that it will benefit future research and applications in the visual generation community.</em>',Z,k,F,K,W,$,X,r,P,re,D,we="Pipeline for text-to-image generation using Kolors.",le,R,Me=`This model inherits from <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`,ae,J,xe="The pipeline also inherits the following loading methods:",de,j,ye='<li><a href="/docs/diffusers/main/en/api/loaders/lora#diffusers.loaders.StableDiffusionXLLoraLoaderMixin.load_lora_weights">load_lora_weights()</a> for loading LoRA weights</li> <li><a href="/docs/diffusers/main/en/api/loaders/lora#diffusers.loaders.StableDiffusionXLLoraLoaderMixin.save_lora_weights">save_lora_weights()</a> for saving LoRA weights</li>',pe,g,E,ce,I,Ue="Encodes the prompt into text encoder hidden states.",me,f,C,ge,O,ke='See <a href="https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298" rel="nofollow">https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298</a>',ee,Q,Ke="<li>all</li> <li><strong>call</strong></li>",te,L,oe,z,ne;return w=new ue({props:{title:"Kolors: Effective Training of Diffusion Model for Photorealistic Text-to-Image Synthesis",local:"kolors-effective-training-of-diffusion-model-for-photorealistic-text-to-image-synthesis",headingTag:"h1"}}),k=new ue({props:{title:"Usage Example",local:"usage-example",headingTag:"h2"}}),K=new De({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRFBNU29sdmVyTXVsdGlzdGVwU2NoZWR1bGVyJTJDJT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W1wbGUucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DPMSolverMultistepScheduler, KolorsPipeline

pipe = KolorsPipeline.from_pretrained(<span class="hljs-string">&quot;Kwai-Kolors/Kolors-diffusers&quot;</span>, torch_dtype=torch.float16, variant=<span class="hljs-string">&quot;fp16&quot;</span>)
pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=<span class="hljs-literal">True</span>)

image = pipe(
    prompt=<span class="hljs-string">&#x27;一张瓢虫的照片，微距，变焦，高质量，电影，拿着一个牌子，写着&quot;可图&quot;&#x27;</span>,
    negative_prompt=<span class="hljs-string">&quot;&quot;</span>,
    guidance_scale=<span class="hljs-number">6.5</span>,
    num_inference_steps=<span class="hljs-number">25</span>,
).images[<span class="hljs-number">0</span>]

image.save(<span class="hljs-string">&quot;kolors_sample.png&quot;</span>)`,wrap:!1}}),$=new ue({props:{title:"KolorsPipeline",local:"diffusers.KolorsPipeline",headingTag:"h2"}}),P=new fe({props:{name:"class diffusers.KolorsPipeline",anchor:"diffusers.KolorsPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": ChatGLMModel"},{name:"tokenizer",val:": ChatGLMTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"force_zeros_for_empty_prompt",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.KolorsPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.KolorsPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>ChatGLMModel</code>) &#x2014;
Frozen text-encoder. Kolors uses <a href="https://huggingface.co/THUDM/chatglm3-6b" rel="nofollow">ChatGLM3-6B</a>.`,name:"text_encoder"},{anchor:"diffusers.KolorsPipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>ChatGLMTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/THUDM/chatglm3-6b/blob/main/tokenization_chatglm.py" rel="nofollow">ChatGLMTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.KolorsPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.KolorsPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/main/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/main/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.KolorsPipeline.force_zeros_for_empty_prompt",description:`<strong>force_zeros_for_empty_prompt</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>&quot;False&quot;</code>) &#x2014;
Whether the negative prompt embeddings shall be forced to always be set to 0. Also see the config of
<code>Kwai-Kolors/Kolors-diffusers</code>.`,name:"force_zeros_for_empty_prompt"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kolors/pipeline_kolors.py#L123"}}),E=new fe({props:{name:"encode_prompt",anchor:"diffusers.KolorsPipeline.encode_prompt",parameters:[{name:"prompt",val:""},{name:"device",val:": Optional = None"},{name:"num_images_per_prompt",val:": int = 1"},{name:"do_classifier_free_guidance",val:": bool = True"},{name:"negative_prompt",val:" = None"},{name:"prompt_embeds",val:": Optional = None"},{name:"pooled_prompt_embeds",val:": Optional = None"},{name:"negative_prompt_embeds",val:": Optional = None"},{name:"negative_pooled_prompt_embeds",val:": Optional = None"},{name:"max_sequence_length",val:": int = 256"}],parametersDescription:[{anchor:"diffusers.KolorsPipeline.encode_prompt.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
prompt to be encoded
device &#x2014; (<code>torch.device</code>):
torch device`,name:"prompt"},{anchor:"diffusers.KolorsPipeline.encode_prompt.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>) &#x2014;
number of images that should be generated per prompt`,name:"num_images_per_prompt"},{anchor:"diffusers.KolorsPipeline.encode_prompt.do_classifier_free_guidance",description:`<strong>do_classifier_free_guidance</strong> (<code>bool</code>) &#x2014;
whether to use classifier free guidance or not`,name:"do_classifier_free_guidance"},{anchor:"diffusers.KolorsPipeline.encode_prompt.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code> instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.KolorsPipeline.encode_prompt.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. 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.KolorsPipeline.encode_prompt.pooled_prompt_embeds",description:`<strong>pooled_prompt_embeds</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Pre-generated pooled text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting.
If not provided, pooled text embeddings will be generated from <code>prompt</code> input argument.`,name:"pooled_prompt_embeds"},{anchor:"diffusers.KolorsPipeline.encode_prompt.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.KolorsPipeline.encode_prompt.negative_pooled_prompt_embeds",description:`<strong>negative_pooled_prompt_embeds</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative pooled text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, pooled negative_prompt_embeds will be generated from <code>negative_prompt</code>
input argument.`,name:"negative_pooled_prompt_embeds"},{anchor:"diffusers.KolorsPipeline.encode_prompt.max_sequence_length",description:"<strong>max_sequence_length</strong> (<code>int</code> defaults to 256) &#x2014; Maximum sequence length to use with the <code>prompt</code>.",name:"max_sequence_length"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kolors/pipeline_kolors.py#L182"}}),C=new fe({props:{name:"get_guidance_scale_embedding",anchor:"diffusers.KolorsPipeline.get_guidance_scale_embedding",parameters:[{name:"w",val:": Tensor"},{name:"embedding_dim",val:": int = 512"},{name:"dtype",val:": dtype = torch.float32"}],parametersDescription:[{anchor:"diffusers.KolorsPipeline.get_guidance_scale_embedding.w",description:`<strong>w</strong> (<code>torch.Tensor</code>) &#x2014;
Generate embedding vectors with a specified guidance scale to subsequently enrich timestep embeddings.`,name:"w"},{anchor:"diffusers.KolorsPipeline.get_guidance_scale_embedding.embedding_dim",description:`<strong>embedding_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 512) &#x2014;
Dimension of the embeddings to generate.`,name:"embedding_dim"},{anchor:"diffusers.KolorsPipeline.get_guidance_scale_embedding.dtype",description:`<strong>dtype</strong> (<code>torch.dtype</code>, <em>optional</em>, defaults to <code>torch.float32</code>) &#x2014;
Data type of the generated embeddings.`,name:"dtype"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kolors/pipeline_kolors.py#L488",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>Embedding vectors with shape <code>(len(w), embedding_dim)</code>.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>torch.Tensor</code></p>
`}}),L=new Re({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/kolors.md"}}),{c(){m=l("meta"),q=n(),S=l("p"),Y=n(),u(w.$$.fragment),H=n(),M=l("p"),M.innerHTML=_e,V=n(),x=l("p"),x.innerHTML=be,B=n(),y=l("p"),y.textContent=ve,A=n(),U=l("p"),U.innerHTML=Te,Z=n(),u(k.$$.fragment),F=n(),u(K.$$.fragment),W=n(),u($.$$.fragment),X=n(),r=l("div"),u(P.$$.fragment),re=n(),D=l("p"),D.textContent=we,le=n(),R=l("p"),R.innerHTML=Me,ae=n(),J=l("p"),J.textContent=xe,de=n(),j=l("ul"),j.innerHTML=ye,pe=n(),g=l("div"),u(E.$$.fragment),ce=n(),I=l("p"),I.textContent=Ue,me=n(),f=l("div"),u(C.$$.fragment),ge=n(),O=l("p"),O.innerHTML=ke,ee=n(),Q=l("ul"),Q.innerHTML=Ke,te=n(),u(L.$$.fragment),oe=n(),z=l("p"),this.h()},l(e){const t=Le("svelte-u9bgzb",document.head);m=a(t,"META",{name:!0,content:!0}),t.forEach(o),q=s(e),S=a(e,"P",{}),N(S).forEach(o),Y=s(e),h(w.$$.fragment,e),H=s(e),M=a(e,"P",{"data-svelte-h":!0}),c(M)!=="svelte-1hwlqdw"&&(M.innerHTML=_e),V=s(e),x=a(e,"P",{"data-svelte-h":!0}),c(x)!=="svelte-1g43t28"&&(x.innerHTML=be),B=s(e),y=a(e,"P",{"data-svelte-h":!0}),c(y)!=="svelte-nj72pd"&&(y.textContent=ve),A=s(e),U=a(e,"P",{"data-svelte-h":!0}),c(U)!=="svelte-vvt3t7"&&(U.innerHTML=Te),Z=s(e),h(k.$$.fragment,e),F=s(e),h(K.$$.fragment,e),W=s(e),h($.$$.fragment,e),X=s(e),r=a(e,"DIV",{class:!0});var p=N(r);h(P.$$.fragment,p),re=s(p),D=a(p,"P",{"data-svelte-h":!0}),c(D)!=="svelte-d2bqje"&&(D.textContent=we),le=s(p),R=a(p,"P",{"data-svelte-h":!0}),c(R)!=="svelte-wu1jmh"&&(R.innerHTML=Me),ae=s(p),J=a(p,"P",{"data-svelte-h":!0}),c(J)!=="svelte-14s6m4u"&&(J.textContent=xe),de=s(p),j=a(p,"UL",{"data-svelte-h":!0}),c(j)!=="svelte-1selnkq"&&(j.innerHTML=ye),pe=s(p),g=a(p,"DIV",{class:!0});var se=N(g);h(E.$$.fragment,se),ce=s(se),I=a(se,"P",{"data-svelte-h":!0}),c(I)!=="svelte-16q0ax1"&&(I.textContent=Ue),se.forEach(o),me=s(p),f=a(p,"DIV",{class:!0});var ie=N(f);h(C.$$.fragment,ie),ge=s(ie),O=a(ie,"P",{"data-svelte-h":!0}),c(O)!=="svelte-vo59ec"&&(O.innerHTML=ke),ie.forEach(o),p.forEach(o),ee=s(e),Q=a(e,"UL",{"data-svelte-h":!0}),c(Q)!=="svelte-1p6h59i"&&(Q.innerHTML=Ke),te=s(e),h(L.$$.fragment,e),oe=s(e),z=a(e,"P",{}),N(z).forEach(o),this.h()},h(){G(m,"name","hf:doc:metadata"),G(m,"content",je),G(g,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),G(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),G(r,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){d(document.head,m),i(e,q,t),i(e,S,t),i(e,Y,t),_(w,e,t),i(e,H,t),i(e,M,t),i(e,V,t),i(e,x,t),i(e,B,t),i(e,y,t),i(e,A,t),i(e,U,t),i(e,Z,t),_(k,e,t),i(e,F,t),_(K,e,t),i(e,W,t),_($,e,t),i(e,X,t),i(e,r,t),_(P,r,null),d(r,re),d(r,D),d(r,le),d(r,R),d(r,ae),d(r,J),d(r,de),d(r,j),d(r,pe),d(r,g),_(E,g,null),d(g,ce),d(g,I),d(r,me),d(r,f),_(C,f,null),d(f,ge),d(f,O),i(e,ee,t),i(e,Q,t),i(e,te,t),_(L,e,t),i(e,oe,t),i(e,z,t),ne=!0},p:Pe,i(e){ne||(b(w.$$.fragment,e),b(k.$$.fragment,e),b(K.$$.fragment,e),b($.$$.fragment,e),b(P.$$.fragment,e),b(E.$$.fragment,e),b(C.$$.fragment,e),b(L.$$.fragment,e),ne=!0)},o(e){v(w.$$.fragment,e),v(k.$$.fragment,e),v(K.$$.fragment,e),v($.$$.fragment,e),v(P.$$.fragment,e),v(E.$$.fragment,e),v(C.$$.fragment,e),v(L.$$.fragment,e),ne=!1},d(e){e&&(o(q),o(S),o(Y),o(H),o(M),o(V),o(x),o(B),o(y),o(A),o(U),o(Z),o(F),o(W),o(X),o(r),o(ee),o(Q),o(te),o(oe),o(z)),o(m),T(w,e),T(k,e),T(K,e),T($,e),T(P),T(E),T(C),T(L,e)}}}const je='{"title":"Kolors: Effective Training of Diffusion Model for Photorealistic Text-to-Image Synthesis","local":"kolors-effective-training-of-diffusion-model-for-photorealistic-text-to-image-synthesis","sections":[{"title":"Usage Example","local":"usage-example","sections":[],"depth":2},{"title":"KolorsPipeline","local":"diffusers.KolorsPipeline","sections":[],"depth":2}],"depth":1}';function Ie(he){return Ee(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qe extends Ce{constructor(m){super(),Qe(this,m,Ie,Je,$e,{})}}export{qe as component};
