import{s as Ue,n as je,o as Ie}from"../chunks/scheduler.9cda857a.js";import{S as Ze,i as ke,e as i,s,c as p,h as ve,a as o,d as l,b as a,f as $e,g as r,j as f,k as me,l as Ge,m as n,n as m,t as u,o as d,p as c}from"../chunks/index.f47f3121.js";import{C as Ee}from"../chunks/CopyLLMTxtMenu.676ed699.js";import{C as ue}from"../chunks/CodeBlock.24d62f98.js";import{H,E as Ce}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.64d112fc.js";function We(de){let g,R,V,N,w,X,T,Q,b,ce='🤗 <a href="https://huggingface.co/docs/peft/index" rel="nofollow">Parameter-Efficient Fine-Tuning (PEFT)</a> is a library for efficiently adapting pre-trained language models to various downstream applications without fine-tuning all the model’s parameters.',Y,y,L,J,fe='You can find PEFT models by filtering at the left of the <a href="https://huggingface.co/models?library=peft&amp;sort=trending" rel="nofollow">models page</a>.',P,$,S,U,ge=`To get started, you can check out the <a href="https://huggingface.co/docs/peft/quicktour" rel="nofollow">Quick Tour in the PEFT docs</a>. To install, follow the <a href="https://huggingface.co/docs/peft/install" rel="nofollow">PEFT installation guide</a>.
You can also use the following one-line install through pip:`,z,j,A,I,q,Z,he="All PEFT models can be loaded from the Hub. To use a PEFT model you also need to load the base model that was fine-tuned, as shown below. Every fine-tuned model has the base model in its model card.",K,k,D,v,Me="Once loaded, you can pass your inputs to the tokenizer to prepare them, and call <code>model.generate()</code> in regular <code>transformers</code> fashion.",O,G,ee,E,we="It outputs the following:",te,C,le,W,Te="If you want to load a specific PEFT model, you can click <code>Use in PEFT</code> in the model card and you will be given a working snippet!",ne,h,be='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/peft_repo_light_new.png"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/peft_repo.png"/>',se,M,ye='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/peft_snippet_light.png"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/peft_snippet.png"/>',ae,_,ie,F,Je='<li>PEFT <a href="https://github.com/huggingface/peft" rel="nofollow">repository</a></li> <li>PEFT <a href="https://huggingface.co/docs/peft/index" rel="nofollow">docs</a></li> <li>PEFT <a href="https://huggingface.co/models?library=peft&amp;sort=trending" rel="nofollow">models</a></li>',oe,B,pe,x,re;return w=new Ee({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),T=new H({props:{title:"Using PEFT at Hugging Face",local:"using-peft-at-hugging-face",headingTag:"h1"}}),y=new H({props:{title:"Exploring PEFT on the Hub",local:"exploring-peft-on-the-hub",headingTag:"h2"}}),$=new H({props:{title:"Installation",local:"installation",headingTag:"h2"}}),j=new ue({props:{code:"JTI0JTIwcGlwJTIwaW5zdGFsbCUyMHBlZnQ=",highlighted:'$ pip <span class="hljs-keyword">install</span> peft',wrap:!1}}),I=new H({props:{title:"Using existing models",local:"using-existing-models",headingTag:"h2"}}),k=new ue({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQWZyb20lMjBwZWZ0JTIwaW1wb3J0JTIwUGVmdE1vZGVsJTJDJTIwUGVmdENvbmZpZyUwQSUwQWJhc2VfbW9kZWwlMjAlM0QlMjAlMjJtaXN0cmFsYWklMkZNaXN0cmFsLTdCLXYwLjElMjIlMEFhZGFwdGVyX21vZGVsJTIwJTNEJTIwJTIyZGZ1cm1hbiUyRk1pc3RyYWwtN0ItSW5zdHJ1Y3QtdjAuMiUyMiUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKGJhc2VfbW9kZWwpJTBBbW9kZWwlMjAlM0QlMjBQZWZ0TW9kZWwuZnJvbV9wcmV0cmFpbmVkKG1vZGVsJTJDJTIwYWRhcHRlcl9tb2RlbCklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChiYXNlX21vZGVsKSUwQSUwQW1vZGVsJTIwJTNEJTIwbW9kZWwudG8oJTIyY3VkYSUyMiklMEFtb2RlbC5ldmFsKCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftModel, PeftConfig

base_model = <span class="hljs-string">&quot;mistralai/Mistral-7B-v0.1&quot;</span>
adapter_model = <span class="hljs-string">&quot;dfurman/Mistral-7B-Instruct-v0.2&quot;</span>

model = AutoModelForCausalLM.from_pretrained(base_model)
model = PeftModel.from_pretrained(model, adapter_model)
tokenizer = AutoTokenizer.from_pretrained(base_model)

model = model.to(<span class="hljs-string">&quot;cuda&quot;</span>)
model.<span class="hljs-built_in">eval</span>()`,wrap:!1}}),G=new ue({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMlRlbGwlMjBtZSUyMHRoZSUyMHJlY2lwZSUyMGZvciUyMGNob2NvbGF0ZSUyMGNoaXAlMjBjb29raWUlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoaW5wdXRfaWRzJTNEaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVELnRvKCUyMmN1ZGElMjIpJTJDJTIwbWF4X25ld190b2tlbnMlM0QxMCklMEElMjAlMjAlMjAlMjBwcmludCh0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKG91dHB1dHMuZGV0YWNoKCkuY3B1KCkubnVtcHkoKSUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQp",highlighted:`inputs = tokenizer(<span class="hljs-string">&quot;Tell me the recipe for chocolate chip cookie&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-keyword">with</span> torch.no_grad():
    outputs = model.generate(input_ids=inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].to(<span class="hljs-string">&quot;cuda&quot;</span>), max_new_tokens=<span class="hljs-number">10</span>)
    <span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>])`,wrap:!1}}),C=new ue({props:{code:"VGVsbCUyMG1lJTIwdGhlJTIwcmVjaXBlJTIwZm9yJTIwY2hvY29sYXRlJTIwY2hpcCUyMGNvb2tpZSUyMGRvdWdoLiUwQSUwQTEuJTIwUHJlaGVhdCUyMG92ZW4lMjB0byUyMDM3NSUyMGRlZ3JlZXMlMjBGJTIwKDE5MCUyMGRlZ3JlZXMlMjBDKS4lMEEyLiUyMEluJTIwYSUyMGxhcmdlJTIwYm93bCUyQyUyMGNyZWFtJTIwdG9nZXRoZXIlMjAxJTJGMiUyMGN1cCUyMCgxJTIwc3RpY2spJTIwb2YlMjBidXR0ZXIlMjBvciUyMG1hcmdhcmluZSUyQyUyMDElMkYyJTIwY3VwJTIwZ3JhbnVsYXRlZCUyMHN1Z2FyJTJDJTIwYW5kJTIwMSUyRjIlMjBjdXAlMjBwYWNrZWQlMjBicm93biUyMHN1Z2FyLiUwQTMuJTIwQmVhdCUyMGluJTIwMSUyMGVnZyUyMGFuZCUyMDElMjB0ZWFzcG9vbiUyMHZhbmlsbGElMjBleHRyYWN0LiUwQTQuJTIwTWl4JTIwaW4lMjAxJTIwMSUyRjQlMjBjdXBzJTIwYWxsLXB1cnBvc2UlMjBmbG91ci4lMEE1LiUyMFN0aXIlMjBpbiUyMDElMkYyJTIwdGVhc3Bvb24lMjBiYWtpbmclMjBzb2RhJTIwYW5kJTIwMSUyRjIlMjB0ZWFzcG9vbiUyMHNhbHQuJTBBNi4lMjBGb2xkJTIwaW4lMjAzJTJGNCUyMGN1cCUyMHNlbWlzd2VldCUyMGNob2NvbGF0ZSUyMGNoaXBzLiUwQTcuJTIwRHJvcCUyMGJ5",highlighted:`Tell me the recipe for chocolate chip cookie dough.

1. Preheat oven to 375 degrees F (190 degrees C).
2. In a large bowl, cream together 1/2 cup (1 stick) of butter or margarine, 1/2 cup granulated sugar, and 1/2 cup packed brown sugar.
3. Beat in 1 egg and 1 teaspoon vanilla extract.
4. Mix in 1 1/4 cups all-purpose flour.
5. Stir in 1/2 teaspoon baking soda and 1/2 teaspoon salt.
6. Fold in 3/4 cup semisweet chocolate chips.
7. Drop by`,wrap:!1}}),_=new H({props:{title:"Additional resources",local:"additional-resources",headingTag:"h2"}}),B=new Ce({props:{source:"https://github.com/huggingface/hub-docs/blob/main/docs/hub/peft.md"}}),{c(){g=i("meta"),R=s(),V=i("p"),N=s(),p(w.$$.fragment),X=s(),p(T.$$.fragment),Q=s(),b=i("p"),b.innerHTML=ce,Y=s(),p(y.$$.fragment),L=s(),J=i("p"),J.innerHTML=fe,P=s(),p($.$$.fragment),S=s(),U=i("p"),U.innerHTML=ge,z=s(),p(j.$$.fragment),A=s(),p(I.$$.fragment),q=s(),Z=i("p"),Z.textContent=he,K=s(),p(k.$$.fragment),D=s(),v=i("p"),v.innerHTML=Me,O=s(),p(G.$$.fragment),ee=s(),E=i("p"),E.textContent=we,te=s(),p(C.$$.fragment),le=s(),W=i("p"),W.innerHTML=Te,ne=s(),h=i("div"),h.innerHTML=be,se=s(),M=i("div"),M.innerHTML=ye,ae=s(),p(_.$$.fragment),ie=s(),F=i("ul"),F.innerHTML=Je,oe=s(),p(B.$$.fragment),pe=s(),x=i("p"),this.h()},l(e){const t=ve("svelte-u9bgzb",document.head);g=o(t,"META",{name:!0,content:!0}),t.forEach(l),R=a(e),V=o(e,"P",{}),$e(V).forEach(l),N=a(e),r(w.$$.fragment,e),X=a(e),r(T.$$.fragment,e),Q=a(e),b=o(e,"P",{"data-svelte-h":!0}),f(b)!=="svelte-1pze80r"&&(b.innerHTML=ce),Y=a(e),r(y.$$.fragment,e),L=a(e),J=o(e,"P",{"data-svelte-h":!0}),f(J)!=="svelte-515lb5"&&(J.innerHTML=fe),P=a(e),r($.$$.fragment,e),S=a(e),U=o(e,"P",{"data-svelte-h":!0}),f(U)!=="svelte-11jm9nl"&&(U.innerHTML=ge),z=a(e),r(j.$$.fragment,e),A=a(e),r(I.$$.fragment,e),q=a(e),Z=o(e,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-1qqfp2y"&&(Z.textContent=he),K=a(e),r(k.$$.fragment,e),D=a(e),v=o(e,"P",{"data-svelte-h":!0}),f(v)!=="svelte-1ohlhfq"&&(v.innerHTML=Me),O=a(e),r(G.$$.fragment,e),ee=a(e),E=o(e,"P",{"data-svelte-h":!0}),f(E)!=="svelte-7whdhn"&&(E.textContent=we),te=a(e),r(C.$$.fragment,e),le=a(e),W=o(e,"P",{"data-svelte-h":!0}),f(W)!=="svelte-gbpq7c"&&(W.innerHTML=Te),ne=a(e),h=o(e,"DIV",{class:!0,"data-svelte-h":!0}),f(h)!=="svelte-1ulotkq"&&(h.innerHTML=be),se=a(e),M=o(e,"DIV",{class:!0,"data-svelte-h":!0}),f(M)!=="svelte-ai6chf"&&(M.innerHTML=ye),ae=a(e),r(_.$$.fragment,e),ie=a(e),F=o(e,"UL",{"data-svelte-h":!0}),f(F)!=="svelte-z8ea3s"&&(F.innerHTML=Je),oe=a(e),r(B.$$.fragment,e),pe=a(e),x=o(e,"P",{}),$e(x).forEach(l),this.h()},h(){me(g,"name","hf:doc:metadata"),me(g,"content",_e),me(h,"class","flex justify-center"),me(M,"class","flex justify-center")},m(e,t){Ge(document.head,g),n(e,R,t),n(e,V,t),n(e,N,t),m(w,e,t),n(e,X,t),m(T,e,t),n(e,Q,t),n(e,b,t),n(e,Y,t),m(y,e,t),n(e,L,t),n(e,J,t),n(e,P,t),m($,e,t),n(e,S,t),n(e,U,t),n(e,z,t),m(j,e,t),n(e,A,t),m(I,e,t),n(e,q,t),n(e,Z,t),n(e,K,t),m(k,e,t),n(e,D,t),n(e,v,t),n(e,O,t),m(G,e,t),n(e,ee,t),n(e,E,t),n(e,te,t),m(C,e,t),n(e,le,t),n(e,W,t),n(e,ne,t),n(e,h,t),n(e,se,t),n(e,M,t),n(e,ae,t),m(_,e,t),n(e,ie,t),n(e,F,t),n(e,oe,t),m(B,e,t),n(e,pe,t),n(e,x,t),re=!0},p:je,i(e){re||(u(w.$$.fragment,e),u(T.$$.fragment,e),u(y.$$.fragment,e),u($.$$.fragment,e),u(j.$$.fragment,e),u(I.$$.fragment,e),u(k.$$.fragment,e),u(G.$$.fragment,e),u(C.$$.fragment,e),u(_.$$.fragment,e),u(B.$$.fragment,e),re=!0)},o(e){d(w.$$.fragment,e),d(T.$$.fragment,e),d(y.$$.fragment,e),d($.$$.fragment,e),d(j.$$.fragment,e),d(I.$$.fragment,e),d(k.$$.fragment,e),d(G.$$.fragment,e),d(C.$$.fragment,e),d(_.$$.fragment,e),d(B.$$.fragment,e),re=!1},d(e){e&&(l(R),l(V),l(N),l(X),l(Q),l(b),l(Y),l(L),l(J),l(P),l(S),l(U),l(z),l(A),l(q),l(Z),l(K),l(D),l(v),l(O),l(ee),l(E),l(te),l(le),l(W),l(ne),l(h),l(se),l(M),l(ae),l(ie),l(F),l(oe),l(pe),l(x)),l(g),c(w,e),c(T,e),c(y,e),c($,e),c(j,e),c(I,e),c(k,e),c(G,e),c(C,e),c(_,e),c(B,e)}}}const _e='{"title":"Using PEFT at Hugging Face","local":"using-peft-at-hugging-face","sections":[{"title":"Exploring PEFT on the Hub","local":"exploring-peft-on-the-hub","sections":[],"depth":2},{"title":"Installation","local":"installation","sections":[],"depth":2},{"title":"Using existing models","local":"using-existing-models","sections":[],"depth":2},{"title":"Additional resources","local":"additional-resources","sections":[],"depth":2}],"depth":1}';function Fe(de){return Ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ne extends Ze{constructor(g){super(),ke(this,g,Fe,We,Ue,{})}}export{Ne as component};
