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 m,d as s,b as i,f as Y,g as T,j as v,k as K,l as g,m as n,n as w,t as _,o as j,p as b}from"../chunks/index.6dd35eb6.js";import{C as we,H as oe,E as _e}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.6888f903.js";import{D as fe}from"../chunks/Docstring.286e0aef.js";import{C as je}from"../chunks/CodeBlock.658dd679.js";import{E as be}from"../chunks/ExampleCodeBlock.3f133c9f.js";function Je(V){let l,x="Example:",h,c,d;return c=new je({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBNaXNzTW9kZWwlMkMlMjBNaXNzQ29uZmlnJTBBJTBBY29uZmlnX3RlJTIwJTNEJTIwTWlzc0NvbmZpZyglMEElMjAlMjAlMjAlMjByJTNEOCUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTIya19wcm9qJTIyJTJDJTIwJTIycV9wcm9qJTIyJTJDJTIwJTIydl9wcm9qJTIyJTJDJTIwJTIyb3V0X3Byb2olMjIlMkMlMjAlMjJmYzElMjIlMkMlMjAlMjJmYzIlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBpbml0X3dlaWdodHMlM0RUcnVlJTJDJTBBKSUwQWNvbmZpZ191bmV0JTIwJTNEJTIwTWlzc0NvbmZpZyglMEElMjAlMjAlMjAlMjByJTNEOCUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycHJval9pbiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnByb2pfb3V0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydG9fayUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnRvX3ElMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0b192JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydG9fb3V0LjAlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJmZi5uZXQuMC5wcm9qJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZmYubmV0LjIlMjIlMkMlMEElMjAlMjAlMjAlMjAlNUQlMkMlMEElMjAlMjAlMjAlMjBpbml0X3dlaWdodHMlM0RUcnVlJTJDJTBBKSUwQSUwQW1vZGVsJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyKSUwQW1vZGVsLnRleHRfZW5jb2RlciUyMCUzRCUyME1pc3NNb2RlbChtb2RlbC50ZXh0X2VuY29kZXIlMkMlMjBjb25maWdfdGUlMkMlMjAlMjJkZWZhdWx0JTIyKSUwQW1vZGVsLnVuZXQlMjAlM0QlMjBNaXNzTW9kZWwobW9kZWwudW5ldCUyQyUyMGNvbmZpZ191bmV0JTJDJTIwJTIyZGVmYXVsdCUyMik=",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> MissModel, MissConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config_te = MissConfig(
<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 = MissConfig(
<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 = MissModel(model.text_encoder, config_te, <span class="hljs-string">&quot;default&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.unet = MissModel(model.unet, config_unet, <span class="hljs-string">&quot;default&quot;</span>)`,wrap:!1}}),{c(){l=p("p"),l.textContent=x,h=o(),y(c.$$.fragment)},l(a){l=m(a,"P",{"data-svelte-h":!0}),v(l)!=="svelte-11lpom8"&&(l.textContent=x),h=i(a),T(c.$$.fragment,a)},m(a,f){n(a,l,f),n(a,h,f),w(c,a,f),d=!0},p:ge,i(a){d||(_(c.$$.fragment,a),d=!0)},o(a){j(c.$$.fragment,a),d=!1},d(a){a&&(s(l),s(h)),b(c,a)}}}function ve(V){let l,x,h,c,d,a,f,R,C,ie='MiSS: Balancing LoRA Performance and Efficiency with Simple Shard Sharing(<a href="https://huggingface.co/papers/2409.15371" rel="nofollow">MiSS</a>) is a novel PEFT method that adopts a low-rank structure, requires only a single trainable matrix, and introduces a new update mechanism distinct from LoRA, achieving an excellent balance between performance and efficiency.',P,$,le="The abstract from the paper is:",H,I,re="<em>Parameter-Efficient Fine-Tuning (PEFT) methods, particularly Low-Rank Adaptation (LoRA), effectively reduce the number of trainable parameters in Large Language Models (LLMs). However, as model scales continue to grow, the demand for computational resources remains a significant challenge. Existing LoRA variants often struggle to strike an optimal balance between adaptability (model performance and convergence speed) and efficiency (computational overhead, memory usage, and initialization time). This paper introduces MiSS(Matrix Shard Sharing ), a novel PEFT approach that addresses this trade-off through a simple shard-sharing mechanism. MiSS leverages the insight that a low-rank adaptation can be achieved by decomposing the weight matrix into multiple fragment matrices and utilizing a shared, trainable common fragment. This method constructs the low-rank update matrix through the replication of these shared, partitioned shards. We also propose a hardware-efficient and broadly applicable implementation for MiSS. Extensive experiments conducted on a range of tasks, alongside a systematic analysis of computational performance, demonstrate MiSS’s superiority. The results show that MiSS significantly outperforms standard LoRA and its prominent variants in both model performance metrics and computational efficiency, including initialization speed and training throughput. By effectively balancing expressive power and resource utilization, MiSS offers a compelling solution for efficiently adapting large-scale models</em>.",Q,U,D,M,S,ee,L,pe="This is the configuration class to store the configuration of a <code>MiSSModel</code>.",z,k,G,r,q,te,Z,me=`Creates Householder reflection adaptation (MiSS) 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>`,se,J,ne,B,ce="<strong>Attributes</strong>:",ae,N,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/miss#peft.MissConfig">MissConfig</a>): The configuration of the MiSS model.</li>',O,A,X,W,F;return d=new we({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),f=new oe({props:{title:"MiSS",local:"miss",headingTag:"h1"}}),U=new oe({props:{title:"MissConfig",local:"peft.MissConfig",headingTag:"h2"}}),S=new fe({props:{name:"class peft.MissConfig",anchor:"peft.MissConfig",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:"miss_dropout",val:": float = 0.0"},{name:"mini_r",val:": int = 1"},{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', 'mini'] = 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.MissConfig.r",description:`<strong>r</strong> (<code>int</code>) &#x2014;
The rank of MiSS across different layers. It is best to set &#x2018;r&#x2019; to an even number; otherwise, the default
initialization method will not work. The rank of MiSS corresponds to a low-rank decomposition along the
in_features dimension.`,name:"r"},{anchor:"peft.MissConfig.miss_dropout",description:`<strong>miss_dropout</strong> (<code>float</code>) &#x2014;
The dropout probability for MiSS layers.`,name:"miss_dropout"},{anchor:"peft.MissConfig.mini_r",description:`<strong>mini_r</strong> (<code>int</code>) &#x2014;
The rank of MiSS corresponds to a low-rank decomposition along the out_features dimension. When you set
<code>init_weights=mini</code>, you need to set <code>mini_r</code>. Please make sure that <code>out_features</code> is divisible by
<code>mini_r</code>.`,name:"mini_r"},{anchor:"peft.MissConfig.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.MissConfig.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.MissConfig.init_weights",description:`<strong>init_weights</strong> (bool | Literal[&#x201C;bat&#x201D;, &#x201C;mini&#x201D;]) &#x2014;
Different initializations correspond to different MiSS variants. By default(balance), the most efficient
and general method in MiSS will be used. &#x2018;bat&#x2019;: In this mode, you can enable nonlinear updates across
different shards. &#x2018;mini&#x2019;: In this mode, you can set a smaller rank to use fewer trainable parameters, but
it is recommended to keep <code>out_features % mini_r == 0</code>.`,name:"init_weights"},{anchor:"peft.MissConfig.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.MissConfig.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.MissConfig.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/miss/config.py#L25"}}),k=new oe({props:{title:"MissModel",local:"peft.MissModel",headingTag:"h2"}}),q=new fe({props:{name:"class peft.MissModel",anchor:"peft.MissModel",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.MissModel.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.MissModel.config",description:'<strong>config</strong> (<a href="/docs/peft/v0.18.0/en/package_reference/miss#peft.MissConfig">MissConfig</a>) &#x2014; The configuration of the MiSS model.',name:"config"},{anchor:"peft.MissModel.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.MissModel.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/miss/model.py#L24",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


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