import{s as $e,o as be,n as we}from"../chunks/scheduler.4cd3e004.js";import{S as xe,i as ve,e as d,s,c as _,h as Te,a as m,d as a,b as l,f as H,g as $,j as C,k as z,l as p,m as r,n as b,t as w,o as x,p as v}from"../chunks/index.b664cb2d.js";import{D as de}from"../chunks/Docstring.9ceb4334.js";import{C as ye}from"../chunks/CodeBlock.8601e34e.js";import{E as Me}from"../chunks/ExampleCodeBlock.4f57b575.js";import{H as ae,E as Ce}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function Je(B){let o,J="Example:",u,c,f;return c=new ye({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(){o=d("p"),o.textContent=J,u=s(),_(c.$$.fragment)},l(n){o=m(n,"P",{"data-svelte-h":!0}),C(o)!=="svelte-11lpom8"&&(o.textContent=J),u=l(n),$(c.$$.fragment,n)},m(n,g){r(n,o,g),r(n,u,g),b(c,n,g),f=!0},p:we,i(n){f||(w(c.$$.fragment,n),f=!0)},o(n){x(c.$$.fragment,n),f=!1},d(n){n&&(a(o),a(u)),v(c,n)}}}function Ie(B){let o,J,u,c,f,n,g,me="A collection of helper functions for PEFT.",S,I,N,T,E,ne,W,ce="Check if the model is a PEFT model.",U,k,Y,i,j,se,A,fe="Context manager to temporarily rescale the scaling of the LoRA adapter in a model.",le,R,he=`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.`,re,V,ge=`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.`,oe,Z,ue=`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.`,ie,M,q,P,K,y,L,pe,X,_e="Context manager disables input dtype casting to the dtype of the weight.",Q,F,O,D,ee;return f=new ae({props:{title:"Helper methods",local:"helper-methods",headingTag:"h1"}}),I=new ae({props:{title:"Checking if a model is a PEFT model",local:"peft.helpers.check_if_peft_model",headingTag:"h2"}}),E=new de({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>
`}}),k=new ae({props:{title:"Temporarily Rescaling Adapter Scale in LoraLayer Modules",local:"peft.helpers.rescale_adapter_scale",headingTag:"h2"}}),j=new de({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>
`}}),M=new Me({props:{anchor:"peft.helpers.rescale_adapter_scale.example",$$slots:{default:[Je]},$$scope:{ctx:B}}}),P=new ae({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"}}),L=new de({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"}}),F=new Ce({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/helpers.md"}}),{c(){o=d("meta"),J=s(),u=d("p"),c=s(),_(f.$$.fragment),n=s(),g=d("p"),g.textContent=me,S=s(),_(I.$$.fragment),N=s(),T=d("div"),_(E.$$.fragment),ne=s(),W=d("p"),W.textContent=ce,U=s(),_(k.$$.fragment),Y=s(),i=d("div"),_(j.$$.fragment),se=s(),A=d("p"),A.textContent=fe,le=s(),R=d("p"),R.textContent=he,re=s(),V=d("p"),V.innerHTML=ge,oe=s(),Z=d("p"),Z.textContent=ue,ie=s(),_(M.$$.fragment),q=s(),_(P.$$.fragment),K=s(),y=d("div"),_(L.$$.fragment),pe=s(),X=d("p"),X.textContent=_e,Q=s(),_(F.$$.fragment),O=s(),D=d("p"),this.h()},l(e){const t=Te("svelte-u9bgzb",document.head);o=m(t,"META",{name:!0,content:!0}),t.forEach(a),J=l(e),u=m(e,"P",{}),H(u).forEach(a),c=l(e),$(f.$$.fragment,e),n=l(e),g=m(e,"P",{"data-svelte-h":!0}),C(g)!=="svelte-13lsaa3"&&(g.textContent=me),S=l(e),$(I.$$.fragment,e),N=l(e),T=m(e,"DIV",{class:!0});var G=H(T);$(E.$$.fragment,G),ne=l(G),W=m(G,"P",{"data-svelte-h":!0}),C(W)!=="svelte-10bf42q"&&(W.textContent=ce),G.forEach(a),U=l(e),$(k.$$.fragment,e),Y=l(e),i=m(e,"DIV",{class:!0});var h=H(i);$(j.$$.fragment,h),se=l(h),A=m(h,"P",{"data-svelte-h":!0}),C(A)!=="svelte-bty642"&&(A.textContent=fe),le=l(h),R=m(h,"P",{"data-svelte-h":!0}),C(R)!=="svelte-bvcnfs"&&(R.textContent=he),re=l(h),V=m(h,"P",{"data-svelte-h":!0}),C(V)!=="svelte-1w8copz"&&(V.innerHTML=ge),oe=l(h),Z=m(h,"P",{"data-svelte-h":!0}),C(Z)!=="svelte-1k7mwln"&&(Z.textContent=ue),ie=l(h),$(M.$$.fragment,h),h.forEach(a),q=l(e),$(P.$$.fragment,e),K=l(e),y=m(e,"DIV",{class:!0});var te=H(y);$(L.$$.fragment,te),pe=l(te),X=m(te,"P",{"data-svelte-h":!0}),C(X)!=="svelte-169ndbq"&&(X.textContent=_e),te.forEach(a),Q=l(e),$(F.$$.fragment,e),O=l(e),D=m(e,"P",{}),H(D).forEach(a),this.h()},h(){z(o,"name","hf:doc:metadata"),z(o,"content",Ee),z(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),z(i,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),z(y,"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,o),r(e,J,t),r(e,u,t),r(e,c,t),b(f,e,t),r(e,n,t),r(e,g,t),r(e,S,t),b(I,e,t),r(e,N,t),r(e,T,t),b(E,T,null),p(T,ne),p(T,W),r(e,U,t),b(k,e,t),r(e,Y,t),r(e,i,t),b(j,i,null),p(i,se),p(i,A),p(i,le),p(i,R),p(i,re),p(i,V),p(i,oe),p(i,Z),p(i,ie),b(M,i,null),r(e,q,t),b(P,e,t),r(e,K,t),r(e,y,t),b(L,y,null),p(y,pe),p(y,X),r(e,Q,t),b(F,e,t),r(e,O,t),r(e,D,t),ee=!0},p(e,[t]){const G={};t&2&&(G.$$scope={dirty:t,ctx:e}),M.$set(G)},i(e){ee||(w(f.$$.fragment,e),w(I.$$.fragment,e),w(E.$$.fragment,e),w(k.$$.fragment,e),w(j.$$.fragment,e),w(M.$$.fragment,e),w(P.$$.fragment,e),w(L.$$.fragment,e),w(F.$$.fragment,e),ee=!0)},o(e){x(f.$$.fragment,e),x(I.$$.fragment,e),x(E.$$.fragment,e),x(k.$$.fragment,e),x(j.$$.fragment,e),x(M.$$.fragment,e),x(P.$$.fragment,e),x(L.$$.fragment,e),x(F.$$.fragment,e),ee=!1},d(e){e&&(a(J),a(u),a(c),a(n),a(g),a(S),a(N),a(T),a(U),a(Y),a(i),a(q),a(K),a(y),a(Q),a(O),a(D)),a(o),v(f,e),v(I,e),v(E),v(k,e),v(j),v(M),v(P,e),v(L),v(F,e)}}}const Ee='{"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}],"depth":1}';function ke(B){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ae extends xe{constructor(o){super(),ve(this,o,ke,Ie,$e,{})}}export{Ae as component};
