import{s as je,n as Ce,o as Me}from"../chunks/scheduler.4cd3e004.js";import{S as Ee,i as Pe,e as i,s as n,c as _,h as He,a,d as t,b as o,f as x,g as T,j as L,k as v,l as m,m as r,n as y,t as $,o as b,p as k}from"../chunks/index.b664cb2d.js";import{D as q}from"../chunks/Docstring.9ceb4334.js";import{H as Se,E as Ie}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";function qe(Te){let l,B,U,J,w,K,D,ve='PEFT provides several internal utilities for <a href="../developer_guides/model_merging">merging LoRA adapters</a> with the TIES and DARE methods.',N,d,j,pe,V,ye="Prune the values of task tensors based on the <code>method</code>.",Q,c,C,ue,A,$e="Get the mask of the majority sign across the task tensors. Task tensors are stacked on dimension 0.",X,p,M,ge,R,be="Merge the task tensors using disjoint merge.",Y,u,E,he,F,ke="Merge the task tensors using <code>task arithmetic</code>.",Z,g,P,fe,G,Le="Merge the task tensors using <code>ties</code>.",ee,h,H,_e,z,we="Merge the task tensors using <code>dare linear</code>.",te,f,S,xe,O,De="Merge the task tensors using <code>dare ties</code>.",se,I,re,W,ne;return w=new Se({props:{title:"Model merge",local:"peft.utils.merge_utils.prune",headingTag:"h1"}}),j=new q({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>
`}}),C=new q({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>
`}}),M=new q({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>
`}}),E=new q({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>
`}}),P=new q({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>
`}}),H=new q({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>
`}}),S=new q({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>
`}}),I=new Ie({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/merge_utils.md"}}),{c(){l=i("meta"),B=n(),U=i("p"),J=n(),_(w.$$.fragment),K=n(),D=i("p"),D.innerHTML=ve,N=n(),d=i("div"),_(j.$$.fragment),pe=n(),V=i("p"),V.innerHTML=ye,Q=n(),c=i("div"),_(C.$$.fragment),ue=n(),A=i("p"),A.textContent=$e,X=n(),p=i("div"),_(M.$$.fragment),ge=n(),R=i("p"),R.textContent=be,Y=n(),u=i("div"),_(E.$$.fragment),he=n(),F=i("p"),F.innerHTML=ke,Z=n(),g=i("div"),_(P.$$.fragment),fe=n(),G=i("p"),G.innerHTML=Le,ee=n(),h=i("div"),_(H.$$.fragment),_e=n(),z=i("p"),z.innerHTML=we,te=n(),f=i("div"),_(S.$$.fragment),xe=n(),O=i("p"),O.innerHTML=De,se=n(),_(I.$$.fragment),re=n(),W=i("p"),this.h()},l(e){const s=He("svelte-u9bgzb",document.head);l=a(s,"META",{name:!0,content:!0}),s.forEach(t),B=o(e),U=a(e,"P",{}),x(U).forEach(t),J=o(e),T(w.$$.fragment,e),K=o(e),D=a(e,"P",{"data-svelte-h":!0}),L(D)!=="svelte-bbuf1j"&&(D.innerHTML=ve),N=o(e),d=a(e,"DIV",{class:!0});var oe=x(d);T(j.$$.fragment,oe),pe=o(oe),V=a(oe,"P",{"data-svelte-h":!0}),L(V)!=="svelte-1y1urne"&&(V.innerHTML=ye),oe.forEach(t),Q=o(e),c=a(e,"DIV",{class:!0});var ie=x(c);T(C.$$.fragment,ie),ue=o(ie),A=a(ie,"P",{"data-svelte-h":!0}),L(A)!=="svelte-1fmtw9r"&&(A.textContent=$e),ie.forEach(t),X=o(e),p=a(e,"DIV",{class:!0});var ae=x(p);T(M.$$.fragment,ae),ge=o(ae),R=a(ae,"P",{"data-svelte-h":!0}),L(R)!=="svelte-1yr0ip4"&&(R.textContent=be),ae.forEach(t),Y=o(e),u=a(e,"DIV",{class:!0});var me=x(u);T(E.$$.fragment,me),he=o(me),F=a(me,"P",{"data-svelte-h":!0}),L(F)!=="svelte-8ih8a2"&&(F.innerHTML=ke),me.forEach(t),Z=o(e),g=a(e,"DIV",{class:!0});var le=x(g);T(P.$$.fragment,le),fe=o(le),G=a(le,"P",{"data-svelte-h":!0}),L(G)!=="svelte-1d45n1k"&&(G.innerHTML=Le),le.forEach(t),ee=o(e),h=a(e,"DIV",{class:!0});var de=x(h);T(H.$$.fragment,de),_e=o(de),z=a(de,"P",{"data-svelte-h":!0}),L(z)!=="svelte-1ox69n2"&&(z.innerHTML=we),de.forEach(t),te=o(e),f=a(e,"DIV",{class:!0});var ce=x(f);T(S.$$.fragment,ce),xe=o(ce),O=a(ce,"P",{"data-svelte-h":!0}),L(O)!=="svelte-xv7fyw"&&(O.innerHTML=De),ce.forEach(t),se=o(e),T(I.$$.fragment,e),re=o(e),W=a(e,"P",{}),x(W).forEach(t),this.h()},h(){v(l,"name","hf:doc:metadata"),v(l,"content",Ve),v(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(g,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(f,"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,l),r(e,B,s),r(e,U,s),r(e,J,s),y(w,e,s),r(e,K,s),r(e,D,s),r(e,N,s),r(e,d,s),y(j,d,null),m(d,pe),m(d,V),r(e,Q,s),r(e,c,s),y(C,c,null),m(c,ue),m(c,A),r(e,X,s),r(e,p,s),y(M,p,null),m(p,ge),m(p,R),r(e,Y,s),r(e,u,s),y(E,u,null),m(u,he),m(u,F),r(e,Z,s),r(e,g,s),y(P,g,null),m(g,fe),m(g,G),r(e,ee,s),r(e,h,s),y(H,h,null),m(h,_e),m(h,z),r(e,te,s),r(e,f,s),y(S,f,null),m(f,xe),m(f,O),r(e,se,s),y(I,e,s),r(e,re,s),r(e,W,s),ne=!0},p:Ce,i(e){ne||($(w.$$.fragment,e),$(j.$$.fragment,e),$(C.$$.fragment,e),$(M.$$.fragment,e),$(E.$$.fragment,e),$(P.$$.fragment,e),$(H.$$.fragment,e),$(S.$$.fragment,e),$(I.$$.fragment,e),ne=!0)},o(e){b(w.$$.fragment,e),b(j.$$.fragment,e),b(C.$$.fragment,e),b(M.$$.fragment,e),b(E.$$.fragment,e),b(P.$$.fragment,e),b(H.$$.fragment,e),b(S.$$.fragment,e),b(I.$$.fragment,e),ne=!1},d(e){e&&(t(B),t(U),t(J),t(K),t(D),t(N),t(d),t(Q),t(c),t(X),t(p),t(Y),t(u),t(Z),t(g),t(ee),t(h),t(te),t(f),t(se),t(re),t(W)),t(l),k(w,e),k(j),k(C),k(M),k(E),k(P),k(H),k(S),k(I,e)}}}const Ve='{"title":"Model merge","local":"peft.utils.merge_utils.prune","sections":[],"depth":1}';function Ae(Te){return Me(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Oe extends Ee{constructor(l){super(),Pe(this,l,Ae,qe,je,{})}}export{Oe as component};
