import{s as ie,o as pe,n as ce}from"../chunks/scheduler.78382b47.js";import{S as de,i as me,e as m,s as l,c as y,h as fe,a as f,d as o,b as r,f as F,g as _,j as E,k as O,l as g,m as s,n as j,t as w,o as T,p as b}from"../chunks/index.6dd35eb6.js";import{C as he,H as te,E as ue}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.6888f903.js";import{D as re}from"../chunks/Docstring.286e0aef.js";import{C as ge}from"../chunks/CodeBlock.658dd679.js";import{E as Me}from"../chunks/ExampleCodeBlock.3f133c9f.js";function ye(B){let n,U="Example:",h,p,c;return p=new ge({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBMb0tyTW9kZWwlMkMlMjBMb0tyQ29uZmlnJTBBJTBBY29uZmlnX3RlJTIwJTNEJTIwTG9LckNvbmZpZyglMEElMjAlMjAlMjAlMjByJTNEOCUyQyUwQSUyMCUyMCUyMCUyMGxvcmFfYWxwaGElM0QzMiUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTNEJTVCJTIya19wcm9qJTIyJTJDJTIwJTIycV9wcm9qJTIyJTJDJTIwJTIydl9wcm9qJTIyJTJDJTIwJTIyb3V0X3Byb2olMjIlMkMlMjAlMjJmYzElMjIlMkMlMjAlMjJmYzIlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjByYW5rX2Ryb3BvdXQlM0QwLjAlMkMlMEElMjAlMjAlMjAlMjBtb2R1bGVfZHJvcG91dCUzRDAuMCUyQyUwQSUyMCUyMCUyMCUyMGluaXRfd2VpZ2h0cyUzRFRydWUlMkMlMEEpJTBBY29uZmlnX3VuZXQlMjAlM0QlMjBMb0tyQ29uZmlnKCUwQSUyMCUyMCUyMCUyMHIlM0Q4JTJDJTBBJTIwJTIwJTIwJTIwbG9yYV9hbHBoYSUzRDMyJTJDJTBBJTIwJTIwJTIwJTI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maWdfdW5ldCUyQyUyMCUyMmRlZmF1bHQlMjIp",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=l(),y(p.$$.fragment)},l(a){n=f(a,"P",{"data-svelte-h":!0}),E(n)!=="svelte-11lpom8"&&(n.textContent=U),h=r(a),_(p.$$.fragment,a)},m(a,d){s(a,n,d),s(a,h,d),j(p,a,d),c=!0},p:ce,i(a){c||(w(p.$$.fragment,a),c=!0)},o(a){T(p.$$.fragment,a),c=!1},d(a){a&&(o(n),o(h)),b(p,a)}}}function _e(B){let n,U,h,p,c,a,d,R,J,oe='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.',V,v,H,M,L,X,K,ae='Configuration class of <a href="/docs/peft/v0.18.0/en/package_reference/lokr#peft.LoKrModel">LoKrModel</a>.',N,k,S,i,x,P,A,ne=`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>`,Y,C,z,Z,se="<strong>Attributes</strong>:",ee,q,le='<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/lokr#peft.LoKrConfig">LoKrConfig</a>): The configuration of the LoKr model.</li>',W,$,D,Q,G;return c=new he({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),d=new te({props:{title:"LoKr",local:"lokr",headingTag:"h1"}}),v=new te({props:{title:"LoKrConfig",local:"peft.LoKrConfig",headingTag:"h2"}}),L=new re({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/v0.18.0/src/peft/tuners/lokr/config.py#L24"}}),k=new te({props:{title:"LoKrModel",local:"peft.LoKrModel",headingTag:"h2"}}),x=new re({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/v0.18.0/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/v0.18.0/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>
`}}),C=new Me({props:{anchor:"peft.LoKrModel.example",$$slots:{default:[ye]},$$scope:{ctx:B}}}),$=new ue({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/lokr.md"}}),{c(){n=m("meta"),U=l(),h=m("p"),p=l(),y(c.$$.fragment),a=l(),y(d.$$.fragment),R=l(),J=m("p"),J.innerHTML=oe,V=l(),y(v.$$.fragment),H=l(),M=m("div"),y(L.$$.fragment),X=l(),K=m("p"),K.innerHTML=ae,N=l(),y(k.$$.fragment),S=l(),i=m("div"),y(x.$$.fragment),P=l(),A=m("p"),A.innerHTML=ne,Y=l(),y(C.$$.fragment),z=l(),Z=m("p"),Z.innerHTML=se,ee=l(),q=m("ul"),q.innerHTML=le,W=l(),y($.$$.fragment),D=l(),Q=m("p"),this.h()},l(e){const t=fe("svelte-u9bgzb",document.head);n=f(t,"META",{name:!0,content:!0}),t.forEach(o),U=r(e),h=f(e,"P",{}),F(h).forEach(o),p=r(e),_(c.$$.fragment,e),a=r(e),_(d.$$.fragment,e),R=r(e),J=f(e,"P",{"data-svelte-h":!0}),E(J)!=="svelte-wnctjh"&&(J.innerHTML=oe),V=r(e),_(v.$$.fragment,e),H=r(e),M=f(e,"DIV",{class:!0});var I=F(M);_(L.$$.fragment,I),X=r(I),K=f(I,"P",{"data-svelte-h":!0}),E(K)!=="svelte-13w9f10"&&(K.innerHTML=ae),I.forEach(o),N=r(e),_(k.$$.fragment,e),S=r(e),i=f(e,"DIV",{class:!0});var u=F(i);_(x.$$.fragment,u),P=r(u),A=f(u,"P",{"data-svelte-h":!0}),E(A)!=="svelte-12gwubp"&&(A.innerHTML=ne),Y=r(u),_(C.$$.fragment,u),z=r(u),Z=f(u,"P",{"data-svelte-h":!0}),E(Z)!=="svelte-1xx6nm4"&&(Z.innerHTML=se),ee=r(u),q=f(u,"UL",{"data-svelte-h":!0}),E(q)!=="svelte-6dkh8s"&&(q.innerHTML=le),u.forEach(o),W=r(e),_($.$$.fragment,e),D=r(e),Q=f(e,"P",{}),F(Q).forEach(o),this.h()},h(){O(n,"name","hf:doc:metadata"),O(n,"content",je),O(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(i,"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),j(c,e,t),s(e,a,t),j(d,e,t),s(e,R,t),s(e,J,t),s(e,V,t),j(v,e,t),s(e,H,t),s(e,M,t),j(L,M,null),g(M,X),g(M,K),s(e,N,t),j(k,e,t),s(e,S,t),s(e,i,t),j(x,i,null),g(i,P),g(i,A),g(i,Y),j(C,i,null),g(i,z),g(i,Z),g(i,ee),g(i,q),s(e,W,t),j($,e,t),s(e,D,t),s(e,Q,t),G=!0},p(e,[t]){const I={};t&2&&(I.$$scope={dirty:t,ctx:e}),C.$set(I)},i(e){G||(w(c.$$.fragment,e),w(d.$$.fragment,e),w(v.$$.fragment,e),w(L.$$.fragment,e),w(k.$$.fragment,e),w(x.$$.fragment,e),w(C.$$.fragment,e),w($.$$.fragment,e),G=!0)},o(e){T(c.$$.fragment,e),T(d.$$.fragment,e),T(v.$$.fragment,e),T(L.$$.fragment,e),T(k.$$.fragment,e),T(x.$$.fragment,e),T(C.$$.fragment,e),T($.$$.fragment,e),G=!1},d(e){e&&(o(U),o(h),o(p),o(a),o(R),o(J),o(V),o(H),o(M),o(N),o(S),o(i),o(W),o(D),o(Q)),o(n),b(c,e),b(d,e),b(v,e),b(L),b(k,e),b(x),b(C),b($,e)}}}const je='{"title":"LoKr","local":"lokr","sections":[{"title":"LoKrConfig","local":"peft.LoKrConfig","sections":[],"depth":2},{"title":"LoKrModel","local":"peft.LoKrModel","sections":[],"depth":2}],"depth":1}';function we(B){return pe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends de{constructor(n){super(),me(this,n,we,_e,ie,{})}}export{Le as component};
