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 l,h as Ie,a,d as t,b as o,f as b,g as d,j as L,k,l as m,m as r,n as c,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.fed9dfe4.js";import{D as V}from"../chunks/Docstring.32e826ec.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,T,P,_e,F,we="Merge the task tensors using <code>task arithmetic</code>.",te,v,H,xe,G,De="Merge the task tensors using <code>ties</code>.",se,$,S,Te,O,je="Merge the task tensors using <code>dare linear</code>.",re,y,I,ve,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/main/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/main/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/main/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/main/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/main/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/main/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/main/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(),l(w.$$.fragment),N=n(),l(D.$$.fragment),Q=n(),j=i("p"),j.innerHTML=ye,X=n(),f=i("div"),l(C.$$.fragment),ge=n(),A=i("p"),A.innerHTML=be,Y=n(),_=i("div"),l(M.$$.fragment),he=n(),R=i("p"),R.textContent=ke,Z=n(),x=i("div"),l(E.$$.fragment),fe=n(),z=i("p"),z.textContent=Le,ee=n(),T=i("div"),l(P.$$.fragment),_e=n(),F=i("p"),F.innerHTML=we,te=n(),v=i("div"),l(H.$$.fragment),xe=n(),G=i("p"),G.innerHTML=De,se=n(),$=i("div"),l(S.$$.fragment),Te=n(),O=i("p"),O.innerHTML=je,re=n(),y=i("div"),l(I.$$.fragment),ve=n(),U=i("p"),U.innerHTML=Ce,ne=n(),l(q.$$.fragment),oe=n(),B=i("p"),this.h()},l(e){const s=Ie("svelte-u9bgzb",document.head);h=a(s,"META",{name:!0,content:!0}),s.forEach(t),J=o(e),W=a(e,"P",{}),b(W).forEach(t),K=o(e),d(w.$$.fragment,e),N=o(e),d(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);d(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 me=b(_);d(M.$$.fragment,me),he=o(me),R=a(me,"P",{"data-svelte-h":!0}),L(R)!=="svelte-1fmtw9r"&&(R.textContent=ke),me.forEach(t),Z=o(e),x=a(e,"DIV",{class:!0});var le=b(x);d(E.$$.fragment,le),fe=o(le),z=a(le,"P",{"data-svelte-h":!0}),L(z)!=="svelte-1yr0ip4"&&(z.textContent=Le),le.forEach(t),ee=o(e),T=a(e,"DIV",{class:!0});var de=b(T);d(P.$$.fragment,de),_e=o(de),F=a(de,"P",{"data-svelte-h":!0}),L(F)!=="svelte-8ih8a2"&&(F.innerHTML=we),de.forEach(t),te=o(e),v=a(e,"DIV",{class:!0});var ce=b(v);d(H.$$.fragment,ce),xe=o(ce),G=a(ce,"P",{"data-svelte-h":!0}),L(G)!=="svelte-1d45n1k"&&(G.innerHTML=De),ce.forEach(t),se=o(e),$=a(e,"DIV",{class:!0});var pe=b($);d(S.$$.fragment,pe),Te=o(pe),O=a(pe,"P",{"data-svelte-h":!0}),L(O)!=="svelte-1ox69n2"&&(O.innerHTML=je),pe.forEach(t),re=o(e),y=a(e,"DIV",{class:!0});var ue=b(y);d(I.$$.fragment,ue),ve=o(ue),U=a(ue,"P",{"data-svelte-h":!0}),L(U)!=="svelte-xv7fyw"&&(U.innerHTML=Ce),ue.forEach(t),ne=o(e),d(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(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(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($,"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,s){m(document.head,h),r(e,J,s),r(e,W,s),r(e,K,s),c(w,e,s),r(e,N,s),c(D,e,s),r(e,Q,s),r(e,j,s),r(e,X,s),r(e,f,s),c(C,f,null),m(f,ge),m(f,A),r(e,Y,s),r(e,_,s),c(M,_,null),m(_,he),m(_,R),r(e,Z,s),r(e,x,s),c(E,x,null),m(x,fe),m(x,z),r(e,ee,s),r(e,T,s),c(P,T,null),m(T,_e),m(T,F),r(e,te,s),r(e,v,s),c(H,v,null),m(v,xe),m(v,G),r(e,se,s),r(e,$,s),c(S,$,null),m($,Te),m($,O),r(e,re,s),r(e,y,s),c(I,y,null),m(y,ve),m(y,U),r(e,ne,s),c(q,e,s),r(e,oe,s),r(e,B,s),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(T),t(te),t(v),t(se),t($),t(re),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};
