Attention Transfer is a feature-based knowledge distillation method where a student model is trained to mimic the attention maps generated by intermediate layers of a larger, pre-trained teacher model. Instead of matching only final outputs, the student learns to replicate the teacher's internal focus and contextual prioritization, typically by minimizing a loss between the Gram matrices or sum of squared values of their respective feature activations. This transfers representational knowledge about where the model should look, enhancing the student's generalization and efficiency.
Glossary
Attention Transfer

What is Attention Transfer?
Attention Transfer is a specific feature distillation technique where a student model is trained to replicate the attention maps from intermediate layers of a teacher model.
The technique is particularly effective for compressing transformer-based architectures, where attention mechanisms are fundamental. By aligning attention patterns, the student inherits the teacher's ability to weigh relevant input features, leading to better performance than logit-based distillation alone. In continual learning, a variant called Attention Distillation for Forgetting uses the model's own previous attention maps as regularization targets to preserve old knowledge when learning new tasks, directly addressing catastrophic forgetting within the plasticity-stability trade-off.
Key Features of Attention Transfer
Attention Transfer is a feature distillation method where a student model is trained to replicate the attention maps from intermediate layers of a teacher model, transferring its focus and contextual understanding.
Attention Map Matching
The core mechanism involves training the student to match attention maps from the teacher. These maps are often calculated as the sum of squared values across channels at specific intermediate layers (e.g., in a ResNet). The loss function minimizes the difference between these spatial attention distributions, forcing the student to learn where the teacher focuses its computational resources.
- Objective: Align student's feature importance with teacher's.
- Common Formulation: Use Mean Squared Error (MSE) or Kullback-Leibler (KL) divergence on normalized attention maps.
- Impact: Transfers inductive bias about salient regions, often leading to better generalization than matching raw feature activations.
Intermediate Layer Guidance
Unlike logit distillation which operates on final outputs, Attention Transfer uses intermediate representations. It provides a richer, more granular supervisory signal by guiding the student's internal feature transformations.
- Hint Layers: The teacher's activations at designated 'hint' layers are transformed into attention maps.
- Guided Layers: Corresponding student layers are trained to produce similar attention.
- Benefit: This mid-level supervision helps the student learn better feature hierarchies and can improve convergence, especially for very deep or thin student networks.
Spatial & Channel-Wise Aggregation
Teacher activations are 3D tensors (channels x height x width). Attention Transfer aggregates across channels to create 2D spatial maps, emphasizing where information is important, not just what features are present.
- Common Method: Sum of squared activations across the channel dimension: (A = \sum_c (F_{h,w,c})^2).
- Normalization: Maps are often spatially normalized (e.g., L2 norm) to focus on relative importance.
- Result: The student learns a compressed, spatial summary of the teacher's feature importance, which is computationally efficient to match.
Complement to Logit Distillation
Attention Transfer is frequently combined with standard logit distillation (matching soft targets) and the task's cross-entropy loss. This creates a multi-objective loss function that transfers knowledge at multiple levels of abstraction.
- Full Loss Function: (L_{total} = L_{task} + \alpha L_{logit} + \beta L_{attention}).
- Synergy: Logit distillation transfers what to predict, while attention transfer guides how to build the representations for that prediction.
- Empirical Result: The combination often yields student models that outperform those trained with either method alone.
Architecture Agnosticism
The method is not tied to a specific network family. While seminal work used ResNets, it has been successfully applied to Transformers (where it aligns attention heads or layer outputs), CNNs, and other architectures.
- Flexibility: The core principle—matching spatial importance—translates across model types.
- Transformer Adaptation: In Vision Transformers (ViTs), attention maps from the multi-head self-attention blocks can be distilled.
- Benefit: Makes it a versatile tool for compressing or training a wide variety of model architectures.
Application in Continual Learning
Attention Transfer is a key technique in distillation for forgetting, used in algorithms like Learning without Forgetting (LwF). Here, the model's own attention maps from a previous task are used as a regularization target when learning a new task.
- Mechanism: The model's frozen copy (teacher on old tasks) provides attention maps. The learning model (student on new task) is penalized for deviating from these maps on rehearsal or generated data.
- Purpose: Preserves the feature-level behavior on old tasks, not just final outputs, which helps maintain representational stability.
- Outcome: Mitigates catastrophic forgetting by anchoring the model's internal feature focus.
Attention Transfer vs. Other Distillation Methods
A technical comparison of Attention Transfer against other primary knowledge distillation techniques, highlighting their mechanisms, objectives, and suitability for continual learning and model compression.
| Feature / Mechanism | Attention Transfer | Logit Distillation | Feature Distillation | Hint-Based (FitNets) |
|---|---|---|---|---|
Core Supervisory Signal | Attention maps (e.g., sum of squared activations across channels) | Softened output logits (pre-softmax) | Intermediate feature maps or activations | Outputs of a designated intermediate 'hint' layer |
Primary Objective | Transfer the teacher's spatial focus and contextual saliency | Mimic the teacher's final output probability distribution | Replicate the teacher's internal feature representations | Guide the student's intermediate layer to match a teacher hint layer |
Loss Function | L2 or L1 loss between attention maps | Kullback-Leibler (KL) Divergence between softened outputs | L2 loss, cosine similarity, or perceptual loss between features | L2 loss between student and teacher hint layer outputs |
Information Transferred | Spatial 'where to look' knowledge | Dark knowledge: relative class similarities | Representational knowledge: feature hierarchies | Representational knowledge at a specific layer depth |
Typical Use Case | Vision tasks (CNNs), Transformer attention heads | General classification, model compression | Architectural compression, training thin/deep nets | Training student networks that are deeper/thinner than teacher |
Computational Overhead | Moderate (requires calculating & comparing attention maps) | Low (only final layer outputs) | High (requires storing & comparing large feature tensors) | High (requires forward pass to specific hint layer) |
Effectiveness in Continual Learning (for Retention) | High (preserves spatial reasoning patterns) | Moderate (preserves output behavior) | High (preserves internal feature manifolds) | Moderate to High (depends on hint layer choice) |
Architecture Flexibility | Requires compatible spatial dimensions; adaptable to transformers | Highly flexible; teacher/student can have different architectures | Requires feature map dimension alignment or adapters | Requires careful selection of hint/guided layer pairs |
Frequently Asked Questions
Attention Transfer is a feature distillation technique for compressing or transferring knowledge between neural networks. It focuses on aligning the internal attention patterns of a student model with those of a teacher model, rather than just matching final outputs.
Attention Transfer is a specific feature distillation method where a smaller student model is trained to replicate the attention maps generated by intermediate layers of a larger, pre-trained teacher model. It works by calculating attention maps, often as the sum of squared values across feature map channels at a given layer, and using a loss function (like L2 or L1) to minimize the difference between the teacher's and student's maps. This transfers the teacher's learned focus on salient input features, guiding the student to develop similar representational priorities.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Attention Transfer is a specific method within the broader family of knowledge distillation techniques used for model compression and continual learning. These related concepts define the framework and mechanisms for transferring knowledge from a teacher model to a student.
Knowledge Distillation
Knowledge distillation is a model compression and transfer learning technique where a smaller, more efficient student model is trained to mimic the behavior of a larger, more complex teacher model. The student learns not just from hard labels but from the teacher's softened output probabilities (logits) or intermediate feature representations, capturing richer relational information known as dark knowledge.
Feature Distillation
Feature distillation is a knowledge distillation method where the student model is trained to replicate the intermediate feature maps or activations from specific layers of the teacher model. Unlike logit distillation, it transfers representational knowledge about how the teacher transforms input data. Common techniques include:
- Hint training (e.g., FitNets), where a student 'hint' layer learns from a teacher 'guided' layer.
- Using loss functions like Mean Squared Error (MSE) or Maximum Mean Discrepancy (MMD) to align feature spaces.
Attention Distillation
Attention distillation is a specialized form of feature distillation tailored for transformer-based architectures. The student is trained to mimic the attention maps or patterns of the teacher model. This transfers the teacher's contextual understanding and focus mechanisms. Common approaches include:
- Matching attention matrices from multi-head attention layers.
- Distilling the sum of squared values across channels for spatial attention maps.
- This technique is foundational to models like TinyBERT, which distill attention from BERT's layers.
Teacher-Student Framework
The teacher-student framework is the foundational architecture for knowledge distillation. It consists of:
- A pre-trained, often larger, teacher model that provides supervisory signals.
- A student model (smaller or more efficient) that learns from these signals.
- A distillation loss (e.g., KL Divergence) that measures the discrepancy between teacher and student outputs or features. The framework can be offline (static teacher) or online (co-evolving models), and is central to techniques like Attention Transfer.
Dark Knowledge & Temperature Scaling
Dark knowledge refers to the rich, non-obvious information contained within the softened probability distribution of a trained neural network's logits. It reveals relative similarities between classes (e.g., a 'cat' is more like a 'dog' than a 'truck').
Temperature scaling is the key technique to access this knowledge. A temperature parameter (T > 1) is applied to the softmax function, softening the output distribution and amplifying the dark knowledge. The student model is then trained on these soft targets.
Distillation for Forgetting (Continual Learning)
Distillation for forgetting applies knowledge distillation as a regularization technique in continual learning to mitigate catastrophic forgetting. The current model's own predictions on data from previous tasks are used as soft targets (or a stored old model acts as the teacher) when learning a new task. This penalizes changes to outputs for old tasks. Key algorithms include:
- Learning without Forgetting (LwF): Uses distillation from the model's previous parameters.
- iCaRL: Combines distillation with an exemplar memory and a nearest-mean classification rule.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us