Inferensys

Glossary

Target Modules

Target modules are the specific layers or components within a neural network architecture where parameter-efficient fine-tuning (PEFT) methods, such as LoRA, inject their small, trainable adapter matrices.
Architect reviewing LLM integration architecture on laptop, system diagrams visible, modern technical office setup.
LOW-RANK ADAPTATION (LORA)

What are Target Modules?

Target modules are the specific layers within a neural network where a parameter-efficient fine-tuning (PEFT) method, such as Low-Rank Adaptation (LoRA), injects its trainable adapter components.

In Low-Rank Adaptation (LoRA), target modules are the pre-defined linear layers or projection matrices within a frozen base model where the low-rank adapter matrices (A and B) are inserted. Common examples in transformer architectures include the query (q_proj), key (k_proj), value (v_proj), and output projection (o_proj) layers within attention blocks, as well as the feed-forward network's dense layers. Selecting these modules is a critical architectural decision that determines which parts of the model are adapted for the new task.

The choice of target modules directly impacts the adaptation capacity, parameter efficiency, and final performance of the fine-tuned model. Injecting adapters into all linear layers offers maximum flexibility but increases trainable parameters, while a selective strategy (e.g., only the value projections) can maintain high efficiency. This configuration is a key hyperparameter specified when applying LoRA through libraries like Hugging Face PEFT, balancing the granularity of the update against computational cost.

LOW-RANK ADAPTATION (LORA)

Common Target Modules in Transformer Models

Target modules are the specific layers within a neural network where Low-Rank Adaptation (LoRA) injects its trainable adapter matrices. Selecting the right modules is critical for balancing adaptation effectiveness with parameter efficiency.

01

Attention Projections (Q, K, V, O)

The most common and effective target modules for LoRA in transformer architectures. These linear layers project the input into query (Q), key (K), value (V), and output (O) representations within the multi-head self-attention mechanism.

  • Why they are targeted: These projections are dense, parameter-rich layers directly responsible for modeling contextual relationships. Adapting them efficiently captures task-specific attention patterns.
  • Typical Practice: Applying LoRA to just the query (Q) and value (V) projections is a standard, highly effective configuration, as popularized by the original LoRA paper for GPT models.
02

Feed-Forward Network (FFN) Layers

The two linear layers (often called the "up" and "down" projections) within the transformer's feed-forward network block. This module applies a position-wise non-linear transformation to each token's representation.

  • Why they are targeted: The FFN layers contain a significant portion of a transformer's parameters and are hypothesized to function as key-value memory networks. Adapting them allows the model to adjust its internal "fact" storage and retrieval for a new domain.
  • Consideration: Applying LoRA to FFN layers often yields substantial gains for knowledge-intensive tasks but increases the number of trainable parameters compared to targeting only attention projections.
03

Embedding & Output Projection Layers

The input token embedding matrix and the final language modeling head (output projection), which are often tied (share weights) in decoder-only LLMs.

  • Why they are targeted: Adapting these layers allows the model to adjust the semantic meaning of tokens for the target domain, which is crucial for specialized vocabulary or terminology.
  • Caveat: Fine-tuning these very large matrices (vocab_size × hidden_dim) with LoRA can be highly parameter-efficient but may have a smaller impact per parameter compared to adapting intermediate layers. It is often used in combination with other modules.
04

Cross-Attention Modules (Encoder-Decoder)

The query (Q) projection within the cross-attention layers of encoder-decoder models (e.g., T5, BART). This layer allows the decoder to attend to the encoder's output representations.

  • Why they are targeted: For sequence-to-sequence tasks like translation or summarization, adapting the cross-attention mechanism is critical for learning task-specific alignment between source and target sequences.
  • Application: In models like T5, applying LoRA to the cross-attention Q projection and the decoder's self-attention projections is a standard and effective strategy.
05

LayerNorm & Bias Terms

The gain and bias parameters of Layer Normalization (LayerNorm) layers. While not a traditional "projection," these are small, per-layer sets of parameters that control feature scaling and shifting.

  • Why they are targeted: Fine-tuning LayerNorm parameters (sometimes called "LN tuning") is an extremely parameter-efficient PEFT method on its own. When combined with LoRA on linear layers, it provides a complementary adaptation mechanism for feature distribution.
  • Efficiency: This adds only 2 × hidden_dim trainable parameters per adapted layer, making it a common supplement to LoRA for marginal cost.
06

Module Selection Strategy

The process of determining which layers to apply LoRA to, balancing performance, efficiency, and task needs.

  • Rule-based Selection: Common heuristics include targeting all attention projections (Q, K, V, O) in specified transformer blocks (e.g., the last N layers).
  • Automated Search: Methods like LoRAHub or Laplacian Singular Value analysis can be used to identify the most impactful layers for adaptation, moving beyond heuristic selection.
  • Performance Trade-off: More target modules generally lead to better task performance but increase the number of trainable parameters and memory overhead. The optimal set is task- and model-dependent.
LOW-RANK ADAPTATION (LORA)

How to Select Target Modules

Selecting target modules is the strategic process of identifying which specific layers within a pre-trained neural network to adapt using a parameter-efficient fine-tuning (PEFT) method like Low-Rank Adaptation (LoRA).

The selection is guided by the network's architecture and the target task. For transformer-based models, the attention mechanism's query (q_proj), key (k_proj), value (v_proj), and output (o_proj) projection matrices are common targets, as they capture task-specific contextual relationships. In feed-forward networks, the dense or fc layers are often selected. The goal is to inject adapters into modules that are most relevant for the new domain while leaving the majority of the model's foundational knowledge frozen and intact.

Empirical analysis and architectural understanding drive the choice. Applying LoRA to all linear layers can be effective but increases parameters. A more efficient strategy is to target only the attention projections or specific blocks, balancing performance gains with parameter efficiency. The selection directly influences the adapter's capacity to learn the task delta, its compute and memory footprint, and the final quality of the fine-tuned model.

SELECTION CRITERIA

Targeting Strategy Comparison

A comparison of strategies for selecting which neural network modules to target when applying Low-Rank Adaptation (LoRA), based on architectural impact, parameter efficiency, and task performance.

Targeting StrategyTarget Modules (Transformer Example)Parameter EfficiencyTask PerformanceCommon Use Case

Attention-Only

Query (Q), Key (K), Value (V), Output (O) projections

High

Strong for language tasks

General instruction tuning of LLMs

Feed-Forward-Only

Up- and down-projection layers in MLP blocks

High

Strong for domain-specific knowledge

Specialized factual adaptation

Attention + MLP

All Q, K, V, O, and MLP projections

Medium

Very Strong

Comprehensive fine-tuning for high-stakes tasks

All Linear Layers

Every linear layer in the transformer (including embeddings)

Low

Strongest (approaches full fine-tuning)

Maximum performance when resources allow

Layer-Specific (e.g., Last N)

Modules in the final N transformer layers only

Very High

Task-dependent

Rapid prototyping or edge-focused adaptation

Task-Specific Heuristic

Modules identified via saliency or gradient analysis

Variable

Optimized for specific task

Research-driven optimization for fixed deployments

Default (Hugging Face PEFT)

Query and Value projections only

Highest

Good general performance

Standardized, low-configuration fine-tuning

TARGET MODULES

Frequently Asked Questions

Target modules are the specific layers within a neural network where parameter-efficient fine-tuning (PEFT) methods, such as LoRA, inject their trainable components. Selecting the right modules is critical for balancing adaptation effectiveness with parameter efficiency.

Target modules in Low-Rank Adaptation (LoRA) are the specific, pre-existing weight matrices within a neural network architecture where the trainable low-rank adapter matrices (A and B) are injected. Instead of fine-tuning the entire model, LoRA adds its small, trainable components only to these selected modules, which are typically the linear projection layers found in a transformer's attention mechanism. The original weights of these target modules remain frozen during training. Common examples in transformer-based Large Language Models (LLMs) include the query (q_proj), key (k_proj), value (v_proj), and output (o_proj) projection matrices within each attention block. The choice of which modules to target is a key hyperparameter that directly influences the performance, parameter efficiency, and computational cost of the fine-tuning process.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.