import{s as ge,n as we,o as be}from"../chunks/scheduler.78382b47.js";import{S as ve,i as ye,e as o,s as i,c as A,h as Te,a as s,d as a,b as l,f as ce,g as J,j as r,k as he,l as $e,m as n,n as k,t as L,o as M,p as P}from"../chunks/index.6dd35eb6.js";import{C as _e,H as te,E as Ie}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.6888f903.js";import{C as xe}from"../chunks/CodeBlock.658dd679.js";function Ce(ae){let m,U,q,E,f,H,d,R,p,ne=`This conceptual guide gives a brief overview of <a href="https://huggingface.co/papers/2205.05638" rel="nofollow">IA3</a>, a parameter-efficient fine tuning technique that is
intended to improve over <a href="./lora">LoRA</a>.`,z,u,ie=`To make fine-tuning more efficient, IA3 (Infused Adapter by Inhibiting and Amplifying Inner Activations)
rescales inner activations with learned vectors. These learned vectors are injected in the attention and feedforward modules
in a typical transformer-based architecture. These learned vectors are the only trainable parameters during fine-tuning, and thus the original
weights remain frozen. Dealing with learned vectors (as opposed to learned low-rank updates to a weight matrix like LoRA)
keeps the number of trainable parameters much smaller.`,F,c,le="Being similar to LoRA, IA3 carries many of the same advantages:",G,h,oe="<li>IA3 makes fine-tuning more efficient by drastically reducing the number of trainable parameters. (For T0, an IA3 model only has about 0.01% trainable parameters, while even LoRA has &gt; 0.1%)</li> <li>The original pre-trained weights are kept frozen, which means you can have multiple lightweight and portable IA3 models for various downstream tasks built on top of them.</li> <li>Performance of models fine-tuned using IA3 is comparable to the performance of fully fine-tuned models.</li> <li>IA3 does not add any inference latency because adapter weights can be merged with the base model.</li>",S,g,se=`In principle, IA3 can be applied to any subset of weight matrices in a neural network to reduce the number of trainable
parameters. Following the authors’ implementation, IA3 weights are added to the key, value and feedforward layers
of a Transformer model. To be specific, for transformer models, IA3 weights are added to the outputs of key and value layers, and to the input of the second feedforward layer
in each transformer block.`,V,w,re=`Given the target layers for injecting IA3 parameters, the number of trainable parameters
can be determined based on the size of the weight matrices.`,B,b,Q,v,me="As with other methods supported by PEFT, to fine-tune a model using IA3, you need to:",W,y,fe="<li>Instantiate a base model.</li> <li>Create a configuration (<code>IA3Config</code>) where you define IA3-specific parameters.</li> <li>Wrap the base model with <code>get_peft_model()</code> to get a trainable <code>PeftModel</code>.</li> <li>Train the <code>PeftModel</code> as you normally would train the base model.</li>",D,T,de="<code>IA3Config</code> allows you to control how IA3 is applied to the base model through the following parameters:",N,$,pe=`<li><code>target_modules</code>: The modules (for example, attention blocks) to apply the IA3 vectors.</li> <li><code>feedforward_modules</code>: The list of modules to be treated as feedforward layers in <code>target_modules</code>. While learned vectors are multiplied with
the output activation for attention blocks, the vectors are multiplied with the input for classic feedforward layers. Note that <code>feedforward_modules</code> must be a subset of <code>target_modules</code>.</li> <li><code>modules_to_save</code>: List of modules apart from IA3 layers to be set as trainable and saved in the final checkpoint. These typically include model’s custom head that is randomly initialized for the fine-tuning task.</li>`,Z,_,O,I,ue="For the task of sequence classification, one can initialize the IA3 config for a Llama model as follows:",X,x,K,C,Y,j,ee;return f=new _e({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),d=new te({props:{title:"IA3",local:"ia3",headingTag:"h1"}}),b=new te({props:{title:"Common IA3 parameters in PEFT",local:"common-ia3-parameters-in-peft",headingTag:"h2"}}),_=new te({props:{title:"Example Usage",local:"example-usage",headingTag:"h2"}}),x=new xe({props:{code:"cGVmdF9jb25maWclMjAlM0QlMjBJQTNDb25maWcoJTBBJTIwJTIwJTIwJTIwdGFza190eXBlJTNEVGFza1R5cGUuU0VRX0NMUyUyQyUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTIya19wcm9qJTIyJTJDJTIwJTIydl9wcm9qJTIyJTJDJTIwJTIyZG93bl9wcm9qJTIyJTVEJTJDJTIwZmVlZGZvcndhcmRfbW9kdWxlcyUzRCU1QiUyMmRvd25fcHJvaiUyMiU1RCUwQSk=",highlighted:`peft_config = IA3Config(
    task_type=TaskType.SEQ_CLS, target_modules=[<span class="hljs-string">&quot;k_proj&quot;</span>, <span class="hljs-string">&quot;v_proj&quot;</span>, <span class="hljs-string">&quot;down_proj&quot;</span>], feedforward_modules=[<span class="hljs-string">&quot;down_proj&quot;</span>]
)`,wrap:!1}}),C=new Ie({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/conceptual_guides/ia3.md"}}),{c(){m=o("meta"),U=i(),q=o("p"),E=i(),A(f.$$.fragment),H=i(),A(d.$$.fragment),R=i(),p=o("p"),p.innerHTML=ne,z=i(),u=o("p"),u.textContent=ie,F=i(),c=o("p"),c.textContent=le,G=i(),h=o("ul"),h.innerHTML=oe,S=i(),g=o("p"),g.textContent=se,V=i(),w=o("p"),w.textContent=re,B=i(),A(b.$$.fragment),Q=i(),v=o("p"),v.textContent=me,W=i(),y=o("ol"),y.innerHTML=fe,D=i(),T=o("p"),T.innerHTML=de,N=i(),$=o("ul"),$.innerHTML=pe,Z=i(),A(_.$$.fragment),O=i(),I=o("p"),I.textContent=ue,X=i(),A(x.$$.fragment),K=i(),A(C.$$.fragment),Y=i(),j=o("p"),this.h()},l(e){const t=Te("svelte-u9bgzb",document.head);m=s(t,"META",{name:!0,content:!0}),t.forEach(a),U=l(e),q=s(e,"P",{}),ce(q).forEach(a),E=l(e),J(f.$$.fragment,e),H=l(e),J(d.$$.fragment,e),R=l(e),p=s(e,"P",{"data-svelte-h":!0}),r(p)!=="svelte-11nly24"&&(p.innerHTML=ne),z=l(e),u=s(e,"P",{"data-svelte-h":!0}),r(u)!=="svelte-iyuejo"&&(u.textContent=ie),F=l(e),c=s(e,"P",{"data-svelte-h":!0}),r(c)!=="svelte-mvs6w2"&&(c.textContent=le),G=l(e),h=s(e,"UL",{"data-svelte-h":!0}),r(h)!=="svelte-1d130bu"&&(h.innerHTML=oe),S=l(e),g=s(e,"P",{"data-svelte-h":!0}),r(g)!=="svelte-x58frj"&&(g.textContent=se),V=l(e),w=s(e,"P",{"data-svelte-h":!0}),r(w)!=="svelte-wbgvs7"&&(w.textContent=re),B=l(e),J(b.$$.fragment,e),Q=l(e),v=s(e,"P",{"data-svelte-h":!0}),r(v)!=="svelte-16q36ht"&&(v.textContent=me),W=l(e),y=s(e,"OL",{"data-svelte-h":!0}),r(y)!=="svelte-1sklxcv"&&(y.innerHTML=fe),D=l(e),T=s(e,"P",{"data-svelte-h":!0}),r(T)!=="svelte-wdoadq"&&(T.innerHTML=de),N=l(e),$=s(e,"UL",{"data-svelte-h":!0}),r($)!=="svelte-crbpqt"&&($.innerHTML=pe),Z=l(e),J(_.$$.fragment,e),O=l(e),I=s(e,"P",{"data-svelte-h":!0}),r(I)!=="svelte-hieagv"&&(I.textContent=ue),X=l(e),J(x.$$.fragment,e),K=l(e),J(C.$$.fragment,e),Y=l(e),j=s(e,"P",{}),ce(j).forEach(a),this.h()},h(){he(m,"name","hf:doc:metadata"),he(m,"content",Ae)},m(e,t){$e(document.head,m),n(e,U,t),n(e,q,t),n(e,E,t),k(f,e,t),n(e,H,t),k(d,e,t),n(e,R,t),n(e,p,t),n(e,z,t),n(e,u,t),n(e,F,t),n(e,c,t),n(e,G,t),n(e,h,t),n(e,S,t),n(e,g,t),n(e,V,t),n(e,w,t),n(e,B,t),k(b,e,t),n(e,Q,t),n(e,v,t),n(e,W,t),n(e,y,t),n(e,D,t),n(e,T,t),n(e,N,t),n(e,$,t),n(e,Z,t),k(_,e,t),n(e,O,t),n(e,I,t),n(e,X,t),k(x,e,t),n(e,K,t),k(C,e,t),n(e,Y,t),n(e,j,t),ee=!0},p:we,i(e){ee||(L(f.$$.fragment,e),L(d.$$.fragment,e),L(b.$$.fragment,e),L(_.$$.fragment,e),L(x.$$.fragment,e),L(C.$$.fragment,e),ee=!0)},o(e){M(f.$$.fragment,e),M(d.$$.fragment,e),M(b.$$.fragment,e),M(_.$$.fragment,e),M(x.$$.fragment,e),M(C.$$.fragment,e),ee=!1},d(e){e&&(a(U),a(q),a(E),a(H),a(R),a(p),a(z),a(u),a(F),a(c),a(G),a(h),a(S),a(g),a(V),a(w),a(B),a(Q),a(v),a(W),a(y),a(D),a(T),a(N),a($),a(Z),a(O),a(I),a(X),a(K),a(Y),a(j)),a(m),P(f,e),P(d,e),P(b,e),P(_,e),P(x,e),P(C,e)}}}const Ae='{"title":"IA3","local":"ia3","sections":[{"title":"Common IA3 parameters in PEFT","local":"common-ia3-parameters-in-peft","sections":[],"depth":2},{"title":"Example Usage","local":"example-usage","sections":[],"depth":2}],"depth":1}';function Je(ae){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qe extends ve{constructor(m){super(),ye(this,m,Je,Ce,ge,{})}}export{qe as component};
