import{s as Be,c as Xe,u as He,g as Ce,b as Ne,o as ze,n as L}from"../chunks/scheduler.78382b47.js";import{S as Qe,i as qe,e as J,a as w,f as je,d as r,k as ge,m as i,t as M,o as y,s as m,c as f,h as Ye,b as u,g,j as U,l as Fe,n as b,p as j}from"../chunks/index.6dd35eb6.js";import{C as Ee,H as be,E as Se}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.8d7e60c0.js";import{C as $}from"../chunks/CodeBlock.4d4112a9.js";import{H as Ve,a as D}from"../chunks/HfOption.a1db6210.js";function Le(h){let t,p,s;const d=h[2].default,l=Xe(d,h,h[1],null);return{c(){t=J("blockquote"),l&&l.c(),this.h()},l(a){t=w(a,"BLOCKQUOTE",{class:!0});var o=je(t);l&&l.l(o),o.forEach(r),this.h()},h(){ge(t,"class",p=h[0]?"warning":"tip")},m(a,o){i(a,t,o),l&&l.m(t,null),s=!0},p(a,[o]){l&&l.p&&(!s||o&2)&&He(l,d,a,a[1],s?Ne(d,a[1],o,null):Ce(a[1]),null),(!s||o&1&&p!==(p=a[0]?"warning":"tip"))&&ge(t,"class",p)},i(a){s||(M(l,a),s=!0)},o(a){y(l,a),s=!1},d(a){a&&r(t),l&&l.d(a)}}}function Ae(h,t,p){let{$$slots:s={},$$scope:d}=t,{warning:l=!1}=t;return h.$$set=a=>{"warning"in a&&p(0,l=a.warning),"$$scope"in a&&p(1,d=a.$$scope)},[l,d,s]}class xe extends Qe{constructor(t){super(),qe(this,t,Ae,Le,Be,{warning:0})}}function De(h){let t,p='When you’re attempting to merge fully trained models with TIES, you should be aware of any special tokens each model may have added to the embedding layer which are not a part of the original checkpoint’s vocabulary. This may cause an issue because each model may have added a special token to the same embedding position. If this is the case, you should use the <a href="https://huggingface.co/docs/transformers/v4.57.1/en/main_classes/model#transformers.PreTrainedModel.resize_token_embeddings" rel="nofollow">resize_token_embeddings</a> method to avoid merging the special tokens at the same embedding index.',s,d,l,a,o="This shouldn’t be an issue if you’re only merging LoRA adapters trained from the same base model.";return{c(){t=J("p"),t.innerHTML=p,s=m(),d=J("br"),l=m(),a=J("p"),a.textContent=o},l(c){t=w(c,"P",{"data-svelte-h":!0}),U(t)!=="svelte-1ivec9p"&&(t.innerHTML=p),s=u(c),d=w(c,"BR",{}),l=u(c),a=w(c,"P",{"data-svelte-h":!0}),U(a)!=="svelte-1bgcfcq"&&(a.textContent=o)},m(c,T){i(c,t,T),i(c,s,T),i(c,d,T),i(c,l,T),i(c,a,T)},p:L,d(c){c&&(r(t),r(s),r(d),r(l),r(a))}}}function Pe(h){let t,p="Weight values greater than <code>1.0</code> typically produce better results because they preserve the correct scale. A good default starting value for the weights is to set all values to <code>1.0</code>.",s,d,l;return d=new $({props:{code:"YWRhcHRlcnMlMjAlM0QlMjAlNUIlMjJub3JvYm90cyUyMiUyQyUyMCUyMmFkY29weSUyMiUyQyUyMCUyMnNxbCUyMiU1RCUwQXdlaWdodHMlMjAlM0QlMjAlNUIyLjAlMkMlMjAxLjAlMkMlMjAxLjAlNUQlMEFhZGFwdGVyX25hbWUlMjAlM0QlMjAlMjJtZXJnZSUyMiUwQWRlbnNpdHklMjAlM0QlMjAwLjIlMEFtb2RlbC5hZGRfd2VpZ2h0ZWRfYWRhcHRlcihhZGFwdGVycyUyQyUyMHdlaWdodHMlMkMlMjBhZGFwdGVyX25hbWUlMkMlMjBjb21iaW5hdGlvbl90eXBlJTNEJTIydGllcyUyMiUyQyUyMGRlbnNpdHklM0RkZW5zaXR5KQ==",highlighted:`adapters = [<span class="hljs-string">&quot;norobots&quot;</span>, <span class="hljs-string">&quot;adcopy&quot;</span>, <span class="hljs-string">&quot;sql&quot;</span>]
weights = [<span class="hljs-number">2.0</span>, <span class="hljs-number">1.0</span>, <span class="hljs-number">1.0</span>]
adapter_name = <span class="hljs-string">&quot;merge&quot;</span>
density = <span class="hljs-number">0.2</span>
model.add_weighted_adapter(adapters, weights, adapter_name, combination_type=<span class="hljs-string">&quot;ties&quot;</span>, density=density)`,wrap:!1}}),{c(){t=J("p"),t.innerHTML=p,s=m(),f(d.$$.fragment)},l(a){t=w(a,"P",{"data-svelte-h":!0}),U(t)!=="svelte-11ncbcn"&&(t.innerHTML=p),s=u(a),g(d.$$.fragment,a)},m(a,o){i(a,t,o),i(a,s,o),b(d,a,o),l=!0},p:L,i(a){l||(M(d.$$.fragment,a),l=!0)},o(a){y(d.$$.fragment,a),l=!1},d(a){a&&(r(t),r(s)),j(d,a)}}}function Ke(h){let t,p;return t=new $({props:{code:"YWRhcHRlcnMlMjAlM0QlMjAlNUIlMjJub3JvYm90cyUyMiUyQyUyMCUyMmFkY29weSUyMiUyQyUyMCUyMnNxbCUyMiU1RCUwQXdlaWdodHMlMjAlM0QlMjAlNUIyLjAlMkMlMjAwLjMlMkMlMjAwLjclNUQlMEFhZGFwdGVyX25hbWUlMjAlM0QlMjAlMjJtZXJnZSUyMiUwQWRlbnNpdHklMjAlM0QlMjAwLjIlMEFtb2RlbC5hZGRfd2VpZ2h0ZWRfYWRhcHRlcihhZGFwdGVycyUyQyUyMHdlaWdodHMlMkMlMjBhZGFwdGVyX25hbWUlMkMlMjBjb21iaW5hdGlvbl90eXBlJTNEJTIyZGFyZV90aWVzJTIyJTJDJTIwZGVuc2l0eSUzRGRlbnNpdHkp",highlighted:`adapters = [<span class="hljs-string">&quot;norobots&quot;</span>, <span class="hljs-string">&quot;adcopy&quot;</span>, <span class="hljs-string">&quot;sql&quot;</span>]
weights = [<span class="hljs-number">2.0</span>, <span class="hljs-number">0.3</span>, <span class="hljs-number">0.7</span>]
adapter_name = <span class="hljs-string">&quot;merge&quot;</span>
density = <span class="hljs-number">0.2</span>
model.add_weighted_adapter(adapters, weights, adapter_name, combination_type=<span class="hljs-string">&quot;dare_ties&quot;</span>, density=density)`,wrap:!1}}),{c(){f(t.$$.fragment)},l(s){g(t.$$.fragment,s)},m(s,d){b(t,s,d),p=!0},p:L,i(s){p||(M(t.$$.fragment,s),p=!0)},o(s){y(t.$$.fragment,s),p=!1},d(s){j(t,s)}}}function Oe(h){let t,p,s,d;return t=new D({props:{id:"merge-method",option:"TIES",$$slots:{default:[Pe]},$$scope:{ctx:h}}}),s=new D({props:{id:"merge-method",option:"DARE",$$slots:{default:[Ke]},$$scope:{ctx:h}}}),{c(){f(t.$$.fragment),p=m(),f(s.$$.fragment)},l(l){g(t.$$.fragment,l),p=u(l),g(s.$$.fragment,l)},m(l,a){b(t,l,a),i(l,p,a),b(s,l,a),d=!0},p(l,a){const o={};a&2&&(o.$$scope={dirty:a,ctx:l}),t.$set(o);const c={};a&2&&(c.$$scope={dirty:a,ctx:l}),s.$set(c)},i(l){d||(M(t.$$.fragment,l),M(s.$$.fragment,l),d=!0)},o(l){y(t.$$.fragment,l),y(s.$$.fragment,l),d=!1},d(l){l&&r(p),j(t,l),j(s,l)}}}function et(h){let t,p;return t=new $({props:{code:"ZGV2aWNlJTIwJTNEJTIwdG9yY2guYWNjZWxlcmF0b3IuY3VycmVudF9hY2NlbGVyYXRvcigpLnR5cGUlMjBpZiUyMGhhc2F0dHIodG9yY2glMkMlMjAlMjJhY2NlbGVyYXRvciUyMiklMjBlbHNlJTIwJTIyY3VkYSUyMiUwQW1lc3NhZ2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIyV3JpdGUlMjBhbiUyMGVzc2F5JTIwYWJvdXQlMjBHZW5lcmF0aXZlJTIwQUkuJTIyJTdEJTJDJTBBJTVEJTBBdGV4dCUyMCUzRCUyMHRva2VuaXplci5hcHBseV9jaGF0X3RlbXBsYXRlKG1lc3NhZ2VzJTJDJTIwYWRkX2dlbmVyYXRpb25fcHJvbXB0JTNEVHJ1ZSUyQyUyMHRva2VuaXplJTNERmFsc2UpJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQWlucHV0cyUyMCUzRCUyMCU3QmslM0ElMjB2LnRvKGRldmljZSklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaW5wdXRzLml0ZW1zKCklN0QlMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBtYXhfbmV3X3Rva2VucyUzRDI1NiUyQyUyMGRvX3NhbXBsZSUzRFRydWUlMkMlMjB0b3BfcCUzRDAuOTUlMkMlMjB0ZW1wZXJhdHVyZSUzRDAuMiUyQyUyMHJlcGV0aXRpb25fcGVuYWx0eSUzRDEuMiUyQyUyMGVvc190b2tlbl9pZCUzRHRva2VuaXplci5lb3NfdG9rZW5faWQpJTBBcHJpbnQodG9rZW5pemVyLmRlY29kZShvdXRwdXRzJTVCMCU1RCkp",highlighted:`device = torch.accelerator.current_accelerator().<span class="hljs-built_in">type</span> <span class="hljs-keyword">if</span> <span class="hljs-built_in">hasattr</span>(torch, <span class="hljs-string">&quot;accelerator&quot;</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cuda&quot;</span>
messages = [
    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Write an essay about Generative AI.&quot;</span>},
]
text = tokenizer.apply_chat_template(messages, add_generation_prompt=<span class="hljs-literal">True</span>, tokenize=<span class="hljs-literal">False</span>)
inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
inputs = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> inputs.items()}
outputs = model.generate(**inputs, max_new_tokens=<span class="hljs-number">256</span>, do_sample=<span class="hljs-literal">True</span>, top_p=<span class="hljs-number">0.95</span>, temperature=<span class="hljs-number">0.2</span>, repetition_penalty=<span class="hljs-number">1.2</span>, eos_token_id=tokenizer.eos_token_id)
<span class="hljs-built_in">print</span>(tokenizer.decode(outputs[<span class="hljs-number">0</span>]))`,wrap:!1}}),{c(){f(t.$$.fragment)},l(s){g(t.$$.fragment,s)},m(s,d){b(t,s,d),p=!0},p:L,i(s){p||(M(t.$$.fragment,s),p=!0)},o(s){y(t.$$.fragment,s),p=!1},d(s){j(t,s)}}}function tt(h){let t,p;return t=new $({props:{code:"ZGV2aWNlJTIwJTNEJTIwdG9yY2guYWNjZWxlcmF0b3IuY3VycmVudF9hY2NlbGVyYXRvcigpLnR5cGUlMjBpZiUyMGhhc2F0dHIodG9yY2glMkMlMjAlMjJhY2NlbGVyYXRvciUyMiklMjBlbHNlJTIwJTIyY3VkYSUyMiUwQW1lc3NhZ2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnN5c3RlbSUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlMjJDcmVhdGUlMjBhJTIwdGV4dCUyMGFkJTIwZ2l2ZW4lMjB0aGUlMjBmb2xsb3dpbmclMjBwcm9kdWN0JTIwYW5kJTIwZGVzY3JpcHRpb24uJTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIyUHJvZHVjdCUzQSUyMFNvbnklMjBQUzUlMjBQbGF5U3RhdGlvbiUyMENvbnNvbGUlNUNuRGVzY3JpcHRpb24lM0ElMjBUaGUlMjBQUzUlMjBjb25zb2xlJTIwdW5sZWFzaGVzJTIwbmV3JTIwZ2FtaW5nJTIwcG9zc2liaWxpdGllcyUyMHRoYXQlMjB5b3UlMjBuZXZlciUyMGFudGljaXBhdGVkLiUyMiU3RCUyQyUwQSU1RCUwQXRleHQlMjAlM0QlMjB0b2tlbml6ZXIuYXBwbHlfY2hhdF90ZW1wbGF0ZShtZXNzYWdlcyUyQyUyMGFkZF9nZW5lcmF0aW9uX3Byb21wdCUzRFRydWUlMkMlMjB0b2tlbml6ZSUzREZhbHNlKSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcih0ZXh0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEFpbnB1dHMlMjAlM0QlMjAlN0JrJTNBJTIwdi50byhkZXZpY2UpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGlucHV0cy5pdGVtcygpJTdEJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzJTJDJTIwbWF4X25ld190b2tlbnMlM0QxMjglMkMlMjBkb19zYW1wbGUlM0RUcnVlJTJDJTIwdG9wX3AlM0QwLjk1JTJDJTIwdGVtcGVyYXR1cmUlM0QwLjIlMkMlMjByZXBldGl0aW9uX3BlbmFsdHklM0QxLjIlMkMlMjBlb3NfdG9rZW5faWQlM0R0b2tlbml6ZXIuZW9zX3Rva2VuX2lkKSUwQXByaW50KHRva2VuaXplci5kZWNvZGUob3V0cHV0cyU1QjAlNUQpKQ==",highlighted:`device = torch.accelerator.current_accelerator().<span class="hljs-built_in">type</span> <span class="hljs-keyword">if</span> <span class="hljs-built_in">hasattr</span>(torch, <span class="hljs-string">&quot;accelerator&quot;</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cuda&quot;</span>
messages = [
    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;system&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Create a text ad given the following product and description.&quot;</span>},
    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Product: Sony PS5 PlayStation Console\\nDescription: The PS5 console unleashes new gaming possibilities that you never anticipated.&quot;</span>},
]
text = tokenizer.apply_chat_template(messages, add_generation_prompt=<span class="hljs-literal">True</span>, tokenize=<span class="hljs-literal">False</span>)
inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
inputs = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> inputs.items()}
outputs = model.generate(**inputs, max_new_tokens=<span class="hljs-number">128</span>, do_sample=<span class="hljs-literal">True</span>, top_p=<span class="hljs-number">0.95</span>, temperature=<span class="hljs-number">0.2</span>, repetition_penalty=<span class="hljs-number">1.2</span>, eos_token_id=tokenizer.eos_token_id)
<span class="hljs-built_in">print</span>(tokenizer.decode(outputs[<span class="hljs-number">0</span>]))`,wrap:!1}}),{c(){f(t.$$.fragment)},l(s){g(t.$$.fragment,s)},m(s,d){b(t,s,d),p=!0},p:L,i(s){p||(M(t.$$.fragment,s),p=!0)},o(s){y(t.$$.fragment,s),p=!1},d(s){j(t,s)}}}function st(h){let t,p;return t=new $({props:{code:"ZGV2aWNlJTIwJTNEJTIwdG9yY2guYWNjZWxlcmF0b3IuY3VycmVudF9hY2NlbGVyYXRvcigpLnR5cGUlMjBpZiUyMGhhc2F0dHIodG9yY2glMkMlMjAlMjJhY2NlbGVyYXRvciUyMiklMjBlbHNlJTIwJTIyY3VkYSUyMiUwQSUwQXRleHQlMjAlM0QlMjAlMjIlMjIlMjJUYWJsZSUzQSUyMDItMTEzNjU1MjgtMiUwQUNvbHVtbnMlM0ElMjAlNUInVGVhbSclMkMlMjAnSGVhZCUyMENvYWNoJyUyQyUyMCdQcmVzaWRlbnQnJTJDJTIwJ0hvbWUlMjBHcm91bmQnJTJDJTIwJ0xvY2F0aW9uJyU1RCUwQU5hdHVyYWwlMjBRdWVyeSUzQSUyMFdobyUyMGlzJTIwdGhlJTIwSGVhZCUyMENvYWNoJTIwb2YlMjB0aGUlMjB0ZWFtJTIwd2hvc2UlMjBQcmVzaWRlbnQlMjBpcyUyME1hcmlvJTIwVm9sYXJldmljJTNGJTBBU1FMJTIwUXVlcnklM0ElMjIlMjIlMjIlMEElMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIodGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBaW5wdXRzJTIwJTNEJTIwJTdCayUzQSUyMHYudG8oZGV2aWNlKSUyMGZvciUyMGslMkMlMjB2JTIwaW4lMjBpbnB1dHMuaXRlbXMoKSU3RCUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMG1heF9uZXdfdG9rZW5zJTNENjQlMkMlMjByZXBldGl0aW9uX3BlbmFsdHklM0QxLjElMkMlMjBlb3NfdG9rZW5faWQlM0R0b2tlbml6ZXIoJTIyJTNDJTJGcyUzRSUyMikuaW5wdXRfaWRzJTVCLTElNUQpJTBBcHJpbnQodG9rZW5pemVyLmRlY29kZShvdXRwdXRzJTVCMCU1RCkp",highlighted:`device = torch.accelerator.current_accelerator().<span class="hljs-built_in">type</span> <span class="hljs-keyword">if</span> <span class="hljs-built_in">hasattr</span>(torch, <span class="hljs-string">&quot;accelerator&quot;</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cuda&quot;</span>

text = <span class="hljs-string">&quot;&quot;&quot;Table: 2-11365528-2
Columns: [&#x27;Team&#x27;, &#x27;Head Coach&#x27;, &#x27;President&#x27;, &#x27;Home Ground&#x27;, &#x27;Location&#x27;]
Natural Query: Who is the Head Coach of the team whose President is Mario Volarevic?
SQL Query:&quot;&quot;&quot;</span>

inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
inputs = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> inputs.items()}
outputs = model.generate(**inputs, max_new_tokens=<span class="hljs-number">64</span>, repetition_penalty=<span class="hljs-number">1.1</span>, eos_token_id=tokenizer(<span class="hljs-string">&quot;&lt;/s&gt;&quot;</span>).input_ids[-<span class="hljs-number">1</span>])
<span class="hljs-built_in">print</span>(tokenizer.decode(outputs[<span class="hljs-number">0</span>]))`,wrap:!1}}),{c(){f(t.$$.fragment)},l(s){g(t.$$.fragment,s)},m(s,d){b(t,s,d),p=!0},p:L,i(s){p||(M(t.$$.fragment,s),p=!0)},o(s){y(t.$$.fragment,s),p=!1},d(s){j(t,s)}}}function lt(h){let t,p,s,d,l,a;return t=new D({props:{id:"ties",option:"instruct",$$slots:{default:[et]},$$scope:{ctx:h}}}),s=new D({props:{id:"ties",option:"ad copy",$$slots:{default:[tt]},$$scope:{ctx:h}}}),l=new D({props:{id:"ties",option:"SQL",$$slots:{default:[st]},$$scope:{ctx:h}}}),{c(){f(t.$$.fragment),p=m(),f(s.$$.fragment),d=m(),f(l.$$.fragment)},l(o){g(t.$$.fragment,o),p=u(o),g(s.$$.fragment,o),d=u(o),g(l.$$.fragment,o)},m(o,c){b(t,o,c),i(o,p,c),b(s,o,c),i(o,d,c),b(l,o,c),a=!0},p(o,c){const T={};c&2&&(T.$$scope={dirty:c,ctx:o}),t.$set(T);const A={};c&2&&(A.$$scope={dirty:c,ctx:o}),s.$set(A);const Z={};c&2&&(Z.$$scope={dirty:c,ctx:o}),l.$set(Z)},i(o){a||(M(t.$$.fragment,o),M(s.$$.fragment,o),M(l.$$.fragment,o),a=!0)},o(o){y(t.$$.fragment,o),y(s.$$.fragment,o),y(l.$$.fragment,o),a=!1},d(o){o&&(r(p),r(d)),j(t,o),j(s,o),j(l,o)}}}function at(h){let t,p,s,d,l,a,o,c,T,A="Training a model for each task can be costly, take up storage space, and the models aren’t able to learn new information to improve their performance. Multitask learning can overcome some of these limitations by training a model to learn several tasks, but it is expensive to train and designing a dataset for it is challenging. <em>Model merging</em> offers a solution to these challenges by combining multiple pretrained models into one model, giving it the combined abilities of each individual model without any additional training.",Z,W,Je="PEFT provides several methods for merging models like a linear or SVD combination. This guide focuses on two methods that are more efficient for merging LoRA adapters by eliminating redundant parameters:",P,v,we='<li><a href="https://hf.co/papers/2306.01708" rel="nofollow">TIES</a> - TrIm, Elect, and Merge (TIES) is a three-step method for merging models. First, redundant parameters are trimmed, then conflicting signs are resolved into an aggregated vector, and finally the parameters whose signs are the same as the aggregate sign are averaged. This method takes into account that some values (redundant and sign disagreement) can degrade performance in the merged model.</li> <li><a href="https://hf.co/papers/2311.03099" rel="nofollow">DARE</a> - Drop And REscale is a method that can be used to prepare for other model merging methods like TIES. It works by randomly dropping parameters according to a drop rate and rescaling the remaining parameters. This helps to reduce the number of redundant and potentially interfering parameters among multiple models.</li>',K,G,Te='Models are merged with the <a href="/docs/peft/v0.18.0.rc0/en/package_reference/lora#peft.LoraModel.add_weighted_adapter">add_weighted_adapter()</a> method, and the specific model merging method is specified in the <code>combination_type</code> parameter.',O,R,ee,V,Ue='With TIES and DARE, merging is enabled by setting <code>combination_type</code> and <code>density</code> to a value of the weights to keep from the individual models. For example, let’s merge three finetuned <a href="https://huggingface.co/TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T" rel="nofollow">TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T</a> models: <a href="https://huggingface.co/smangrul/tinyllama_lora_norobots" rel="nofollow">tinyllama_lora_nobots</a>, <a href="https://huggingface.co/smangrul/tinyllama_lora_sql" rel="nofollow">tinyllama_lora_sql</a>, and <a href="https://huggingface.co/smangrul/tinyllama_lora_adcopy" rel="nofollow">tinyllama_lora_adcopy</a>.',te,_,se,B,$e='Load a base model and can use the <a href="/docs/peft/v0.18.0.rc0/en/package_reference/peft_model#peft.PeftModel.load_adapter">load_adapter()</a> method to load and assign each adapter a name:',le,Q,ae,q,_e='Set the adapters, weights, <code>adapter_name</code>, <code>combination_type</code>, and <code>density</code> with the <a href="/docs/peft/v0.18.0.rc0/en/package_reference/lora#peft.LoraModel.add_weighted_adapter">add_weighted_adapter()</a> method.',ne,I,oe,X,Ie='Set the newly merged model as the active model with the <a href="/docs/peft/v0.18.0.rc0/en/package_reference/tuners#peft.tuners.tuners_utils.BaseTuner.set_adapter">set_adapter()</a> method.',re,H,ie,C,ke="Now you can use the merged model as an instruction-tuned model to write ad copy or SQL queries!",pe,k,de,N,ce,z,Ze="The (IA)³ models facilitate linear merging of adapters. To merge adapters in an (IA)³ model, utilize the <code>add_weighted_adapter</code> method from the <code>IA3Model</code> class. This method is analogous to the <code>add_weighted_adapter</code> method used in <code>LoraModel</code>, with the key difference being the absence of the <code>combination_type</code> parameter. For example, to merge three (IA)³ adapters into a PEFT model, you would proceed as follows:",me,Y,ue,F,We="It is recommended that the weights sum to 1.0 to preserve the scale of the model. The merged model can then be set as the active model using the <code>set_adapter</code> method:",he,E,Me,S,ye,x,fe;return l=new Ee({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),o=new be({props:{title:"Model merging",local:"model-merging",headingTag:"h1"}}),R=new be({props:{title:"Merge method",local:"merge-method",headingTag:"h2"}}),_=new xe({props:{warninig:!0,$$slots:{default:[De]},$$scope:{ctx:h}}}),Q=new $({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBQZWZ0Q29uZmlnJTJDJTIwUGVmdE1vZGVsJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQWltcG9ydCUyMHRvcmNoJTBBJTBBY29uZmlnJTIwJTNEJTIwUGVmdENvbmZpZy5mcm9tX3ByZXRyYWluZWQoJTIyc21hbmdydWwlMkZ0aW55bGxhbWFfbG9yYV9ub3JvYm90cyUyMiklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChjb25maWcuYmFzZV9tb2RlbF9uYW1lX29yX3BhdGglMkMlMjBsb2FkX2luXzRiaXQlM0RUcnVlJTJDJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIpLmV2YWwoKSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMnNtYW5ncnVsJTJGdGlueWxsYW1hX2xvcmFfbm9yb2JvdHMlMjIpJTBBJTBBbW9kZWwuY29uZmlnLnZvY2FiX3NpemUlMjAlM0QlMjAzMjAwNSUwQW1vZGVsLnJlc2l6ZV90b2tlbl9lbWJlZGRpbmdzKDMyMDA1KSUwQSUwQW1vZGVsJTIwJTNEJTIwUGVmdE1vZGVsLmZyb21fcHJldHJhaW5lZChtb2RlbCUyQyUyMCUyMnNtYW5ncnVsJTJGdGlueWxsYW1hX2xvcmFfbm9yb2JvdHMlMjIlMkMlMjBhZGFwdGVyX25hbWUlM0QlMjJub3JvYm90cyUyMiklMEFfJTIwJTNEJTIwbW9kZWwubG9hZF9hZGFwdGVyKCUyMnNtYW5ncnVsJTJGdGlueWxsYW1hX2xvcmFfc3FsJTIyJTJDJTIwYWRhcHRlcl9uYW1lJTNEJTIyc3FsJTIyKSUwQV8lMjAlM0QlMjBtb2RlbC5sb2FkX2FkYXB0ZXIoJTIyc21hbmdydWwlMkZ0aW55bGxhbWFfbG9yYV9hZGNvcHklMjIlMkMlMjBhZGFwdGVyX25hbWUlM0QlMjJhZGNvcHklMjIp",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftConfig, PeftModel
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">import</span> torch

config = PeftConfig.from_pretrained(<span class="hljs-string">&quot;smangrul/tinyllama_lora_norobots&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, load_in_4bit=<span class="hljs-literal">True</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>).<span class="hljs-built_in">eval</span>()
tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;smangrul/tinyllama_lora_norobots&quot;</span>)

model.config.vocab_size = <span class="hljs-number">32005</span>
model.resize_token_embeddings(<span class="hljs-number">32005</span>)

model = PeftModel.from_pretrained(model, <span class="hljs-string">&quot;smangrul/tinyllama_lora_norobots&quot;</span>, adapter_name=<span class="hljs-string">&quot;norobots&quot;</span>)
_ = model.load_adapter(<span class="hljs-string">&quot;smangrul/tinyllama_lora_sql&quot;</span>, adapter_name=<span class="hljs-string">&quot;sql&quot;</span>)
_ = model.load_adapter(<span class="hljs-string">&quot;smangrul/tinyllama_lora_adcopy&quot;</span>, adapter_name=<span class="hljs-string">&quot;adcopy&quot;</span>)`,wrap:!1}}),I=new Ve({props:{id:"merge-method",options:["TIES","DARE"],$$slots:{default:[Oe]},$$scope:{ctx:h}}}),H=new $({props:{code:"bW9kZWwuc2V0X2FkYXB0ZXIoJTIybWVyZ2UlMjIp",highlighted:'model.set_adapter(<span class="hljs-string">&quot;merge&quot;</span>)',wrap:!1}}),k=new Ve({props:{id:"ties",options:["instruct","ad copy","SQL"],$$slots:{default:[lt]},$$scope:{ctx:h}}}),N=new be({props:{title:"Merging (IA)³ Models",local:"merging-ia³-models",headingTag:"h2"}}),Y=new $({props:{code:"YWRhcHRlcnMlMjAlM0QlMjAlNUIlMjJhZGFwdGVyMSUyMiUyQyUyMCUyMmFkYXB0ZXIyJTIyJTJDJTIwJTIyYWRhcHRlcjMlMjIlNUQlMEF3ZWlnaHRzJTIwJTNEJTIwJTVCMC40JTJDJTIwMC4zJTJDJTIwMC4zJTVEJTBBYWRhcHRlcl9uYW1lJTIwJTNEJTIwJTIybWVyZ2UlMjIlMEFtb2RlbC5hZGRfd2VpZ2h0ZWRfYWRhcHRlcihhZGFwdGVycyUyQyUyMHdlaWdodHMlMkMlMjBhZGFwdGVyX25hbWUp",highlighted:`adapters = [<span class="hljs-string">&quot;adapter1&quot;</span>, <span class="hljs-string">&quot;adapter2&quot;</span>, <span class="hljs-string">&quot;adapter3&quot;</span>]
weights = [<span class="hljs-number">0.4</span>, <span class="hljs-number">0.3</span>, <span class="hljs-number">0.3</span>]
adapter_name = <span class="hljs-string">&quot;merge&quot;</span>
model.add_weighted_adapter(adapters, weights, adapter_name)`,wrap:!1}}),E=new $({props:{code:"bW9kZWwuc2V0X2FkYXB0ZXIoJTIybWVyZ2UlMjIp",highlighted:'model.set_adapter(<span class="hljs-string">&quot;merge&quot;</span>)',wrap:!1}}),S=new Se({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/developer_guides/model_merging.md"}}),{c(){t=J("meta"),p=m(),s=J("p"),d=m(),f(l.$$.fragment),a=m(),f(o.$$.fragment),c=m(),T=J("p"),T.innerHTML=A,Z=m(),W=J("p"),W.textContent=Je,P=m(),v=J("ul"),v.innerHTML=we,K=m(),G=J("p"),G.innerHTML=Te,O=m(),f(R.$$.fragment),ee=m(),V=J("p"),V.innerHTML=Ue,te=m(),f(_.$$.fragment),se=m(),B=J("p"),B.innerHTML=$e,le=m(),f(Q.$$.fragment),ae=m(),q=J("p"),q.innerHTML=_e,ne=m(),f(I.$$.fragment),oe=m(),X=J("p"),X.innerHTML=Ie,re=m(),f(H.$$.fragment),ie=m(),C=J("p"),C.textContent=ke,pe=m(),f(k.$$.fragment),de=m(),f(N.$$.fragment),ce=m(),z=J("p"),z.innerHTML=Ze,me=m(),f(Y.$$.fragment),ue=m(),F=J("p"),F.innerHTML=We,he=m(),f(E.$$.fragment),Me=m(),f(S.$$.fragment),ye=m(),x=J("p"),this.h()},l(e){const n=Ye("svelte-u9bgzb",document.head);t=w(n,"META",{name:!0,content:!0}),n.forEach(r),p=u(e),s=w(e,"P",{}),je(s).forEach(r),d=u(e),g(l.$$.fragment,e),a=u(e),g(o.$$.fragment,e),c=u(e),T=w(e,"P",{"data-svelte-h":!0}),U(T)!=="svelte-1aet04z"&&(T.innerHTML=A),Z=u(e),W=w(e,"P",{"data-svelte-h":!0}),U(W)!=="svelte-1c8162a"&&(W.textContent=Je),P=u(e),v=w(e,"UL",{"data-svelte-h":!0}),U(v)!=="svelte-wlbyrl"&&(v.innerHTML=we),K=u(e),G=w(e,"P",{"data-svelte-h":!0}),U(G)!=="svelte-j1a7ch"&&(G.innerHTML=Te),O=u(e),g(R.$$.fragment,e),ee=u(e),V=w(e,"P",{"data-svelte-h":!0}),U(V)!=="svelte-gz5qim"&&(V.innerHTML=Ue),te=u(e),g(_.$$.fragment,e),se=u(e),B=w(e,"P",{"data-svelte-h":!0}),U(B)!=="svelte-19oxsx4"&&(B.innerHTML=$e),le=u(e),g(Q.$$.fragment,e),ae=u(e),q=w(e,"P",{"data-svelte-h":!0}),U(q)!=="svelte-1imlyqr"&&(q.innerHTML=_e),ne=u(e),g(I.$$.fragment,e),oe=u(e),X=w(e,"P",{"data-svelte-h":!0}),U(X)!=="svelte-11bbnzi"&&(X.innerHTML=Ie),re=u(e),g(H.$$.fragment,e),ie=u(e),C=w(e,"P",{"data-svelte-h":!0}),U(C)!=="svelte-12c7cn9"&&(C.textContent=ke),pe=u(e),g(k.$$.fragment,e),de=u(e),g(N.$$.fragment,e),ce=u(e),z=w(e,"P",{"data-svelte-h":!0}),U(z)!=="svelte-r9tv7c"&&(z.innerHTML=Ze),me=u(e),g(Y.$$.fragment,e),ue=u(e),F=w(e,"P",{"data-svelte-h":!0}),U(F)!=="svelte-dmzjk6"&&(F.innerHTML=We),he=u(e),g(E.$$.fragment,e),Me=u(e),g(S.$$.fragment,e),ye=u(e),x=w(e,"P",{}),je(x).forEach(r),this.h()},h(){ge(t,"name","hf:doc:metadata"),ge(t,"content",nt)},m(e,n){Fe(document.head,t),i(e,p,n),i(e,s,n),i(e,d,n),b(l,e,n),i(e,a,n),b(o,e,n),i(e,c,n),i(e,T,n),i(e,Z,n),i(e,W,n),i(e,P,n),i(e,v,n),i(e,K,n),i(e,G,n),i(e,O,n),b(R,e,n),i(e,ee,n),i(e,V,n),i(e,te,n),b(_,e,n),i(e,se,n),i(e,B,n),i(e,le,n),b(Q,e,n),i(e,ae,n),i(e,q,n),i(e,ne,n),b(I,e,n),i(e,oe,n),i(e,X,n),i(e,re,n),b(H,e,n),i(e,ie,n),i(e,C,n),i(e,pe,n),b(k,e,n),i(e,de,n),b(N,e,n),i(e,ce,n),i(e,z,n),i(e,me,n),b(Y,e,n),i(e,ue,n),i(e,F,n),i(e,he,n),b(E,e,n),i(e,Me,n),b(S,e,n),i(e,ye,n),i(e,x,n),fe=!0},p(e,[n]){const ve={};n&2&&(ve.$$scope={dirty:n,ctx:e}),_.$set(ve);const Ge={};n&2&&(Ge.$$scope={dirty:n,ctx:e}),I.$set(Ge);const Re={};n&2&&(Re.$$scope={dirty:n,ctx:e}),k.$set(Re)},i(e){fe||(M(l.$$.fragment,e),M(o.$$.fragment,e),M(R.$$.fragment,e),M(_.$$.fragment,e),M(Q.$$.fragment,e),M(I.$$.fragment,e),M(H.$$.fragment,e),M(k.$$.fragment,e),M(N.$$.fragment,e),M(Y.$$.fragment,e),M(E.$$.fragment,e),M(S.$$.fragment,e),fe=!0)},o(e){y(l.$$.fragment,e),y(o.$$.fragment,e),y(R.$$.fragment,e),y(_.$$.fragment,e),y(Q.$$.fragment,e),y(I.$$.fragment,e),y(H.$$.fragment,e),y(k.$$.fragment,e),y(N.$$.fragment,e),y(Y.$$.fragment,e),y(E.$$.fragment,e),y(S.$$.fragment,e),fe=!1},d(e){e&&(r(p),r(s),r(d),r(a),r(c),r(T),r(Z),r(W),r(P),r(v),r(K),r(G),r(O),r(ee),r(V),r(te),r(se),r(B),r(le),r(ae),r(q),r(ne),r(oe),r(X),r(re),r(ie),r(C),r(pe),r(de),r(ce),r(z),r(me),r(ue),r(F),r(he),r(Me),r(ye),r(x)),r(t),j(l,e),j(o,e),j(R,e),j(_,e),j(Q,e),j(I,e),j(H,e),j(k,e),j(N,e),j(Y,e),j(E,e),j(S,e)}}}const nt='{"title":"Model merging","local":"model-merging","sections":[{"title":"Merge method","local":"merge-method","sections":[],"depth":2},{"title":"Merging (IA)³ Models","local":"merging-ia³-models","sections":[],"depth":2}],"depth":1}';function ot(h){return ze(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class mt extends Qe{constructor(t){super(),qe(this,t,ot,at,Be,{})}}export{mt as component};
