import{s as Fe,f as je,n as ve,o as _e}from"../chunks/scheduler.8c3d61f6.js";import{S as ke,i as Ee,g as s,s as a,r as f,A as $e,h as o,f as l,c as n,j as ue,u,x as r,k as B,y as Ce,a as i,v as c,d,t as M,w as h}from"../chunks/index.da70eac4.js";import{C as pe}from"../chunks/CodeBlock.a9c4becf.js";import{H as fe,E as Ie}from"../chunks/getInferenceSnippets.28ca3596.js";function We(ce){let p,V,x,X,g,H,y,de='The GGUF file format is typically used to store models for inference with <a href="https://github.com/ggerganov/ggml" rel="nofollow">GGML</a> and supports a variety of block wise quantization options. Diffusers supports loading checkpoints prequantized and saved in the GGUF format via <code>from_single_file</code> loading with Model classes. Loading GGUF checkpoints via Pipelines is currently not supported.',Q,J,Me='The following example will load the <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" rel="nofollow">FLUX.1 DEV</a> transformer model using the GGUF Q2_K quantization variant.',Y,b,he="Before starting please install gguf in your environment",A,w,L,T,ge='Since GGUF is a single file format, use <code>~FromSingleFileMixin.from_single_file</code> to load the model and pass in the <a href="/docs/diffusers/main/en/api/quantization#diffusers.GGUFQuantizationConfig">GGUFQuantizationConfig</a>.',q,U,ye="When using GGUF checkpoints, the quantized weights remain in a low memory <code>dtype</code>(typically <code>torch.uint8</code>) and are dynamically dequantized and cast to the configured <code>compute_dtype</code> during each module’s forward pass through the model. The <code>GGUFQuantizationConfig</code> allows you to set the <code>compute_dtype</code>.",S,G,Je='The functions used for dynamic dequantizatation are based on the great work done by <a href="https://github.com/city96/ComfyUI-GGUF" rel="nofollow">city96</a>, who created the Pytorch ports of the original <a href="https://github.com/ggerganov/llama.cpp/blob/master/gguf-py/gguf/quants.py" rel="nofollow"><code>numpy</code></a> implementation by <a href="https://github.com/compilade" rel="nofollow">compilade</a>.',N,Z,D,F,P,j,be="Optimized CUDA kernels can accelerate GGUF quantized model inference by approximately 10%. This functionality requires a compatible GPU with <code>torch.cuda.get_device_capability</code> greater than 7 and the kernels library:",K,v,O,_,we="Once installed, set <code>DIFFUSERS_GGUF_CUDA_KERNELS=true</code>  to use optimized kernels when available. Note that CUDA kernels may introduce minor numerical differences compared to the original GGUF implementation, potentially causing subtle visual variations in generated images. To disable CUDA kernel usage, set the environment variable <code>DIFFUSERS_GGUF_CUDA_KERNELS=false</code>.",ee,k,te,E,Te="<li>BF16</li> <li>Q4_0</li> <li>Q4_1</li> <li>Q5_0</li> <li>Q5_1</li> <li>Q8_0</li> <li>Q2_K</li> <li>Q3_K</li> <li>Q4_K</li> <li>Q5_K</li> <li>Q6_K</li>",le,$,ie,C,Ue=`Use the Space below to convert a Diffusers checkpoint into the GGUF format for inference.
run conversion:`,ae,m,Ge,ne,I,se,W,Ze=`When using Diffusers format GGUF checkpoints, it’s a must to provide the model <code>config</code> path. If the
model config resides in a <code>subfolder</code>, that needs to be specified, too.`,oe,R,re,z,me;return g=new fe({props:{title:"GGUF",local:"gguf",headingTag:"h1"}}),w=new pe({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwZ2d1Zg==",highlighted:"pip install -U gguf",wrap:!1}}),Z=new pe({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTJDJTIwRmx1eFRyYW5zZm9ybWVyMkRNb2RlbCUyQyUyMEdHVUZRdWFudGl6YXRpb25Db25maWclMEElMEFja3B0X3BhdGglMjAlM0QlMjAoJTBBJTIwJTIwJTIwJTIwJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmNpdHk5NiUyRkZMVVguMS1kZXYtZ2d1ZiUyRmJsb2IlMkZtYWluJTJGZmx1eDEtZGV2LVEyX0suZ2d1ZiUyMiUwQSklMEF0cmFuc2Zvcm1lciUyMCUzRCUyMEZsdXhUcmFuc2Zvcm1lcjJETW9kZWwuZnJvbV9zaW5nbGVfZmlsZSglMEElMjAlMjAlMjAlMjBja3B0X3BhdGglMkMlMEElMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNER0dVRlF1YW50aXphdGlvbkNvbmZpZyhjb21wdXRlX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSklMEFwaXBlJTIwJTNEJTIwRmx1eFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJibGFjay1mb3Jlc3QtbGFicyUyRkZMVVguMS1kZXYlMjIlMkMlMEElMjAlMjAlMjAlMjB0cmFuc2Zvcm1lciUzRHRyYW5zZm9ybWVyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSklMEFwaXBlLmVuYWJsZV9tb2RlbF9jcHVfb2ZmbG9hZCgpJTBBcHJvbXB0JTIwJTNEJTIwJTIyQSUyMGNhdCUyMGhvbGRpbmclMjBhJTIwc2lnbiUyMHRoYXQlMjBzYXlzJTIwaGVsbG8lMjB3b3JsZCUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBnZW5lcmF0b3IlM0R0b3JjaC5tYW51YWxfc2VlZCgwKSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyZmx1eC1nZ3VmLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline, FluxTransformer2DModel, GGUFQuantizationConfig

ckpt_path = (
    <span class="hljs-string">&quot;https://huggingface.co/city96/FLUX.1-dev-gguf/blob/main/flux1-dev-Q2_K.gguf&quot;</span>
)
transformer = FluxTransformer2DModel.from_single_file(
    ckpt_path,
    quantization_config=GGUFQuantizationConfig(compute_dtype=torch.bfloat16),
    torch_dtype=torch.bfloat16,
)
pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    transformer=transformer,
    torch_dtype=torch.bfloat16,
)
pipe.enable_model_cpu_offload()
prompt = <span class="hljs-string">&quot;A cat holding a sign that says hello world&quot;</span>
image = pipe(prompt, generator=torch.manual_seed(<span class="hljs-number">0</span>)).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;flux-gguf.png&quot;</span>)`,wrap:!1}}),F=new fe({props:{title:"Using Optimized CUDA Kernels with GGUF",local:"using-optimized-cuda-kernels-with-gguf",headingTag:"h2"}}),v=new pe({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwa2VybmVscw==",highlighted:"pip install -U kernels",wrap:!1}}),k=new fe({props:{title:"Supported Quantization Types",local:"supported-quantization-types",headingTag:"h2"}}),$=new fe({props:{title:"Convert to GGUF",local:"convert-to-gguf",headingTag:"h2"}}),I=new pe({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTJDJTIwRmx1eFRyYW5zZm9ybWVyMkRNb2RlbCUyQyUyMEdHVUZRdWFudGl6YXRpb25Db25maWclMEElMEFja3B0X3BhdGglMjAlM0QlMjAoJTBBJTIwJTIwJTIwJTIwJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRnNheWFrcGF1bCUyRmRpZmZlcmVudC1sb3JhLWZyb20tY2l2aXRhaSUyRmJsb2IlMkZtYWluJTJGZmx1eF9kZXZfZGlmZnVzZXJzLXE0XzAuZ2d1ZiUyMiUwQSklMEF0cmFuc2Zvcm1lciUyMCUzRCUyMEZsdXhUcmFuc2Zvcm1lcjJETW9kZWwuZnJvbV9zaW5nbGVfZmlsZSglMEElMjAlMjAlMjAlMjBja3B0X3BhdGglMkMlMEElMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNER0dVRlF1YW50aXphdGlvbkNvbmZpZyhjb21wdXRlX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTJDJTBBJTIwJTIwJTIwJTIwY29uZmlnJTNEJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZGTFVYLjEtZGV2JTIyJTJDJTBBJTIwJTIwJTIwJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTJDJTBBKSUwQXBpcGUlMjAlM0QlMjBGbHV4UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGRkxVWC4xLWRldiUyMiUyQyUwQSUyMCUyMCUyMCUyMHRyYW5zZm9ybWVyJTNEdHJhbnNmb3JtZXIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTJDJTBBKSUwQXBpcGUuZW5hYmxlX21vZGVsX2NwdV9vZmZsb2FkKCklMEFwcm9tcHQlMjAlM0QlMjAlMjJBJTIwY2F0JTIwaG9sZGluZyUyMGElMjBzaWduJTIwdGhhdCUyMHNheXMlMjBoZWxsbyUyMHdvcmxkJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCUyQyUyMGdlbmVyYXRvciUzRHRvcmNoLm1hbnVhbF9zZWVkKDApKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJmbHV4LWdndWYucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline, FluxTransformer2DModel, GGUFQuantizationConfig

ckpt_path = (
    <span class="hljs-string">&quot;https://huggingface.co/sayakpaul/different-lora-from-civitai/blob/main/flux_dev_diffusers-q4_0.gguf&quot;</span>
)
transformer = FluxTransformer2DModel.from_single_file(
    ckpt_path,
    quantization_config=GGUFQuantizationConfig(compute_dtype=torch.bfloat16),
    config=<span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    torch_dtype=torch.bfloat16,
)
pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    transformer=transformer,
    torch_dtype=torch.bfloat16,
)
pipe.enable_model_cpu_offload()
prompt = <span class="hljs-string">&quot;A cat holding a sign that says hello world&quot;</span>
image = pipe(prompt, generator=torch.manual_seed(<span class="hljs-number">0</span>)).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;flux-gguf.png&quot;</span>)`,wrap:!1}}),R=new Ie({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/quantization/gguf.md"}}),{c(){p=s("meta"),V=a(),x=s("p"),X=a(),f(g.$$.fragment),H=a(),y=s("p"),y.innerHTML=de,Q=a(),J=s("p"),J.innerHTML=Me,Y=a(),b=s("p"),b.textContent=he,A=a(),f(w.$$.fragment),L=a(),T=s("p"),T.innerHTML=ge,q=a(),U=s("p"),U.innerHTML=ye,S=a(),G=s("p"),G.innerHTML=Je,N=a(),f(Z.$$.fragment),D=a(),f(F.$$.fragment),P=a(),j=s("p"),j.innerHTML=be,K=a(),f(v.$$.fragment),O=a(),_=s("p"),_.innerHTML=we,ee=a(),f(k.$$.fragment),te=a(),E=s("ul"),E.innerHTML=Te,le=a(),f($.$$.fragment),ie=a(),C=s("p"),C.textContent=Ue,ae=a(),m=s("iframe"),ne=a(),f(I.$$.fragment),se=a(),W=s("p"),W.innerHTML=Ze,oe=a(),f(R.$$.fragment),re=a(),z=s("p"),this.h()},l(e){const t=$e("svelte-u9bgzb",document.head);p=o(t,"META",{name:!0,content:!0}),t.forEach(l),V=n(e),x=o(e,"P",{}),ue(x).forEach(l),X=n(e),u(g.$$.fragment,e),H=n(e),y=o(e,"P",{"data-svelte-h":!0}),r(y)!=="svelte-th49fe"&&(y.innerHTML=de),Q=n(e),J=o(e,"P",{"data-svelte-h":!0}),r(J)!=="svelte-15l4qp1"&&(J.innerHTML=Me),Y=n(e),b=o(e,"P",{"data-svelte-h":!0}),r(b)!=="svelte-1s5awbc"&&(b.textContent=he),A=n(e),u(w.$$.fragment,e),L=n(e),T=o(e,"P",{"data-svelte-h":!0}),r(T)!=="svelte-v5zdiv"&&(T.innerHTML=ge),q=n(e),U=o(e,"P",{"data-svelte-h":!0}),r(U)!=="svelte-1tiy01a"&&(U.innerHTML=ye),S=n(e),G=o(e,"P",{"data-svelte-h":!0}),r(G)!=="svelte-2xs1wc"&&(G.innerHTML=Je),N=n(e),u(Z.$$.fragment,e),D=n(e),u(F.$$.fragment,e),P=n(e),j=o(e,"P",{"data-svelte-h":!0}),r(j)!=="svelte-gm6vu2"&&(j.innerHTML=be),K=n(e),u(v.$$.fragment,e),O=n(e),_=o(e,"P",{"data-svelte-h":!0}),r(_)!=="svelte-14ty30u"&&(_.innerHTML=we),ee=n(e),u(k.$$.fragment,e),te=n(e),E=o(e,"UL",{"data-svelte-h":!0}),r(E)!=="svelte-1dde1tf"&&(E.innerHTML=Te),le=n(e),u($.$$.fragment,e),ie=n(e),C=o(e,"P",{"data-svelte-h":!0}),r(C)!=="svelte-13q7i79"&&(C.textContent=Ue),ae=n(e),m=o(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),ue(m).forEach(l),ne=n(e),u(I.$$.fragment,e),se=n(e),W=o(e,"P",{"data-svelte-h":!0}),r(W)!=="svelte-sfexoo"&&(W.innerHTML=Ze),oe=n(e),u(R.$$.fragment,e),re=n(e),z=o(e,"P",{}),ue(z).forEach(l),this.h()},h(){B(p,"name","hf:doc:metadata"),B(p,"content",Re),je(m.src,Ge="https://diffusers-internal-dev-diffusers-to-gguf.hf.space")||B(m,"src",Ge),B(m,"frameborder","0"),B(m,"width","850"),B(m,"height","450")},m(e,t){Ce(document.head,p),i(e,V,t),i(e,x,t),i(e,X,t),c(g,e,t),i(e,H,t),i(e,y,t),i(e,Q,t),i(e,J,t),i(e,Y,t),i(e,b,t),i(e,A,t),c(w,e,t),i(e,L,t),i(e,T,t),i(e,q,t),i(e,U,t),i(e,S,t),i(e,G,t),i(e,N,t),c(Z,e,t),i(e,D,t),c(F,e,t),i(e,P,t),i(e,j,t),i(e,K,t),c(v,e,t),i(e,O,t),i(e,_,t),i(e,ee,t),c(k,e,t),i(e,te,t),i(e,E,t),i(e,le,t),c($,e,t),i(e,ie,t),i(e,C,t),i(e,ae,t),i(e,m,t),i(e,ne,t),c(I,e,t),i(e,se,t),i(e,W,t),i(e,oe,t),c(R,e,t),i(e,re,t),i(e,z,t),me=!0},p:ve,i(e){me||(d(g.$$.fragment,e),d(w.$$.fragment,e),d(Z.$$.fragment,e),d(F.$$.fragment,e),d(v.$$.fragment,e),d(k.$$.fragment,e),d($.$$.fragment,e),d(I.$$.fragment,e),d(R.$$.fragment,e),me=!0)},o(e){M(g.$$.fragment,e),M(w.$$.fragment,e),M(Z.$$.fragment,e),M(F.$$.fragment,e),M(v.$$.fragment,e),M(k.$$.fragment,e),M($.$$.fragment,e),M(I.$$.fragment,e),M(R.$$.fragment,e),me=!1},d(e){e&&(l(V),l(x),l(X),l(H),l(y),l(Q),l(J),l(Y),l(b),l(A),l(L),l(T),l(q),l(U),l(S),l(G),l(N),l(D),l(P),l(j),l(K),l(O),l(_),l(ee),l(te),l(E),l(le),l(ie),l(C),l(ae),l(m),l(ne),l(se),l(W),l(oe),l(re),l(z)),l(p),h(g,e),h(w,e),h(Z,e),h(F,e),h(v,e),h(k,e),h($,e),h(I,e),h(R,e)}}}const Re='{"title":"GGUF","local":"gguf","sections":[{"title":"Using Optimized CUDA Kernels with GGUF","local":"using-optimized-cuda-kernels-with-gguf","sections":[],"depth":2},{"title":"Supported Quantization Types","local":"supported-quantization-types","sections":[],"depth":2},{"title":"Convert to GGUF","local":"convert-to-gguf","sections":[],"depth":2}],"depth":1}';function Be(ce){return _e(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class He extends ke{constructor(p){super(),Ee(this,p,Be,We,Fe,{})}}export{He as component};
