target_modules in a PEFT config: what does this list control?
target_modules picks which linear submodules inside the transformer get a LoRA adapter wrapped around them. Everything not named stays frozen at base weights.
Think of the base model as a long row of doors. Behind each door is a giant grid of numbers the model uses for one specific job, like routing queries or expanding the hidden state. LoRA does not knock on every door. It only wraps adapters around the doors you point at. The target_modules argument is the list of door labels you hand over. Name two doors and only those two get an adapter; the rest stay locked and unchanged. Name all the doors and you wrap every one, which costs more compute but gives the adapter more places to learn. The list controls reach, and reach controls both quality and cost.
Detailed answer & concept explanation~7 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.
3 min: define the argument, walk through the three forms it accepts, show the q-v versus all-linear tradeoff, and end with the cost and architecture-portability traps.
Real products, models, and research that use this idea.
- Hugging Face PEFT exposes target_modules as a list, regex, or the special string 'all-linear' across every 2026 release.
- Axolotl and Unsloth Llama 4 Maverick recipes typically set target_modules to 'all-linear' for code and math fine-tunes.
- The QLoRA paper measured that targeting all linear layers consistently outperformed attention-only on GLUE and MMLU, and the recommendation has held in 2026 PEFT defaults.
- Mistral 7B and Llama 4 share the same projection names, so a single target_modules list ports between them, while DeepSeek V4's MoE layers use mlp.experts.* paths that require regex matching.
- Hugging Face PEFT documentation for Gemini 3.1 Pro and Gemma 4 includes architecture-specific target_modules examples because the projection names vary slightly across families.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the parameter count for a LoRA adapter scale with the choice of target_modules and the rank?
QWhy is all-linear typically the right default for hard domain shifts but overkill for style transfer?
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.
Defaulting to q_proj and v_proj only on every project, regardless of difficulty. For complex domain shifts that under-targets the MLP path, where most of the model's capacity actually lives.
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.