import{s as xe,o as Me,n as be}from"../chunks/scheduler.4cd3e004.js";import{S as $e,i as ve,e as p,s as i,c as b,h as ye,a as f,d as n,b as o,f as Y,g as $,j as _,k as K,l as c,m as a,n as v,t as y,o as T,p as C}from"../chunks/index.b664cb2d.js";import{D as _e}from"../chunks/Docstring.9ceb4334.js";import{C as Te}from"../chunks/CodeBlock.8601e34e.js";import{E as Ce}from"../chunks/ExampleCodeBlock.4f57b575.js";import{H as oe,E as Ue}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function je(G){let l,U="Example:",h,d,u;return d=new Te({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBQcmVmaXhFbmNvZGVyJTJDJTIwUHJlZml4VHVuaW5nQ29uZmlnJTBBJTBBY29uZmlnJTIwJTNEJTIwUHJlZml4VHVuaW5nQ29uZmlnKCUwQSUyMCUyMCUyMCUyMHBlZnRfdHlwZSUzRCUyMlBSRUZJWF9UVU5JTkclMjIlMkMlMEElMjAlMjAlMjAlMjB0YXNrX3R5cGUlM0QlMjJTRVFfMl9TRVFfTE0lMjIlMkMlMEElMjAlMjAlMjAlMjBudW1fdmlydHVhbF90b2tlbnMlM0QyMCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuX2RpbSUzRDc2OCUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFuc2Zvcm1lcl9zdWJtb2R1bGVzJTNEMSUyQyUwQSUyMCUyMCUyMCUyMG51bV9hdHRlbnRpb25faGVhZHMlM0QxMiUyQyUwQSUyMCUyMCUyMCUyMG51bV9sYXllcnMlM0QxMiUyQyUwQSUyMCUyMCUyMCUyMGVuY29kZXJfaGlkZGVuX3NpemUlM0Q3NjglMkMlMEEpJTBBcHJlZml4X2VuY29kZXIlMjAlM0QlMjBQcmVmaXhFbmNvZGVyKGNvbmZpZyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PrefixEncoder, PrefixTuningConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config = PrefixTuningConfig(
<span class="hljs-meta">... </span>    peft_type=<span class="hljs-string">&quot;PREFIX_TUNING&quot;</span>,
<span class="hljs-meta">... </span>    task_type=<span class="hljs-string">&quot;SEQ_2_SEQ_LM&quot;</span>,
<span class="hljs-meta">... </span>    num_virtual_tokens=<span class="hljs-number">20</span>,
<span class="hljs-meta">... </span>    token_dim=<span class="hljs-number">768</span>,
<span class="hljs-meta">... </span>    num_transformer_submodules=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>    num_attention_heads=<span class="hljs-number">12</span>,
<span class="hljs-meta">... </span>    num_layers=<span class="hljs-number">12</span>,
<span class="hljs-meta">... </span>    encoder_hidden_size=<span class="hljs-number">768</span>,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>prefix_encoder = PrefixEncoder(config)`,wrap:!1}}),{c(){l=p("p"),l.textContent=U,h=i(),b(d.$$.fragment)},l(s){l=f(s,"P",{"data-svelte-h":!0}),_(l)!=="svelte-11lpom8"&&(l.textContent=U),h=o(s),$(d.$$.fragment,s)},m(s,g){a(s,l,g),a(s,h,g),v(d,s,g),u=!0},p:be,i(s){u||(y(d.$$.fragment,s),u=!0)},o(s){T(d.$$.fragment,s),u=!1},d(s){s&&(n(l),n(h)),C(d,s)}}}function Pe(G){let l,U,h,d,u,s,g,le='<a href="https://hf.co/papers/2101.00190" rel="nofollow">Prefix tuning</a> prefixes a series of task-specific vectors to the input sequence that can be learned while keeping the pretrained model frozen. The prefix parameters are inserted in all of the model layers.',R,j,pe="The abstract from the paper is:",O,P,fe="<em>Fine-tuning is the de facto way to leverage large pretrained language models to perform downstream tasks. However, it modifies all the language model parameters and therefore necessitates storing a full copy for each task. In this paper, we propose prefix-tuning, a lightweight alternative to fine-tuning for natural language generation tasks, which keeps language model parameters frozen, but optimizes a small continuous task-specific vector (called the prefix). Prefix-tuning draws inspiration from prompting, allowing subsequent tokens to attend to this prefix as if it were “virtual tokens”. We apply prefix-tuning to GPT-2 for table-to-text generation and to BART for summarization. We find that by learning only 0.1\\% of the parameters, prefix-tuning obtains comparable performance in the full data setting, outperforms fine-tuning in low-data settings, and extrapolates better to examples with topics unseen during training</em>.",I,w,X,x,k,ee,V,me='This is the configuration class to store the configuration of a <a href="/docs/peft/main/en/package_reference/prefix_tuning#peft.PrefixEncoder">PrefixEncoder</a>.',F,E,q,r,H,te,L,ce="The <code>torch.nn</code> model to encode the prefix.",ne,M,ae,Z,de="<strong>Attributes</strong>:",se,J,ue=`<li><strong>embedding</strong> (<code>torch.nn.Embedding</code>) — The embedding layer of the prefix encoder.</li> <li><strong>transform</strong> (<code>torch.nn.Sequential</code>) — The two-layer MLP to transform the prefix embeddings if
<code>prefix_projection</code> is <code>True</code>.</li> <li><strong>prefix_projection</strong> (<code>bool</code>) — Whether to project the prefix embeddings.</li>`,re,z,ge="Input shape: (<code>batch_size</code>, <code>num_virtual_tokens</code>)",ie,B,he="Output shape: (<code>batch_size</code>, <code>num_virtual_tokens</code>, <code>2*layers*hidden</code>)",A,Q,W,S,D;return u=new oe({props:{title:"Prefix tuning",local:"prefix-tuning",headingTag:"h1"}}),w=new oe({props:{title:"PrefixTuningConfig",local:"peft.PrefixTuningConfig",headingTag:"h2"}}),k=new _e({props:{name:"class peft.PrefixTuningConfig",anchor:"peft.PrefixTuningConfig",parameters:[{name:"task_type",val:": Optional[Union[str, TaskType]] = None"},{name:"peft_type",val:": Optional[Union[str, PeftType]] = None"},{name:"auto_mapping",val:": Optional[dict] = None"},{name:"peft_version",val:": Optional[str] = None"},{name:"base_model_name_or_path",val:": Optional[str] = None"},{name:"revision",val:": Optional[str] = None"},{name:"inference_mode",val:": bool = False"},{name:"num_virtual_tokens",val:": int = None"},{name:"token_dim",val:": int = None"},{name:"num_transformer_submodules",val:": Optional[int] = None"},{name:"num_attention_heads",val:": Optional[int] = None"},{name:"num_layers",val:": Optional[int] = None"},{name:"modules_to_save",val:": Optional[list[str]] = None"},{name:"encoder_hidden_size",val:": int = None"},{name:"prefix_projection",val:": bool = False"}],parametersDescription:[{anchor:"peft.PrefixTuningConfig.encoder_hidden_size",description:"<strong>encoder_hidden_size</strong> (<code>int</code>) &#x2014; The hidden size of the prompt encoder.",name:"encoder_hidden_size"},{anchor:"peft.PrefixTuningConfig.prefix_projection",description:"<strong>prefix_projection</strong> (<code>bool</code>) &#x2014; Whether to project the prefix embeddings.",name:"prefix_projection"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/prefix_tuning/config.py#L22"}}),E=new oe({props:{title:"PrefixEncoder",local:"peft.PrefixEncoder",headingTag:"h2"}}),H=new _e({props:{name:"class peft.PrefixEncoder",anchor:"peft.PrefixEncoder",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"peft.PrefixEncoder.config",description:'<strong>config</strong> (<a href="/docs/peft/main/en/package_reference/prefix_tuning#peft.PrefixTuningConfig">PrefixTuningConfig</a>) &#x2014; The configuration of the prefix encoder.',name:"config"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/prefix_tuning/model.py#L20"}}),M=new Ce({props:{anchor:"peft.PrefixEncoder.example",$$slots:{default:[je]},$$scope:{ctx:G}}}),Q=new Ue({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/prefix_tuning.md"}}),{c(){l=p("meta"),U=i(),h=p("p"),d=i(),b(u.$$.fragment),s=i(),g=p("p"),g.innerHTML=le,R=i(),j=p("p"),j.textContent=pe,O=i(),P=p("p"),P.innerHTML=fe,I=i(),b(w.$$.fragment),X=i(),x=p("div"),b(k.$$.fragment),ee=i(),V=p("p"),V.innerHTML=me,F=i(),b(E.$$.fragment),q=i(),r=p("div"),b(H.$$.fragment),te=i(),L=p("p"),L.innerHTML=ce,ne=i(),b(M.$$.fragment),ae=i(),Z=p("p"),Z.innerHTML=de,se=i(),J=p("ul"),J.innerHTML=ue,re=i(),z=p("p"),z.innerHTML=ge,ie=i(),B=p("p"),B.innerHTML=he,A=i(),b(Q.$$.fragment),W=i(),S=p("p"),this.h()},l(e){const t=ye("svelte-u9bgzb",document.head);l=f(t,"META",{name:!0,content:!0}),t.forEach(n),U=o(e),h=f(e,"P",{}),Y(h).forEach(n),d=o(e),$(u.$$.fragment,e),s=o(e),g=f(e,"P",{"data-svelte-h":!0}),_(g)!=="svelte-arymvv"&&(g.innerHTML=le),R=o(e),j=f(e,"P",{"data-svelte-h":!0}),_(j)!=="svelte-1cwsb16"&&(j.textContent=pe),O=o(e),P=f(e,"P",{"data-svelte-h":!0}),_(P)!=="svelte-pu6a2e"&&(P.innerHTML=fe),I=o(e),$(w.$$.fragment,e),X=o(e),x=f(e,"DIV",{class:!0});var N=Y(x);$(k.$$.fragment,N),ee=o(N),V=f(N,"P",{"data-svelte-h":!0}),_(V)!=="svelte-1q81emz"&&(V.innerHTML=me),N.forEach(n),F=o(e),$(E.$$.fragment,e),q=o(e),r=f(e,"DIV",{class:!0});var m=Y(r);$(H.$$.fragment,m),te=o(m),L=f(m,"P",{"data-svelte-h":!0}),_(L)!=="svelte-18w6err"&&(L.innerHTML=ce),ne=o(m),$(M.$$.fragment,m),ae=o(m),Z=f(m,"P",{"data-svelte-h":!0}),_(Z)!=="svelte-1xx6nm4"&&(Z.innerHTML=de),se=o(m),J=f(m,"UL",{"data-svelte-h":!0}),_(J)!=="svelte-1fcqv17"&&(J.innerHTML=ue),re=o(m),z=f(m,"P",{"data-svelte-h":!0}),_(z)!=="svelte-15aa8e5"&&(z.innerHTML=ge),ie=o(m),B=f(m,"P",{"data-svelte-h":!0}),_(B)!=="svelte-1k69wor"&&(B.innerHTML=he),m.forEach(n),A=o(e),$(Q.$$.fragment,e),W=o(e),S=f(e,"P",{}),Y(S).forEach(n),this.h()},h(){K(l,"name","hf:doc:metadata"),K(l,"content",we),K(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),K(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){c(document.head,l),a(e,U,t),a(e,h,t),a(e,d,t),v(u,e,t),a(e,s,t),a(e,g,t),a(e,R,t),a(e,j,t),a(e,O,t),a(e,P,t),a(e,I,t),v(w,e,t),a(e,X,t),a(e,x,t),v(k,x,null),c(x,ee),c(x,V),a(e,F,t),v(E,e,t),a(e,q,t),a(e,r,t),v(H,r,null),c(r,te),c(r,L),c(r,ne),v(M,r,null),c(r,ae),c(r,Z),c(r,se),c(r,J),c(r,re),c(r,z),c(r,ie),c(r,B),a(e,A,t),v(Q,e,t),a(e,W,t),a(e,S,t),D=!0},p(e,[t]){const N={};t&2&&(N.$$scope={dirty:t,ctx:e}),M.$set(N)},i(e){D||(y(u.$$.fragment,e),y(w.$$.fragment,e),y(k.$$.fragment,e),y(E.$$.fragment,e),y(H.$$.fragment,e),y(M.$$.fragment,e),y(Q.$$.fragment,e),D=!0)},o(e){T(u.$$.fragment,e),T(w.$$.fragment,e),T(k.$$.fragment,e),T(E.$$.fragment,e),T(H.$$.fragment,e),T(M.$$.fragment,e),T(Q.$$.fragment,e),D=!1},d(e){e&&(n(U),n(h),n(d),n(s),n(g),n(R),n(j),n(O),n(P),n(I),n(X),n(x),n(F),n(q),n(r),n(A),n(W),n(S)),n(l),C(u,e),C(w,e),C(k),C(E,e),C(H),C(M),C(Q,e)}}}const we='{"title":"Prefix tuning","local":"prefix-tuning","sections":[{"title":"PrefixTuningConfig","local":"peft.PrefixTuningConfig","sections":[],"depth":2},{"title":"PrefixEncoder","local":"peft.PrefixEncoder","sections":[],"depth":2}],"depth":1}';function ke(G){return Me(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ze extends $e{constructor(l){super(),ve(this,l,ke,Pe,xe,{})}}export{Ze as component};
