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

<span class="hljs-meta">&gt;&gt;&gt; </span>config = PromptEncoderConfig(
<span class="hljs-meta">... </span>    peft_type=<span class="hljs-string">&quot;P_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_reparameterization_type=<span class="hljs-string">&quot;MLP&quot;</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>prompt_encoder = PromptEncoder(config)`,wrap:!1}}),{c(){p=l("p"),p.textContent=U,g=s(),M(f.$$.fragment)},l(r){p=m(r,"P",{"data-svelte-h":!0}),_(p)!=="svelte-11lpom8"&&(p.textContent=U),g=i(r),v(f.$$.fragment,r)},m(r,h){o(r,p,h),o(r,g,h),T(f,r,h),u=!0},p:Me,i(r){u||($(f.$$.fragment,r),u=!0)},o(r){P(f.$$.fragment,r),u=!1},d(r){r&&(n(p),n(g)),E(f,r)}}}function we(V){let p,U,g,f,u,r,h,pe='<a href="https://hf.co/papers/2103.10385" rel="nofollow">P-tuning</a> adds trainable prompt embeddings to the input that is optimized by a prompt encoder to find a better prompt, eliminating the need to manually design prompts. The prompt tokens can be added anywhere in the input sequence, and p-tuning also introduces anchor tokens for improving performance.',I,C,le="The abstract from the paper is:",X,w,me="<em>While GPTs with traditional fine-tuning fail to achieve strong results on natural language understanding (NLU), we show that GPTs can be better than or comparable to similar-sized BERTs on NLU tasks with a novel method P-tuning — which employs trainable continuous prompt embeddings. On the knowledge probing (LAMA) benchmark, the best GPT recovers 64\\% (P@1) of world knowledge without any additional text provided during test time, which substantially improves the previous best by 20+ percentage points. On the SuperGlue benchmark, GPTs achieve comparable and sometimes better performance to similar-sized BERTs in supervised learning. Importantly, we find that P-tuning also improves BERTs’ performance in both few-shot and supervised settings while largely reducing the need for prompt engineering. Consequently, P-tuning outperforms the state-of-the-art approaches on the few-shot SuperGlue benchmark.</em>.",O,j,Z,b,k,ee,N,ce='This is the configuration class to store the configuration of a <a href="/docs/peft/main/en/package_reference/p_tuning#peft.PromptEncoder">PromptEncoder</a>.',A,z,F,a,x,te,R,de="The prompt encoder network that is used to generate the virtual token embeddings for p-tuning.",ne,y,oe,H,fe="<strong>Attributes</strong>:",re,Q,ue=`<li><strong>embedding</strong> (<code>torch.nn.Embedding</code>) — The embedding layer of the prompt encoder.</li> <li><strong>mlp_head</strong> (<code>torch.nn.Sequential</code>) — The MLP head of the prompt encoder if <code>inference_mode=False</code>.</li> <li><strong>lstm_head</strong> (<code>torch.nn.LSTM</code>) — The LSTM head of the prompt encoder if <code>inference_mode=False</code> and
<code>encoder_reparameterization_type=&quot;LSTM&quot;</code>.</li> <li><strong>token_dim</strong> (<code>int</code>) — The hidden embedding dimension of the base transformer model.</li> <li><strong>input_size</strong> (<code>int</code>) — The input size of the prompt encoder.</li> <li><strong>output_size</strong> (<code>int</code>) — The output size of the prompt encoder.</li> <li><strong>hidden_size</strong> (<code>int</code>) — The hidden size of the prompt encoder.</li> <li><strong>total_virtual_tokens</strong> (<code>int</code>): The total number of virtual tokens of the
prompt encoder.</li> <li><strong>encoder_type</strong> (Union[<code>PromptEncoderReparameterizationType</code>, <code>str</code>]): The encoder type of the prompt
encoder.</li>`,ae,S,he="Input shape: (<code>batch_size</code>, <code>total_virtual_tokens</code>)",se,B,ge="Output shape: (<code>batch_size</code>, <code>total_virtual_tokens</code>, <code>token_dim</code>)",q,J,D,G,W;return u=new ie({props:{title:"P-tuning",local:"p-tuning",headingTag:"h1"}}),j=new ie({props:{title:"PromptEncoderConfig",local:"peft.PromptEncoderConfig",headingTag:"h2"}}),k=new _e({props:{name:"class peft.PromptEncoderConfig",anchor:"peft.PromptEncoderConfig",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_reparameterization_type",val:": typing.Union[str, peft.tuners.p_tuning.config.PromptEncoderReparameterizationType] = <PromptEncoderReparameterizationType.MLP: 'MLP'>"},{name:"encoder_hidden_size",val:": int = None"},{name:"encoder_num_layers",val:": int = 2"},{name:"encoder_dropout",val:": float = 0.0"}],parametersDescription:[{anchor:"peft.PromptEncoderConfig.encoder_reparameterization_type",description:`<strong>encoder_reparameterization_type</strong> (Union[<code>PromptEncoderReparameterizationType</code>, <code>str</code>]) &#x2014;
The type of reparameterization to use.`,name:"encoder_reparameterization_type"},{anchor:"peft.PromptEncoderConfig.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.PromptEncoderConfig.encoder_num_layers",description:"<strong>encoder_num_layers</strong> (<code>int</code>) &#x2014; The number of layers of the prompt encoder.",name:"encoder_num_layers"},{anchor:"peft.PromptEncoderConfig.encoder_dropout",description:"<strong>encoder_dropout</strong> (<code>float</code>) &#x2014; The dropout probability of the prompt encoder.",name:"encoder_dropout"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/p_tuning/config.py#L29"}}),z=new ie({props:{title:"PromptEncoder",local:"peft.PromptEncoder",headingTag:"h2"}}),x=new _e({props:{name:"class peft.PromptEncoder",anchor:"peft.PromptEncoder",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"peft.PromptEncoder.config",description:'<strong>config</strong> (<a href="/docs/peft/main/en/package_reference/p_tuning#peft.PromptEncoderConfig">PromptEncoderConfig</a>) &#x2014; The configuration of the prompt encoder.',name:"config"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/p_tuning/model.py#L24"}}),y=new Ee({props:{anchor:"peft.PromptEncoder.example",$$slots:{default:[Ce]},$$scope:{ctx:V}}}),J=new Ue({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/p_tuning.md"}}),{c(){p=l("meta"),U=s(),g=l("p"),f=s(),M(u.$$.fragment),r=s(),h=l("p"),h.innerHTML=pe,I=s(),C=l("p"),C.textContent=le,X=s(),w=l("p"),w.innerHTML=me,O=s(),M(j.$$.fragment),Z=s(),b=l("div"),M(k.$$.fragment),ee=s(),N=l("p"),N.innerHTML=ce,A=s(),M(z.$$.fragment),F=s(),a=l("div"),M(x.$$.fragment),te=s(),R=l("p"),R.textContent=de,ne=s(),M(y.$$.fragment),oe=s(),H=l("p"),H.innerHTML=fe,re=s(),Q=l("ul"),Q.innerHTML=ue,ae=s(),S=l("p"),S.innerHTML=he,se=s(),B=l("p"),B.innerHTML=ge,q=s(),M(J.$$.fragment),D=s(),G=l("p"),this.h()},l(e){const t=$e("svelte-u9bgzb",document.head);p=m(t,"META",{name:!0,content:!0}),t.forEach(n),U=i(e),g=m(e,"P",{}),Y(g).forEach(n),f=i(e),v(u.$$.fragment,e),r=i(e),h=m(e,"P",{"data-svelte-h":!0}),_(h)!=="svelte-zvad53"&&(h.innerHTML=pe),I=i(e),C=m(e,"P",{"data-svelte-h":!0}),_(C)!=="svelte-1cwsb16"&&(C.textContent=le),X=i(e),w=m(e,"P",{"data-svelte-h":!0}),_(w)!=="svelte-131yaps"&&(w.innerHTML=me),O=i(e),v(j.$$.fragment,e),Z=i(e),b=m(e,"DIV",{class:!0});var L=Y(b);v(k.$$.fragment,L),ee=i(L),N=m(L,"P",{"data-svelte-h":!0}),_(N)!=="svelte-b0lt2j"&&(N.innerHTML=ce),L.forEach(n),A=i(e),v(z.$$.fragment,e),F=i(e),a=m(e,"DIV",{class:!0});var c=Y(a);v(x.$$.fragment,c),te=i(c),R=m(c,"P",{"data-svelte-h":!0}),_(R)!=="svelte-2xuoj1"&&(R.textContent=de),ne=i(c),v(y.$$.fragment,c),oe=i(c),H=m(c,"P",{"data-svelte-h":!0}),_(H)!=="svelte-1xx6nm4"&&(H.innerHTML=fe),re=i(c),Q=m(c,"UL",{"data-svelte-h":!0}),_(Q)!=="svelte-17fn2on"&&(Q.innerHTML=ue),ae=i(c),S=m(c,"P",{"data-svelte-h":!0}),_(S)!=="svelte-b3kmuz"&&(S.innerHTML=he),se=i(c),B=m(c,"P",{"data-svelte-h":!0}),_(B)!=="svelte-17eznf9"&&(B.innerHTML=ge),c.forEach(n),q=i(e),v(J.$$.fragment,e),D=i(e),G=m(e,"P",{}),Y(G).forEach(n),this.h()},h(){K(p,"name","hf:doc:metadata"),K(p,"content",je),K(b,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),K(a,"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){d(document.head,p),o(e,U,t),o(e,g,t),o(e,f,t),T(u,e,t),o(e,r,t),o(e,h,t),o(e,I,t),o(e,C,t),o(e,X,t),o(e,w,t),o(e,O,t),T(j,e,t),o(e,Z,t),o(e,b,t),T(k,b,null),d(b,ee),d(b,N),o(e,A,t),T(z,e,t),o(e,F,t),o(e,a,t),T(x,a,null),d(a,te),d(a,R),d(a,ne),T(y,a,null),d(a,oe),d(a,H),d(a,re),d(a,Q),d(a,ae),d(a,S),d(a,se),d(a,B),o(e,q,t),T(J,e,t),o(e,D,t),o(e,G,t),W=!0},p(e,[t]){const L={};t&2&&(L.$$scope={dirty:t,ctx:e}),y.$set(L)},i(e){W||($(u.$$.fragment,e),$(j.$$.fragment,e),$(k.$$.fragment,e),$(z.$$.fragment,e),$(x.$$.fragment,e),$(y.$$.fragment,e),$(J.$$.fragment,e),W=!0)},o(e){P(u.$$.fragment,e),P(j.$$.fragment,e),P(k.$$.fragment,e),P(z.$$.fragment,e),P(x.$$.fragment,e),P(y.$$.fragment,e),P(J.$$.fragment,e),W=!1},d(e){e&&(n(U),n(g),n(f),n(r),n(h),n(I),n(C),n(X),n(w),n(O),n(Z),n(b),n(A),n(F),n(a),n(q),n(D),n(G)),n(p),E(u,e),E(j,e),E(k),E(z,e),E(x),E(y),E(J,e)}}}const je='{"title":"P-tuning","local":"p-tuning","sections":[{"title":"PromptEncoderConfig","local":"peft.PromptEncoderConfig","sections":[],"depth":2},{"title":"PromptEncoder","local":"peft.PromptEncoder","sections":[],"depth":2}],"depth":1}';function ke(V){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class He extends ve{constructor(p){super(),Te(this,p,ke,we,be,{})}}export{He as component};
