import{s as be,o as Te,n as ve}from"../chunks/scheduler.4cd3e004.js";import{S as ye,i as Ie,e as d,s,c as w,h as $e,a as p,d as a,b as r,f as D,g as b,j as T,k as H,l as m,m as n,n as v,t as y,o as I,p as $}from"../chunks/index.b664cb2d.js";import{D as de}from"../chunks/Docstring.9ceb4334.js";import{C as Me}from"../chunks/CodeBlock.8601e34e.js";import{E as xe}from"../chunks/ExampleCodeBlock.4f57b575.js";import{H as pe,E as Ae}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function Je(V){let i,A="Example:",u,c,f;return c=new Me({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMGlhM0NvbmZpZyUwQWZyb20lMjBwZWZ0JTIwaW1wb3J0JTIwSUEzTW9kZWwlMkMlMjBJQTNDb25maWclMEElMEFjb25maWclMjAlM0QlMjBJQTNDb25maWcoJTBBJTIwJTIwJTIwJTIwcGVmdF90eXBlJTNEJTIySUEzJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGFza190eXBlJTNEJTIyU0VRXzJfU0VRX0xNJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X21vZHVsZXMlM0QlNUIlMjJrJTIyJTJDJTIwJTIydiUyMiUyQyUyMCUyMncwJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZmVlZGZvcndhcmRfbW9kdWxlcyUzRCU1QiUyMncwJTIyJTVEJTJDJTBBKSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJ0NS1iYXNlJTIyKSUwQWlhM19tb2RlbCUyMCUzRCUyMElBM01vZGVsKGNvbmZpZyUyQyUyMG1vZGVsKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, ia3Config
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> IA3Model, IA3Config

<span class="hljs-meta">&gt;&gt;&gt; </span>config = IA3Config(
<span class="hljs-meta">... </span>    peft_type=<span class="hljs-string">&quot;IA3&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>    target_modules=[<span class="hljs-string">&quot;k&quot;</span>, <span class="hljs-string">&quot;v&quot;</span>, <span class="hljs-string">&quot;w0&quot;</span>],
<span class="hljs-meta">... </span>    feedforward_modules=[<span class="hljs-string">&quot;w0&quot;</span>],
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;t5-base&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>ia3_model = IA3Model(config, model)`,wrap:!1}}),{c(){i=d("p"),i.textContent=A,u=s(),w(c.$$.fragment)},l(o){i=p(o,"P",{"data-svelte-h":!0}),T(i)!=="svelte-11lpom8"&&(i.textContent=A),u=r(o),b(c.$$.fragment,o)},m(o,h){n(o,i,h),n(o,u,h),v(c,o,h),f=!0},p:ve,i(o){f||(y(c.$$.fragment,o),f=!0)},o(o){I(c.$$.fragment,o),f=!1},d(o){o&&(a(i),a(u)),$(c,o)}}}function Ce(V){let i,A,u,c,f,o,h,me='Infused Adapter by Inhibiting and Amplifying Inner Activations, or <a href="https://hf.co/papers/2205.05638" rel="nofollow">IA3</a>, is a method that adds three learned vectors to rescale the keys and values of the self-attention and encoder-decoder attention layers, and the intermediate activation of the position-wise feed-forward network.',O,J,ce="The abstract from the paper is:",Q,C,fe="<em>Few-shot in-context learning (ICL) enables pre-trained language models to perform a previously-unseen task without any gradient-based training by feeding a small number of training examples as part of the input. ICL incurs substantial computational, memory, and storage costs because it involves processing all of the training examples every time a prediction is made. Parameter-efficient fine-tuning (PEFT) (e.g. adapter modules, prompt tuning, sparse update methods, etc.) offers an alternative paradigm where a small set of parameters are trained to enable a model to perform the new task. In this paper, we rigorously compare few-shot ICL and PEFT and demonstrate that the latter offers better accuracy as well as dramatically lower computational costs. Along the way, we introduce a new PEFT method called (IA)^3 that scales activations by learned vectors, attaining stronger performance while only introducing a relatively tiny amount of new parameters. We also propose a simple recipe based on the T0 model called T-Few that can be applied to new tasks without task-specific tuning or modifications. We validate the effectiveness of T-Few on completely unseen tasks by applying it to the RAFT benchmark, attaining super-human performance for the first time and outperforming the state-of-the-art by 6% absolute. All of the code used in our experiments is publicly available</em>.",G,U,z,_,k,ae,Z,ge='This is the configuration class to store the configuration of a <a href="/docs/peft/main/en/package_reference/ia3#peft.IA3Model">IA3Model</a>.',R,L,X,l,E,ne,q,he=`Creates a Infused Adapter by Inhibiting and Amplifying Inner Activations ((IA)^3) model from a pretrained
transformers model. The method is described in detail in <a href="https://huggingface.co/papers/2205.05638" rel="nofollow">https://huggingface.co/papers/2205.05638</a>`,oe,M,se,W,ue="<strong>Attributes</strong>:",re,B,_e='<li><strong>model</strong> (<a href="https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel" rel="nofollow">PreTrainedModel</a>) — The model to be adapted.</li> <li><strong>peft_config</strong> (<code>ia3Config</code>): The configuration of the (IA)^3 model.</li>',ie,x,j,le,F,we="This method adds a new adapter by merging the given adapters with the given weights.",K,N,Y,S,ee;return f=new pe({props:{title:"IA3",local:"ia3",headingTag:"h1"}}),U=new pe({props:{title:"IA3Config",local:"peft.IA3Config",headingTag:"h2"}}),k=new de({props:{name:"class peft.IA3Config",anchor:"peft.IA3Config",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:"target_modules",val:": Optional[Union[list[str], str]] = None"},{name:"exclude_modules",val:": Optional[Union[list[str], str]] = None"},{name:"feedforward_modules",val:": Optional[Union[list[str], str]] = None"},{name:"fan_in_fan_out",val:": bool = False"},{name:"modules_to_save",val:": Optional[list[str]] = None"},{name:"init_ia3_weights",val:": bool = True"}],parametersDescription:[{anchor:"peft.IA3Config.target_modules",description:`<strong>target_modules</strong> (<code>Optional[Union[List[str], str]]</code>) &#x2014;
The names of the modules to apply the adapter to. If this is specified, only the modules with the specified
names will be replaced. When passing a string, a regex match will be performed. When passing a list of
strings, either an exact match will be performed or it is checked if the name of the module ends with any
of the passed strings. If this is specified as &#x2018;all-linear&#x2019;, then all linear/Conv1D modules are chosen,
excluding the output layer. If this is not specified, modules will be chosen according to the model
architecture. If the architecture is not known, an error will be raised &#x2014; in this case, you should specify
the target modules manually.`,name:"target_modules"},{anchor:"peft.IA3Config.exclude_modules",description:`<strong>exclude_modules</strong> (<code>Optional[Union[List[str], str]]</code>) &#x2014;
The names of the modules to not apply the adapter. When passing a string, a regex match will be performed.
When passing a list of strings, either an exact match will be performed or it is checked if the name of the
module ends with any of the passed strings.`,name:"exclude_modules"},{anchor:"peft.IA3Config.feedforward_modules",description:`<strong>feedforward_modules</strong> (<code>Optional[Union[List[str], str]]</code>) &#x2014;
The names of the modules to be treated as feedforward modules, as in the original paper. These modules will
have (IA)&#xB3; vectors multiplied to the input, instead of the output. <code>feedforward_modules</code> must be a name or
a subset of names present in <code>target_modules</code>.`,name:"feedforward_modules"},{anchor:"peft.IA3Config.fan_in_fan_out",description:`<strong>fan_in_fan_out</strong> (<code>bool</code>) &#x2014;
Set this to True if the layer to replace stores weight like (fan_in, fan_out). For example, gpt-2 uses
<code>Conv1D</code> which stores weights like (fan_in, fan_out) and hence this should be set to <code>True</code>.`,name:"fan_in_fan_out"},{anchor:"peft.IA3Config.modules_to_save",description:`<strong>modules_to_save</strong> (<code>Optional[List[str]]</code>) &#x2014;
List of modules apart from (IA)&#xB3; layers to be set as trainable and saved in the final checkpoint.`,name:"modules_to_save"},{anchor:"peft.IA3Config.init_ia3_weights",description:`<strong>init_ia3_weights</strong> (<code>bool</code>) &#x2014;
Whether to initialize the vectors in the (IA)&#xB3; layers, defaults to <code>True</code>. Setting this to <code>False</code> is
discouraged.`,name:"init_ia3_weights"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/ia3/config.py#L25"}}),L=new pe({props:{title:"IA3Model",local:"peft.IA3Model",headingTag:"h2"}}),E=new de({props:{name:"class peft.IA3Model",anchor:"peft.IA3Model",parameters:[{name:"model",val:""},{name:"peft_config",val:": Union[PeftConfig, dict[str, PeftConfig]]"},{name:"adapter_name",val:": str"},{name:"low_cpu_mem_usage",val:": bool = False"},{name:"state_dict",val:": Optional[dict[str, torch.Tensor]] = None"}],parametersDescription:[{anchor:"peft.IA3Model.model",description:'<strong>model</strong> (<a href="https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel" rel="nofollow">PreTrainedModel</a>) &#x2014; The model to be adapted.',name:"model"},{anchor:"peft.IA3Model.config",description:'<strong>config</strong> (<a href="/docs/peft/main/en/package_reference/ia3#peft.IA3Config">IA3Config</a>) &#x2014; The configuration of the (IA)^3 model.',name:"config"},{anchor:"peft.IA3Model.adapter_name",description:"<strong>adapter_name</strong> (<code>str</code>) &#x2014; The name of the adapter, defaults to <code>&quot;default&quot;</code>.",name:"adapter_name"},{anchor:"peft.IA3Model.low_cpu_mem_usage",description:`<strong>low_cpu_mem_usage</strong> (<code>bool</code>, <code>optional</code>, defaults to <code>False</code>) &#x2014;
Create empty adapter weights on meta device. Useful to speed up the loading process.`,name:"low_cpu_mem_usage"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/ia3/model.py#L36",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The (IA)^3 model.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>torch.nn.Module</code></p>
`}}),M=new xe({props:{anchor:"peft.IA3Model.example",$$slots:{default:[Je]},$$scope:{ctx:V}}}),j=new de({props:{name:"add_weighted_adapter",anchor:"peft.IA3Model.add_weighted_adapter",parameters:[{name:"adapters",val:": list[str]"},{name:"weights",val:": list[float]"},{name:"adapter_name",val:": str"}],parametersDescription:[{anchor:"peft.IA3Model.add_weighted_adapter.adapters",description:`<strong>adapters</strong> (<code>list</code>) &#x2014;
List of adapter names to be merged.`,name:"adapters"},{anchor:"peft.IA3Model.add_weighted_adapter.weights",description:`<strong>weights</strong> (<code>list</code>) &#x2014;
List of weights for each adapter.`,name:"weights"},{anchor:"peft.IA3Model.add_weighted_adapter.adapter_name",description:`<strong>adapter_name</strong> (<code>str</code>) &#x2014;
Name of the new adapter.`,name:"adapter_name"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/ia3/model.py#L266"}}),N=new Ae({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/ia3.md"}}),{c(){i=d("meta"),A=s(),u=d("p"),c=s(),w(f.$$.fragment),o=s(),h=d("p"),h.innerHTML=me,O=s(),J=d("p"),J.textContent=ce,Q=s(),C=d("p"),C.innerHTML=fe,G=s(),w(U.$$.fragment),z=s(),_=d("div"),w(k.$$.fragment),ae=s(),Z=d("p"),Z.innerHTML=ge,R=s(),w(L.$$.fragment),X=s(),l=d("div"),w(E.$$.fragment),ne=s(),q=d("p"),q.innerHTML=he,oe=s(),w(M.$$.fragment),se=s(),W=d("p"),W.innerHTML=ue,re=s(),B=d("ul"),B.innerHTML=_e,ie=s(),x=d("div"),w(j.$$.fragment),le=s(),F=d("p"),F.textContent=we,K=s(),w(N.$$.fragment),Y=s(),S=d("p"),this.h()},l(e){const t=$e("svelte-u9bgzb",document.head);i=p(t,"META",{name:!0,content:!0}),t.forEach(a),A=r(e),u=p(e,"P",{}),D(u).forEach(a),c=r(e),b(f.$$.fragment,e),o=r(e),h=p(e,"P",{"data-svelte-h":!0}),T(h)!=="svelte-1bb1wl3"&&(h.innerHTML=me),O=r(e),J=p(e,"P",{"data-svelte-h":!0}),T(J)!=="svelte-1cwsb16"&&(J.textContent=ce),Q=r(e),C=p(e,"P",{"data-svelte-h":!0}),T(C)!=="svelte-6ze8zr"&&(C.innerHTML=fe),G=r(e),b(U.$$.fragment,e),z=r(e),_=p(e,"DIV",{class:!0});var P=D(_);b(k.$$.fragment,P),ae=r(P),Z=p(P,"P",{"data-svelte-h":!0}),T(Z)!=="svelte-13612p0"&&(Z.innerHTML=ge),P.forEach(a),R=r(e),b(L.$$.fragment,e),X=r(e),l=p(e,"DIV",{class:!0});var g=D(l);b(E.$$.fragment,g),ne=r(g),q=p(g,"P",{"data-svelte-h":!0}),T(q)!=="svelte-87vt46"&&(q.innerHTML=he),oe=r(g),b(M.$$.fragment,g),se=r(g),W=p(g,"P",{"data-svelte-h":!0}),T(W)!=="svelte-1xx6nm4"&&(W.innerHTML=ue),re=r(g),B=p(g,"UL",{"data-svelte-h":!0}),T(B)!=="svelte-1cvf3ph"&&(B.innerHTML=_e),ie=r(g),x=p(g,"DIV",{class:!0});var te=D(x);b(j.$$.fragment,te),le=r(te),F=p(te,"P",{"data-svelte-h":!0}),T(F)!=="svelte-lg9b7q"&&(F.textContent=we),te.forEach(a),g.forEach(a),K=r(e),b(N.$$.fragment,e),Y=r(e),S=p(e,"P",{}),D(S).forEach(a),this.h()},h(){H(i,"name","hf:doc:metadata"),H(i,"content",Ue),H(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(l,"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){m(document.head,i),n(e,A,t),n(e,u,t),n(e,c,t),v(f,e,t),n(e,o,t),n(e,h,t),n(e,O,t),n(e,J,t),n(e,Q,t),n(e,C,t),n(e,G,t),v(U,e,t),n(e,z,t),n(e,_,t),v(k,_,null),m(_,ae),m(_,Z),n(e,R,t),v(L,e,t),n(e,X,t),n(e,l,t),v(E,l,null),m(l,ne),m(l,q),m(l,oe),v(M,l,null),m(l,se),m(l,W),m(l,re),m(l,B),m(l,ie),m(l,x),v(j,x,null),m(x,le),m(x,F),n(e,K,t),v(N,e,t),n(e,Y,t),n(e,S,t),ee=!0},p(e,[t]){const P={};t&2&&(P.$$scope={dirty:t,ctx:e}),M.$set(P)},i(e){ee||(y(f.$$.fragment,e),y(U.$$.fragment,e),y(k.$$.fragment,e),y(L.$$.fragment,e),y(E.$$.fragment,e),y(M.$$.fragment,e),y(j.$$.fragment,e),y(N.$$.fragment,e),ee=!0)},o(e){I(f.$$.fragment,e),I(U.$$.fragment,e),I(k.$$.fragment,e),I(L.$$.fragment,e),I(E.$$.fragment,e),I(M.$$.fragment,e),I(j.$$.fragment,e),I(N.$$.fragment,e),ee=!1},d(e){e&&(a(A),a(u),a(c),a(o),a(h),a(O),a(J),a(Q),a(C),a(G),a(z),a(_),a(R),a(X),a(l),a(K),a(Y),a(S)),a(i),$(f,e),$(U,e),$(k),$(L,e),$(E),$(M),$(j),$(N,e)}}}const Ue='{"title":"IA3","local":"ia3","sections":[{"title":"IA3Config","local":"peft.IA3Config","sections":[],"depth":2},{"title":"IA3Model","local":"peft.IA3Model","sections":[],"depth":2}],"depth":1}';function ke(V){return Te(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qe extends ye{constructor(i){super(),Ie(this,i,ke,Ce,be,{})}}export{qe as component};
