import{s as Je,n as Ue,o as ze}from"../chunks/scheduler.25b97de1.js";import{S as qe,i as Qe,g as a,s as n,r as f,A as Be,h as r,f as l,c as o,j as Ge,u as m,x as s,k as Ze,y as Ee,a as i,v as u,d,t as h,w as c}from"../chunks/index.d9030fc9.js";import{C as He}from"../chunks/CodeBlock.e6cd0d95.js";import{H as X,E as Pe}from"../chunks/EditOnGithub.91d95064.js";function Xe(he){let p,S,E,V,g,F,y,ce=`The GGUF file format is used to store models for inference with <a href="https://github.com/ggerganov/ggml" rel="nofollow">GGML</a> and other
libraries that depend on it, like the very popular <a href="https://github.com/ggerganov/llama.cpp" rel="nofollow">llama.cpp</a> or
<a href="https://github.com/ggerganov/whisper.cpp" rel="nofollow">whisper.cpp</a>.`,j,w,ge=`It is a file format <a href="https://huggingface.co/docs/hub/en/gguf" rel="nofollow">supported by the Hugging Face Hub</a> with features
allowing for quick inspection of tensors and metadata within the file.`,I,b,ye=`This file format is designed as a “single-file-format” where a single file usually contains both the configuration
attributes, the tokenizer vocabulary and other attributes, as well as all tensors to be loaded in the model. These
files come in different formats according to the quantization type of the file. We briefly go over some of them
<a href="https://huggingface.co/docs/hub/en/gguf#quantization-types" rel="nofollow">here</a>.`,Y,T,R,v,we=`We have added the ability to load <code>gguf</code> files within <code>transformers</code> in order to offer further training/fine-tuning
capabilities to gguf models, before converting back those models to <code>gguf</code> to use within the <code>ggml</code> ecosystem. When
loading a model, we first dequantize it to fp32, before loading the weights to be used in PyTorch.`,N,$,be=`<p>[!NOTE]
The support is still very exploratory and we welcome contributions in order to solidify it across quantization types
and model architectures.</p>`,A,M,Te="For now, here are the supported model architectures and quantization types:",K,x,D,_,ve=`The initial supported quantization types are decided according to the popular quantized files that have been shared
on the Hub.`,O,k,$e="<li>F32</li> <li>Q2_K</li> <li>Q3_K</li> <li>Q4_0</li> <li>Q4_K</li> <li>Q5_K</li> <li>Q6_K</li> <li>Q8_0</li>",ee,C,Me=`We take example from the excellent <a href="https://github.com/99991/pygguf" rel="nofollow">99991/pygguf</a> Python parser to dequantize the
weights.`,te,L,le,W,xe="For now the supported model architectures are the architectures that have been very popular on the Hub, namely:",ie,G,_e="<li>LLaMa</li> <li>Mistral</li> <li>Qwen2</li>",ne,Z,oe,H,ke=`In order to load <code>gguf</code> files in <code>transformers</code>, you should specify the <code>gguf_file</code> argument to the <code>from_pretrained</code>
methods of both tokenizers and models. Here is how one would load a tokenizer and a model, which can be loaded
from the exact same file:`,ae,J,re,U,Ce=`Now you have access to the full, unquantized version of the model in the PyTorch ecosystem, where you can combine it
with a plethora of other tools.`,se,z,Le=`In order to convert back to a <code>gguf</code> file, we recommend using the
<a href="https://github.com/ggerganov/llama.cpp/blob/master/convert-hf-to-gguf.py" rel="nofollow"><code>convert-hf-to-gguf.py</code> file</a> from llama.cpp.`,pe,q,We="Here’s how you would complete the script above to save the model and export it back to <code>gguf</code>:",fe,Q,me,B,ue,P,de;return g=new X({props:{title:"GGUF and interaction with Transformers",local:"gguf-and-interaction-with-transformers",headingTag:"h1"}}),T=new X({props:{title:"Support within Transformers",local:"support-within-transformers",headingTag:"h2"}}),x=new X({props:{title:"Supported quantization types",local:"supported-quantization-types",headingTag:"h3"}}),L=new X({props:{title:"Supported model architectures",local:"supported-model-architectures",headingTag:"h3"}}),Z=new X({props:{title:"Example usage",local:"example-usage",headingTag:"h2"}}),J=new He({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyVGhlQmxva2UlMkZUaW55TGxhbWEtMS4xQi1DaGF0LXYxLjAtR0dVRiUyMiUwQWZpbGVuYW1lJTIwJTNEJTIwJTIydGlueWxsYW1hLTEuMWItY2hhdC12MS4wLlE2X0suZ2d1ZiUyMiUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwZ2d1Zl9maWxlJTNEZmlsZW5hbWUpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjBnZ3VmX2ZpbGUlM0RmaWxlbmFtZSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM

model_id = <span class="hljs-string">&quot;TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF&quot;</span>
filename = <span class="hljs-string">&quot;tinyllama-1.1b-chat-v1.0.Q6_K.gguf&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=filename)
model = AutoModelForCausalLM.from_pretrained(model_id, gguf_file=filename)`,wrap:!1}}),Q=new He({props:{code:"dG9rZW5pemVyLnNhdmVfcHJldHJhaW5lZCgnZGlyZWN0b3J5JyklMEFtb2RlbC5zYXZlX3ByZXRyYWluZWQoJ2RpcmVjdG9yeScpJTBBJTBBIXB5dGhvbiUyMCUyNCU3QnBhdGhfdG9fbGxhbWFfY3BwJTdEJTJGY29udmVydC1oZi10by1nZ3VmLnB5JTIwJTI0JTdCZGlyZWN0b3J5JTdE",highlighted:`tokenizer.save_pretrained(<span class="hljs-string">&#x27;directory&#x27;</span>)
model.save_pretrained(<span class="hljs-string">&#x27;directory&#x27;</span>)

!python \${path_to_llama_cpp}/convert-hf-to-gguf.py \${directory}`,wrap:!1}}),B=new Pe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/gguf.md"}}),{c(){p=a("meta"),S=n(),E=a("p"),V=n(),f(g.$$.fragment),F=n(),y=a("p"),y.innerHTML=ce,j=n(),w=a("p"),w.innerHTML=ge,I=n(),b=a("p"),b.innerHTML=ye,Y=n(),f(T.$$.fragment),R=n(),v=a("p"),v.innerHTML=we,N=n(),$=a("blockquote"),$.innerHTML=be,A=n(),M=a("p"),M.textContent=Te,K=n(),f(x.$$.fragment),D=n(),_=a("p"),_.textContent=ve,O=n(),k=a("ul"),k.innerHTML=$e,ee=n(),C=a("p"),C.innerHTML=Me,te=n(),f(L.$$.fragment),le=n(),W=a("p"),W.textContent=xe,ie=n(),G=a("ul"),G.innerHTML=_e,ne=n(),f(Z.$$.fragment),oe=n(),H=a("p"),H.innerHTML=ke,ae=n(),f(J.$$.fragment),re=n(),U=a("p"),U.textContent=Ce,se=n(),z=a("p"),z.innerHTML=Le,pe=n(),q=a("p"),q.innerHTML=We,fe=n(),f(Q.$$.fragment),me=n(),f(B.$$.fragment),ue=n(),P=a("p"),this.h()},l(e){const t=Be("svelte-u9bgzb",document.head);p=r(t,"META",{name:!0,content:!0}),t.forEach(l),S=o(e),E=r(e,"P",{}),Ge(E).forEach(l),V=o(e),m(g.$$.fragment,e),F=o(e),y=r(e,"P",{"data-svelte-h":!0}),s(y)!=="svelte-117klwz"&&(y.innerHTML=ce),j=o(e),w=r(e,"P",{"data-svelte-h":!0}),s(w)!=="svelte-14alsnt"&&(w.innerHTML=ge),I=o(e),b=r(e,"P",{"data-svelte-h":!0}),s(b)!=="svelte-1lcntb8"&&(b.innerHTML=ye),Y=o(e),m(T.$$.fragment,e),R=o(e),v=r(e,"P",{"data-svelte-h":!0}),s(v)!=="svelte-1fcaojo"&&(v.innerHTML=we),N=o(e),$=r(e,"BLOCKQUOTE",{"data-svelte-h":!0}),s($)!=="svelte-13g437o"&&($.innerHTML=be),A=o(e),M=r(e,"P",{"data-svelte-h":!0}),s(M)!=="svelte-lue5cc"&&(M.textContent=Te),K=o(e),m(x.$$.fragment,e),D=o(e),_=r(e,"P",{"data-svelte-h":!0}),s(_)!=="svelte-1r2kpez"&&(_.textContent=ve),O=o(e),k=r(e,"UL",{"data-svelte-h":!0}),s(k)!=="svelte-sks6kq"&&(k.innerHTML=$e),ee=o(e),C=r(e,"P",{"data-svelte-h":!0}),s(C)!=="svelte-1k8rx5j"&&(C.innerHTML=Me),te=o(e),m(L.$$.fragment,e),le=o(e),W=r(e,"P",{"data-svelte-h":!0}),s(W)!=="svelte-tmyftl"&&(W.textContent=xe),ie=o(e),G=r(e,"UL",{"data-svelte-h":!0}),s(G)!=="svelte-1hysn31"&&(G.innerHTML=_e),ne=o(e),m(Z.$$.fragment,e),oe=o(e),H=r(e,"P",{"data-svelte-h":!0}),s(H)!=="svelte-1lj1hm3"&&(H.innerHTML=ke),ae=o(e),m(J.$$.fragment,e),re=o(e),U=r(e,"P",{"data-svelte-h":!0}),s(U)!=="svelte-16kc502"&&(U.textContent=Ce),se=o(e),z=r(e,"P",{"data-svelte-h":!0}),s(z)!=="svelte-uk9y6w"&&(z.innerHTML=Le),pe=o(e),q=r(e,"P",{"data-svelte-h":!0}),s(q)!=="svelte-eicl62"&&(q.innerHTML=We),fe=o(e),m(Q.$$.fragment,e),me=o(e),m(B.$$.fragment,e),ue=o(e),P=r(e,"P",{}),Ge(P).forEach(l),this.h()},h(){Ze(p,"name","hf:doc:metadata"),Ze(p,"content",Se)},m(e,t){Ee(document.head,p),i(e,S,t),i(e,E,t),i(e,V,t),u(g,e,t),i(e,F,t),i(e,y,t),i(e,j,t),i(e,w,t),i(e,I,t),i(e,b,t),i(e,Y,t),u(T,e,t),i(e,R,t),i(e,v,t),i(e,N,t),i(e,$,t),i(e,A,t),i(e,M,t),i(e,K,t),u(x,e,t),i(e,D,t),i(e,_,t),i(e,O,t),i(e,k,t),i(e,ee,t),i(e,C,t),i(e,te,t),u(L,e,t),i(e,le,t),i(e,W,t),i(e,ie,t),i(e,G,t),i(e,ne,t),u(Z,e,t),i(e,oe,t),i(e,H,t),i(e,ae,t),u(J,e,t),i(e,re,t),i(e,U,t),i(e,se,t),i(e,z,t),i(e,pe,t),i(e,q,t),i(e,fe,t),u(Q,e,t),i(e,me,t),u(B,e,t),i(e,ue,t),i(e,P,t),de=!0},p:Ue,i(e){de||(d(g.$$.fragment,e),d(T.$$.fragment,e),d(x.$$.fragment,e),d(L.$$.fragment,e),d(Z.$$.fragment,e),d(J.$$.fragment,e),d(Q.$$.fragment,e),d(B.$$.fragment,e),de=!0)},o(e){h(g.$$.fragment,e),h(T.$$.fragment,e),h(x.$$.fragment,e),h(L.$$.fragment,e),h(Z.$$.fragment,e),h(J.$$.fragment,e),h(Q.$$.fragment,e),h(B.$$.fragment,e),de=!1},d(e){e&&(l(S),l(E),l(V),l(F),l(y),l(j),l(w),l(I),l(b),l(Y),l(R),l(v),l(N),l($),l(A),l(M),l(K),l(D),l(_),l(O),l(k),l(ee),l(C),l(te),l(le),l(W),l(ie),l(G),l(ne),l(oe),l(H),l(ae),l(re),l(U),l(se),l(z),l(pe),l(q),l(fe),l(me),l(ue),l(P)),l(p),c(g,e),c(T,e),c(x,e),c(L,e),c(Z,e),c(J,e),c(Q,e),c(B,e)}}}const Se='{"title":"GGUF and interaction with Transformers","local":"gguf-and-interaction-with-transformers","sections":[{"title":"Support within Transformers","local":"support-within-transformers","sections":[{"title":"Supported quantization types","local":"supported-quantization-types","sections":[],"depth":3},{"title":"Supported model architectures","local":"supported-model-architectures","sections":[],"depth":3}],"depth":2},{"title":"Example usage","local":"example-usage","sections":[],"depth":2}],"depth":1}';function Ve(he){return ze(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends qe{constructor(p){super(),Qe(this,p,Ve,Xe,Je,{})}}export{Re as component};
