import{s as ce,n as he,o as ge}from"../chunks/scheduler.4cd3e004.js";import{S as we,i as be,e as o,s as i,c as J,h as ve,a as s,d as a,b as l,f as pe,g as k,j as r,k as ue,l as Te,m as n,n as L,t as M,o as P,p as q}from"../chunks/index.b664cb2d.js";import{C as ye}from"../chunks/CodeBlock.8601e34e.js";import{H as Y,E as _e}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function Ie(ee){let m,j,x,U,d,E,f,te=`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>.`,H,p,ae=`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.`,R,u,ne="Being similar to LoRA, IA3 carries many of the same advantages:",z,c,ie="<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>",F,h,le=`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.`,G,g,oe=`Given the target layers for injecting IA3 parameters, the number of trainable parameters
can be determined based on the size of the weight matrices.`,V,w,B,b,se="As with other methods supported by PEFT, to fine-tune a model using IA3, you need to:",Q,v,re="<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>",S,T,me="<code>IA3Config</code> allows you to control how IA3 is applied to the base model through the following parameters:",W,y,de=`<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>`,D,_,N,I,fe="For the task of sequence classification, one can initialize the IA3 config for a Llama model as follows:",Z,$,O,C,X,A,K;return d=new Y({props:{title:"IA3",local:"ia3",headingTag:"h1"}}),w=new Y({props:{title:"Common IA3 parameters in PEFT",local:"common-ia3-parameters-in-peft",headingTag:"h2"}}),_=new Y({props:{title:"Example Usage",local:"example-usage",headingTag:"h2"}}),$=new ye({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 _e({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/conceptual_guides/ia3.md"}}),{c(){m=o("meta"),j=i(),x=o("p"),U=i(),J(d.$$.fragment),E=i(),f=o("p"),f.innerHTML=te,H=i(),p=o("p"),p.textContent=ae,R=i(),u=o("p"),u.textContent=ne,z=i(),c=o("ul"),c.innerHTML=ie,F=i(),h=o("p"),h.textContent=le,G=i(),g=o("p"),g.textContent=oe,V=i(),J(w.$$.fragment),B=i(),b=o("p"),b.textContent=se,Q=i(),v=o("ol"),v.innerHTML=re,S=i(),T=o("p"),T.innerHTML=me,W=i(),y=o("ul"),y.innerHTML=de,D=i(),J(_.$$.fragment),N=i(),I=o("p"),I.textContent=fe,Z=i(),J($.$$.fragment),O=i(),J(C.$$.fragment),X=i(),A=o("p"),this.h()},l(e){const t=ve("svelte-u9bgzb",document.head);m=s(t,"META",{name:!0,content:!0}),t.forEach(a),j=l(e),x=s(e,"P",{}),pe(x).forEach(a),U=l(e),k(d.$$.fragment,e),E=l(e),f=s(e,"P",{"data-svelte-h":!0}),r(f)!=="svelte-11nly24"&&(f.innerHTML=te),H=l(e),p=s(e,"P",{"data-svelte-h":!0}),r(p)!=="svelte-iyuejo"&&(p.textContent=ae),R=l(e),u=s(e,"P",{"data-svelte-h":!0}),r(u)!=="svelte-mvs6w2"&&(u.textContent=ne),z=l(e),c=s(e,"UL",{"data-svelte-h":!0}),r(c)!=="svelte-1d130bu"&&(c.innerHTML=ie),F=l(e),h=s(e,"P",{"data-svelte-h":!0}),r(h)!=="svelte-x58frj"&&(h.textContent=le),G=l(e),g=s(e,"P",{"data-svelte-h":!0}),r(g)!=="svelte-wbgvs7"&&(g.textContent=oe),V=l(e),k(w.$$.fragment,e),B=l(e),b=s(e,"P",{"data-svelte-h":!0}),r(b)!=="svelte-16q36ht"&&(b.textContent=se),Q=l(e),v=s(e,"OL",{"data-svelte-h":!0}),r(v)!=="svelte-1sklxcv"&&(v.innerHTML=re),S=l(e),T=s(e,"P",{"data-svelte-h":!0}),r(T)!=="svelte-wdoadq"&&(T.innerHTML=me),W=l(e),y=s(e,"UL",{"data-svelte-h":!0}),r(y)!=="svelte-crbpqt"&&(y.innerHTML=de),D=l(e),k(_.$$.fragment,e),N=l(e),I=s(e,"P",{"data-svelte-h":!0}),r(I)!=="svelte-hieagv"&&(I.textContent=fe),Z=l(e),k($.$$.fragment,e),O=l(e),k(C.$$.fragment,e),X=l(e),A=s(e,"P",{}),pe(A).forEach(a),this.h()},h(){ue(m,"name","hf:doc:metadata"),ue(m,"content",$e)},m(e,t){Te(document.head,m),n(e,j,t),n(e,x,t),n(e,U,t),L(d,e,t),n(e,E,t),n(e,f,t),n(e,H,t),n(e,p,t),n(e,R,t),n(e,u,t),n(e,z,t),n(e,c,t),n(e,F,t),n(e,h,t),n(e,G,t),n(e,g,t),n(e,V,t),L(w,e,t),n(e,B,t),n(e,b,t),n(e,Q,t),n(e,v,t),n(e,S,t),n(e,T,t),n(e,W,t),n(e,y,t),n(e,D,t),L(_,e,t),n(e,N,t),n(e,I,t),n(e,Z,t),L($,e,t),n(e,O,t),L(C,e,t),n(e,X,t),n(e,A,t),K=!0},p:he,i(e){K||(M(d.$$.fragment,e),M(w.$$.fragment,e),M(_.$$.fragment,e),M($.$$.fragment,e),M(C.$$.fragment,e),K=!0)},o(e){P(d.$$.fragment,e),P(w.$$.fragment,e),P(_.$$.fragment,e),P($.$$.fragment,e),P(C.$$.fragment,e),K=!1},d(e){e&&(a(j),a(x),a(U),a(E),a(f),a(H),a(p),a(R),a(u),a(z),a(c),a(F),a(h),a(G),a(g),a(V),a(B),a(b),a(Q),a(v),a(S),a(T),a(W),a(y),a(D),a(N),a(I),a(Z),a(O),a(X),a(A)),a(m),q(d,e),q(w,e),q(_,e),q($,e),q(C,e)}}}const $e='{"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 Ce(ee){return ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends we{constructor(m){super(),be(this,m,Ce,Ie,ce,{})}}export{Le as component};
