import{s as he,o as ue,n as ge}from"../chunks/scheduler.78382b47.js";import{S as Me,i as ye,e as p,s as o,c as y,h as Te,a as c,d as n,b as l,f as Y,g as T,j as B,k as K,l as g,m as a,n as w,t as j,o as b,p as _}from"../chunks/index.6dd35eb6.js";import{C as we,H as oe,E as je}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.6888f903.js";import{D as fe}from"../chunks/Docstring.286e0aef.js";import{C as be}from"../chunks/CodeBlock.658dd679.js";import{E as _e}from"../chunks/ExampleCodeBlock.3f133c9f.js";function Je(N){let i,v="Example:",h,m,d;return m=new be({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBCb25lTW9kZWwlMkMlMjBCb25lQ29uZmlnJTBBJTBBY29uZmlnX3RlJTIwJTNEJTIwQm9uZUNvbmZpZyglMEElMjAlMjAlMjAlMjByJTNEOCUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTIya19wcm9qJTIyJTJDJTIwJTIycV9wcm9qJTIyJTJDJTIwJTIydl9wcm9qJTIyJTJDJTIwJTIyb3V0X3Byb2olMjIlMkMlMjAlMjJmYzElMjIlMkMlMjAlMjJmYzIlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBpbml0X3dlaWdodHMlM0RUcnVlJTJDJTBBKSUwQWNvbmZpZ191bmV0JTIwJTNEJTIwQm9uZUNvbmZpZyglMEElMjAlMjAlMjAlMjByJTNEOCUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycHJval9pbiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnByb2pfb3V0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydG9fayUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnRvX3ElMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0b192JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydG9fb3V0LjAlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJmZi5uZXQuMC5wcm9qJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZmYubmV0LjIlMjIlMkMlMEElMjAlMjAlMjAlMjAlNUQlMkMlMEElMjAlMjAlMjAlMjBpbml0X3dlaWdodHMlM0RUcnVlJTJDJTBBKSUwQSUwQW1vZGVsJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyKSUwQW1vZGVsLnRleHRfZW5jb2RlciUyMCUzRCUyMEJvbmVNb2RlbChtb2RlbC50ZXh0X2VuY29kZXIlMkMlMjBjb25maWdfdGUlMkMlMjAlMjJkZWZhdWx0JTIyKSUwQW1vZGVsLnVuZXQlMjAlM0QlMjBCb25lTW9kZWwobW9kZWwudW5ldCUyQyUyMGNvbmZpZ191bmV0JTJDJTIwJTIyZGVmYXVsdCUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> BoneModel, BoneConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config_te = BoneConfig(
<span class="hljs-meta">... </span>    r=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    target_modules=[<span class="hljs-string">&quot;k_proj&quot;</span>, <span class="hljs-string">&quot;q_proj&quot;</span>, <span class="hljs-string">&quot;v_proj&quot;</span>, <span class="hljs-string">&quot;out_proj&quot;</span>, <span class="hljs-string">&quot;fc1&quot;</span>, <span class="hljs-string">&quot;fc2&quot;</span>],
<span class="hljs-meta">... </span>    init_weights=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>config_unet = BoneConfig(
<span class="hljs-meta">... </span>    r=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    target_modules=[
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;proj_in&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;proj_out&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;to_k&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;to_q&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;to_v&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;to_out.0&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;ff.net.0.proj&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;ff.net.2&quot;</span>,
<span class="hljs-meta">... </span>    ],
<span class="hljs-meta">... </span>    init_weights=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.text_encoder = BoneModel(model.text_encoder, config_te, <span class="hljs-string">&quot;default&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.unet = BoneModel(model.unet, config_unet, <span class="hljs-string">&quot;default&quot;</span>)`,wrap:!1}}),{c(){i=p("p"),i.textContent=v,h=o(),y(m.$$.fragment)},l(s){i=c(s,"P",{"data-svelte-h":!0}),B(i)!=="svelte-11lpom8"&&(i.textContent=v),h=l(s),T(m.$$.fragment,s)},m(s,f){a(s,i,f),a(s,h,f),w(m,s,f),d=!0},p:ge,i(s){d||(j(m.$$.fragment,s),d=!0)},o(s){b(m.$$.fragment,s),d=!1},d(s){s&&(n(i),n(h)),_(m,s)}}}function Be(N){let i,v,h,m,d,s,f,S,C,le='DiSHA: Dimension-Sharding Adaptation (<a href="https://huggingface.co/papers/2409.15371" rel="nofollow">DiSHA</a>) We introduce Dimension-Sharding Adaptation (DiSHA), which expands the PEFT design space to unlock lower intrinsic ranks and faster convergence by default. Building on DiSHA, we propose an efficient algorithm called Block-Affine Adaptation (Bone) structure and a non-linear update method called Block Affine Transformation Adaptation (BAT).',V,$,ie="The abstract from the paper is:",R,I,re="Low-Rank Adaptation (LoRA) leverages the low intrinsic rank of weight updates in Large Language Models (LLMs), establishing a Parameter-Efficient Fine-Tuning (PEFT) paradigm. However, LoRA suffers from slow convergence. We introduce Dimension-Sharding Adaptation (DiSHA), which expands the PEFT design space to unlock lower intrinsic ranks and faster convergence by default. Within DiSHA’s design space, we propose Block Affine Adaptation (Bone), a computationally efficient structure that delivers both high performance and efficiency. While certain DiSHA configurations may result in colinear updates to weight shards, we address this with Block Affine Transformation Adaptation (BAT), a nonlinear variant of DiSHA. BAT introduces nonlinearity by combining trainable matrices with original weight shards in a nonlinear manner, inducing nonlinearity in matrix updates without introducing additional parameters. Empirical results show that Bone, under the DiSHA framework, consistently outperforms LoRA variants in both NLG and NLU tasks, with significantly improved computational efficiency. Further analysis demonstrates that BAT enhances model capabilities by leveraging its nonlinear design.",Q,U,P,M,x,ee,E,pe='This is the configuration class to store the configuration of a <a href="/docs/peft/v0.18.0/en/package_reference/bone#peft.BoneModel">BoneModel</a>.',G,A,O,r,k,te,L,ce=`Creates Householder reflection adaptation (Bone) model from a pretrained model. The method is described in
<a href="https://huggingface.co/papers/2409.15371" rel="nofollow">https://huggingface.co/papers/2409.15371</a>`,ne,J,ae,D,me="<strong>Attributes</strong>:",se,W,de='<li><strong>model</strong> (<code>~torch.nn.Module</code>) — The model to be adapted.</li> <li><strong>peft_config</strong> (<a href="/docs/peft/v0.18.0/en/package_reference/bone#peft.BoneConfig">BoneConfig</a>): The configuration of the Bone model.</li>',F,q,X,H,z;return d=new we({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),f=new oe({props:{title:"Bone",local:"bone",headingTag:"h1"}}),U=new oe({props:{title:"BoneConfig",local:"peft.BoneConfig",headingTag:"h2"}}),x=new fe({props:{name:"class peft.BoneConfig",anchor:"peft.BoneConfig",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 = 64"},{name:"target_modules",val:": Optional[Union[list[str], str]] = None"},{name:"exclude_modules",val:": Optional[Union[list[str], str]] = None"},{name:"init_weights",val:": bool | Literal['bat'] = True"},{name:"layers_to_transform",val:": Optional[Union[list[int], int]] = None"},{name:"layers_pattern",val:": Optional[str] = None"},{name:"bias",val:": str = 'none'"},{name:"modules_to_save",val:": Optional[list[str]] = None"}],parametersDescription:[{anchor:"peft.BoneConfig.r",description:`<strong>r</strong> (<code>int</code>) &#x2014;
The rank of Bone across different layers. It is best to set &#x2018;r&#x2019; to an even number; otherwise, the default
initialization method will not work.`,name:"r"},{anchor:"peft.BoneConfig.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 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.BoneConfig.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.BoneConfig.init_weights",description:`<strong>init_weights</strong> (bool | Literal[&#x201C;bat&#x201D;]) &#x2014;
Different initializations correspond to different Bone variants. By default, setting True uses the Bone
structure, while &#x201C;bat&#x201D; selects the Bat structure.`,name:"init_weights"},{anchor:"peft.BoneConfig.layers_to_transform",description:`<strong>layers_to_transform</strong> (<code>Union[List[int], int]</code>) &#x2014;
The layer indices to transform. If a list of ints is passed, it will apply the adapter to the layer indices
that are specified in this list. If a single integer is passed, it will apply the transformations on the
layer at this index.`,name:"layers_to_transform"},{anchor:"peft.BoneConfig.layers_pattern",description:`<strong>layers_pattern</strong> (<code>str</code>) &#x2014;
The layer pattern name, used only if <code>layers_to_transform</code> is different from <code>None</code>.`,name:"layers_pattern"},{anchor:"peft.BoneConfig.modules_to_save",description:`<strong>modules_to_save</strong> (<code>List[str]</code>) &#x2014;
List of modules apart from adapter layers to be set as trainable and saved in the final checkpoint.`,name:"modules_to_save"}],source:"https://github.com/huggingface/peft/blob/v0.18.0/src/peft/tuners/bone/config.py#L26"}}),A=new oe({props:{title:"BoneModel",local:"peft.BoneModel",headingTag:"h2"}}),k=new fe({props:{name:"class peft.BoneModel",anchor:"peft.BoneModel",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.BoneModel.model",description:"<strong>model</strong> (<code>torch.nn.Module</code>) &#x2014; The model to which the adapter tuner layers will be attached.",name:"model"},{anchor:"peft.BoneModel.config",description:'<strong>config</strong> (<a href="/docs/peft/v0.18.0/en/package_reference/bone#peft.BoneConfig">BoneConfig</a>) &#x2014; The configuration of the Bone model.',name:"config"},{anchor:"peft.BoneModel.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.BoneModel.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/v0.18.0/src/peft/tuners/bone/model.py#L24",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.nn.Module</code></p>
`}}),J=new _e({props:{anchor:"peft.BoneModel.example",$$slots:{default:[Je]},$$scope:{ctx:N}}}),q=new je({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/bone.md"}}),{c(){i=p("meta"),v=o(),h=p("p"),m=o(),y(d.$$.fragment),s=o(),y(f.$$.fragment),S=o(),C=p("p"),C.innerHTML=le,V=o(),$=p("p"),$.textContent=ie,R=o(),I=p("p"),I.textContent=re,Q=o(),y(U.$$.fragment),P=o(),M=p("div"),y(x.$$.fragment),ee=o(),E=p("p"),E.innerHTML=pe,G=o(),y(A.$$.fragment),O=o(),r=p("div"),y(k.$$.fragment),te=o(),L=p("p"),L.innerHTML=ce,ne=o(),y(J.$$.fragment),ae=o(),D=p("p"),D.innerHTML=me,se=o(),W=p("ul"),W.innerHTML=de,F=o(),y(q.$$.fragment),X=o(),H=p("p"),this.h()},l(e){const t=Te("svelte-u9bgzb",document.head);i=c(t,"META",{name:!0,content:!0}),t.forEach(n),v=l(e),h=c(e,"P",{}),Y(h).forEach(n),m=l(e),T(d.$$.fragment,e),s=l(e),T(f.$$.fragment,e),S=l(e),C=c(e,"P",{"data-svelte-h":!0}),B(C)!=="svelte-aemu8y"&&(C.innerHTML=le),V=l(e),$=c(e,"P",{"data-svelte-h":!0}),B($)!=="svelte-1cwsb16"&&($.textContent=ie),R=l(e),I=c(e,"P",{"data-svelte-h":!0}),B(I)!=="svelte-18pyqgo"&&(I.textContent=re),Q=l(e),T(U.$$.fragment,e),P=l(e),M=c(e,"DIV",{class:!0});var Z=Y(M);T(x.$$.fragment,Z),ee=l(Z),E=c(Z,"P",{"data-svelte-h":!0}),B(E)!=="svelte-kzbkr5"&&(E.innerHTML=pe),Z.forEach(n),G=l(e),T(A.$$.fragment,e),O=l(e),r=c(e,"DIV",{class:!0});var u=Y(r);T(k.$$.fragment,u),te=l(u),L=c(u,"P",{"data-svelte-h":!0}),B(L)!=="svelte-186pinq"&&(L.innerHTML=ce),ne=l(u),T(J.$$.fragment,u),ae=l(u),D=c(u,"P",{"data-svelte-h":!0}),B(D)!=="svelte-1xx6nm4"&&(D.innerHTML=me),se=l(u),W=c(u,"UL",{"data-svelte-h":!0}),B(W)!=="svelte-13y0q8w"&&(W.innerHTML=de),u.forEach(n),F=l(e),T(q.$$.fragment,e),X=l(e),H=c(e,"P",{}),Y(H).forEach(n),this.h()},h(){K(i,"name","hf:doc:metadata"),K(i,"content",ve),K(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),K(r,"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){g(document.head,i),a(e,v,t),a(e,h,t),a(e,m,t),w(d,e,t),a(e,s,t),w(f,e,t),a(e,S,t),a(e,C,t),a(e,V,t),a(e,$,t),a(e,R,t),a(e,I,t),a(e,Q,t),w(U,e,t),a(e,P,t),a(e,M,t),w(x,M,null),g(M,ee),g(M,E),a(e,G,t),w(A,e,t),a(e,O,t),a(e,r,t),w(k,r,null),g(r,te),g(r,L),g(r,ne),w(J,r,null),g(r,ae),g(r,D),g(r,se),g(r,W),a(e,F,t),w(q,e,t),a(e,X,t),a(e,H,t),z=!0},p(e,[t]){const Z={};t&2&&(Z.$$scope={dirty:t,ctx:e}),J.$set(Z)},i(e){z||(j(d.$$.fragment,e),j(f.$$.fragment,e),j(U.$$.fragment,e),j(x.$$.fragment,e),j(A.$$.fragment,e),j(k.$$.fragment,e),j(J.$$.fragment,e),j(q.$$.fragment,e),z=!0)},o(e){b(d.$$.fragment,e),b(f.$$.fragment,e),b(U.$$.fragment,e),b(x.$$.fragment,e),b(A.$$.fragment,e),b(k.$$.fragment,e),b(J.$$.fragment,e),b(q.$$.fragment,e),z=!1},d(e){e&&(n(v),n(h),n(m),n(s),n(S),n(C),n(V),n($),n(R),n(I),n(Q),n(P),n(M),n(G),n(O),n(r),n(F),n(X),n(H)),n(i),_(d,e),_(f,e),_(U,e),_(x),_(A,e),_(k),_(J),_(q,e)}}}const ve='{"title":"Bone","local":"bone","sections":[{"title":"BoneConfig","local":"peft.BoneConfig","sections":[],"depth":2},{"title":"BoneModel","local":"peft.BoneModel","sections":[],"depth":2}],"depth":1}';function Ce(N){return ue(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qe extends Me{constructor(i){super(),ye(this,i,Ce,Be,he,{})}}export{qe as component};
