Layer-Specific Attention Masking for Long-Context LLM Memory Limits

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Large language models (LLMs) face memory constraints due to their context windows, particularly in edge deployments, limiting their performance on natural-language tasks, and existing methods to expand context windows are either resource-intensive or yield poor performance.

Innovation Solution

Implementing a variable, layer-specific attention mask generated by a trained mask-generation model during inference, which dynamically focuses the attention window on the most relevant tokens, combined with sparse attention kernels, to enhance the effective attention window without retraining the model.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If the context window size is increased to improve performance on natural-language tasks, then the LLM's ability to maintain coherence over long conversations improves, but the memory resources required (particularly GPU memory) increase significantly

Engineering Contradiction:
Improvecoherence over long conversationsVSAvoidmemory resources
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

The patent extracts and processes only the most relevant tokens from the context window using a trained mask generation model. Instead of treating all tokens equally, the system identifies and extracts a sparse subset of attention-relevant tokens, thereby reducing memory requirements while preserving the ability to maintain coherence over long conversations.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent applies different treatment to different parts of the context window by generating layer-specific attention masks. Each layer of the neural network receives a customized mask that highlights locally relevant tokens, allowing the system to maintain high coherence where needed while reducing memory usage in less critical regions.

Inventive Principle:
Principle #3Local quality

2Reliability

If deep attention mechanisms are used to improve performance, then the quality of natural-language processing improves, but the memory requirements scale quadratically with context length

Engineering Contradiction:
Improveperformance qualityVSAvoidmemory requirements
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

The patent changes the parameter of attention computation from dense to sparse by introducing learned attention masks. These masks modify the attention weights to focus computation on relevant token pairs, transforming the quadratic memory scaling into a more manageable complexity that preserves performance quality.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The patent introduces dynamic attention masks that are generated during inference based on the specific input sequence. Rather than using a static attention pattern, the system adaptively determines which tokens require attention, allowing the attention mechanism to remain high-quality while reducing unnecessary computations and memory usage for irrelevant token pairs.

Inventive Principle:
Principle #15Dynamics

3Quantity of substance

If static or statistically-based attention masks are used to expand context window, then memory usage is reduced, but the performance suffers due to poor adaptability

Engineering Contradiction:
Improvememory usageVSAvoidperformance adaptability
Core Design Contradiction:
Quantity of substanceVSAdaptability or versatility

Solution Approach 1:

The patent implements a self-service mechanism where the mask generation model is trained on the specific LLM's attention patterns and automatically generates appropriate masks during inference. The system serves itself by learning from the model's own attention behavior and applying that knowledge to optimize subsequent processing, thereby maintaining both memory efficiency and performance adaptability.

Inventive Principle:
Principle #25Self-service

Solution Approach 2:

The patent incorporates feedback loops where the attention masks are continuously refined based on the LLM's performance and attention patterns. The mask generation model learns from the interaction between the LLM and the masks, adjusting the masking strategy to better serve the specific model's needs, thus achieving both memory reduction and performance preservation.

Inventive Principle:
Principle #23Feedback

Data Source

PatentUS20250348732A1Memory Efficient Attention Window Expansion For Trained LLMs
Publication Date: 2025.11.13 SAMSUNG ELECTRONICS CO LTD
  • US20250348732A1 patent drawing
  • US20250348732A1 patent drawing
  • US20250348732A1 patent drawing

AI summary

In one embodiment, a method includes predicting, by a decoder of an LLM and in response to an input sequence provided to an encoder of the LLM, s tokens of an output sequence. The method further includes accessing, for each of one or more attention layers of the LLM, a set of attention logits specific to that attention layer and used by the LLM to predict the n most recent tokens of the s tokens; determining, for each of the one or more attention layers and by a trained mask generation model, a layer-specific attention mask for the set of attention logits specific to that attention layer; and predicting, by the decoder of the LLM, the next m tokens of the output sequence using the set of attention logits as masked by the layer-specific attention mask for each layer.