import{s as $e,o as ve,n as be}from"../chunks/scheduler.78382b47.js";import{S as ye,i as Te,e as p,s as r,c as M,h as Ce,a as f,d as n,b as s,f as ee,g as $,j as x,k as te,l as c,m as a,n as v,t as b,o as y,p as T}from"../chunks/index.6dd35eb6.js";import{C as Ue,H as pe,E as je}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.8d7e60c0.js";import{D as Me}from"../chunks/Docstring.57cb1354.js";import{C as Pe}from"../chunks/CodeBlock.4d4112a9.js";import{E as we}from"../chunks/ExampleCodeBlock.7440be11.js";function ke(R){let l,U="Example:",h,d,u;return d=new Pe({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=r(),M(d.$$.fragment)},l(i){l=f(i,"P",{"data-svelte-h":!0}),x(l)!=="svelte-11lpom8"&&(l.textContent=U),h=s(i),$(d.$$.fragment,i)},m(i,g){a(i,l,g),a(i,h,g),v(d,i,g),u=!0},p:be,i(i){u||(b(d.$$.fragment,i),u=!0)},o(i){y(d.$$.fragment,i),u=!1},d(i){i&&(n(l),n(h)),T(d,i)}}}function Ee(R){let l,U,h,d,u,i,g,O,j,fe='<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.',I,P,me="The abstract from the paper is:",X,w,ce="<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>.",F,k,A,_,E,ne,V,de='This is the configuration class to store the configuration of a <a href="/docs/peft/v0.18.0.rc0/en/package_reference/prefix_tuning#peft.PrefixEncoder">PrefixEncoder</a>.',q,H,W,o,Q,ae,Z,ue="The <code>torch.nn</code> model to encode the prefix.",re,C,se,J,ge="<strong>Attributes</strong>:",ie,z,he=`<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>`,oe,B,xe="Input shape: (<code>batch_size</code>, <code>num_virtual_tokens</code>)",le,S,_e="Output shape: (<code>batch_size</code>, <code>num_virtual_tokens</code>, <code>2*layers*hidden</code>)",D,L,Y,G,K;return u=new Ue({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new pe({props:{title:"Prefix tuning",local:"prefix-tuning",headingTag:"h1"}}),k=new pe({props:{title:"PrefixTuningConfig",local:"peft.PrefixTuningConfig",headingTag:"h2"}}),E=new Me({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/v0.18.0.rc0/src/peft/tuners/prefix_tuning/config.py#L22"}}),H=new pe({props:{title:"PrefixEncoder",local:"peft.PrefixEncoder",headingTag:"h2"}}),Q=new Me({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/v0.18.0.rc0/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/v0.18.0.rc0/src/peft/tuners/prefix_tuning/model.py#L20"}}),C=new we({props:{anchor:"peft.PrefixEncoder.example",$$slots:{default:[ke]},$$scope:{ctx:R}}}),L=new je({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/prefix_tuning.md"}}),{c(){l=p("meta"),U=r(),h=p("p"),d=r(),M(u.$$.fragment),i=r(),M(g.$$.fragment),O=r(),j=p("p"),j.innerHTML=fe,I=r(),P=p("p"),P.textContent=me,X=r(),w=p("p"),w.innerHTML=ce,F=r(),M(k.$$.fragment),A=r(),_=p("div"),M(E.$$.fragment),ne=r(),V=p("p"),V.innerHTML=de,q=r(),M(H.$$.fragment),W=r(),o=p("div"),M(Q.$$.fragment),ae=r(),Z=p("p"),Z.innerHTML=ue,re=r(),M(C.$$.fragment),se=r(),J=p("p"),J.innerHTML=ge,ie=r(),z=p("ul"),z.innerHTML=he,oe=r(),B=p("p"),B.innerHTML=xe,le=r(),S=p("p"),S.innerHTML=_e,D=r(),M(L.$$.fragment),Y=r(),G=p("p"),this.h()},l(e){const t=Ce("svelte-u9bgzb",document.head);l=f(t,"META",{name:!0,content:!0}),t.forEach(n),U=s(e),h=f(e,"P",{}),ee(h).forEach(n),d=s(e),$(u.$$.fragment,e),i=s(e),$(g.$$.fragment,e),O=s(e),j=f(e,"P",{"data-svelte-h":!0}),x(j)!=="svelte-arymvv"&&(j.innerHTML=fe),I=s(e),P=f(e,"P",{"data-svelte-h":!0}),x(P)!=="svelte-1cwsb16"&&(P.textContent=me),X=s(e),w=f(e,"P",{"data-svelte-h":!0}),x(w)!=="svelte-pu6a2e"&&(w.innerHTML=ce),F=s(e),$(k.$$.fragment,e),A=s(e),_=f(e,"DIV",{class:!0});var N=ee(_);$(E.$$.fragment,N),ne=s(N),V=f(N,"P",{"data-svelte-h":!0}),x(V)!=="svelte-kmtgas"&&(V.innerHTML=de),N.forEach(n),q=s(e),$(H.$$.fragment,e),W=s(e),o=f(e,"DIV",{class:!0});var m=ee(o);$(Q.$$.fragment,m),ae=s(m),Z=f(m,"P",{"data-svelte-h":!0}),x(Z)!=="svelte-18w6err"&&(Z.innerHTML=ue),re=s(m),$(C.$$.fragment,m),se=s(m),J=f(m,"P",{"data-svelte-h":!0}),x(J)!=="svelte-1xx6nm4"&&(J.innerHTML=ge),ie=s(m),z=f(m,"UL",{"data-svelte-h":!0}),x(z)!=="svelte-1fcqv17"&&(z.innerHTML=he),oe=s(m),B=f(m,"P",{"data-svelte-h":!0}),x(B)!=="svelte-15aa8e5"&&(B.innerHTML=xe),le=s(m),S=f(m,"P",{"data-svelte-h":!0}),x(S)!=="svelte-1k69wor"&&(S.innerHTML=_e),m.forEach(n),D=s(e),$(L.$$.fragment,e),Y=s(e),G=f(e,"P",{}),ee(G).forEach(n),this.h()},h(){te(l,"name","hf:doc:metadata"),te(l,"content",He),te(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),te(o,"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,i,t),v(g,e,t),a(e,O,t),a(e,j,t),a(e,I,t),a(e,P,t),a(e,X,t),a(e,w,t),a(e,F,t),v(k,e,t),a(e,A,t),a(e,_,t),v(E,_,null),c(_,ne),c(_,V),a(e,q,t),v(H,e,t),a(e,W,t),a(e,o,t),v(Q,o,null),c(o,ae),c(o,Z),c(o,re),v(C,o,null),c(o,se),c(o,J),c(o,ie),c(o,z),c(o,oe),c(o,B),c(o,le),c(o,S),a(e,D,t),v(L,e,t),a(e,Y,t),a(e,G,t),K=!0},p(e,[t]){const N={};t&2&&(N.$$scope={dirty:t,ctx:e}),C.$set(N)},i(e){K||(b(u.$$.fragment,e),b(g.$$.fragment,e),b(k.$$.fragment,e),b(E.$$.fragment,e),b(H.$$.fragment,e),b(Q.$$.fragment,e),b(C.$$.fragment,e),b(L.$$.fragment,e),K=!0)},o(e){y(u.$$.fragment,e),y(g.$$.fragment,e),y(k.$$.fragment,e),y(E.$$.fragment,e),y(H.$$.fragment,e),y(Q.$$.fragment,e),y(C.$$.fragment,e),y(L.$$.fragment,e),K=!1},d(e){e&&(n(U),n(h),n(d),n(i),n(O),n(j),n(I),n(P),n(X),n(w),n(F),n(A),n(_),n(q),n(W),n(o),n(D),n(Y),n(G)),n(l),T(u,e),T(g,e),T(k,e),T(E),T(H,e),T(Q),T(C),T(L,e)}}}const He='{"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 Qe(R){return ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Be extends ye{constructor(l){super(),Te(this,l,Qe,Ee,$e,{})}}export{Be as component};
