import{s as ve,c as Qe,u as Xe,g as qe,b as He,o as Ce,n as S}from"../chunks/scheduler.4cd3e004.js";import{S as Ve,i as Be,e as J,a as w,f as be,d as r,k as fe,m as p,t as M,o as y,s as m,c as f,h as Ne,b as u,g,j as T,l as Ye,n as b,p as j}from"../chunks/index.b664cb2d.js";import{C as _}from"../chunks/CodeBlock.8601e34e.js";import{H as ge,E as ze}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";import{H as Re,a as x}from"../chunks/HfOption.7d47ae41.js";function Fe(h){let t,i,s;const d=h[2].default,l=Qe(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=be(t);l&&l.l(o),o.forEach(r),this.h()},h(){fe(t,"class",i=h[0]?"warning":"tip")},m(a,o){p(a,t,o),l&&l.m(t,null),s=!0},p(a,[o]){l&&l.p&&(!s||o&2)&&Xe(l,d,a,a[1],s?He(d,a[1],o,null):qe(a[1]),null),(!s||o&1&&i!==(i=a[0]?"warning":"tip"))&&fe(t,"class",i)},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 Ee(h,t,i){let{$$slots:s={},$$scope:d}=t,{warning:l=!1}=t;return h.$$set=a=>{"warning"in a&&i(0,l=a.warning),"$$scope"in a&&i(1,d=a.$$scope)},[l,d,s]}class Se extends Ve{constructor(t){super(),Be(this,t,Ee,Fe,ve,{warning:0})}}function Ae(h){let t,i='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/main/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=i,s=m(),d=J("br"),l=m(),a=J("p"),a.textContent=o},l(c){t=w(c,"P",{"data-svelte-h":!0}),T(t)!=="svelte-1x85egj"&&(t.innerHTML=i),s=u(c),d=w(c,"BR",{}),l=u(c),a=w(c,"P",{"data-svelte-h":!0}),T(a)!=="svelte-1bgcfcq"&&(a.textContent=o)},m(c,U){p(c,t,U),p(c,s,U),p(c,d,U),p(c,l,U),p(c,a,U)},p:S,d(c){c&&(r(t),r(s),r(d),r(l),r(a))}}}function Le(h){let t,i="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=i,s=m(),f(d.$$.fragment)},l(a){t=w(a,"P",{"data-svelte-h":!0}),T(t)!=="svelte-11ncbcn"&&(t.innerHTML=i),s=u(a),g(d.$$.fragment,a)},m(a,o){p(a,t,o),p(a,s,o),b(d,a,o),l=!0},p:S,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 xe(h){let t,i;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),i=!0},p:S,i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){y(t.$$.fragment,s),i=!1},d(s){j(t,s)}}}function De(h){let t,i,s,d;return t=new x({props:{id:"merge-method",option:"TIES",$$slots:{default:[Le]},$$scope:{ctx:h}}}),s=new x({props:{id:"merge-method",option:"DARE",$$slots:{default:[xe]},$$scope:{ctx:h}}}),{c(){f(t.$$.fragment),i=m(),f(s.$$.fragment)},l(l){g(t.$$.fragment,l),i=u(l),g(s.$$.fragment,l)},m(l,a){b(t,l,a),p(l,i,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(i),j(t,l),j(s,l)}}}function Pe(h){let t,i;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),i=!0},p:S,i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){y(t.$$.fragment,s),i=!1},d(s){j(t,s)}}}function Ke(h){let t,i;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),i=!0},p:S,i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){y(t.$$.fragment,s),i=!1},d(s){j(t,s)}}}function Oe(h){let t,i;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),i=!0},p:S,i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){y(t.$$.fragment,s),i=!1},d(s){j(t,s)}}}function et(h){let t,i,s,d,l,a;return t=new x({props:{id:"ties",option:"instruct",$$slots:{default:[Pe]},$$scope:{ctx:h}}}),s=new x({props:{id:"ties",option:"ad copy",$$slots:{default:[Ke]},$$scope:{ctx:h}}}),l=new x({props:{id:"ties",option:"SQL",$$slots:{default:[Oe]},$$scope:{ctx:h}}}),{c(){f(t.$$.fragment),i=m(),f(s.$$.fragment),d=m(),f(l.$$.fragment)},l(o){g(t.$$.fragment,o),i=u(o),g(s.$$.fragment,o),d=u(o),g(l.$$.fragment,o)},m(o,c){b(t,o,c),p(o,i,c),b(s,o,c),p(o,d,c),b(l,o,c),a=!0},p(o,c){const U={};c&2&&(U.$$scope={dirty:c,ctx:o}),t.$set(U);const $={};c&2&&($.$$scope={dirty:c,ctx:o}),s.$set($);const A={};c&2&&(A.$$scope={dirty:c,ctx:o}),l.$set(A)},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(i),r(d)),j(t,o),j(s,o),j(l,o)}}}function tt(h){let t,i,s,d,l,a,o,c="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.",U,$,A="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:",D,W,je='<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>',P,G,Je='Models are merged with the <a href="/docs/peft/main/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.',K,R,O,v,we='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>.',ee,I,te,V,Te='Load a base model and can use the <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel.load_adapter">load_adapter()</a> method to load and assign each adapter a name:',se,B,le,Q,Ue='Set the adapters, weights, <code>adapter_name</code>, <code>combination_type</code>, and <code>density</code> with the <a href="/docs/peft/main/en/package_reference/lora#peft.LoraModel.add_weighted_adapter">add_weighted_adapter()</a> method.',ae,k,ne,X,$e='Set the newly merged model as the active model with the <a href="/docs/peft/main/en/package_reference/tuners#peft.tuners.tuners_utils.BaseTuner.set_adapter">set_adapter()</a> method.',oe,q,re,H,_e="Now you can use the merged model as an instruction-tuned model to write ad copy or SQL queries!",ie,Z,pe,C,de,N,Ie="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:",ce,Y,me,z,ke="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:",ue,F,he,E,Me,L,ye;return l=new ge({props:{title:"Model merging",local:"model-merging",headingTag:"h1"}}),R=new ge({props:{title:"Merge method",local:"merge-method",headingTag:"h2"}}),I=new Se({props:{warninig:!0,$$slots:{default:[Ae]},$$scope:{ctx:h}}}),B=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}}),k=new Re({props:{id:"merge-method",options:["TIES","DARE"],$$slots:{default:[De]},$$scope:{ctx:h}}}),q=new _({props:{code:"bW9kZWwuc2V0X2FkYXB0ZXIoJTIybWVyZ2UlMjIp",highlighted:'model.set_adapter(<span class="hljs-string">&quot;merge&quot;</span>)',wrap:!1}}),Z=new Re({props:{id:"ties",options:["instruct","ad copy","SQL"],$$slots:{default:[et]},$$scope:{ctx:h}}}),C=new ge({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}}),F=new _({props:{code:"bW9kZWwuc2V0X2FkYXB0ZXIoJTIybWVyZ2UlMjIp",highlighted:'model.set_adapter(<span class="hljs-string">&quot;merge&quot;</span>)',wrap:!1}}),E=new ze({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/developer_guides/model_merging.md"}}),{c(){t=J("meta"),i=m(),s=J("p"),d=m(),f(l.$$.fragment),a=m(),o=J("p"),o.innerHTML=c,U=m(),$=J("p"),$.textContent=A,D=m(),W=J("ul"),W.innerHTML=je,P=m(),G=J("p"),G.innerHTML=Je,K=m(),f(R.$$.fragment),O=m(),v=J("p"),v.innerHTML=we,ee=m(),f(I.$$.fragment),te=m(),V=J("p"),V.innerHTML=Te,se=m(),f(B.$$.fragment),le=m(),Q=J("p"),Q.innerHTML=Ue,ae=m(),f(k.$$.fragment),ne=m(),X=J("p"),X.innerHTML=$e,oe=m(),f(q.$$.fragment),re=m(),H=J("p"),H.textContent=_e,ie=m(),f(Z.$$.fragment),pe=m(),f(C.$$.fragment),de=m(),N=J("p"),N.innerHTML=Ie,ce=m(),f(Y.$$.fragment),me=m(),z=J("p"),z.innerHTML=ke,ue=m(),f(F.$$.fragment),he=m(),f(E.$$.fragment),Me=m(),L=J("p"),this.h()},l(e){const n=Ne("svelte-u9bgzb",document.head);t=w(n,"META",{name:!0,content:!0}),n.forEach(r),i=u(e),s=w(e,"P",{}),be(s).forEach(r),d=u(e),g(l.$$.fragment,e),a=u(e),o=w(e,"P",{"data-svelte-h":!0}),T(o)!=="svelte-1aet04z"&&(o.innerHTML=c),U=u(e),$=w(e,"P",{"data-svelte-h":!0}),T($)!=="svelte-1c8162a"&&($.textContent=A),D=u(e),W=w(e,"UL",{"data-svelte-h":!0}),T(W)!=="svelte-wlbyrl"&&(W.innerHTML=je),P=u(e),G=w(e,"P",{"data-svelte-h":!0}),T(G)!=="svelte-objsws"&&(G.innerHTML=Je),K=u(e),g(R.$$.fragment,e),O=u(e),v=w(e,"P",{"data-svelte-h":!0}),T(v)!=="svelte-gz5qim"&&(v.innerHTML=we),ee=u(e),g(I.$$.fragment,e),te=u(e),V=w(e,"P",{"data-svelte-h":!0}),T(V)!=="svelte-4a7cwn"&&(V.innerHTML=Te),se=u(e),g(B.$$.fragment,e),le=u(e),Q=w(e,"P",{"data-svelte-h":!0}),T(Q)!=="svelte-1f2h8yo"&&(Q.innerHTML=Ue),ae=u(e),g(k.$$.fragment,e),ne=u(e),X=w(e,"P",{"data-svelte-h":!0}),T(X)!=="svelte-9g49a9"&&(X.innerHTML=$e),oe=u(e),g(q.$$.fragment,e),re=u(e),H=w(e,"P",{"data-svelte-h":!0}),T(H)!=="svelte-12c7cn9"&&(H.textContent=_e),ie=u(e),g(Z.$$.fragment,e),pe=u(e),g(C.$$.fragment,e),de=u(e),N=w(e,"P",{"data-svelte-h":!0}),T(N)!=="svelte-r9tv7c"&&(N.innerHTML=Ie),ce=u(e),g(Y.$$.fragment,e),me=u(e),z=w(e,"P",{"data-svelte-h":!0}),T(z)!=="svelte-dmzjk6"&&(z.innerHTML=ke),ue=u(e),g(F.$$.fragment,e),he=u(e),g(E.$$.fragment,e),Me=u(e),L=w(e,"P",{}),be(L).forEach(r),this.h()},h(){fe(t,"name","hf:doc:metadata"),fe(t,"content",st)},m(e,n){Ye(document.head,t),p(e,i,n),p(e,s,n),p(e,d,n),b(l,e,n),p(e,a,n),p(e,o,n),p(e,U,n),p(e,$,n),p(e,D,n),p(e,W,n),p(e,P,n),p(e,G,n),p(e,K,n),b(R,e,n),p(e,O,n),p(e,v,n),p(e,ee,n),b(I,e,n),p(e,te,n),p(e,V,n),p(e,se,n),b(B,e,n),p(e,le,n),p(e,Q,n),p(e,ae,n),b(k,e,n),p(e,ne,n),p(e,X,n),p(e,oe,n),b(q,e,n),p(e,re,n),p(e,H,n),p(e,ie,n),b(Z,e,n),p(e,pe,n),b(C,e,n),p(e,de,n),p(e,N,n),p(e,ce,n),b(Y,e,n),p(e,me,n),p(e,z,n),p(e,ue,n),b(F,e,n),p(e,he,n),b(E,e,n),p(e,Me,n),p(e,L,n),ye=!0},p(e,[n]){const Ze={};n&2&&(Ze.$$scope={dirty:n,ctx:e}),I.$set(Ze);const We={};n&2&&(We.$$scope={dirty:n,ctx:e}),k.$set(We);const Ge={};n&2&&(Ge.$$scope={dirty:n,ctx:e}),Z.$set(Ge)},i(e){ye||(M(l.$$.fragment,e),M(R.$$.fragment,e),M(I.$$.fragment,e),M(B.$$.fragment,e),M(k.$$.fragment,e),M(q.$$.fragment,e),M(Z.$$.fragment,e),M(C.$$.fragment,e),M(Y.$$.fragment,e),M(F.$$.fragment,e),M(E.$$.fragment,e),ye=!0)},o(e){y(l.$$.fragment,e),y(R.$$.fragment,e),y(I.$$.fragment,e),y(B.$$.fragment,e),y(k.$$.fragment,e),y(q.$$.fragment,e),y(Z.$$.fragment,e),y(C.$$.fragment,e),y(Y.$$.fragment,e),y(F.$$.fragment,e),y(E.$$.fragment,e),ye=!1},d(e){e&&(r(i),r(s),r(d),r(a),r(o),r(U),r($),r(D),r(W),r(P),r(G),r(K),r(O),r(v),r(ee),r(te),r(V),r(se),r(le),r(Q),r(ae),r(ne),r(X),r(oe),r(re),r(H),r(ie),r(pe),r(de),r(N),r(ce),r(me),r(z),r(ue),r(he),r(Me),r(L)),r(t),j(l,e),j(R,e),j(I,e),j(B,e),j(k,e),j(q,e),j(Z,e),j(C,e),j(Y,e),j(F,e),j(E,e)}}}const st='{"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 lt(h){return Ce(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pt extends Ve{constructor(t){super(),Be(this,t,lt,tt,ve,{})}}export{pt as component};
