When does a PEFT config actually need `modules_to_save` set, and what goes in it?
modules_to_save trains listed modules fully alongside the LoRA adapter, typically embed_tokens and lm_head when the tokenizer gains new tokens whose random rows LoRA cannot reach.
Imagine your model is a giant library with a fixed catalogue of book topics. LoRA is a small set of margin notes you can scribble on existing pages to adjust how they read. Then one day you add brand new book categories to the library, categories the original catalogue never had. Those new categories need fresh full pages in the index, not margin notes. modules_to_save is the list of pages you mark as needing fresh full pages instead of margin notes. The most common case is adding new words to the model's vocabulary; the input lookup table and the output prediction layer both need new full pages for the new words to make sense.
Detailed answer & concept explanation~10 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: name modules_to_save's semantics, place vocab extension as the canonical use case, list embed_tokens and lm_head, contrast with target_modules, and surface the tied weight and memory caveats.
Real products, models, and research that use this idea.
- Hugging Face PEFT LoraConfig exposes modules_to_save as a top-level field used in Llama 4 fine-tuning recipes when adding domain markers to the tokenizer.
- Axolotl recipes for multilingual continued training of Mistral list embed_tokens and lm_head in modules_to_save when extending the tokenizer for new scripts.
- DeepSeek V4 distillation pipelines that add special function-calling tokens use modules_to_save to ensure the embedding and output projection rows for the new tokens train fully.
- Unsloth tutorials for fine-tuning Gemma 4 on tool-use data demonstrate modules_to_save with embed_tokens and lm_head when introducing new tool framing tokens.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is LoRA fundamentally unable to teach new vocabulary tokens added after pretraining?
QWhen tying embed_tokens and lm_head, how does modules_to_save behave?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating modules_to_save as a list of LoRA target modules. It is the opposite: these modules bypass LoRA entirely and train at full precision in full rank.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.