import{s as xe,o as Ye,n as ze}from"../chunks/scheduler.4cd3e004.js";import{S as De,i as Oe,e as u,s as o,c as d,h as Ke,a as f,d as a,b as p,f as Ze,g as y,j as h,k as te,l as ve,m as s,n as j,t as T,o as J,p as b}from"../chunks/index.b664cb2d.js";import{C as _}from"../chunks/CodeBlock.8601e34e.js";import{H as Ie,E as et}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.179b63f8.js";import{H as tt,a as Ne}from"../chunks/HfOption.7d47ae41.js";function at($){let r,M,i,g='You can create your own configuration for training by initializing a <a href="/docs/peft/main/en/package_reference/lora#peft.LoraConfig">LoraConfig</a>.',n,c,m;return r=new _({props:{code:"JTdCJTBBJTIwJTIwJTIyYmFzZV9tb2RlbF9uYW1lX29yX3BhdGglMjIlM0ElMjAlMjJmYWNlYm9vayUyRm9wdC0zNTBtJTIyJTJDJTIwJTIzYmFzZSUyMG1vZGVsJTIwdG8lMjBhcHBseSUyMExvUkElMjB0byUwQSUyMCUyMCUyMmJpYXMlMjIlM0ElMjAlMjJub25lJTIyJTJDJTBBJTIwJTIwJTIyZmFuX2luX2Zhbl9vdXQlMjIlM0ElMjBmYWxzZSUyQyUwQSUyMCUyMCUyMmluZmVyZW5jZV9tb2RlJTIyJTNBJTIwdHJ1ZSUyQyUwQSUyMCUyMCUyMmluaXRfbG9yYV93ZWlnaHRzJTIyJTNBJTIwdHJ1ZSUyQyUwQSUyMCUyMCUyMmxheWVyc19wYXR0ZXJuJTIyJTNBJTIwbnVsbCUyQyUwQSUyMCUyMCUyMmxheWVyc190b190cmFuc2Zvcm0lMjIlM0ElMjBudWxsJTJDJTBBJTIwJTIwJTIybG9yYV9hbHBoYSUyMiUzQSUyMDMyJTJDJTBBJTIwJTIwJTIybG9yYV9kcm9wb3V0JTIyJTNBJTIwMC4wNSUyQyUwQSUyMCUyMCUyMm1vZHVsZXNfdG9fc2F2ZSUyMiUzQSUyMG51bGwlMkMlMEElMjAlMjAlMjJwZWZ0X3R5cGUlMjIlM0ElMjAlMjJMT1JBJTIyJTJDJTIwJTIzUEVGVCUyMG1ldGhvZCUyMHR5cGUlMEElMjAlMjAlMjJyJTIyJTNBJTIwMTYlMkMlMEElMjAlMjAlMjJyZXZpc2lvbiUyMiUzQSUyMG51bGwlMkMlMEElMjAlMjAlMjJ0YXJnZXRfbW9kdWxlcyUyMiUzQSUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMnFfcHJvaiUyMiUyQyUyMCUyM21vZGVsJTIwbW9kdWxlcyUyMHRvJTIwYXBwbHklMjBMb1JBJTIwdG8lMjAocXVlcnklMjBhbmQlMjB2YWx1ZSUyMHByb2plY3Rpb24lMjBsYXllcnMpJTBBJTIwJTIwJTIwJTIwJTIydl9wcm9qJTIyJTBBJTIwJTIwJTVEJTJDJTBBJTIwJTIwJTIydGFza190eXBlJTIyJTNBJTIwJTIyQ0FVU0FMX0xNJTIyJTIwJTIzdHlwZSUyMG9mJTIwdGFzayUyMHRvJTIwdHJhaW4lMjBtb2RlbCUyMG9uJTBBJTdE",highlighted:`<span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;base_model_name_or_path&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;facebook/opt-350m&quot;</span><span class="hljs-punctuation">,</span> #base model to apply LoRA to
  <span class="hljs-attr">&quot;bias&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;none&quot;</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;fan_in_fan_out&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;inference_mode&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;init_lora_weights&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;layers_pattern&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;layers_to_transform&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;lora_alpha&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">32</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;lora_dropout&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0.05</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;modules_to_save&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;peft_type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;LORA&quot;</span><span class="hljs-punctuation">,</span> #PEFT method type
  <span class="hljs-attr">&quot;r&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">16</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;revision&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;target_modules&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>
    <span class="hljs-string">&quot;q_proj&quot;</span><span class="hljs-punctuation">,</span> #model modules to apply LoRA to (query and value projection layers)
    <span class="hljs-string">&quot;v_proj&quot;</span>
  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;task_type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;CAUSAL_LM&quot;</span> #type of task to train model on
<span class="hljs-punctuation">}</span>`,wrap:!1}}),c=new _({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBMb3JhQ29uZmlnJTJDJTIwVGFza1R5cGUlMEElMEFsb3JhX2NvbmZpZyUyMCUzRCUyMExvcmFDb25maWcoJTBBJTIwJTIwJTIwJTIwciUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X21vZHVsZXMlM0QlNUIlMjJxX3Byb2olMjIlMkMlMjAlMjJ2X3Byb2olMjIlNUQlMkMlMEElMjAlMjAlMjAlMjB0YXNrX3R5cGUlM0RUYXNrVHlwZS5DQVVTQUxfTE0lMkMlMEElMjAlMjAlMjAlMjBsb3JhX2FscGhhJTNEMzIlMkMlMEElMjAlMjAlMjAlMjBsb3JhX2Ryb3BvdXQlM0QwLjA1JTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> LoraConfig, TaskType

lora_config = LoraConfig(
    r=<span class="hljs-number">16</span>,
    target_modules=[<span class="hljs-string">&quot;q_proj&quot;</span>, <span class="hljs-string">&quot;v_proj&quot;</span>],
    task_type=TaskType.CAUSAL_LM,
    lora_alpha=<span class="hljs-number">32</span>,
    lora_dropout=<span class="hljs-number">0.05</span>
)`,wrap:!1}}),{c(){d(r.$$.fragment),M=o(),i=u("p"),i.innerHTML=g,n=o(),d(c.$$.fragment)},l(l){y(r.$$.fragment,l),M=p(l),i=f(l,"P",{"data-svelte-h":!0}),h(i)!=="svelte-1g4hwov"&&(i.innerHTML=g),n=p(l),y(c.$$.fragment,l)},m(l,w){j(r,l,w),s(l,M,w),s(l,i,w),s(l,n,w),j(c,l,w),m=!0},p:ze,i(l){m||(T(r.$$.fragment,l),T(c.$$.fragment,l),m=!0)},o(l){J(r.$$.fragment,l),J(c.$$.fragment,l),m=!1},d(l){l&&(a(M),a(i),a(n)),b(r,l),b(c,l)}}}function st($){let r,M,i,g='You can create your own configuration for training by initializing a <a href="/docs/peft/main/en/package_reference/p_tuning#peft.PromptEncoderConfig">PromptEncoderConfig</a>.',n,c,m;return r=new _({props:{code:"JTdCJTBBJTIwJTIwJTIyYmFzZV9tb2RlbF9uYW1lX29yX3BhdGglMjIlM0ElMjAlMjJyb2JlcnRhLWxhcmdlJTIyJTJDJTIwJTIzYmFzZSUyMG1vZGVsJTIwdG8lMjBhcHBseSUyMHAtdHVuaW5nJTIwdG8lMEElMjAlMjAlMjJlbmNvZGVyX2Ryb3BvdXQlMjIlM0ElMjAwLjAlMkMlMEElMjAlMjAlMjJlbmNvZGVyX2hpZGRlbl9zaXplJTIyJTNBJTIwMTI4JTJDJTBBJTIwJTIwJTIyZW5jb2Rlcl9udW1fbGF5ZXJzJTIyJTNBJTIwMiUyQyUwQSUyMCUyMCUyMmVuY29kZXJfcmVwYXJhbWV0ZXJpemF0aW9uX3R5cGUlMjIlM0ElMjAlMjJNTFAlMjIlMkMlMEElMjAlMjAlMjJpbmZlcmVuY2VfbW9kZSUyMiUzQSUyMHRydWUlMkMlMEElMjAlMjAlMjJudW1fYXR0ZW50aW9uX2hlYWRzJTIyJTNBJTIwMTYlMkMlMEElMjAlMjAlMjJudW1fbGF5ZXJzJTIyJTNBJTIwMjQlMkMlMEElMjAlMjAlMjJudW1fdHJhbnNmb3JtZXJfc3VibW9kdWxlcyUyMiUzQSUyMDElMkMlMEElMjAlMjAlMjJudW1fdmlydHVhbF90b2tlbnMlMjIlM0ElMjAyMCUyQyUwQSUyMCUyMCUyMnBlZnRfdHlwZSUyMiUzQSUyMCUyMlBfVFVOSU5HJTIyJTJDJTIwJTIzUEVGVCUyMG1ldGhvZCUyMHR5cGUlMEElMjAlMjAlMjJ0YXNrX3R5cGUlMjIlM0ElMjAlMjJTRVFfQ0xTJTIyJTJDJTIwJTIzdHlwZSUyMG9mJTIwdGFzayUyMHRvJTIwdHJhaW4lMjBtb2RlbCUyMG9uJTBBJTIwJTIwJTIydG9rZW5fZGltJTIyJTNBJTIwMTAyNCUwQSU3RA==",highlighted:`<span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;base_model_name_or_path&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;roberta-large&quot;</span><span class="hljs-punctuation">,</span> #base model to apply p-tuning to
  <span class="hljs-attr">&quot;encoder_dropout&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0.0</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;encoder_hidden_size&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">128</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;encoder_num_layers&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;encoder_reparameterization_type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;MLP&quot;</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;inference_mode&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;num_attention_heads&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">16</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;num_layers&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">24</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;num_transformer_submodules&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;num_virtual_tokens&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">20</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;peft_type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;P_TUNING&quot;</span><span class="hljs-punctuation">,</span> #PEFT method type
  <span class="hljs-attr">&quot;task_type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;SEQ_CLS&quot;</span><span class="hljs-punctuation">,</span> #type of task to train model on
  <span class="hljs-attr">&quot;token_dim&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1024</span>
<span class="hljs-punctuation">}</span>`,wrap:!1}}),c=new _({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBQcm9tcHRFbmNvZGVyQ29uZmlnJTJDJTIwVGFza1R5cGUlMEElMEFwX3R1bmluZ19jb25maWclMjAlM0QlMjBQcm9tcHRFbmNvZGVyQ29uZmlnKCUwQSUyMCUyMCUyMCUyMGVuY29kZXJfcmVwYXJhbWV0ZXJpemF0aW9uX3R5cGUlM0QlMjJNTFAlMjIlMkMlMEElMjAlMjAlMjAlMjBlbmNvZGVyX2hpZGRlbl9zaXplJTNEMTI4JTJDJTBBJTIwJTIwJTIwJTIwbnVtX2F0dGVudGlvbl9oZWFkcyUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwbnVtX2xheWVycyUzRDI0JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYW5zZm9ybWVyX3N1Ym1vZHVsZXMlM0QxJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3ZpcnR1YWxfdG9rZW5zJTNEMjAlMkMlMEElMjAlMjAlMjAlMjB0b2tlbl9kaW0lM0QxMDI0JTJDJTBBJTIwJTIwJTIwJTIwdGFza190eXBlJTNEVGFza1R5cGUuU0VRX0NMUyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PromptEncoderConfig, TaskType

p_tuning_config = PromptEncoderConfig(
    encoder_reparameterization_type=<span class="hljs-string">&quot;MLP&quot;</span>,
    encoder_hidden_size=<span class="hljs-number">128</span>,
    num_attention_heads=<span class="hljs-number">16</span>,
    num_layers=<span class="hljs-number">24</span>,
    num_transformer_submodules=<span class="hljs-number">1</span>,
    num_virtual_tokens=<span class="hljs-number">20</span>,
    token_dim=<span class="hljs-number">1024</span>,
    task_type=TaskType.SEQ_CLS
)`,wrap:!1}}),{c(){d(r.$$.fragment),M=o(),i=u("p"),i.innerHTML=g,n=o(),d(c.$$.fragment)},l(l){y(r.$$.fragment,l),M=p(l),i=f(l,"P",{"data-svelte-h":!0}),h(i)!=="svelte-k8gydr"&&(i.innerHTML=g),n=p(l),y(c.$$.fragment,l)},m(l,w){j(r,l,w),s(l,M,w),s(l,i,w),s(l,n,w),j(c,l,w),m=!0},p:ze,i(l){m||(T(r.$$.fragment,l),T(c.$$.fragment,l),m=!0)},o(l){J(r.$$.fragment,l),J(c.$$.fragment,l),m=!1},d(l){l&&(a(M),a(i),a(n)),b(r,l),b(c,l)}}}function lt($){let r,M,i,g;return r=new Ne({props:{id:"config",option:"LoraConfig",$$slots:{default:[at]},$$scope:{ctx:$}}}),i=new Ne({props:{id:"config",option:"PromptEncoderConfig",$$slots:{default:[st]},$$scope:{ctx:$}}}),{c(){d(r.$$.fragment),M=o(),d(i.$$.fragment)},l(n){y(r.$$.fragment,n),M=p(n),y(i.$$.fragment,n)},m(n,c){j(r,n,c),s(n,M,c),j(i,n,c),g=!0},p(n,c){const m={};c&2&&(m.$$scope={dirty:c,ctx:n}),r.$set(m);const l={};c&2&&(l.$$scope={dirty:c,ctx:n}),i.$set(l)},i(n){g||(T(r.$$.fragment,n),T(i.$$.fragment,n),g=!0)},o(n){J(r.$$.fragment,n),J(i.$$.fragment,n),g=!1},d(n){n&&a(M),b(r,n),b(i,n)}}}function nt($){let r,M,i,g,n,c,m,l="The sheer size of today’s large pretrained models - which commonly have billions of parameters - presents a significant training challenge because they require more storage space and more computational power to crunch all those calculations. You’ll need access to powerful GPUs or TPUs to train these large pretrained models which is expensive, not widely accessible to everyone, not environmentally friendly, and not very practical. PEFT methods address many of these challenges. There are several types of PEFT methods (soft prompting, matrix decomposition, adapters), but they all focus on the same thing, reduce the number of trainable parameters. This makes it more accessible to train and store large models on consumer hardware.",w,Z,Ee='The PEFT library is designed to help you quickly train large models on free or low-cost GPUs, and in this tutorial, you’ll learn how to setup a configuration to apply a PEFT method to a pretrained base model for training. Once the PEFT configuration is setup, you can use any training framework you like (Transformer’s <a href="https://huggingface.co/docs/transformers/main/en/main_classes/trainer#transformers.Trainer" rel="nofollow">Trainer</a> class, <a href="https://hf.co/docs/accelerate" rel="nofollow">Accelerate</a>, a custom PyTorch training loop).',ae,v,se,k,Ce="<p>Learn more about the parameters you can configure for each PEFT method in their respective API reference page.</p>",le,E,qe="A configuration stores important parameters that specify how a particular PEFT method should be applied.",ne,C,Ge='For example, take a look at the following <a href="https://huggingface.co/ybelkada/opt-350m-lora/blob/main/adapter_config.json" rel="nofollow"><code>LoraConfig</code></a> for applying LoRA and <a href="https://huggingface.co/smangrul/roberta-large-peft-p-tuning/blob/main/adapter_config.json" rel="nofollow"><code>PromptEncoderConfig</code></a> for applying p-tuning (these configuration files are already JSON-serialized). Whenever you load a PEFT adapter, it is a good idea to check whether it has an associated adapter_config.json file which is required.',oe,I,pe,q,re,G,Pe='With a PEFT configuration in hand, you can now apply it to any pretrained model to create a <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a>. Choose from any of the state-of-the-art models from the <a href="https://hf.co/docs/transformers" rel="nofollow">Transformers</a> library, a custom model, and even new and unsupported transformer architectures.',ie,P,We='For this tutorial, load a base <a href="https://huggingface.co/facebook/opt-350m" rel="nofollow">facebook/opt-350m</a> model to finetune.',ce,W,ue,F,Fe='Use the <a href="/docs/peft/main/en/package_reference/peft_model#peft.get_peft_model">get_peft_model()</a> function to create a <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> from the base facebook/opt-350m model and the <code>lora_config</code> you created earlier.',fe,Q,me,B,Qe='<p>When calling <a href="/docs/peft/main/en/package_reference/peft_model#peft.get_peft_model">get_peft_model()</a>, the base model will be modified <em>in-place</em>. That means, when calling <a href="/docs/peft/main/en/package_reference/peft_model#peft.get_peft_model">get_peft_model()</a> on a model that was already modified in the same way before, this model will be further mutated. Therefore, if you would like to modify your PEFT configuration after having called <code>get_peft_model()</code> before, you would first have to unload the model with <a href="/docs/peft/main/en/package_reference/tuners#peft.tuners.tuners_utils.BaseTuner.unload">unload()</a> and then call <code>get_peft_model()</code> with your new configuration. Alternatively, you can re-initialize the model to ensure a fresh, unmodified state before applying a new PEFT configuration.</p>',Me,A,Ae='Now you can train the <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> with your preferred training framework! After training, you can save your model locally with <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel.save_pretrained">save_pretrained()</a> or upload it to the Hub with the <a href="https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.push_to_hub" rel="nofollow">push_to_hub</a> method.',he,H,de,X,He='To load a <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> for inference, you’ll need to provide the <a href="/docs/peft/main/en/package_reference/config#peft.PeftConfig">PeftConfig</a> used to create it and the base model it was trained from.',ye,V,je,U,K,Xe='By default, the <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> is set for inference, but if you’d like to train the adapter some more you can set <code>is_trainable=True</code>.',Be,R,Te,L,Ve='The <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel.from_pretrained">PeftModel.from_pretrained()</a> method is the most flexible way to load a <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> because it doesn’t matter what model framework was used (Transformers, timm, a generic PyTorch model). Other classes, like <a href="/docs/peft/main/en/package_reference/auto_class#peft.AutoPeftModel">AutoPeftModel</a>, are just a convenient wrapper around the base <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a>, and makes it easier to load PEFT models directly from the Hub or locally where the PEFT weights are stored.',Je,S,be,N,Re='Take a look at the <a href="package_reference/auto_class">AutoPeftModel</a> API reference to learn more about the <a href="/docs/peft/main/en/package_reference/auto_class#peft.AutoPeftModel">AutoPeftModel</a> classes.',we,z,ge,x,Le='With the appropriate <a href="/docs/peft/main/en/package_reference/config#peft.PeftConfig">PeftConfig</a>, you can apply it to any pretrained model to create a <a href="/docs/peft/main/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> and train large powerful models faster on freely available GPUs! To learn more about PEFT configurations and models, the following guide may be helpful:',_e,Y,Se='<li>Learn how to configure a PEFT method for models that aren’t from Transformers in the <a href="../developer_guides/custom_models">Working with custom models</a> guide.</li>',Ue,D,$e,ee,ke;return n=new Ie({props:{title:"PEFT configurations and models",local:"peft-configurations-and-models",headingTag:"h1"}}),v=new Ie({props:{title:"PEFT configurations",local:"peft-configurations",headingTag:"h2"}}),I=new tt({props:{id:"config",options:["LoraConfig","PromptEncoderConfig"],$$slots:{default:[lt]},$$scope:{ctx:$}}}),q=new Ie({props:{title:"PEFT models",local:"peft-models",headingTag:"h2"}}),W=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZvcHQtMzUwbSUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-350m&quot;</span>)`,wrap:!1}}),Q=new _({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBnZXRfcGVmdF9tb2RlbCUwQSUwQWxvcmFfbW9kZWwlMjAlM0QlMjBnZXRfcGVmdF9tb2RlbChtb2RlbCUyQyUyMGxvcmFfY29uZmlnKSUwQWxvcmFfbW9kZWwucHJpbnRfdHJhaW5hYmxlX3BhcmFtZXRlcnMoKSUwQSUyMnRyYWluYWJsZSUyMHBhcmFtcyUzQSUyMDElMkM1NzIlMkM4NjQlMjAlN0MlN0MlMjBhbGwlMjBwYXJhbXMlM0ElMjAzMzIlMkM3NjklMkMyODAlMjAlN0MlN0MlMjB0cmFpbmFibGUlMjUlM0ElMjAwLjQ3MjY1OTAxNDY3ODI3OCUyMg==",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> get_peft_model

lora_model = get_peft_model(model, lora_config)
lora_model.print_trainable_parameters()
<span class="hljs-string">&quot;trainable params: 1,572,864 || all params: 332,769,280 || trainable%: 0.472659014678278&quot;</span>`,wrap:!1}}),H=new _({props:{code:"JTIzJTIwc2F2ZSUyMGxvY2FsbHklMEFsb3JhX21vZGVsLnNhdmVfcHJldHJhaW5lZCglMjJ5b3VyLW5hbWUlMkZvcHQtMzUwbS1sb3JhJTIyKSUwQSUwQSUyMyUyMHB1c2glMjB0byUyMEh1YiUwQWxvcmFfbW9kZWwucHVzaF90b19odWIoJTIyeW91ci1uYW1lJTJGb3B0LTM1MG0tbG9yYSUyMik=",highlighted:`<span class="hljs-comment"># save locally</span>
lora_model.save_pretrained(<span class="hljs-string">&quot;your-name/opt-350m-lora&quot;</span>)

<span class="hljs-comment"># push to Hub</span>
lora_model.push_to_hub(<span class="hljs-string">&quot;your-name/opt-350m-lora&quot;</span>)`,wrap:!1}}),V=new _({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBQZWZ0TW9kZWwlMkMlMjBQZWZ0Q29uZmlnJTBBJTBBY29uZmlnJTIwJTNEJTIwUGVmdENvbmZpZy5mcm9tX3ByZXRyYWluZWQoJTIyeWJlbGthZGElMkZvcHQtMzUwbS1sb3JhJTIyKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKGNvbmZpZy5iYXNlX21vZGVsX25hbWVfb3JfcGF0aCklMEFsb3JhX21vZGVsJTIwJTNEJTIwUGVmdE1vZGVsLmZyb21fcHJldHJhaW5lZChtb2RlbCUyQyUyMCUyMnliZWxrYWRhJTJGb3B0LTM1MG0tbG9yYSUyMik=",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftModel, PeftConfig

config = PeftConfig.from_pretrained(<span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path)
lora_model = PeftModel.from_pretrained(model, <span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>)`,wrap:!1}}),R=new _({props:{code:"bG9yYV9tb2RlbCUyMCUzRCUyMFBlZnRNb2RlbC5mcm9tX3ByZXRyYWluZWQobW9kZWwlMkMlMjAlMjJ5YmVsa2FkYSUyRm9wdC0zNTBtLWxvcmElMjIlMkMlMjBpc190cmFpbmFibGUlM0RUcnVlKQ==",highlighted:'lora_model = PeftModel.from_pretrained(model, <span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>, is_trainable=<span class="hljs-literal">True</span>)',wrap:!1}}),S=new _({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBBdXRvUGVmdE1vZGVsRm9yQ2F1c2FsTE0lMEElMEFsb3JhX21vZGVsJTIwJTNEJTIwQXV0b1BlZnRNb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMjJ5YmVsa2FkYSUyRm9wdC0zNTBtLWxvcmElMjIp",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> AutoPeftModelForCausalLM

lora_model = AutoPeftModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>)`,wrap:!1}}),z=new Ie({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),D=new et({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/tutorial/peft_model_config.md"}}),{c(){r=u("meta"),M=o(),i=u("p"),g=o(),d(n.$$.fragment),c=o(),m=u("p"),m.textContent=l,w=o(),Z=u("p"),Z.innerHTML=Ee,ae=o(),d(v.$$.fragment),se=o(),k=u("blockquote"),k.innerHTML=Ce,le=o(),E=u("p"),E.textContent=qe,ne=o(),C=u("p"),C.innerHTML=Ge,oe=o(),d(I.$$.fragment),pe=o(),d(q.$$.fragment),re=o(),G=u("p"),G.innerHTML=Pe,ie=o(),P=u("p"),P.innerHTML=We,ce=o(),d(W.$$.fragment),ue=o(),F=u("p"),F.innerHTML=Fe,fe=o(),d(Q.$$.fragment),me=o(),B=u("blockquote"),B.innerHTML=Qe,Me=o(),A=u("p"),A.innerHTML=Ae,he=o(),d(H.$$.fragment),de=o(),X=u("p"),X.innerHTML=He,ye=o(),d(V.$$.fragment),je=o(),U=u("blockquote"),K=u("p"),K.innerHTML=Xe,Be=o(),d(R.$$.fragment),Te=o(),L=u("p"),L.innerHTML=Ve,Je=o(),d(S.$$.fragment),be=o(),N=u("p"),N.innerHTML=Re,we=o(),d(z.$$.fragment),ge=o(),x=u("p"),x.innerHTML=Le,_e=o(),Y=u("ul"),Y.innerHTML=Se,Ue=o(),d(D.$$.fragment),$e=o(),ee=u("p"),this.h()},l(e){const t=Ke("svelte-u9bgzb",document.head);r=f(t,"META",{name:!0,content:!0}),t.forEach(a),M=p(e),i=f(e,"P",{}),Ze(i).forEach(a),g=p(e),y(n.$$.fragment,e),c=p(e),m=f(e,"P",{"data-svelte-h":!0}),h(m)!=="svelte-hwy4y1"&&(m.textContent=l),w=p(e),Z=f(e,"P",{"data-svelte-h":!0}),h(Z)!=="svelte-1lzwkqs"&&(Z.innerHTML=Ee),ae=p(e),y(v.$$.fragment,e),se=p(e),k=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),h(k)!=="svelte-1ttb3zu"&&(k.innerHTML=Ce),le=p(e),E=f(e,"P",{"data-svelte-h":!0}),h(E)!=="svelte-16b4gu"&&(E.textContent=qe),ne=p(e),C=f(e,"P",{"data-svelte-h":!0}),h(C)!=="svelte-2s9teg"&&(C.innerHTML=Ge),oe=p(e),y(I.$$.fragment,e),pe=p(e),y(q.$$.fragment,e),re=p(e),G=f(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-1ukcst6"&&(G.innerHTML=Pe),ie=p(e),P=f(e,"P",{"data-svelte-h":!0}),h(P)!=="svelte-1d979vk"&&(P.innerHTML=We),ce=p(e),y(W.$$.fragment,e),ue=p(e),F=f(e,"P",{"data-svelte-h":!0}),h(F)!=="svelte-10io0nf"&&(F.innerHTML=Fe),fe=p(e),y(Q.$$.fragment,e),me=p(e),B=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),h(B)!=="svelte-1sc4szi"&&(B.innerHTML=Qe),Me=p(e),A=f(e,"P",{"data-svelte-h":!0}),h(A)!=="svelte-1wn52l6"&&(A.innerHTML=Ae),he=p(e),y(H.$$.fragment,e),de=p(e),X=f(e,"P",{"data-svelte-h":!0}),h(X)!=="svelte-6sje64"&&(X.innerHTML=He),ye=p(e),y(V.$$.fragment,e),je=p(e),U=f(e,"BLOCKQUOTE",{class:!0});var O=Ze(U);K=f(O,"P",{"data-svelte-h":!0}),h(K)!=="svelte-1fifxfw"&&(K.innerHTML=Xe),Be=p(O),y(R.$$.fragment,O),O.forEach(a),Te=p(e),L=f(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-12bnmaq"&&(L.innerHTML=Ve),Je=p(e),y(S.$$.fragment,e),be=p(e),N=f(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-15zug4g"&&(N.innerHTML=Re),we=p(e),y(z.$$.fragment,e),ge=p(e),x=f(e,"P",{"data-svelte-h":!0}),h(x)!=="svelte-p58zi1"&&(x.innerHTML=Le),_e=p(e),Y=f(e,"UL",{"data-svelte-h":!0}),h(Y)!=="svelte-imcrah"&&(Y.innerHTML=Se),Ue=p(e),y(D.$$.fragment,e),$e=p(e),ee=f(e,"P",{}),Ze(ee).forEach(a),this.h()},h(){te(r,"name","hf:doc:metadata"),te(r,"content",ot),te(k,"class","tip"),te(B,"class","warning"),te(U,"class","tip")},m(e,t){ve(document.head,r),s(e,M,t),s(e,i,t),s(e,g,t),j(n,e,t),s(e,c,t),s(e,m,t),s(e,w,t),s(e,Z,t),s(e,ae,t),j(v,e,t),s(e,se,t),s(e,k,t),s(e,le,t),s(e,E,t),s(e,ne,t),s(e,C,t),s(e,oe,t),j(I,e,t),s(e,pe,t),j(q,e,t),s(e,re,t),s(e,G,t),s(e,ie,t),s(e,P,t),s(e,ce,t),j(W,e,t),s(e,ue,t),s(e,F,t),s(e,fe,t),j(Q,e,t),s(e,me,t),s(e,B,t),s(e,Me,t),s(e,A,t),s(e,he,t),j(H,e,t),s(e,de,t),s(e,X,t),s(e,ye,t),j(V,e,t),s(e,je,t),s(e,U,t),ve(U,K),ve(U,Be),j(R,U,null),s(e,Te,t),s(e,L,t),s(e,Je,t),j(S,e,t),s(e,be,t),s(e,N,t),s(e,we,t),j(z,e,t),s(e,ge,t),s(e,x,t),s(e,_e,t),s(e,Y,t),s(e,Ue,t),j(D,e,t),s(e,$e,t),s(e,ee,t),ke=!0},p(e,[t]){const O={};t&2&&(O.$$scope={dirty:t,ctx:e}),I.$set(O)},i(e){ke||(T(n.$$.fragment,e),T(v.$$.fragment,e),T(I.$$.fragment,e),T(q.$$.fragment,e),T(W.$$.fragment,e),T(Q.$$.fragment,e),T(H.$$.fragment,e),T(V.$$.fragment,e),T(R.$$.fragment,e),T(S.$$.fragment,e),T(z.$$.fragment,e),T(D.$$.fragment,e),ke=!0)},o(e){J(n.$$.fragment,e),J(v.$$.fragment,e),J(I.$$.fragment,e),J(q.$$.fragment,e),J(W.$$.fragment,e),J(Q.$$.fragment,e),J(H.$$.fragment,e),J(V.$$.fragment,e),J(R.$$.fragment,e),J(S.$$.fragment,e),J(z.$$.fragment,e),J(D.$$.fragment,e),ke=!1},d(e){e&&(a(M),a(i),a(g),a(c),a(m),a(w),a(Z),a(ae),a(se),a(k),a(le),a(E),a(ne),a(C),a(oe),a(pe),a(re),a(G),a(ie),a(P),a(ce),a(ue),a(F),a(fe),a(me),a(B),a(Me),a(A),a(he),a(de),a(X),a(ye),a(je),a(U),a(Te),a(L),a(Je),a(be),a(N),a(we),a(ge),a(x),a(_e),a(Y),a(Ue),a($e),a(ee)),a(r),b(n,e),b(v,e),b(I,e),b(q,e),b(W,e),b(Q,e),b(H,e),b(V,e),b(R),b(S,e),b(z,e),b(D,e)}}}const ot='{"title":"PEFT configurations and models","local":"peft-configurations-and-models","sections":[{"title":"PEFT configurations","local":"peft-configurations","sections":[],"depth":2},{"title":"PEFT models","local":"peft-models","sections":[],"depth":2},{"title":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}';function pt($){return Ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class mt extends De{constructor(r){super(),Oe(this,r,pt,nt,xe,{})}}export{mt as component};
