import{s as Pe,o as Ae,n as Ze}from"../chunks/scheduler.78382b47.js";import{S as Be,i as De,e as c,s as l,c as b,h as ze,a as m,d as n,b as s,f as q,g as w,j as T,k as O,l as p,m as o,n as _,t as y,o as x,p as v}from"../chunks/index.6dd35eb6.js";import{C as He,H as te,E as Ye}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.fed9dfe4.js";import{D as ge}from"../chunks/Docstring.32e826ec.js";import{C as Le}from"../chunks/CodeBlock.af1ec02e.js";import{E as Ve}from"../chunks/ExampleCodeBlock.7f184f2e.js";function Xe(B){let r,C="Example:",f,i,d;return i=new Le({props:{code:"bW9kZWwlMjAlM0QlMjBNb2RlbFdpdGhMb3JhTGF5ZXIoKSUwQW11bHRpcGxpZXIlMjAlM0QlMjAwLjUlMEF3aXRoJTIwcmVzY2FsZV9hZGFwdGVyX3NjYWxlKG1vZGVsJTJDJTIwbXVsdGlwbGllciklM0ElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpJTIwJTIwJTIzJTIwUGVyZm9ybSUyMG9wZXJhdGlvbnMlMjB3aXRoJTIwdGhlJTIwc2NhbGVkJTIwbW9kZWwlMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpJTIwJTIwJTIzJTIwVGhlJTIwb3JpZ2luYWwlMjBzY2FsaW5nJTIwdmFsdWVzJTIwYXJlJTIwcmVzdG9yZWQlMjBoZXJl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>model = ModelWithLoraLayer()
<span class="hljs-meta">&gt;&gt;&gt; </span>multiplier = <span class="hljs-number">0.5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> rescale_adapter_scale(model, multiplier):
<span class="hljs-meta">... </span>    outputs = model(**inputs)  <span class="hljs-comment"># Perform operations with the scaled model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)  <span class="hljs-comment"># The original scaling values are restored here</span>`,wrap:!1}}),{c(){r=c("p"),r.textContent=C,f=l(),b(i.$$.fragment)},l(a){r=m(a,"P",{"data-svelte-h":!0}),T(r)!=="svelte-11lpom8"&&(r.textContent=C),f=s(a),w(i.$$.fragment,a)},m(a,g){o(a,r,g),o(a,f,g),_(i,a,g),d=!0},p:Ze,i(a){d||(y(i.$$.fragment,a),d=!0)},o(a){x(i.$$.fragment,a),d=!1},d(a){a&&(n(r),n(f)),v(i,a)}}}function Se(B){let r,C="Example:",f,i,d;return i=new Le({props:{code:"ZnJvbSUyMHBlZnQuaGVscGVycyUyMGltcG9ydCUyMGVuYWJsZV9kb3JhX3NjYWxpbmclMEElMEFtb2RlbC5ldmFsKCklMjAlMjAlMjMlMjBwdXQlMjBpbiUyMGV2YWwlMjBtb2RlbCUyMGZvciUyMGNhY2hpbmclMjB0byUyMHdvcmslMEElMEF3aXRoJTIwRG9yYUNhY2hpbmcoKSUzQSUyMCUyMCUyMyUyMHVzZSUyMGFzJTIwYSUyMGNvbnRleHQlMjBtYW5hZ2VyJTBBJTIwJTIwJTIwJTIwb3V0cHV0JTIwJTNEJTIwbW9kZWwoaW5wdXRzKSUwQSUwQWRvcmFfY2FjaGluZyUyMCUzRCUyMERvcmFDYWNoaW5nKCklMEFkb3JhX2NhY2hpbmcoZW5hYmxlZCUzRFRydWUpJTIwJTIwJTIzJTIwcGVybWFuZW50bHklMjBlbmFibGUlMjBjYWNoaW5nJTBBb3V0cHV0JTIwJTNEJTIwbW9kZWwoaW5wdXRzKSUwQWRvcmFfY2FjaGluZyhlbmFibGVkJTNERmFsc2UpJTIwJTIwJTIzJTIwcGVybWFuZW50bHklMjBkaXNhYmxlJTIwY2FjaGluZyUwQW91dHB1dCUyMCUzRCUyMG1vZGVsKGlucHV0cyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> peft.helpers <span class="hljs-keyword">import</span> enable_dora_scaling

<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">eval</span>()  <span class="hljs-comment"># put in eval model for caching to work</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> DoraCaching():  <span class="hljs-comment"># use as a context manager</span>
<span class="hljs-meta">... </span>    output = model(inputs)

<span class="hljs-meta">&gt;&gt;&gt; </span>dora_caching = DoraCaching()
<span class="hljs-meta">&gt;&gt;&gt; </span>dora_caching(enabled=<span class="hljs-literal">True</span>)  <span class="hljs-comment"># permanently enable caching</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>output = model(inputs)
<span class="hljs-meta">&gt;&gt;&gt; </span>dora_caching(enabled=<span class="hljs-literal">False</span>)  <span class="hljs-comment"># permanently disable caching</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>output = model(inputs)`,wrap:!1}}),{c(){r=c("p"),r.textContent=C,f=l(),b(i.$$.fragment)},l(a){r=m(a,"P",{"data-svelte-h":!0}),T(r)!=="svelte-11lpom8"&&(r.textContent=C),f=s(a),w(i.$$.fragment,a)},m(a,g){o(a,r,g),o(a,f,g),_(i,a,g),d=!0},p:Ze,i(a){d||(y(i.$$.fragment,a),d=!0)},o(a){x(i.$$.fragment,a),d=!1},d(a){a&&(n(r),n(f)),v(i,a)}}}function Ne(B){let r,C,f,i,d,a,g,ae,W,je="A collection of helper functions for PEFT.",ne,E,le,j,G,ue,D,Je="Check if the model is a PEFT model.",se,R,re,h,F,$e,z,Ie="Context manager to temporarily rescale the scaling of the LoRA adapter in a model.",be,H,ke=`The original scaling values are restored when the context manager exits. This context manager works with the
transformers and diffusers models that have directly loaded LoRA adapters.`,we,Y,We=`For LoRA, applying this context manager with multiplier in [0, 1] is strictly equivalent to applying
<a href="https://huggingface.co/papers/2109.01903" rel="nofollow">wise-ft</a> (see <a href="https://github.com/huggingface/peft/issues/1940" rel="nofollow">#1940</a>
for details). It can improve the performances of the model if there is a distribution shiftbetween the training
data used for fine-tuning, and the test data used during inference.`,_e,X,Ee=`Warning: It has been reported that when using Apple’s MPS backend for PyTorch, it is necessary to add a short sleep
time after exiting the context before the scales are fully restored.`,ye,I,oe,U,pe,J,V,xe,S,Ge="Context manager disables input dtype casting to the dtype of the weight.",ie,Z,ce,u,L,ve,N,Re="Context manager to enable DoRA caching, which improves speed of DoRA inference at the expense of memory.",Te,Q,Fe=`With active caching, the materialized LoRA weight (B @ A) and the weight norm (base weight + LoRA weight) are
cached.`,Ce,K,Ue=`Even within the caching context, if the model is in training mode, caching is disabled. When the model switches to
training mode, the cache will be cleared.`,Me,k,me,P,de,ee,he;return d=new He({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new te({props:{title:"Helper methods",local:"helper-methods",headingTag:"h1"}}),E=new te({props:{title:"Checking if a model is a PEFT model",local:"peft.helpers.check_if_peft_model",headingTag:"h2"}}),G=new ge({props:{name:"peft.helpers.check_if_peft_model",anchor:"peft.helpers.check_if_peft_model",parameters:[{name:"model_name_or_path",val:": str"}],parametersDescription:[{anchor:"peft.helpers.check_if_peft_model.model_name_or_path",description:`<strong>model_name_or_path</strong> (<code>str</code>) &#x2014;
Model id to check, can be local or on the Hugging Face Hub.`,name:"model_name_or_path"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/helpers.py#L135",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>True if the model is a PEFT model, False otherwise.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>bool</code></p>
`}}),R=new te({props:{title:"Temporarily Rescaling Adapter Scale in LoraLayer Modules",local:"peft.helpers.rescale_adapter_scale",headingTag:"h2"}}),F=new ge({props:{name:"peft.helpers.rescale_adapter_scale",anchor:"peft.helpers.rescale_adapter_scale",parameters:[{name:"model",val:""},{name:"multiplier",val:""}],parametersDescription:[{anchor:"peft.helpers.rescale_adapter_scale.model",description:"<strong>model</strong> &#x2014; The model containing <code>LoraLayer</code> modules whose scaling is to be adjusted.",name:"model"},{anchor:"peft.helpers.rescale_adapter_scale.multiplier",description:`<strong>multiplier</strong> (float or int) &#x2014;
The multiplier that rescales the <code>scaling</code> attribute. Must be of type float or int.`,name:"multiplier"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/helpers.py#L156",raiseDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li><code>ValueError</code> — If the model does not contain any <code>LoraLayer</code>
instances, indicating that the model does not support scaling.</li>
</ul>
`,raiseType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>ValueError</code></p>
`}}),I=new Ve({props:{anchor:"peft.helpers.rescale_adapter_scale.example",$$slots:{default:[Xe]},$$scope:{ctx:B}}}),U=new te({props:{title:"Context manager to disable input dtype casting in the forward method of LoRA layers",local:"peft.helpers.disable_input_dtype_casting",headingTag:"h2"}}),V=new ge({props:{name:"peft.helpers.disable_input_dtype_casting",anchor:"peft.helpers.disable_input_dtype_casting",parameters:[{name:"model",val:": Module"},{name:"active",val:": bool = True"}],parametersDescription:[{anchor:"peft.helpers.disable_input_dtype_casting.model",description:`<strong>model</strong> (nn.Module) &#x2014;
The model containing PEFT modules whose input dtype casting is to be adjusted.`,name:"model"},{anchor:"peft.helpers.disable_input_dtype_casting.active",description:`<strong>active</strong> (bool) &#x2014;
Whether the context manager is active (default) or inactive.`,name:"active"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/helpers.py#L217"}}),Z=new te({props:{title:"Context manager to enable DoRA caching (faster at inference time but requires more memory)",local:"peft.helpers.DoraCaching",headingTag:"h2"}}),L=new ge({props:{name:"class peft.helpers.DoraCaching",anchor:"peft.helpers.DoraCaching",parameters:[{name:"enabled",val:": bool = True"}],source:"https://github.com/huggingface/peft/blob/main/src/peft/helpers.py#L254"}}),k=new Ve({props:{anchor:"peft.helpers.DoraCaching.example",$$slots:{default:[Se]},$$scope:{ctx:B}}}),P=new Ye({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/helpers.md"}}),{c(){r=c("meta"),C=l(),f=c("p"),i=l(),b(d.$$.fragment),a=l(),b(g.$$.fragment),ae=l(),W=c("p"),W.textContent=je,ne=l(),b(E.$$.fragment),le=l(),j=c("div"),b(G.$$.fragment),ue=l(),D=c("p"),D.textContent=Je,se=l(),b(R.$$.fragment),re=l(),h=c("div"),b(F.$$.fragment),$e=l(),z=c("p"),z.textContent=Ie,be=l(),H=c("p"),H.textContent=ke,we=l(),Y=c("p"),Y.innerHTML=We,_e=l(),X=c("p"),X.textContent=Ee,ye=l(),b(I.$$.fragment),oe=l(),b(U.$$.fragment),pe=l(),J=c("div"),b(V.$$.fragment),xe=l(),S=c("p"),S.textContent=Ge,ie=l(),b(Z.$$.fragment),ce=l(),u=c("div"),b(L.$$.fragment),ve=l(),N=c("p"),N.textContent=Re,Te=l(),Q=c("p"),Q.textContent=Fe,Ce=l(),K=c("p"),K.textContent=Ue,Me=l(),b(k.$$.fragment),me=l(),b(P.$$.fragment),de=l(),ee=c("p"),this.h()},l(e){const t=ze("svelte-u9bgzb",document.head);r=m(t,"META",{name:!0,content:!0}),t.forEach(n),C=s(e),f=m(e,"P",{}),q(f).forEach(n),i=s(e),w(d.$$.fragment,e),a=s(e),w(g.$$.fragment,e),ae=s(e),W=m(e,"P",{"data-svelte-h":!0}),T(W)!=="svelte-13lsaa3"&&(W.textContent=je),ne=s(e),w(E.$$.fragment,e),le=s(e),j=m(e,"DIV",{class:!0});var A=q(j);w(G.$$.fragment,A),ue=s(A),D=m(A,"P",{"data-svelte-h":!0}),T(D)!=="svelte-10bf42q"&&(D.textContent=Je),A.forEach(n),se=s(e),w(R.$$.fragment,e),re=s(e),h=m(e,"DIV",{class:!0});var $=q(h);w(F.$$.fragment,$),$e=s($),z=m($,"P",{"data-svelte-h":!0}),T(z)!=="svelte-bty642"&&(z.textContent=Ie),be=s($),H=m($,"P",{"data-svelte-h":!0}),T(H)!=="svelte-bvcnfs"&&(H.textContent=ke),we=s($),Y=m($,"P",{"data-svelte-h":!0}),T(Y)!=="svelte-1w8copz"&&(Y.innerHTML=We),_e=s($),X=m($,"P",{"data-svelte-h":!0}),T(X)!=="svelte-1k7mwln"&&(X.textContent=Ee),ye=s($),w(I.$$.fragment,$),$.forEach(n),oe=s(e),w(U.$$.fragment,e),pe=s(e),J=m(e,"DIV",{class:!0});var fe=q(J);w(V.$$.fragment,fe),xe=s(fe),S=m(fe,"P",{"data-svelte-h":!0}),T(S)!=="svelte-169ndbq"&&(S.textContent=Ge),fe.forEach(n),ie=s(e),w(Z.$$.fragment,e),ce=s(e),u=m(e,"DIV",{class:!0});var M=q(u);w(L.$$.fragment,M),ve=s(M),N=m(M,"P",{"data-svelte-h":!0}),T(N)!=="svelte-y9ste4"&&(N.textContent=Re),Te=s(M),Q=m(M,"P",{"data-svelte-h":!0}),T(Q)!=="svelte-h3jq9g"&&(Q.textContent=Fe),Ce=s(M),K=m(M,"P",{"data-svelte-h":!0}),T(K)!=="svelte-1yvuk9a"&&(K.textContent=Ue),Me=s(M),w(k.$$.fragment,M),M.forEach(n),me=s(e),w(P.$$.fragment,e),de=s(e),ee=m(e,"P",{}),q(ee).forEach(n),this.h()},h(){O(r,"name","hf:doc:metadata"),O(r,"content",Qe),O(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(u,"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){p(document.head,r),o(e,C,t),o(e,f,t),o(e,i,t),_(d,e,t),o(e,a,t),_(g,e,t),o(e,ae,t),o(e,W,t),o(e,ne,t),_(E,e,t),o(e,le,t),o(e,j,t),_(G,j,null),p(j,ue),p(j,D),o(e,se,t),_(R,e,t),o(e,re,t),o(e,h,t),_(F,h,null),p(h,$e),p(h,z),p(h,be),p(h,H),p(h,we),p(h,Y),p(h,_e),p(h,X),p(h,ye),_(I,h,null),o(e,oe,t),_(U,e,t),o(e,pe,t),o(e,J,t),_(V,J,null),p(J,xe),p(J,S),o(e,ie,t),_(Z,e,t),o(e,ce,t),o(e,u,t),_(L,u,null),p(u,ve),p(u,N),p(u,Te),p(u,Q),p(u,Ce),p(u,K),p(u,Me),_(k,u,null),o(e,me,t),_(P,e,t),o(e,de,t),o(e,ee,t),he=!0},p(e,[t]){const A={};t&2&&(A.$$scope={dirty:t,ctx:e}),I.$set(A);const $={};t&2&&($.$$scope={dirty:t,ctx:e}),k.$set($)},i(e){he||(y(d.$$.fragment,e),y(g.$$.fragment,e),y(E.$$.fragment,e),y(G.$$.fragment,e),y(R.$$.fragment,e),y(F.$$.fragment,e),y(I.$$.fragment,e),y(U.$$.fragment,e),y(V.$$.fragment,e),y(Z.$$.fragment,e),y(L.$$.fragment,e),y(k.$$.fragment,e),y(P.$$.fragment,e),he=!0)},o(e){x(d.$$.fragment,e),x(g.$$.fragment,e),x(E.$$.fragment,e),x(G.$$.fragment,e),x(R.$$.fragment,e),x(F.$$.fragment,e),x(I.$$.fragment,e),x(U.$$.fragment,e),x(V.$$.fragment,e),x(Z.$$.fragment,e),x(L.$$.fragment,e),x(k.$$.fragment,e),x(P.$$.fragment,e),he=!1},d(e){e&&(n(C),n(f),n(i),n(a),n(ae),n(W),n(ne),n(le),n(j),n(se),n(re),n(h),n(oe),n(pe),n(J),n(ie),n(ce),n(u),n(me),n(de),n(ee)),n(r),v(d,e),v(g,e),v(E,e),v(G),v(R,e),v(F),v(I),v(U,e),v(V),v(Z,e),v(L),v(k),v(P,e)}}}const Qe='{"title":"Helper methods","local":"helper-methods","sections":[{"title":"Checking if a model is a PEFT model","local":"peft.helpers.check_if_peft_model","sections":[],"depth":2},{"title":"Temporarily Rescaling Adapter Scale in LoraLayer Modules","local":"peft.helpers.rescale_adapter_scale","sections":[],"depth":2},{"title":"Context manager to disable input dtype casting in the forward method of LoRA layers","local":"peft.helpers.disable_input_dtype_casting","sections":[],"depth":2},{"title":"Context manager to enable DoRA caching (faster at inference time but requires more memory)","local":"peft.helpers.DoraCaching","sections":[],"depth":2}],"depth":1}';function Ke(B){return Ae(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class lt extends Be{constructor(r){super(),De(this,r,Ke,Ne,Pe,{})}}export{lt as component};
