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