Buckets:

download
raw
17.8 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Parameter efficient fine-tuning methods&quot;,&quot;local&quot;:&quot;parameter-efficient-fine-tuning-methods&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Prompt-based methods&quot;,&quot;local&quot;:&quot;prompt-based-methods&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Layer Tuning&quot;,&quot;local&quot;:&quot;layer-tuning&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Adapter methods&quot;,&quot;local&quot;:&quot;adapter-methods&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/peft/pr_3270/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/entry/start.f28557bc.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/scheduler.78382b47.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/singletons.2ac5b46a.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/index.fadd215c.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/paths.992e82e0.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/entry/app.2273f60f.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/preload-helper.251eab2a.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/index.6dd35eb6.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/nodes/0.aaf7e185.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/nodes/18.d906efd5.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/CopyLLMTxtMenu.ddc04658.js">
<link rel="modulepreload" href="/docs/peft/pr_3270/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.3b3e5fc5.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Parameter efficient fine-tuning methods&quot;,&quot;local&quot;:&quot;parameter-efficient-fine-tuning-methods&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Prompt-based methods&quot;,&quot;local&quot;:&quot;prompt-based-methods&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Layer Tuning&quot;,&quot;local&quot;:&quot;layer-tuning&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Adapter methods&quot;,&quot;local&quot;:&quot;adapter-methods&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="parameter-efficient-fine-tuning-methods" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#parameter-efficient-fine-tuning-methods"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Parameter efficient fine-tuning methods</span></h1> <p data-svelte-h="svelte-1isgham">PEFT methods train as few parameters as possible while aiming for performance comparable to full fine-tuning. Fewer trainable parameters are less expressive, so the same performance isn’t guaranteed. In exchange you use less memory, often less compute, and gain features like fast hot-swapping between expert adapters and less forgetting of prior knowledge.</p> <p data-svelte-h="svelte-p4iz30">Giving general advice for training large models is hard but for generative models, especially language models, you can follow these steps:</p> <ol data-svelte-h="svelte-1vrqkgf"><li>use prompting (e.g. few-shot examples in the prompt) to see if the model is already capable of the task. If the model solves your problem, great! You can now use <a href="#prompt-based-methods">Prompt-based methods</a> to learn the prompt and save precious tokens.</li> <li>If prompt-based methods are not sufficient you can use <a href="#layer-tuning">layer tuning</a> and <a href="#adapter-methods">adapter methods</a>. These methods are generally more expressive than prompt-based methods and get closer to full-finetuning.</li> <li>Make sure to measure retention of already learnt knowledge since each fine-tuning step is potentially unlearning past knowledge.</li></ol> <p data-svelte-h="svelte-1m1g1k6">The <a href="https://huggingface.co/spaces/peft-internal-testing/PEFT-method-comparison" rel="nofollow">PEFT method comparison suite</a> aims to give a rough overview of (most) implemented methods on selected benchmarks and models.</p> <blockquote class="note" data-svelte-h="svelte-13zq41f"><p>Not all PEFT methods are created equal and there are differences between capabilities:</p> <ul><li>Quantization: not all methods support quantized base models</li> <li>Features: not all features are supported for all methods (e.g., multiple adapters, mixed adapter inference, merging/unmerging)</li> <li>Layer types: linear layers are generally supported, but not all adapter methods support embedding (important for extending vocabulary) or convolutional layers (important for some image models)</li> <li>Runtime: PEFT methods generally add runtime overhead but some of that can be mitigated (e.g., by <a href="../developer_guides/checkpoint#merge-the-weights">merging the adapter weights</a>)</li></ul></blockquote> <h2 class="relative group"><a id="prompt-based-methods" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#prompt-based-methods"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Prompt-based methods</span></h2> <p data-svelte-h="svelte-17ds5qt">Prompting primes a frozen pretrained model for a specific downstream task by including a text prompt that describes the task or even demonstrates an example of the task. With prompting, you can avoid fully training a separate model for each downstream task, and use the same frozen pretrained model instead. This is a lot easier because you can use the same model for several different tasks, and it is significantly more efficient to train and store a smaller set of prompt parameters than to train all the model’s parameters.</p> <p data-svelte-h="svelte-xiexj5">There are two categories of prompting methods:</p> <ul data-svelte-h="svelte-1gvlyfh"><li>hard prompts are manually handcrafted text prompts with discrete input tokens; the downside is that it requires a lot of effort to create a good prompt</li> <li>soft prompts are learnable tensors concatenated with the input embeddings that can be optimized to a dataset; the downside is that they aren’t human readable because you aren’t matching these “virtual tokens” to the embeddings of a real word</li></ul> <p data-svelte-h="svelte-1hlk144">The PEFT library supports several types of prompting methods (p-tuning, prefix tuning, prompt tuning, …), explore the table of contents for a full listing of soft prompt methods.
If you’re interested in applying these methods to other tasks and use cases, take a look at our <a href="https://huggingface.co/spaces/PEFT/soft-prompting" rel="nofollow">notebook collection</a>!</p> <blockquote class="tip" data-svelte-h="svelte-1xrd9so"><p>Some familiarity with the general process of training a causal language model would be really helpful and allow you to focus on the soft prompting methods. If you’re new, we recommend taking a look at the <a href="https://huggingface.co/docs/transformers/tasks/language_modeling" rel="nofollow">Causal language modeling</a> guide first from the Transformers documentation. When you’re ready, come back and see how easy it is to drop PEFT into your training!</p></blockquote> <h2 class="relative group"><a id="layer-tuning" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#layer-tuning"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Layer Tuning</span></h2> <p data-svelte-h="svelte-1dh2cmc">Layer Tuning categorizes methods that target one type of layer or one aspect of a layer specifically, for example <a href="../package_reference/layernorm_tuning">LayerNorm Tuning</a> targets only <a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.LayerNorm.html" rel="nofollow"><code>LayerNorm</code></a> layers and <a href="../package_reference/trainable_tokens">TrainableTokens</a> only targets specific tokens in the embedding matrix. This contrasts prompt-based methods which work with the model input or adapter methods which extend the existing weights and are generally more independent of the layer type, targeting linear or convolutional layers.</p> <h2 class="relative group"><a id="adapter-methods" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#adapter-methods"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Adapter methods</span></h2> <p data-svelte-h="svelte-1ja6lv6">Adapter methods can be seen as ways of adding relatively small, trainable matrices to existing models for fine-tuning. The goal is to introduce few trainable parameters to steer the big model in the direction of the task that needs fine-tuning to save on resources, such as memory or compute.</p> <p data-svelte-h="svelte-jo0z9">A popular way to realize adapters is to insert smaller trainable matrices that are a low-rank decomposition of the adapted weight’s layout to save on memory. There are several different ways to express the weight matrix as a low-rank decomposition, but <a href="../package_reference/lora">Low-Rank Adaptation (LoRA)</a> is the most common method. The PEFT library supports several other variations of this formulation - some are direct variants of LoRA and are documented under LoRA, some are different enough to count as their own methods, such as <a href="../package_reference/loha">Low-Rank Hadamard Product (LoHa)</a>, <a href="../package_reference/lokr">Low-Rank Kronecker Product (LoKr)</a>, and <a href="../package_reference/adalora">Adaptive Low-Rank Adaptation (AdaLoRA)</a>. If you’re interested in applying these methods to other tasks and use cases like semantic segmentation, token classification, take a look at our <a href="https://huggingface.co/collections/PEFT/notebooks-6573b28b33e5a4bf5b157fc1" rel="nofollow">notebook collection</a>!</p> <blockquote class="tip" data-svelte-h="svelte-1wx7gg2"><p>LoRA is one of the most popular PEFT methods and a good starting point if you’re just getting started with PEFT. It was originally developed for large language models but it is a tremendously popular training method for diffusion models because of its efficiency and effectiveness.</p></blockquote> <p data-svelte-h="svelte-1nmmt7v">Low-rank adapters are only one possible adapter formulation, PEFT implements many other types of adapters as well. For example, Orthogonal Fine-Tuning methods (<a href="../package_reference/oft">OFT</a>, <a href="../package_reference/boft">BOFT</a>, …) use orthogonal decompositions of the adapter weights to achieve small size. Methods like <a href="../package_reference/miss">MiSS</a> shard matrices and share these shards to save on memory. <a href="../package_reference/ia3">IA3</a> introduces learned vectors that rescale the key, value, and feed-forward activations.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/peft/blob/main/docs/source/methods/overview.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1xnt4vv = {
assets: "/docs/peft/pr_3270/en",
base: "/docs/peft/pr_3270/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/peft/pr_3270/en/_app/immutable/entry/start.f28557bc.js"),
import("/docs/peft/pr_3270/en/_app/immutable/entry/app.2273f60f.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 18],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
17.8 kB
·
Xet hash:
6d527703e69831f13bb65bf38bd6982e2adffa80619fa031025769a764e4c6f3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.