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.8d7e60c0.js";import{C as _}from"../chunks/CodeBlock.4d4112a9.js";import{H as lt,a as ze}from"../chunks/HfOption.a1db6210.js";function nt($){let r,M,c,g='You can create your own configuration for training by initializing a <a href="/docs/peft/v0.18.0.rc0/en/package_reference/lora#peft.LoraConfig">LoraConfig</a>.',n,i,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}}),i=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(),c=u("p"),c.innerHTML=g,n=o(),d(i.$$.fragment)},l(l){y(r.$$.fragment,l),M=p(l),c=f(l,"P",{"data-svelte-h":!0}),w(c)!=="svelte-16hzn6i"&&(c.innerHTML=g),n=p(l),y(i.$$.fragment,l)},m(l,h){j(r,l,h),a(l,M,h),a(l,c,h),a(l,n,h),j(i,l,h),m=!0},p:Ye,i(l){m||(T(r.$$.fragment,l),T(i.$$.fragment,l),m=!0)},o(l){J(r.$$.fragment,l),J(i.$$.fragment,l),m=!1},d(l){l&&(s(M),s(c),s(n)),b(r,l),b(i,l)}}}function ot($){let r,M,c,g='You can create your own configuration for training by initializing a <a href="/docs/peft/v0.18.0.rc0/en/package_reference/p_tuning#peft.PromptEncoderConfig">PromptEncoderConfig</a>.',n,i,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}}),i=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(),c=u("p"),c.innerHTML=g,n=o(),d(i.$$.fragment)},l(l){y(r.$$.fragment,l),M=p(l),c=f(l,"P",{"data-svelte-h":!0}),w(c)!=="svelte-19e5sx6"&&(c.innerHTML=g),n=p(l),y(i.$$.fragment,l)},m(l,h){j(r,l,h),a(l,M,h),a(l,c,h),a(l,n,h),j(i,l,h),m=!0},p:Ye,i(l){m||(T(r.$$.fragment,l),T(i.$$.fragment,l),m=!0)},o(l){J(r.$$.fragment,l),J(i.$$.fragment,l),m=!1},d(l){l&&(s(M),s(c),s(n)),b(r,l),b(i,l)}}}function pt($){let r,M,c,g;return r=new ze({props:{id:"config",option:"LoraConfig",$$slots:{default:[nt]},$$scope:{ctx:$}}}),c=new ze({props:{id:"config",option:"PromptEncoderConfig",$$slots:{default:[ot]},$$scope:{ctx:$}}}),{c(){d(r.$$.fragment),M=o(),d(c.$$.fragment)},l(n){y(r.$$.fragment,n),M=p(n),y(c.$$.fragment,n)},m(n,i){j(r,n,i),a(n,M,i),j(c,n,i),g=!0},p(n,i){const m={};i&2&&(m.$$scope={dirty:i,ctx:n}),r.$set(m);const l={};i&2&&(l.$$scope={dirty:i,ctx:n}),c.$set(l)},i(n){g||(T(r.$$.fragment,n),T(c.$$.fragment,n),g=!0)},o(n){J(r.$$.fragment,n),J(c.$$.fragment,n),g=!1},d(n){n&&s(M),b(r,n),b(c,n)}}}function rt($){let r,M,c,g,n,i,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,v,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,k,re,q,ce,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.rc0/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,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.rc0/en/package_reference/peft_model#peft.get_peft_model">get_peft_model()</a> function to create a <a href="/docs/peft/v0.18.0.rc0/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.rc0/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.rc0/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.rc0/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.rc0/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.rc0/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.rc0/en/package_reference/peft_model#peft.PeftModel">PeftModel</a> for inference, you’ll need to provide the <a href="/docs/peft/v0.18.0.rc0/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.rc0/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.rc0/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.rc0/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.rc0/en/package_reference/auto_class#peft.AutoPeftModel">AutoPeftModel</a>, are just a convenient wrapper around the base <a href="/docs/peft/v0.18.0.rc0/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,S,we,x,Se='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.rc0/en/package_reference/auto_class#peft.AutoPeftModel">AutoPeftModel</a> classes.',ge,N,_e,z,xe='With the appropriate <a href="/docs/peft/v0.18.0.rc0/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.rc0/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,ve,ee,ke;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"}}),k=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}}),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}}),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(),c=u("p"),g=o(),d(n.$$.fragment),i=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(),v=u("blockquote"),v.innerHTML=Ge,ne=o(),E=u("p"),E.textContent=Pe,oe=o(),C=u("p"),C.innerHTML=We,pe=o(),d(k.$$.fragment),re=o(),d(q.$$.fragment),ce=o(),G=u("p"),G.innerHTML=Fe,ie=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(S.$$.fragment),we=o(),x=u("p"),x.innerHTML=Se,ge=o(),d(N.$$.fragment),_e=o(),z=u("p"),z.innerHTML=xe,Ue=o(),Y=u("ul"),Y.innerHTML=Ne,$e=o(),d(D.$$.fragment),ve=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),c=f(e,"P",{}),Ze(c).forEach(s),g=p(e),y(n.$$.fragment,e),i=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),v=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(v)!=="svelte-1ttb3zu"&&(v.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(k.$$.fragment,e),re=p(e),y(q.$$.fragment,e),ce=p(e),G=f(e,"P",{"data-svelte-h":!0}),w(G)!=="svelte-qapaon"&&(G.innerHTML=Fe),ie=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-8ljw8h"&&(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-1yjgplv"&&(I.innerHTML=He),he=p(e),A=f(e,"P",{"data-svelte-h":!0}),w(A)!=="svelte-1gj50oy"&&(A.innerHTML=Xe),de=p(e),y(H.$$.fragment,e),ye=p(e),X=f(e,"P",{"data-svelte-h":!0}),w(X)!=="svelte-15om39w"&&(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-onno23"&&(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-9s0uve"&&(L.innerHTML=Le),be=p(e),y(S.$$.fragment,e),we=p(e),x=f(e,"P",{"data-svelte-h":!0}),w(x)!=="svelte-1tcds1z"&&(x.innerHTML=Se),ge=p(e),y(N.$$.fragment,e),_e=p(e),z=f(e,"P",{"data-svelte-h":!0}),w(z)!=="svelte-1svvkcp"&&(z.innerHTML=xe),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),ve=p(e),ee=f(e,"P",{}),Ze(ee).forEach(s),this.h()},h(){te(r,"name","hf:doc:metadata"),te(r,"content",ct),te(v,"class","tip"),te(I,"class","warning"),te(U,"class","tip")},m(e,t){Ee(document.head,r),a(e,M,t),a(e,c,t),a(e,g,t),j(n,e,t),a(e,i,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,v,t),a(e,ne,t),a(e,E,t),a(e,oe,t),a(e,C,t),a(e,pe,t),j(k,e,t),a(e,re,t),j(q,e,t),a(e,ce,t),a(e,G,t),a(e,ie,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(S,e,t),a(e,we,t),a(e,x,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,ve,t),a(e,ee,t),ke=!0},p(e,[t]){const O={};t&2&&(O.$$scope={dirty:t,ctx:e}),k.$set(O)},i(e){ke||(T(n.$$.fragment,e),T(m.$$.fragment,e),T(Z.$$.fragment,e),T(k.$$.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(N.$$.fragment,e),T(D.$$.fragment,e),ke=!0)},o(e){J(n.$$.fragment,e),J(m.$$.fragment,e),J(Z.$$.fragment,e),J(k.$$.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(N.$$.fragment,e),J(D.$$.fragment,e),ke=!1},d(e){e&&(s(M),s(c),s(g),s(i),s(l),s(h),s(se),s(B),s(ae),s(le),s(v),s(ne),s(E),s(oe),s(C),s(pe),s(re),s(ce),s(G),s(ie),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(x),s(ge),s(_e),s(z),s(Ue),s(Y),s($e),s(ve),s(ee)),s(r),b(n,e),b(m,e),b(Z,e),b(k,e),b(q,e),b(W,e),b(Q,e),b(H,e),b(V,e),b(R),b(S,e),b(N,e),b(D,e)}}}const ct='{"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 it($){return Oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class dt extends Ke{constructor(r){super(),et(this,r,it,rt,De,{})}}export{dt as component};
