import{s as Me,n as Ee,o as Pe}from"../chunks/scheduler.78382b47.js";import{S as He,i as Se,e as i,s as n,c as m,h as Ie,a,d as t,b as o,f as b,g as c,j as L,k,l,m as s,n as d,t as p,o as u,p as g}from"../chunks/index.6dd35eb6.js";import{C as qe,H as Ve,E as Ae}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.8d7e60c0.js";import{D as V}from"../chunks/Docstring.57cb1354.js";function Re($e){let h,J,W,K,w,N,D,Q,j,ye='PEFT provides several internal utilities for <a href="../developer_guides/model_merging">merging LoRA adapters</a> with the TIES and DARE methods.',X,f,C,ge,A,be="Prune the values of task tensors based on the <code>method</code>.",Y,_,M,he,R,ke="Get the mask of the majority sign across the task tensors. Task tensors are stacked on dimension 0.",Z,x,E,fe,z,Le="Merge the task tensors using disjoint merge.",ee,v,P,_e,F,we="Merge the task tensors using <code>task arithmetic</code>.",te,T,H,xe,G,De="Merge the task tensors using <code>ties</code>.",re,$,S,ve,O,je="Merge the task tensors using <code>dare linear</code>.",se,y,I,Te,U,Ce="Merge the task tensors using <code>dare ties</code>.",ne,q,oe,B,ie;return w=new qe({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),D=new Ve({props:{title:"Model merge",local:"peft.utils.merge_utils.prune",headingTag:"h1"}}),C=new V({props:{name:"peft.utils.merge_utils.prune",anchor:"peft.utils.merge_utils.prune",parameters:[{name:"tensor",val:": Tensor"},{name:"density",val:": float"},{name:"method",val:": typing.Literal['magnitude', 'random']"},{name:"rescale",val:": bool = False"}],parametersDescription:[{anchor:"peft.utils.merge_utils.prune.tensor",description:"<strong>tensor</strong> (<code>torch.Tensor</code>) &#x2014;The tensor to prune.",name:"tensor"},{anchor:"peft.utils.merge_utils.prune.density",description:"<strong>density</strong> (<code>float</code>) &#x2014;The fraction of values to preserve. Should be in [0,1].",name:"density"},{anchor:"peft.utils.merge_utils.prune.method",description:"<strong>method</strong> (<code>str</code>) &#x2014;The method to use to prune. Should be one of [&#x201C;magnitude&#x201D;, &#x201C;random&#x201D;].",name:"method"},{anchor:"peft.utils.merge_utils.prune.rescale",description:"<strong>rescale</strong> (<code>bool</code>) &#x2014;Whether to rescale the result to preserve the expected value of the original tensor.",name:"rescale"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L75",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),M=new V({props:{name:"peft.utils.merge_utils.calculate_majority_sign_mask",anchor:"peft.utils.merge_utils.calculate_majority_sign_mask",parameters:[{name:"tensor",val:": Tensor"},{name:"method",val:": typing.Literal['total', 'frequency'] = 'total'"}],parametersDescription:[{anchor:"peft.utils.merge_utils.calculate_majority_sign_mask.tensor",description:"<strong>tensor</strong> (<code>torch.Tensor</code>) &#x2014;The tensor to get the mask from.",name:"tensor"},{anchor:"peft.utils.merge_utils.calculate_majority_sign_mask.method",description:"<strong>method</strong> (<code>str</code>) &#x2014;The method to use to get the mask. Should be one of [&#x201C;total&#x201D;, &#x201C;frequency&#x201D;].",name:"method"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L103",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),E=new V({props:{name:"peft.utils.merge_utils.disjoint_merge",anchor:"peft.utils.merge_utils.disjoint_merge",parameters:[{name:"task_tensors",val:": Tensor"},{name:"majority_sign_mask",val:": Tensor"}],parametersDescription:[{anchor:"peft.utils.merge_utils.disjoint_merge.task_tensors",description:"<strong>task_tensors</strong> (<code>torch.Tensor</code>) &#x2014;The task tensors to merge.",name:"task_tensors"},{anchor:"peft.utils.merge_utils.disjoint_merge.majority_sign_mask",description:"<strong>majority_sign_mask</strong> (<code>torch.Tensor</code>) &#x2014;The mask of the majority sign across the task tensors.",name:"majority_sign_mask"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L128",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),P=new V({props:{name:"peft.utils.merge_utils.task_arithmetic",anchor:"peft.utils.merge_utils.task_arithmetic",parameters:[{name:"task_tensors",val:": list"},{name:"weights",val:": Tensor"}],parametersDescription:[{anchor:"peft.utils.merge_utils.task_arithmetic.task_tensors(List[torch.Tensor])",description:"<strong>task_tensors(<code>List[torch.Tensor]</code>)</strong> &#x2014;The task tensors to merge.",name:"task_tensors(List[torch.Tensor])"},{anchor:"peft.utils.merge_utils.task_arithmetic.weights",description:"<strong>weights</strong> (<code>torch.Tensor</code>) &#x2014;The weights of the task tensors.",name:"weights"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L144",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),H=new V({props:{name:"peft.utils.merge_utils.ties",anchor:"peft.utils.merge_utils.ties",parameters:[{name:"task_tensors",val:": list"},{name:"weights",val:": Tensor"},{name:"density",val:": float"},{name:"majority_sign_method",val:": typing.Literal['total', 'frequency'] = 'total'"}],parametersDescription:[{anchor:"peft.utils.merge_utils.ties.task_tensors(List[torch.Tensor])",description:"<strong>task_tensors(<code>List[torch.Tensor]</code>)</strong> &#x2014;The task tensors to merge.",name:"task_tensors(List[torch.Tensor])"},{anchor:"peft.utils.merge_utils.ties.weights",description:"<strong>weights</strong> (<code>torch.Tensor</code>) &#x2014;The weights of the task tensors.",name:"weights"},{anchor:"peft.utils.merge_utils.ties.density",description:"<strong>density</strong> (<code>float</code>) &#x2014;The fraction of values to preserve. Should be in [0,1].",name:"density"},{anchor:"peft.utils.merge_utils.ties.majority_sign_method",description:`<strong>majority_sign_method</strong> (<code>str</code>) &#x2014;
The method to use to get the majority sign mask. Should be one of [&#x201C;total&#x201D;, &#x201C;frequency&#x201D;].`,name:"majority_sign_method"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L185",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),S=new V({props:{name:"peft.utils.merge_utils.dare_linear",anchor:"peft.utils.merge_utils.dare_linear",parameters:[{name:"task_tensors",val:": list"},{name:"weights",val:": Tensor"},{name:"density",val:": float"}],parametersDescription:[{anchor:"peft.utils.merge_utils.dare_linear.task_tensors(List[torch.Tensor])",description:"<strong>task_tensors(<code>List[torch.Tensor]</code>)</strong> &#x2014;The task tensors to merge.",name:"task_tensors(List[torch.Tensor])"},{anchor:"peft.utils.merge_utils.dare_linear.weights",description:"<strong>weights</strong> (<code>torch.Tensor</code>) &#x2014;The weights of the task tensors.",name:"weights"},{anchor:"peft.utils.merge_utils.dare_linear.density",description:"<strong>density</strong> (<code>float</code>) &#x2014;The fraction of values to preserve. Should be in [0,1].",name:"density"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L217",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),I=new V({props:{name:"peft.utils.merge_utils.dare_ties",anchor:"peft.utils.merge_utils.dare_ties",parameters:[{name:"task_tensors",val:": list"},{name:"weights",val:": Tensor"},{name:"density",val:": float"},{name:"majority_sign_method",val:": typing.Literal['total', 'frequency'] = 'total'"}],parametersDescription:[{anchor:"peft.utils.merge_utils.dare_ties.task_tensors(List[torch.Tensor])",description:"<strong>task_tensors(<code>List[torch.Tensor]</code>)</strong> &#x2014;The task tensors to merge.",name:"task_tensors(List[torch.Tensor])"},{anchor:"peft.utils.merge_utils.dare_ties.weights",description:"<strong>weights</strong> (<code>torch.Tensor</code>) &#x2014;The weights of the task tensors.",name:"weights"},{anchor:"peft.utils.merge_utils.dare_ties.density",description:"<strong>density</strong> (<code>float</code>) &#x2014;The fraction of values to preserve. Should be in [0,1].",name:"density"},{anchor:"peft.utils.merge_utils.dare_ties.majority_sign_method",description:`<strong>majority_sign_method</strong> (<code>str</code>) &#x2014;
The method to use to get the majority sign mask. Should be one of [&#x201C;total&#x201D;, &#x201C;frequency&#x201D;].`,name:"majority_sign_method"}],source:"https://github.com/huggingface/peft/blob/v0.18.0.rc0/src/peft/utils/merge_utils.py#L239",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


<p><code>torch.Tensor</code></p>
`}}),q=new Ae({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/merge_utils.md"}}),{c(){h=i("meta"),J=n(),W=i("p"),K=n(),m(w.$$.fragment),N=n(),m(D.$$.fragment),Q=n(),j=i("p"),j.innerHTML=ye,X=n(),f=i("div"),m(C.$$.fragment),ge=n(),A=i("p"),A.innerHTML=be,Y=n(),_=i("div"),m(M.$$.fragment),he=n(),R=i("p"),R.textContent=ke,Z=n(),x=i("div"),m(E.$$.fragment),fe=n(),z=i("p"),z.textContent=Le,ee=n(),v=i("div"),m(P.$$.fragment),_e=n(),F=i("p"),F.innerHTML=we,te=n(),T=i("div"),m(H.$$.fragment),xe=n(),G=i("p"),G.innerHTML=De,re=n(),$=i("div"),m(S.$$.fragment),ve=n(),O=i("p"),O.innerHTML=je,se=n(),y=i("div"),m(I.$$.fragment),Te=n(),U=i("p"),U.innerHTML=Ce,ne=n(),m(q.$$.fragment),oe=n(),B=i("p"),this.h()},l(e){const r=Ie("svelte-u9bgzb",document.head);h=a(r,"META",{name:!0,content:!0}),r.forEach(t),J=o(e),W=a(e,"P",{}),b(W).forEach(t),K=o(e),c(w.$$.fragment,e),N=o(e),c(D.$$.fragment,e),Q=o(e),j=a(e,"P",{"data-svelte-h":!0}),L(j)!=="svelte-bbuf1j"&&(j.innerHTML=ye),X=o(e),f=a(e,"DIV",{class:!0});var ae=b(f);c(C.$$.fragment,ae),ge=o(ae),A=a(ae,"P",{"data-svelte-h":!0}),L(A)!=="svelte-1y1urne"&&(A.innerHTML=be),ae.forEach(t),Y=o(e),_=a(e,"DIV",{class:!0});var le=b(_);c(M.$$.fragment,le),he=o(le),R=a(le,"P",{"data-svelte-h":!0}),L(R)!=="svelte-1fmtw9r"&&(R.textContent=ke),le.forEach(t),Z=o(e),x=a(e,"DIV",{class:!0});var me=b(x);c(E.$$.fragment,me),fe=o(me),z=a(me,"P",{"data-svelte-h":!0}),L(z)!=="svelte-1yr0ip4"&&(z.textContent=Le),me.forEach(t),ee=o(e),v=a(e,"DIV",{class:!0});var ce=b(v);c(P.$$.fragment,ce),_e=o(ce),F=a(ce,"P",{"data-svelte-h":!0}),L(F)!=="svelte-8ih8a2"&&(F.innerHTML=we),ce.forEach(t),te=o(e),T=a(e,"DIV",{class:!0});var de=b(T);c(H.$$.fragment,de),xe=o(de),G=a(de,"P",{"data-svelte-h":!0}),L(G)!=="svelte-1d45n1k"&&(G.innerHTML=De),de.forEach(t),re=o(e),$=a(e,"DIV",{class:!0});var pe=b($);c(S.$$.fragment,pe),ve=o(pe),O=a(pe,"P",{"data-svelte-h":!0}),L(O)!=="svelte-1ox69n2"&&(O.innerHTML=je),pe.forEach(t),se=o(e),y=a(e,"DIV",{class:!0});var ue=b(y);c(I.$$.fragment,ue),Te=o(ue),U=a(ue,"P",{"data-svelte-h":!0}),L(U)!=="svelte-xv7fyw"&&(U.innerHTML=Ce),ue.forEach(t),ne=o(e),c(q.$$.fragment,e),oe=o(e),B=a(e,"P",{}),b(B).forEach(t),this.h()},h(){k(h,"name","hf:doc:metadata"),k(h,"content",ze),k(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),k(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),k(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),k(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),k(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),k($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),k(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,r){l(document.head,h),s(e,J,r),s(e,W,r),s(e,K,r),d(w,e,r),s(e,N,r),d(D,e,r),s(e,Q,r),s(e,j,r),s(e,X,r),s(e,f,r),d(C,f,null),l(f,ge),l(f,A),s(e,Y,r),s(e,_,r),d(M,_,null),l(_,he),l(_,R),s(e,Z,r),s(e,x,r),d(E,x,null),l(x,fe),l(x,z),s(e,ee,r),s(e,v,r),d(P,v,null),l(v,_e),l(v,F),s(e,te,r),s(e,T,r),d(H,T,null),l(T,xe),l(T,G),s(e,re,r),s(e,$,r),d(S,$,null),l($,ve),l($,O),s(e,se,r),s(e,y,r),d(I,y,null),l(y,Te),l(y,U),s(e,ne,r),d(q,e,r),s(e,oe,r),s(e,B,r),ie=!0},p:Ee,i(e){ie||(p(w.$$.fragment,e),p(D.$$.fragment,e),p(C.$$.fragment,e),p(M.$$.fragment,e),p(E.$$.fragment,e),p(P.$$.fragment,e),p(H.$$.fragment,e),p(S.$$.fragment,e),p(I.$$.fragment,e),p(q.$$.fragment,e),ie=!0)},o(e){u(w.$$.fragment,e),u(D.$$.fragment,e),u(C.$$.fragment,e),u(M.$$.fragment,e),u(E.$$.fragment,e),u(P.$$.fragment,e),u(H.$$.fragment,e),u(S.$$.fragment,e),u(I.$$.fragment,e),u(q.$$.fragment,e),ie=!1},d(e){e&&(t(J),t(W),t(K),t(N),t(Q),t(j),t(X),t(f),t(Y),t(_),t(Z),t(x),t(ee),t(v),t(te),t(T),t(re),t($),t(se),t(y),t(ne),t(oe),t(B)),t(h),g(w,e),g(D,e),g(C),g(M),g(E),g(P),g(H),g(S),g(I),g(q,e)}}}const ze='{"title":"Model merge","local":"peft.utils.merge_utils.prune","sections":[],"depth":1}';function Fe($e){return Pe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Be extends He{constructor(h){super(),Se(this,h,Fe,Re,Me,{})}}export{Be as component};
