import{s as Be,n as je,o as Ie}from"../chunks/scheduler.78382b47.js";import{S as Re,i as De,e as r,s as o,c as M,h as We,a as s,d as n,b as i,f as me,g as k,j as l,k as ue,l as p,m as a,n as H,t as O,o as U,p as z}from"../chunks/index.6dd35eb6.js";import{C as Se,H as xe,E as Ke}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.fed9dfe4.js";import{D as Fe}from"../chunks/Docstring.32e826ec.js";function Ve(Pe){let u,K,W,V,f,G,h,Q,g,Te=`<a href="https://arxiv.org/abs/2410.01870" rel="nofollow">PEANuT</a> is a parameter-efficient fine-tuning technique that introduces
weight-aware neural tweakers to generate adapter updates from the frozen pretrained weights themselves. Instead of
learning a purely linear low-rank update as in LoRA, PEANuT conditions the adapter transformation on the base weight,
which makes the update rule more expressive while keeping the number of trainable parameters small.`,J,v,ye=`PEANuT uses an input projection <code>A</code>, an output projection <code>B</code>, and optional intermediate residual encoder/decoder
pairs with non-linear activations. This makes it possible to model more complex update patterns than weight-agnostic
linear adapters while still remaining within the PEFT setting.`,X,_,be="PEANuT currently has the following tradeoffs:",Y,w,Ce="Pros:",Z,x,$e="<li>Higher theoretical expressiveness than linear low-rank updates.</li> <li>Better performance than LoRA on a range of tasks under similar budgets.</li> <li>Works well in very low-parameter regimes, for example around <code>0.2M</code> trainable parameters.</li>",ee,P,Ae="Cons:",te,T,Le="<li>Higher memory usage than LoRA, because <code>ΔW</code> is explicitly constructed before being applied.</li> <li>Slower training and inference than LoRA, and deeper intermediate layers increase the overhead further.</li> <li>The non-linearity can require more careful hyperparameter tuning, especially learning rate and related optimization settings.</li>",ne,y,Ee="If these tradeoffs do not fit your use case, consider other PEFT methods such as LoRA.",ae,b,Ne="The abstract from the paper is:",oe,C,Me="<p>Fine-tuning large pre-trained foundation models often yields excellent downstream performance but is prohibitively expensive when updating all parameters. Parameter-efficient fine-tuning (PEFT) methods such as LoRA alleviate this by introducing lightweight update modules, yet they commonly rely on weight-agnostic linear approximations, limiting their expressiveness. In this work, we propose PEANuT, a novel PEFT framework that introduces weight-aware neural tweakers, compact neural modules that generate task-adaptive updates conditioned on frozen pre-trained weights. PEANuT provides a flexible yet efficient way to capture complex update patterns without full model tuning. We theoretically show that PEANuT achieves equivalent or greater expressivity than existing linear PEFT methods with comparable or fewer parameters. Extensive experiments across four benchmarks with over twenty datasets demonstrate that PEANuT consistently outperforms strong baselines in both NLP and vision tasks, while maintaining low computational overhead.</p>",ie,$,re,c,A,fe,q,ke='This is the configuration class to store the configuration of a <a href="/docs/peft/main/en/package_reference/peanut#peft.PeanutModel">PeanutModel</a>.',he,F,He=`Notes:
PEANuT uses a weight-aware pathway, where the delta weight is conditioned on the base weight. The <code>A</code> adapter
is applied over the base weight’s output dimension, so <code>A</code> has shape <code>(out_dim -&gt; r)</code> rather than the usual
<code>(in_dim -&gt; r)</code> used by LoRA-like methods.`,se,L,le,d,E,ge,B,Oe="Creates a PEANuT model from a pretrained transformers model.",ve,j,Ue='The method is described in detail in <a href="https://arxiv.org/abs/2410.01870" rel="nofollow">https://arxiv.org/abs/2410.01870</a>.',_e,I,ze="<strong>Attributes</strong>:",we,R,qe='<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> (<a href="/docs/peft/main/en/package_reference/peanut#peft.PeanutConfig">PeanutConfig</a>): The configuration of the PEANuT model.</li>',de,N,pe,S,ce;return f=new Se({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),h=new xe({props:{title:"PEANuT: Parameter-Efficient Adaptation with Weight-aware Neural Tweakers",local:"peanut-parameter-efficient-adaptation-with-weight-aware-neural-tweakers",headingTag:"h1"}}),$=new xe({props:{title:"PeanutConfig",local:"peft.PeanutConfig",headingTag:"h2"}}),A=new Fe({props:{name:"class peft.PeanutConfig",anchor:"peft.PeanutConfig",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:"r",val:": int = 32"},{name:"depth",val:": int = 0"},{name:"act_fn",val:": str = 'relu'"},{name:"scaling",val:": float = 1.0"},{name:"target_modules",val:": Optional[Union[list[str], str]] = None"},{name:"exclude_modules",val:": Optional[Union[list[str], str]] = None"},{name:"modules_to_save",val:": Optional[list[str]] = None"},{name:"layers_to_transform",val:": Optional[Union[list[int], int]] = None"},{name:"layers_pattern",val:": Optional[Union[list[str], str]] = None"},{name:"init_weights",val:": bool = True"}],parametersDescription:[{anchor:"peft.PeanutConfig.r",description:`<strong>r</strong> (<code>int</code>) &#x2014;
PEANuT rank. This is the hidden dimension used by the adapters. Similar to LoRA rank, larger <code>r</code> increases
adapter capacity and trainable parameters.`,name:"r"},{anchor:"peft.PeanutConfig.depth",description:`<strong>depth</strong> (<code>int</code>) &#x2014;
Number of hidden adapter layers per encoder/decoder side in PEANuT. The input projection <code>A</code> and output
projection <code>B</code> are always present in addition to these hidden layers. Therefore, <code>depth</code> must be a
non-negative integer.</p>
<ul>
<li><code>depth=0</code>: <code>A</code>, <code>B</code>.</li>
<li><code>depth=1</code>: <code>A</code>, one encoder, one decoder, <code>B</code>.</li>
<li><code>depth=2</code>: <code>A</code>, two encoders, two decoders, <code>B</code>.</li>
<li><code>depth=3</code>: <code>A</code>, three encoders, three decoders, <code>B</code>, etc.</li>
</ul>`,name:"depth"},{anchor:"peft.PeanutConfig.act_fn",description:`<strong>act_fn</strong> (<code>str</code>) &#x2014;
Non-linear activation applied in the PEANuT network. This corresponds to <code>non_linear</code> in the vanilla
PyTorch implementation. Default is <code>&quot;relu&quot;</code>. Any activation key available in
<code>transformers.activations.ACT2FN</code> is supported and may perform better on different tasks.`,name:"act_fn"},{anchor:"peft.PeanutConfig.scaling",description:`<strong>scaling</strong> (<code>float</code>) &#x2014;
A scalar multiplier applied to the PEANuT output before adding it to the frozen base layer output. The
final adapter contribution is <code>scaling * (x @ delta_w)</code>.`,name:"scaling"},{anchor:"peft.PeanutConfig.target_modules",description:`<strong>target_modules</strong> (<code>Union[List[str], str]</code>, <em>optional</em>) &#x2014;
The names of the modules to apply PEANuT to. Can be a list of module name strings (e.g. <code>[&apos;q_proj&apos;, &apos;v_proj&apos;]</code>) or a regex pattern.`,name:"target_modules"},{anchor:"peft.PeanutConfig.modules_to_save",description:`<strong>modules_to_save</strong> (<code>List[str]</code>, <em>optional</em>) &#x2014;
List of modules apart from PEANuT layers to be set as trainable and saved in the final checkpoint.`,name:"modules_to_save"},{anchor:"peft.PeanutConfig.exclude_modules",description:`<strong>exclude_modules</strong> (<code>Union[List[str], str]</code>, <em>optional</em>) &#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.PeanutConfig.layers_to_transform",description:`<strong>layers_to_transform</strong> (<code>Union[list[int], int]</code>, <em>optional</em>) &#x2014;
The layer indexes to transform. If this argument is specified, PEFT will transform only the layer indexes
that are specified in this list. If a single integer is passed, PEFT will transform only the layer at this
index.`,name:"layers_to_transform"},{anchor:"peft.PeanutConfig.layers_pattern",description:`<strong>layers_pattern</strong> (<code>Optional[Union[List[str], str]]</code>, <em>optional</em>) &#x2014;
The layer pattern name, used only if <code>layers_to_transform</code> is not None and if the layer pattern is not in
the common layers pattern.`,name:"layers_pattern"},{anchor:"peft.PeanutConfig.init_weights",description:`<strong>init_weights</strong> (<code>bool</code>) &#x2014;
Whether to initialize PEANuT adapter weights using the default initialization scheme:</p>
<ul>
<li>If <code>True</code>: all weights except <code>B</code> are initialized with Kaiming uniform, and <code>B</code> is initialized to zero.</li>
<li>If <code>False</code>: all weights (including <code>B</code>) are initialized with Kaiming uniform.</li>
</ul>
<p>Initializing <code>B</code> to zero makes the adapter start as an exact no-op.`,name:"init_weights"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/peanut/config.py#L26"}}),L=new xe({props:{title:"PeanutModel",local:"peft.PeanutModel",headingTag:"h2"}}),E=new Fe({props:{name:"class peft.PeanutModel",anchor:"peft.PeanutModel",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.PeanutModel.model",description:"<strong>model</strong> (<code>torch.nn.Module</code>) &#x2014; The model to be adapted.",name:"model"},{anchor:"peft.PeanutModel.config",description:'<strong>config</strong> (<a href="/docs/peft/main/en/package_reference/peanut#peft.PeanutConfig">PeanutConfig</a>) &#x2014; The configuration of the PEANuT model.',name:"config"},{anchor:"peft.PeanutModel.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"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/tuners/peanut/model.py#L28",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The PEANuT PEFT model.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>torch.nn.Module</code></p>
`}}),N=new Ke({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/peanut.md"}}),{c(){u=r("meta"),K=o(),W=r("p"),V=o(),M(f.$$.fragment),G=o(),M(h.$$.fragment),Q=o(),g=r("p"),g.innerHTML=Te,J=o(),v=r("p"),v.innerHTML=ye,X=o(),_=r("p"),_.textContent=be,Y=o(),w=r("p"),w.textContent=Ce,Z=o(),x=r("ul"),x.innerHTML=$e,ee=o(),P=r("p"),P.textContent=Ae,te=o(),T=r("ul"),T.innerHTML=Le,ne=o(),y=r("p"),y.textContent=Ee,ae=o(),b=r("p"),b.textContent=Ne,oe=o(),C=r("blockquote"),C.innerHTML=Me,ie=o(),M($.$$.fragment),re=o(),c=r("div"),M(A.$$.fragment),fe=o(),q=r("p"),q.innerHTML=ke,he=o(),F=r("p"),F.innerHTML=He,se=o(),M(L.$$.fragment),le=o(),d=r("div"),M(E.$$.fragment),ge=o(),B=r("p"),B.textContent=Oe,ve=o(),j=r("p"),j.innerHTML=Ue,_e=o(),I=r("p"),I.innerHTML=ze,we=o(),R=r("ul"),R.innerHTML=qe,de=o(),M(N.$$.fragment),pe=o(),S=r("p"),this.h()},l(e){const t=We("svelte-u9bgzb",document.head);u=s(t,"META",{name:!0,content:!0}),t.forEach(n),K=i(e),W=s(e,"P",{}),me(W).forEach(n),V=i(e),k(f.$$.fragment,e),G=i(e),k(h.$$.fragment,e),Q=i(e),g=s(e,"P",{"data-svelte-h":!0}),l(g)!=="svelte-e8sjct"&&(g.innerHTML=Te),J=i(e),v=s(e,"P",{"data-svelte-h":!0}),l(v)!=="svelte-jefvip"&&(v.innerHTML=ye),X=i(e),_=s(e,"P",{"data-svelte-h":!0}),l(_)!=="svelte-eqgcef"&&(_.textContent=be),Y=i(e),w=s(e,"P",{"data-svelte-h":!0}),l(w)!=="svelte-nbbe2"&&(w.textContent=Ce),Z=i(e),x=s(e,"UL",{"data-svelte-h":!0}),l(x)!=="svelte-1yp9v8x"&&(x.innerHTML=$e),ee=i(e),P=s(e,"P",{"data-svelte-h":!0}),l(P)!=="svelte-domxx"&&(P.textContent=Ae),te=i(e),T=s(e,"UL",{"data-svelte-h":!0}),l(T)!=="svelte-7gspaf"&&(T.innerHTML=Le),ne=i(e),y=s(e,"P",{"data-svelte-h":!0}),l(y)!=="svelte-1qfagt2"&&(y.textContent=Ee),ae=i(e),b=s(e,"P",{"data-svelte-h":!0}),l(b)!=="svelte-1cwsb16"&&(b.textContent=Ne),oe=i(e),C=s(e,"BLOCKQUOTE",{"data-svelte-h":!0}),l(C)!=="svelte-1a7unc2"&&(C.innerHTML=Me),ie=i(e),k($.$$.fragment,e),re=i(e),c=s(e,"DIV",{class:!0});var D=me(c);k(A.$$.fragment,D),fe=i(D),q=s(D,"P",{"data-svelte-h":!0}),l(q)!=="svelte-1a3y9dc"&&(q.innerHTML=ke),he=i(D),F=s(D,"P",{"data-svelte-h":!0}),l(F)!=="svelte-1cbwfrj"&&(F.innerHTML=He),D.forEach(n),se=i(e),k(L.$$.fragment,e),le=i(e),d=s(e,"DIV",{class:!0});var m=me(d);k(E.$$.fragment,m),ge=i(m),B=s(m,"P",{"data-svelte-h":!0}),l(B)!=="svelte-v1qcry"&&(B.textContent=Oe),ve=i(m),j=s(m,"P",{"data-svelte-h":!0}),l(j)!=="svelte-cd6uod"&&(j.innerHTML=Ue),_e=i(m),I=s(m,"P",{"data-svelte-h":!0}),l(I)!=="svelte-1xx6nm4"&&(I.innerHTML=ze),we=i(m),R=s(m,"UL",{"data-svelte-h":!0}),l(R)!=="svelte-ogfze6"&&(R.innerHTML=qe),m.forEach(n),de=i(e),k(N.$$.fragment,e),pe=i(e),S=s(e,"P",{}),me(S).forEach(n),this.h()},h(){ue(u,"name","hf:doc:metadata"),ue(u,"content",Ge),ue(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),ue(d,"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){p(document.head,u),a(e,K,t),a(e,W,t),a(e,V,t),H(f,e,t),a(e,G,t),H(h,e,t),a(e,Q,t),a(e,g,t),a(e,J,t),a(e,v,t),a(e,X,t),a(e,_,t),a(e,Y,t),a(e,w,t),a(e,Z,t),a(e,x,t),a(e,ee,t),a(e,P,t),a(e,te,t),a(e,T,t),a(e,ne,t),a(e,y,t),a(e,ae,t),a(e,b,t),a(e,oe,t),a(e,C,t),a(e,ie,t),H($,e,t),a(e,re,t),a(e,c,t),H(A,c,null),p(c,fe),p(c,q),p(c,he),p(c,F),a(e,se,t),H(L,e,t),a(e,le,t),a(e,d,t),H(E,d,null),p(d,ge),p(d,B),p(d,ve),p(d,j),p(d,_e),p(d,I),p(d,we),p(d,R),a(e,de,t),H(N,e,t),a(e,pe,t),a(e,S,t),ce=!0},p:je,i(e){ce||(O(f.$$.fragment,e),O(h.$$.fragment,e),O($.$$.fragment,e),O(A.$$.fragment,e),O(L.$$.fragment,e),O(E.$$.fragment,e),O(N.$$.fragment,e),ce=!0)},o(e){U(f.$$.fragment,e),U(h.$$.fragment,e),U($.$$.fragment,e),U(A.$$.fragment,e),U(L.$$.fragment,e),U(E.$$.fragment,e),U(N.$$.fragment,e),ce=!1},d(e){e&&(n(K),n(W),n(V),n(G),n(Q),n(g),n(J),n(v),n(X),n(_),n(Y),n(w),n(Z),n(x),n(ee),n(P),n(te),n(T),n(ne),n(y),n(ae),n(b),n(oe),n(C),n(ie),n(re),n(c),n(se),n(le),n(d),n(de),n(pe),n(S)),n(u),z(f,e),z(h,e),z($,e),z(A),z(L,e),z(E),z(N,e)}}}const Ge='{"title":"PEANuT: Parameter-Efficient Adaptation with Weight-aware Neural Tweakers","local":"peanut-parameter-efficient-adaptation-with-weight-aware-neural-tweakers","sections":[{"title":"PeanutConfig","local":"peft.PeanutConfig","sections":[],"depth":2},{"title":"PeanutModel","local":"peft.PeanutModel","sections":[],"depth":2}],"depth":1}';function Qe(Pe){return Ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class et extends Re{constructor(u){super(),De(this,u,Qe,Ve,Be,{})}}export{et as component};
