import{s as de,o as fe,n as he}from"../chunks/scheduler.4cd3e004.js";import{S as ue,i as ge,e as p,s as i,c as T,h as Me,a as m,d as s,b as l,f as X,g as w,j as _,k as F,l as g,m as n,n as b,t as j,o as J,p as v}from"../chunks/index.b664cb2d.js";import{D as ce}from"../chunks/Docstring.9ceb4334.js";import{C as ye}from"../chunks/CodeBlock.8601e34e.js";import{E as Te}from"../chunks/ExampleCodeBlock.4f57b575.js";import{H as ne,E as we}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function _e(W){let o,x="Example:",h,c,d;return c=new ye({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(){o=p("p"),o.textContent=x,h=i(),T(c.$$.fragment)},l(a){o=m(a,"P",{"data-svelte-h":!0}),_(o)!=="svelte-11lpom8"&&(o.textContent=x),h=l(a),w(c.$$.fragment,a)},m(a,f){n(a,o,f),n(a,h,f),b(c,a,f),d=!0},p:he,i(a){d||(j(c.$$.fragment,a),d=!0)},o(a){J(c.$$.fragment,a),d=!1},d(a){a&&(s(o),s(h)),v(c,a)}}}function be(W){let o,x,h,c,d,a,f,ae='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.',V,C,oe="The abstract from the paper is:",R,I,ie="<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>.",P,U,H,M,$,Y,E,le="This is the configuration class to store the configuration of a <code>MiSSModel</code>.",Q,S,D,r,k,K,Z,re=`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>`,ee,y,te,L,pe="<strong>Attributes</strong>:",se,B,me='<li><strong>model</strong> (<code>~torch.nn.Module</code>) — The model to be adapted.</li> <li><strong>peft_config</strong> (<a href="/docs/peft/main/en/package_reference/miss#peft.MissConfig">MissConfig</a>): The configuration of the MiSS model.</li>',z,q,G,N,O;return d=new ne({props:{title:"MiSS",local:"miss",headingTag:"h1"}}),U=new ne({props:{title:"MissConfig",local:"peft.MissConfig",headingTag:"h2"}}),$=new ce({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/main/src/peft/tuners/miss/config.py#L25"}}),S=new ne({props:{title:"MissModel",local:"peft.MissModel",headingTag:"h2"}}),k=new ce({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/main/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/main/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>
`}}),y=new Te({props:{anchor:"peft.MissModel.example",$$slots:{default:[_e]},$$scope:{ctx:W}}}),q=new we({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/miss.md"}}),{c(){o=p("meta"),x=i(),h=p("p"),c=i(),T(d.$$.fragment),a=i(),f=p("p"),f.innerHTML=ae,V=i(),C=p("p"),C.textContent=oe,R=i(),I=p("p"),I.innerHTML=ie,P=i(),T(U.$$.fragment),H=i(),M=p("div"),T($.$$.fragment),Y=i(),E=p("p"),E.innerHTML=le,Q=i(),T(S.$$.fragment),D=i(),r=p("div"),T(k.$$.fragment),K=i(),Z=p("p"),Z.innerHTML=re,ee=i(),T(y.$$.fragment),te=i(),L=p("p"),L.innerHTML=pe,se=i(),B=p("ul"),B.innerHTML=me,z=i(),T(q.$$.fragment),G=i(),N=p("p"),this.h()},l(e){const t=Me("svelte-u9bgzb",document.head);o=m(t,"META",{name:!0,content:!0}),t.forEach(s),x=l(e),h=m(e,"P",{}),X(h).forEach(s),c=l(e),w(d.$$.fragment,e),a=l(e),f=m(e,"P",{"data-svelte-h":!0}),_(f)!=="svelte-13lq3jc"&&(f.innerHTML=ae),V=l(e),C=m(e,"P",{"data-svelte-h":!0}),_(C)!=="svelte-1cwsb16"&&(C.textContent=oe),R=l(e),I=m(e,"P",{"data-svelte-h":!0}),_(I)!=="svelte-168bh5l"&&(I.innerHTML=ie),P=l(e),w(U.$$.fragment,e),H=l(e),M=m(e,"DIV",{class:!0});var A=X(M);w($.$$.fragment,A),Y=l(A),E=m(A,"P",{"data-svelte-h":!0}),_(E)!=="svelte-sq3sqi"&&(E.innerHTML=le),A.forEach(s),Q=l(e),w(S.$$.fragment,e),D=l(e),r=m(e,"DIV",{class:!0});var u=X(r);w(k.$$.fragment,u),K=l(u),Z=m(u,"P",{"data-svelte-h":!0}),_(Z)!=="svelte-1fhwidk"&&(Z.innerHTML=re),ee=l(u),w(y.$$.fragment,u),te=l(u),L=m(u,"P",{"data-svelte-h":!0}),_(L)!=="svelte-1xx6nm4"&&(L.innerHTML=pe),se=l(u),B=m(u,"UL",{"data-svelte-h":!0}),_(B)!=="svelte-ryiwzo"&&(B.innerHTML=me),u.forEach(s),z=l(e),w(q.$$.fragment,e),G=l(e),N=m(e,"P",{}),X(N).forEach(s),this.h()},h(){F(o,"name","hf:doc:metadata"),F(o,"content",je),F(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),F(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,o),n(e,x,t),n(e,h,t),n(e,c,t),b(d,e,t),n(e,a,t),n(e,f,t),n(e,V,t),n(e,C,t),n(e,R,t),n(e,I,t),n(e,P,t),b(U,e,t),n(e,H,t),n(e,M,t),b($,M,null),g(M,Y),g(M,E),n(e,Q,t),b(S,e,t),n(e,D,t),n(e,r,t),b(k,r,null),g(r,K),g(r,Z),g(r,ee),b(y,r,null),g(r,te),g(r,L),g(r,se),g(r,B),n(e,z,t),b(q,e,t),n(e,G,t),n(e,N,t),O=!0},p(e,[t]){const A={};t&2&&(A.$$scope={dirty:t,ctx:e}),y.$set(A)},i(e){O||(j(d.$$.fragment,e),j(U.$$.fragment,e),j($.$$.fragment,e),j(S.$$.fragment,e),j(k.$$.fragment,e),j(y.$$.fragment,e),j(q.$$.fragment,e),O=!0)},o(e){J(d.$$.fragment,e),J(U.$$.fragment,e),J($.$$.fragment,e),J(S.$$.fragment,e),J(k.$$.fragment,e),J(y.$$.fragment,e),J(q.$$.fragment,e),O=!1},d(e){e&&(s(x),s(h),s(c),s(a),s(f),s(V),s(C),s(R),s(I),s(P),s(H),s(M),s(Q),s(D),s(r),s(z),s(G),s(N)),s(o),v(d,e),v(U,e),v($),v(S,e),v(k),v(y),v(q,e)}}}const je='{"title":"MiSS","local":"miss","sections":[{"title":"MissConfig","local":"peft.MissConfig","sections":[],"depth":2},{"title":"MissModel","local":"peft.MissModel","sections":[],"depth":2}],"depth":1}';function Je(W){return fe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends ue{constructor(o){super(),ge(this,o,Je,be,de,{})}}export{Se as component};
