import{s as De,o as Oe,n as Ye}from"../chunks/scheduler.78382b47.js";import{S as Ke,i as et,e as u,s as o,c as d,h as tt,a as f,d as s,b as p,f as Ze,g as y,j as w,k as te,l as Ee,m as a,n as j,t as T,o as J,p as b}from"../chunks/index.6dd35eb6.js";import{C as st,H as Ie,E as at}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.6888f903.js";import{C as _}from"../chunks/CodeBlock.658dd679.js";import{H as lt,a as ze}from"../chunks/HfOption.a1db6210.js";function nt($){let r,M,i,g='You can create your own configuration for training by initializing a <a href="/docs/peft/v0.18.0/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}),w(i)!=="svelte-uh2fej"&&(i.innerHTML=g),n=p(l),y(c.$$.fragment,l)},m(l,h){j(r,l,h),a(l,M,h),a(l,i,h),a(l,n,h),j(c,l,h),m=!0},p:Ye,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&&(s(M),s(i),s(n)),b(r,l),b(c,l)}}}function ot($){let r,M,i,g='You can create your own configuration for training by initializing a <a href="/docs/peft/v0.18.0/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}),w(i)!=="svelte-12hxeff"&&(i.innerHTML=g),n=p(l),y(c.$$.fragment,l)},m(l,h){j(r,l,h),a(l,M,h),a(l,i,h),a(l,n,h),j(c,l,h),m=!0},p:Ye,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&&(s(M),s(i),s(n)),b(r,l),b(c,l)}}}function pt($){let r,M,i,g;return r=new ze({props:{id:"config",option:"LoraConfig",$$slots:{default:[nt]},$$scope:{ctx:$}}}),i=new ze({props:{id:"config",option:"PromptEncoderConfig",$$slots:{default:[ot]},$$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),a(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&&s(M),b(r,n),b(i,n)}}}function rt($){let r,M,i,g,n,c,m,l,h,Ce="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.",se,B,qe='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/v4.57.1/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,Z,le,k,Ge="<p>Learn more about the parameters you can configure for each PEFT method in their respective API reference page.</p>",ne,E,Pe="A configuration stores important parameters that specify how a particular PEFT method should be applied.",oe,C,We='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.',pe,v,re,q,ie,G,Fe='With a PEFT configuration in hand, you can now apply it to any pretrained model to create a <a href="/docs/peft/v0.18.0/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.',ce,P,Qe='For this tutorial, load a base <a href="https://huggingface.co/facebook/opt-350m" rel="nofollow">facebook/opt-350m</a> model to finetune.',ue,W,fe,F,Ae='Use the <a href="/docs/peft/v0.18.0/en/package_reference/peft_model#peft.get_peft_model">get_peft_model()</a> function to create a <a href="/docs/peft/v0.18.0/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.',me,Q,Me,I,He='<p>When calling <a href="/docs/peft/v0.18.0/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/v0.18.0/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/v0.18.0/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>',he,A,Xe='Now you can train the <a href="/docs/peft/v0.18.0/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/v0.18.0/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/v4.57.1/en/main_classes/model#transformers.PreTrainedModel.push_to_hub" rel="nofollow">push_to_hub</a> method.',de,H,ye,X,Ve='To load a <a href="/docs/peft/v0.18.0/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> for inference, you’ll need to provide the <a href="/docs/peft/v0.18.0/en/package_reference/config#peft.PeftConfig">PeftConfig</a> used to create it and the base model it was trained from.',je,V,Te,U,K,Re='By default, the <a href="/docs/peft/v0.18.0/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,Je,L,Le='The <a href="/docs/peft/v0.18.0/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/v0.18.0/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/v0.18.0/en/package_reference/auto_class#peft.AutoPeftModel">AutoPeftModel</a>, are just a convenient wrapper around the base <a href="/docs/peft/v0.18.0/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.',be,x,we,S,xe='Take a look at the <a href="package_reference/auto_class">AutoPeftModel</a> API reference to learn more about the <a href="/docs/peft/v0.18.0/en/package_reference/auto_class#peft.AutoPeftModel">AutoPeftModel</a> classes.',ge,N,_e,z,Se='With the appropriate <a href="/docs/peft/v0.18.0/en/package_reference/config#peft.PeftConfig">PeftConfig</a>, you can apply it to any pretrained model to create a <a href="/docs/peft/v0.18.0/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:',Ue,Y,Ne='<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>',$e,D,ke,ee,ve;return n=new st({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),m=new Ie({props:{title:"PEFT configurations and models",local:"peft-configurations-and-models",headingTag:"h1"}}),Z=new Ie({props:{title:"PEFT configurations",local:"peft-configurations",headingTag:"h2"}}),v=new lt({props:{id:"config",options:["LoraConfig","PromptEncoderConfig"],$$slots:{default:[pt]},$$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}}),x=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}}),N=new Ie({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),D=new at({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(),d(m.$$.fragment),l=o(),h=u("p"),h.textContent=Ce,se=o(),B=u("p"),B.innerHTML=qe,ae=o(),d(Z.$$.fragment),le=o(),k=u("blockquote"),k.innerHTML=Ge,ne=o(),E=u("p"),E.textContent=Pe,oe=o(),C=u("p"),C.innerHTML=We,pe=o(),d(v.$$.fragment),re=o(),d(q.$$.fragment),ie=o(),G=u("p"),G.innerHTML=Fe,ce=o(),P=u("p"),P.innerHTML=Qe,ue=o(),d(W.$$.fragment),fe=o(),F=u("p"),F.innerHTML=Ae,me=o(),d(Q.$$.fragment),Me=o(),I=u("blockquote"),I.innerHTML=He,he=o(),A=u("p"),A.innerHTML=Xe,de=o(),d(H.$$.fragment),ye=o(),X=u("p"),X.innerHTML=Ve,je=o(),d(V.$$.fragment),Te=o(),U=u("blockquote"),K=u("p"),K.innerHTML=Re,Be=o(),d(R.$$.fragment),Je=o(),L=u("p"),L.innerHTML=Le,be=o(),d(x.$$.fragment),we=o(),S=u("p"),S.innerHTML=xe,ge=o(),d(N.$$.fragment),_e=o(),z=u("p"),z.innerHTML=Se,Ue=o(),Y=u("ul"),Y.innerHTML=Ne,$e=o(),d(D.$$.fragment),ke=o(),ee=u("p"),this.h()},l(e){const t=tt("svelte-u9bgzb",document.head);r=f(t,"META",{name:!0,content:!0}),t.forEach(s),M=p(e),i=f(e,"P",{}),Ze(i).forEach(s),g=p(e),y(n.$$.fragment,e),c=p(e),y(m.$$.fragment,e),l=p(e),h=f(e,"P",{"data-svelte-h":!0}),w(h)!=="svelte-hwy4y1"&&(h.textContent=Ce),se=p(e),B=f(e,"P",{"data-svelte-h":!0}),w(B)!=="svelte-1wr40ig"&&(B.innerHTML=qe),ae=p(e),y(Z.$$.fragment,e),le=p(e),k=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(k)!=="svelte-1ttb3zu"&&(k.innerHTML=Ge),ne=p(e),E=f(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-16b4gu"&&(E.textContent=Pe),oe=p(e),C=f(e,"P",{"data-svelte-h":!0}),w(C)!=="svelte-2s9teg"&&(C.innerHTML=We),pe=p(e),y(v.$$.fragment,e),re=p(e),y(q.$$.fragment,e),ie=p(e),G=f(e,"P",{"data-svelte-h":!0}),w(G)!=="svelte-5epge4"&&(G.innerHTML=Fe),ce=p(e),P=f(e,"P",{"data-svelte-h":!0}),w(P)!=="svelte-1d979vk"&&(P.innerHTML=Qe),ue=p(e),y(W.$$.fragment,e),fe=p(e),F=f(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-1b1mgbx"&&(F.innerHTML=Ae),me=p(e),y(Q.$$.fragment,e),Me=p(e),I=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(I)!=="svelte-evgkfq"&&(I.innerHTML=He),he=p(e),A=f(e,"P",{"data-svelte-h":!0}),w(A)!=="svelte-1vsuyea"&&(A.innerHTML=Xe),de=p(e),y(H.$$.fragment,e),ye=p(e),X=f(e,"P",{"data-svelte-h":!0}),w(X)!=="svelte-18tgqge"&&(X.innerHTML=Ve),je=p(e),y(V.$$.fragment,e),Te=p(e),U=f(e,"BLOCKQUOTE",{class:!0});var O=Ze(U);K=f(O,"P",{"data-svelte-h":!0}),w(K)!=="svelte-cw4hm0"&&(K.innerHTML=Re),Be=p(O),y(R.$$.fragment,O),O.forEach(s),Je=p(e),L=f(e,"P",{"data-svelte-h":!0}),w(L)!=="svelte-1vhdpb8"&&(L.innerHTML=Le),be=p(e),y(x.$$.fragment,e),we=p(e),S=f(e,"P",{"data-svelte-h":!0}),w(S)!=="svelte-873x2k"&&(S.innerHTML=xe),ge=p(e),y(N.$$.fragment,e),_e=p(e),z=f(e,"P",{"data-svelte-h":!0}),w(z)!=="svelte-sx50lz"&&(z.innerHTML=Se),Ue=p(e),Y=f(e,"UL",{"data-svelte-h":!0}),w(Y)!=="svelte-imcrah"&&(Y.innerHTML=Ne),$e=p(e),y(D.$$.fragment,e),ke=p(e),ee=f(e,"P",{}),Ze(ee).forEach(s),this.h()},h(){te(r,"name","hf:doc:metadata"),te(r,"content",it),te(k,"class","tip"),te(I,"class","warning"),te(U,"class","tip")},m(e,t){Ee(document.head,r),a(e,M,t),a(e,i,t),a(e,g,t),j(n,e,t),a(e,c,t),j(m,e,t),a(e,l,t),a(e,h,t),a(e,se,t),a(e,B,t),a(e,ae,t),j(Z,e,t),a(e,le,t),a(e,k,t),a(e,ne,t),a(e,E,t),a(e,oe,t),a(e,C,t),a(e,pe,t),j(v,e,t),a(e,re,t),j(q,e,t),a(e,ie,t),a(e,G,t),a(e,ce,t),a(e,P,t),a(e,ue,t),j(W,e,t),a(e,fe,t),a(e,F,t),a(e,me,t),j(Q,e,t),a(e,Me,t),a(e,I,t),a(e,he,t),a(e,A,t),a(e,de,t),j(H,e,t),a(e,ye,t),a(e,X,t),a(e,je,t),j(V,e,t),a(e,Te,t),a(e,U,t),Ee(U,K),Ee(U,Be),j(R,U,null),a(e,Je,t),a(e,L,t),a(e,be,t),j(x,e,t),a(e,we,t),a(e,S,t),a(e,ge,t),j(N,e,t),a(e,_e,t),a(e,z,t),a(e,Ue,t),a(e,Y,t),a(e,$e,t),j(D,e,t),a(e,ke,t),a(e,ee,t),ve=!0},p(e,[t]){const O={};t&2&&(O.$$scope={dirty:t,ctx:e}),v.$set(O)},i(e){ve||(T(n.$$.fragment,e),T(m.$$.fragment,e),T(Z.$$.fragment,e),T(v.$$.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(x.$$.fragment,e),T(N.$$.fragment,e),T(D.$$.fragment,e),ve=!0)},o(e){J(n.$$.fragment,e),J(m.$$.fragment,e),J(Z.$$.fragment,e),J(v.$$.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(x.$$.fragment,e),J(N.$$.fragment,e),J(D.$$.fragment,e),ve=!1},d(e){e&&(s(M),s(i),s(g),s(c),s(l),s(h),s(se),s(B),s(ae),s(le),s(k),s(ne),s(E),s(oe),s(C),s(pe),s(re),s(ie),s(G),s(ce),s(P),s(ue),s(fe),s(F),s(me),s(Me),s(I),s(he),s(A),s(de),s(ye),s(X),s(je),s(Te),s(U),s(Je),s(L),s(be),s(we),s(S),s(ge),s(_e),s(z),s(Ue),s(Y),s($e),s(ke),s(ee)),s(r),b(n,e),b(m,e),b(Z,e),b(v,e),b(q,e),b(W,e),b(Q,e),b(H,e),b(V,e),b(R),b(x,e),b(N,e),b(D,e)}}}const it='{"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 ct($){return Oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class dt extends Ke{constructor(r){super(),et(this,r,ct,rt,De,{})}}export{dt as component};
