import{s as le,o as re,n as ie}from"../chunks/scheduler.4cd3e004.js";import{S as pe,i as ce,e as m,s as r,c as _,h as de,a as f,d as o,b as i,f as D,g as j,j as q,k as G,l as g,m as s,n as w,t as b,o as T,p as C}from"../chunks/index.b664cb2d.js";import{D as se}from"../chunks/Docstring.9ceb4334.js";import{C as me}from"../chunks/CodeBlock.8601e34e.js";import{E as fe}from"../chunks/ExampleCodeBlock.4f57b575.js";import{H as z,E as he}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function ue(Q){let n,U="Example:",h,p,c;return p=new me({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBMb0tyTW9kZWwlMkMlMjBMb0tyQ29uZmlnJTBBJTBBY29uZmlnX3RlJTIwJTNEJTIwTG9LckNvbmZpZyglMEElMjAlMjAlMjAlMjByJTNEOCUyQyUwQSUyMCUyMCUyMCUyMGxvcmFfYWxwaGElM0QzMiUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTIya19wcm9qJTIyJTJDJTIwJTIycV9wcm9qJTIyJTJDJTIwJTIydl9wcm9qJTIyJTJDJTIwJTIyb3V0X3Byb2olMjIlMkMlMjAlMjJmYzElMjIlMkMlMjAlMjJmYzIlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjByYW5rX2Ryb3BvdXQlM0QwLjAlMkMlMEElMjAlMjAlMjAlMjBtb2R1bGVfZHJvcG91dCUzRDAuMCUyQyUwQSUyMCUyMCUyMCUyMGluaXRfd2VpZ2h0cyUzRFRydWUlMkMlMEEpJTBBY29uZmlnX3VuZXQlMjAlM0QlMjBMb0tyQ29uZmlnKCUwQSUyMCUyMCUyMCUyMHIlM0Q4JTJDJTBBJTIwJTIwJTIwJTIwbG9yYV9hbHBoYSUzRDMyJTJDJTBBJTIwJTIwJTIwJTIwdGF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dW5ldCUyQyUyMCUyMmRlZmF1bHQlMjIp",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> LoKrModel, LoKrConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config_te = LoKrConfig(
<span class="hljs-meta">... </span>    r=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    lora_alpha=<span class="hljs-number">32</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>    rank_dropout=<span class="hljs-number">0.0</span>,
<span class="hljs-meta">... </span>    module_dropout=<span class="hljs-number">0.0</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 = LoKrConfig(
<span class="hljs-meta">... </span>    r=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    lora_alpha=<span class="hljs-number">32</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>    rank_dropout=<span class="hljs-number">0.0</span>,
<span class="hljs-meta">... </span>    module_dropout=<span class="hljs-number">0.0</span>,
<span class="hljs-meta">... </span>    init_weights=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    use_effective_conv2d=<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 = LoKrModel(model.text_encoder, config_te, <span class="hljs-string">&quot;default&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.unet = LoKrModel(model.unet, config_unet, <span class="hljs-string">&quot;default&quot;</span>)`,wrap:!1}}),{c(){n=m("p"),n.textContent=U,h=r(),_(p.$$.fragment)},l(a){n=f(a,"P",{"data-svelte-h":!0}),q(n)!=="svelte-11lpom8"&&(n.textContent=U),h=i(a),j(p.$$.fragment,a)},m(a,d){s(a,n,d),s(a,h,d),w(p,a,d),c=!0},p:ie,i(a){c||(b(p.$$.fragment,a),c=!0)},o(a){T(p.$$.fragment,a),c=!1},d(a){a&&(o(n),o(h)),C(p,a)}}}function ge(Q){let n,U,h,p,c,a,d,ee='Low-Rank Kronecker Product (<a href="https://hf.co/papers/2309.14859" rel="nofollow">LoKr</a>), is a LoRA-variant method that approximates the large weight matrix with two low-rank matrices and combines them with the Kronecker product. LoKr also provides an optional third low-rank matrix to provide better control during fine-tuning.',B,J,R,M,v,F,I,te='Configuration class of <a href="/docs/peft/main/en/package_reference/lokr#peft.LoKrModel">LoKrModel</a>.',V,L,H,l,k,O,K,oe=`Creates Low-Rank Kronecker Product model from a pretrained model. The original method is partially described in
<a href="https://huggingface.co/papers/2108.06098" rel="nofollow">https://huggingface.co/papers/2108.06098</a> and in <a href="https://huggingface.co/papers/2309.14859" rel="nofollow">https://huggingface.co/papers/2309.14859</a> Current implementation
heavily borrows from
<a href="https://github.com/KohakuBlueleaf/LyCORIS/blob/eb460098187f752a5d66406d3affade6f0a07ece/lycoris/modules/lokr.py" rel="nofollow">https://github.com/KohakuBlueleaf/LyCORIS/blob/eb460098187f752a5d66406d3affade6f0a07ece/lycoris/modules/lokr.py</a>`,X,y,P,A,ae="<strong>Attributes</strong>:",Y,Z,ne='<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/lokr#peft.LoKrConfig">LoKrConfig</a>): The configuration of the LoKr model.</li>',N,x,S,E,W;return c=new z({props:{title:"LoKr",local:"lokr",headingTag:"h1"}}),J=new z({props:{title:"LoKrConfig",local:"peft.LoKrConfig",headingTag:"h2"}}),v=new se({props:{name:"class peft.LoKrConfig",anchor:"peft.LoKrConfig",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:"rank_pattern",val:": Optional[dict] = <factory>"},{name:"alpha_pattern",val:": Optional[dict] = <factory>"},{name:"r",val:": int = 8"},{name:"alpha",val:": int = 8"},{name:"rank_dropout",val:": float = 0.0"},{name:"module_dropout",val:": float = 0.0"},{name:"use_effective_conv2d",val:": bool = False"},{name:"decompose_both",val:": bool = False"},{name:"decompose_factor",val:": int = -1"},{name:"rank_dropout_scale",val:": bool = False"},{name:"target_modules",val:": Optional[Union[list[str], str]] = None"},{name:"exclude_modules",val:": Optional[Union[list[str], str]] = None"},{name:"init_weights",val:": Union[bool, Literal['lycoris']] = True"},{name:"layers_to_transform",val:": Optional[Union[list[int], int]] = None"},{name:"layers_pattern",val:": Optional[Union[list[str], str]] = None"},{name:"modules_to_save",val:": Optional[list[str]] = None"}],parametersDescription:[{anchor:"peft.LoKrConfig.r",description:`<strong>r</strong> (<code>int</code>) &#x2014;
LoKr rank.`,name:"r"},{anchor:"peft.LoKrConfig.alpha",description:`<strong>alpha</strong> (<code>int</code>) &#x2014;
The alpha parameter for LoKr scaling.`,name:"alpha"},{anchor:"peft.LoKrConfig.rank_dropout",description:`<strong>rank_dropout</strong> (<code>float</code>) &#x2014;
The dropout probability for rank dimension during training.`,name:"rank_dropout"},{anchor:"peft.LoKrConfig.module_dropout",description:`<strong>module_dropout</strong> (<code>float</code>) &#x2014;
The dropout probability for disabling LoKr modules during training.`,name:"module_dropout"},{anchor:"peft.LoKrConfig.use_effective_conv2d",description:`<strong>use_effective_conv2d</strong> (<code>bool</code>) &#x2014;
Use parameter effective decomposition for Conv2d (and Conv1d) with ksize &gt; 1 (&#x201C;Proposition 3&#x201D; from FedPara
paper).`,name:"use_effective_conv2d"},{anchor:"peft.LoKrConfig.decompose_both",description:`<strong>decompose_both</strong> (<code>bool</code>) &#x2014;
Perform rank decomposition of left kronecker product matrix.`,name:"decompose_both"},{anchor:"peft.LoKrConfig.decompose_factor",description:`<strong>decompose_factor</strong> (<code>int</code>) &#x2014;
Kronecker product decomposition factor.`,name:"decompose_factor"},{anchor:"peft.LoKrConfig.rank_dropout_scale",description:`<strong>rank_dropout_scale</strong> (&#x2018;bool) &#x2014;
Whether to scale the rank dropout while training, defaults to <code>False</code>.`,name:"rank_dropout_scale"},{anchor:"peft.LoKrConfig.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/Conv1D 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.LoKrConfig.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.LoKrConfig.init_weights",description:`<strong>init_weights</strong> (<code>bool</code>) &#x2014;
Whether to perform initialization of adapter weights. This defaults to <code>True</code>. Use &#x201C;lycoris&#x201D; to initialize
weights in the style of the LYCORIS repository. Passing <code>False</code> is discouraged.`,name:"init_weights"},{anchor:"peft.LoKrConfig.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.LoKrConfig.layers_pattern",description:`<strong>layers_pattern</strong> (<code>Optional[Union[List[str], str]]</code>) &#x2014;
The layer pattern name, used only if <code>layers_to_transform</code> is different from <code>None</code>. This should target the
<code>nn.ModuleList</code> of the model, which is often called <code>&apos;layers&apos;</code> or <code>&apos;h&apos;</code>.`,name:"layers_pattern"},{anchor:"peft.LoKrConfig.rank_pattern",description:`<strong>rank_pattern</strong> (<code>dict</code>) &#x2014;
The mapping from layer names or regexp expression to ranks which are different from the default rank
specified by <code>r</code>. For example, <code>{&apos;^model.decoder.layers.0.encoder_attn.k_proj&apos;: 16}</code>.`,name:"rank_pattern"},{anchor:"peft.LoKrConfig.alpha_pattern",description:`<strong>alpha_pattern</strong> (<code>dict</code>) &#x2014;
The mapping from layer names or regexp expression to alphas which are different from the default alpha
specified by <code>alpha</code>. For example, <code>{&apos;^model.decoder.layers.0.encoder_attn.k_proj&apos;: 16}</code>.`,name:"alpha_pattern"},{anchor:"peft.LoKrConfig.modules_to_save",description:`<strong>modules_to_save</strong> (<code>Optional[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/lokr/config.py#L24"}}),L=new z({props:{title:"LoKrModel",local:"peft.LoKrModel",headingTag:"h2"}}),k=new se({props:{name:"class peft.LoKrModel",anchor:"peft.LoKrModel",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.LoKrModel.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.LoKrModel.config",description:'<strong>config</strong> (<a href="/docs/peft/main/en/package_reference/lokr#peft.LoKrConfig">LoKrConfig</a>) &#x2014; The configuration of the LoKr model.',name:"config"},{anchor:"peft.LoKrModel.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.LoKrModel.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/lokr/model.py#L27",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


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