DEV Community

oooocean66
oooocean66

Posted on

Why Do the Latest LLMs Choose a Hybrid Structure? Unraveling the Role Division of Attention through Gemma and Qwen

Currently, the latest LLMs such as Qwen, Nemotron, Gemma-4, and LFM 2.5 are processing at high speed and accurately while keeping GPU costs down, without causing the KV cache to explode even when large volumes of text are incorporated as context information.

However, engineers, hasn't this astonishing performance become completely "taken for granted," and aren't opportunities to care about the evolution of the internal structure behind it decreasing, I wonder?

In this article, I will explain, using diagrams for each model, how the "weaknesses of conventional GQA (Grouped Query Attention)" exposed by changes in the environment such as "long-contextualization of contexts" due to the spread of RAG (Retrieval Augmented Generation), etc., were overcome, and how they evolved into the "hybrid attention structure" such as "Condensation Layer + Global Layer" and "Local Layer + Global Layer" that are currently becoming mainstream.

Furthermore, in this article, I intentionally do not delve into deep areas such as complex mathematical proofs like those in papers or low-layer implementation codes like CUDA. The purpose is strictly to overlook "what kind of logical structure and role division each model has internally" and to intuitively grasp the overall picture.

I would be happy if this is read by those who, like me, have the intellectual curiosity of wanting to "first roughly know the contents of the black box of the latest LLMs that we use as a matter of course every day, as a concept."

Introduction

A Crucial Component Then and Now: Grouped Query Attention

I recognize that the model that established the structure of current LLMs, it is no exaggeration to say, is the LLaMa 2 series released by Meta.

Among them, Grouped Query Attention (GQA) is used as an attention structure to grasp the entire text.

LLaMa 2 combined GQA with a mechanism called RoPE (Rotary Positional Embedding), which correctly conveys the positional information of characters even in long-text structures, and came into the limelight as a very sophisticated Transformer architecture at the time.

Even now, GQA is valued along with RoPE as an important component for accurately grasping the entire text structure.

Figure 1 Structure of Grouped Query Attention
Figure 1 Structure of Grouped Query Attention

Weaknesses of Grouped Query Attention

The structure called GQA used in the LLaMa architecture is a structure that is still heavily used today because of its high functionality and accuracy. However, there is a problem that the more the context size is expanded, the more the KV cache capacity increases.

The capacity calculation formula for the KV cache is as follows.

ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 58: …\times \text{kv_̲heads} \times \…
  • layers : Number of layers using GQA
  • kv_heads : Number of KV heads
  • head_dim : Dimensionality of KV heads
  • seq_len : Context length
  • batch_size : Batch size
  • bytes_per_element : Number of bytes allocated to each element (depends on numerical precision)

Since the formula consists entirely of multiplication, for example, if the number of layers doubles, its capacity also doubles, and if the context length doubles, an even further doubled capacity will be required.

If hypothetically the context length is set to 256k in the LLaMa-2-70B-it architecture, indeed the following capacity will become necessary.

Table 1 Values required for various cache capacity calculations of LLaMa 2

Variable Value
layers 80
kv_heads 8
head_dim 128
batch_size 1
bytes_per_element 2 (Assuming FP16)
KV Cache Capacity=2×80×8×128×262144×1×2=85,899,345,920 Bytes=80 GiB \text{KV Cache Capacity} = 2 \times 80 \times 8 \times 128 \times 262144 \times 1 \times 2 = 85,899,345,920 \text{ Bytes} = 80 \text{ GiB}

In this way, a very large capacity becomes necessary, and as a single GPU, a high-end graphics board at the time, at a minimum the NVIDIA A100 80GB, becomes necessary just for the KV cache. (It is inferred that it would probably overflow in reality.)

Also, as another weakness, GQA is essentially an attention structure that improved the mechanism of Multi-head Self-Attention (MHA), which traditionally had processing efficiency problems, but its calculation cost is no different from traditional attention structures, being O(n2)O(n^2) ( nn : context length). Because of this, by passing through many GQAs, there is a problem that calculation cost rises and response output speed decreases.

At the time, with the advent of RAG (Retrieval Augmented Generation), the volume of retrieved information became very large, so it was also an era where the expansion of context size was very strongly demanded.

Even in my own experience, rather than using a vector search engine to quote documents divided into chunk units, incorporating the document itself entirely as context information yielded much higher response accuracy, and there were many cases where I sighed, "I wish I could stuff the whole document in..."

I wish I could include longer texts as context information; it seems there were a great many such needs.

Illustration: Context Window Limit

What is a Hybrid Attention Structure?

That is where the "Hybrid Attention Structure" appeared.

A hybrid attention structure is a mechanism that uses different attention structures per layer in the preliminary stages among the layer structures that form the LLM. The attention structure has the effect of deciphering and linking the relationships between tokens.

It is a structure born to clear various problems of architectures using GQA.

Attention Structures Broadly Divided into Two Types

It is a hybrid structure often adopted currently, but it is broadly classified into 2 types.

One is the "Condensation Layer + Global Layer" configuration.

In the condensation layer, it captures the overall information and operates by compressing and packing that information into a fixed memory space. The global layer expands that result while performing the refinement of blurred information by identifying slight differences in the packed information, neatly shaping the overall information.

Figure 2 Concept of Condensation Layer + Global Layer Configuration
Figure 2 Concept of Condensation Layer + Global Layer Configuration

The other is the "Local Layer + Global Layer" configuration.

This refers to information locally using a structure called Sliding Window Attention (SWA), and it does not care about other information. It refers to information through a window of a determined size respectively, and accurately captures its contents. The global layer accumulates that information and grasps the overall information as a result.

Figure 3 Concept of Local Layer + Global Layer
Figure 3 Concept of Local Layer + Global Layer

Models with Condensation Layer + Global Layer Configuration

Then, first I will introduce models with the "Condensation Layer + Global Layer configuration."

Because the condensation layers used in these models use a state space model, they often take a special configuration, so their logical configuration is also illustrated together.

NVIDIA Nemotron Series (Mamba-2 Architecture)

At NVIDIA, as a model structure enabling inference while lowering calculation costs compared to transformers, they have been researching the State Space Model (SSM) from an early stage, and as a culmination of that, created an architecture called Mamba, releasing the Nemotron series as LLMs utilizing it with open weights.

Figure 4 Structure of the Nemotron 3 Nano 30B Model using Mamba-2
Figure 4 Structure of the Nemotron 3 Nano 30B Model using Mamba-2

Such mechanisms are called linear transformers, aiming for application to long contexts and improvement of computational efficiency. However, when writing new information into memory, because it used a simple addition method (Additive Update), the memory easily saturated, and in particular, there was the issue that the capability for Associative Recall, which is "accurately recalling a specific value for a specific key," was low, and I remember that unfortunately not very satisfactory results were obtained.

Alibaba Qwen Series (3.5 and later: Gated DeltaNet Architecture)

The "Gated DeltaNet" architecture, which combined the aforementioned Mamba-2 with a previously existing architecture called DeltaNet, was developed through joint research by MIT and NVIDIA, and its paper was also published in December 2024.

Figure 5 Gated DeltaNet Logo
Figure 5 Gated DeltaNet Logo

It is said that Gated DeltaNet is achieving significant evolution by adding the precise rewriting capability (delta rule) that DeltaNet has to the adaptive forgetting capability that Mamba-2 has.

It was the Qwen team of the Alibaba Group that quickly caught this mechanism and applied it to LLMs. Architectures for Qwen3.5 and later operate by combining this Gated DeltaNet and GQA at a 3:1 ratio.

Figure 6 Structure of Qwen3.5 Series Models using Gated DeltaNet
Figure 6 Structure of Qwen3.5 Series Models using Gated DeltaNet

Moonshot AI Kimi-K3

From Moonshot AI, a Chinese company like Qwen's developer, a model called Kimi-K3 appeared. This is famous as a model that hammered out performance standing shoulder-to-shoulder with frontier models from America, but this also possesses a similar mechanism.

Figure 7 Cited from Kimi Linear: An expressive, efficient attention architecture
Figure 7 Cited from Kimi Linear: An expressive, efficient attention architecture

The part indicated by the abbreviation "KDA" in the above figure is called Kimi Delta Attention, which becomes its core, and the structure itself combining Mamba-2 and Delta Net is quite close to that of Qwen.

Actually, this KDA is an improved mechanism of Gated DeltaNet, and by further deepening the forgetting capability possessed by GDN and introducing individual attenuation per channel (an element of information) (Channel-wise decay), it has acquired the capability to precisely control the retention period of memory for each dimension.

The integration layer has a structure handled by Multi-Head Latent Attention (MLA), and this has a configuration that does not connect RoPE. Because it does not connect to RoPE, it is perhaps a mechanism dedicated entirely to overall integration.

Multi-Head Latent Attention is a technology created by DeepSeek-AI, and it has a structure where a layer called "Latent" is sandwiched between layers where vectors are incorporated divided into Query/Key/Value.

Figure 8 Structure of Multi-Head Latent Attention
Figure 8 Structure of Multi-Head Latent Attention

I think it can be said to be a model that aims for further efficiency by incorporating a mechanism to compress the integrating side as well into the mechanism originally aiming for compression with Mamba-2 and DeltaNet.

The Appearance of Gated DeltaNet-2

A further linear attention structure has been proposed by NVIDIA. Its name is the Gated DeltaNet-2 structure, and as the name implies, it is an enhancement by NVIDIA itself of the originally existing Gated DeltaNet.

Diagram: Gated DeltaNet-2 Architecture

The characteristic is that in addition to the logarithmic decay projection α\alpha and the channel-wise erase gate β\beta that were conventionally configured, a channel-wise write gate ww has been added. And, the sigmoid function SiLU is applied to β\beta and ww .

In GDN and KDA, the forgetting of old information and writing of new information operated as one body, making it a specification that moved exactly as "information rewriting."

In GDN2, that capability is explicitly separated, and by individually configuring gates for the actions of "erasing old information" and "writing new information," each act was made so it could be performed independently.

Thereby, situations such as "having to forget something to write new information" or "having to insert some information to forget something" are improved, and it has become possible to control information without memory contention or interference.

Models with Local Layer + Global Layer Configuration

Next, I will introduce models with the "Local Layer + Global Layer" configuration.

SWA is almost identical in logical structure to GQA, and what differs greatly is the point that the size of the area referring to that information is fixed. To say specifically what differs, it is the difference in the mask matrix within the Attention structure.

The following indicates the internal structure of the Self-Attention layer, which is the origin of GQA.

Figure 9 Position in the Attention Structure Performing Calculation with Mask Matrix
Figure 9 Position in the Attention Structure Performing Calculation with Mask Matrix

As in the above figure, the dot product of the mask matrix and state vector is performed inside Self-Attention. Usually, a special matrix called a lower triangular matrix is applied. By doing so, future tokens are excluded. This movement is identical to what is performed in the global layer.

However, in SWA, a special mask matrix where only a certain determined section is 1 is used.

Figure 10 Different Mask Matrices between Local Layer and Global Layer
Figure 10 Different Mask Matrices between Local Layer and Global Layer

Meta Muse Glimmer 30B

The 30B model named Muse Glimmer released for the first time in a while by Meta takes a typical "Local Layer + Global Layer type" hybrid attention structure.

Figure 11 Structure of Muse Glimmer 30B
Figure 11 Structure of Muse Glimmer 30B

This, differing from what I introduced until just now, has its role clearly composed of "Local Layer + Global Layer." The parts written as SA mean it is SWA. It places main emphasis on memory reduction and calculation cost reduction, and is specialized in accurately grasping information within a certain fixed range. In the case of Muse Glimmer, because it is set to 2,048, it bears the role of accurately grasping information for 2,048 tokens.

The part written as FA points to "Full Attention (practically similar to GQA)," and this handles grasping overall information, but here processing without using RoPE takes place, and it is configured strictly specialized for precisely seizing the overall information.

Also, the ratio is assembled with a combination of "a small number of SWA and Full Attention" similar to the Qwen series, and that ratio is 3:1.

To allow processing as lightly as possible, Full Attention (GQA) has the number of heads and dimensions set on the low side, and because of that, it is expected that the appearance frequency of Full Attention (GQA) becomes high.

Google Gemma-4

This model, which it seems many already know. This model is also a model with a "Local Layer + Global Layer" configuration. The Window size is 1,024.

Figure 12 Model Structure of Gemma-4
Figure 12 Model Structure of Gemma-4

This has a very high ratio of SWA, and that ratio is 5:1. The Global Attention (GQA) layer, which becomes the global layer, has quite a rich configuration, and the number of heads and dimensions handled there are set high. It is thought that it is assembled to firmly grasp the entire information consolidated by many SWA layers, perhaps.

RoPE takes two different RoPE configurations, and it is assembled so that something called proportional RoPE, which is said to be very strong for super context, is applied to Global Attention (GQA). Besides that, measures such as KV cache sharing and Embedding information sharing are taken, and it is made to firmly care for parts where semantic information tends to fade when it becomes a long context.

Liquid AI LFM 2.5 Series

A model possessing a unique "Local Layer + Global Layer" type attention structure distinct from this also exists. That is the Liquid Foundation Models put up by Liquid AI.

The figure below is the structure diagram of a model named LFM2.5-8B-A1B, which is one of them.

Figure 13 Model Structure of LFM2.5-8B-A1B
Figure 13 Model Structure of LFM2.5-8B-A1B

The feature is that it uses a new mechanism called Gated Short Convolution Block, which further simplified the SSM that becomes the core positioning in the Mamba series. It is said that this layer plays the role of locally filtering information and blending between tokens. Because of that, as a classification, it is classified into the "Local Layer + Global Layer" type.

The GSC layer connects with the FFN (Feed Forward Network) of the Dense layer until it passes GQA once, and after that it has a special structure connecting with the FFN of the MoE layer, but this is said to be because in the early stage the structure of the MoE (Mixture of Experts) layer is almost useless, and there is a need to properly perform brute-force processing with memory and fully connected layers.

Through thorough weight reduction using this GSC, it has obtained response speeds that can be called astonishing, and realizes high-speed output of 100.18 tok/s even on an entry-class older GPU, NVIDIA GeForce RTX 3050 (VRAM 8GB).

Although its ability concerning tool utilization as an agent is very weak, it possesses an ability for text proofreading and summarization that can be called outstanding, and expectations can be held going forward.

At Liquid AI, they continuously push out various super-lightweight models, and recently brought out a model named LFM2.5-VL-3B which is also usable as multimodal.

Also, in the latter half of October 2026, the LFM3 series appeared, and in LFM3-1.7B among them, it has changed to a structure like the following.

Figure 14 Architecture of LFM3-1.7B
Figure 14 Architecture of LFM3-1.7B

The configuration that was composed of GSC+GQA in LFM2.5 came to be composed of 3 types: GSC+GQA+SWA (Sliding Window Attention) in LFM3. By this, it became able to catch local information more, and its maximum context size has expanded from 128K tokens to 256K tokens.

In actual inference, the feeling of lacking ability cannot be denied yet, but even with a lightweight architecture and small number of parameters, it became able to firmly make movements close to an agent AI, and is expected as a model for edge devices in the future.

What are the Advantages of a Hybrid Model?

Why did hybrid models start to become popular? At least at the present moment, the aim is to expand the maximum context size longer.

Expansion of Context Length through Reduction of KV Cache Capacity

Among that, several methods to reduce memory consumption have been devised. One of them is a technology called Sliding Window, and the technology called Gated DeltaNet. These are technologies that, when seeking the KV cache, fit the "sequence length: context length," which is a factor increasing endlessly, into a certain fixed size.

By giving it a function of "it doesn't have to grasp the entirety, so it will accurately grasp at least partial area information," mechanisms where it was possible to lower calculation costs and fix the KV cache size had been devised. (Details of the mechanism are described later.)

However, models composed only of those layers were far too lacking in ability to use as an LLM, and did not reach the point of successfully outputting results.

However, by alternately arranging this and GQA at a fixed ratio, it led to a massive reduction in the KV cache.

For example, in the case of Qwen, because it arranges Gated DeltaNet and GQA at 3:1, the number of its GQAs is reduced to 1/4. In other words, if the KV cache capacity is based on the capacity attempted to assemble with the LLaMa 2 architecture mentioned earlier, it decreases from 80GB to 20GB+ α\alpha . Actually, Gated DeltaNet is said to be a mechanism making KV cache unnecessary, and α=0\alpha=0 . That is to say, the KV cache requirement quantity neatly becomes 1/4.

For example, in the case of a structure like Gemma-4, it arranges SWA and GQA at 5:1. Because of that, the number of its GQAs is reduced to 1/6. Looking similarly, it becomes 80GB →\rightarrow 13.3GB + α\alpha .

Regarding Sliding Window, in the case of Gemma-4 it is 1,024, so calculating just for 1,024 tokens, its KV cache capacity will suffice with:

2×80×8×128×1024×1×2=335,544,320 Bytes≈320 MiB 2 \times 80 \times 8 \times 128 \times 1024 \times 1 \times 2 = 335,544,320 \text{ Bytes} \approx 320 \text{ MiB}

Therefore, it becomes 13.3 GiB+0.32 GiB=13.62 GiB13.3 \text{ GiB} + 0.32 \text{ GiB} = 13.62 \text{ GiB} .

Improvement of Computational Efficiency

At the same time, mechanisms like GDN and SWA are also considered regarding computational efficiency; in the case of GDN, its computational order has become O(n)O(n) , and in the case of SWA, although there is no change in order, it suffices if it calculates just for the window size within it, so the actual number of calculations is vastly reduced.

Only GQA is what must properly calculate at O(n2)O(n^2) , and even if context length gets large, its number of calculations becomes hard to increase, and as a result, response output speed will also vastly improve.

The Surprisingly Long History of Hybrid Attention Structures

Production-Class Hybrid Models in 2024

The hybrid attention structure is one of the architectures that has come to be heard often lately, but actually it is an architecture that has existed since relatively long ago.

Among them, the model possessing the first hybrid attention mechanism that appeared as the first production-grade model is "Jamba" developed by Israel's AI21 Labs. What appeared was in March 2024.

This model took a structure with a hybrid configuration of an architecture called Mamba, which is the predecessor of Mamba-2, and an architecture called Transformer.

It was designed aiming to maintain quality close to Transformer-based models while improving memory consumption and inference speed when handling long contexts, and is said to have surprised experts at the time.

Actually, it hoisted that the maximum context length already supported up to 256k since this time. However, because its strengths were biased towards long-text processing and supported languages were few, etc., I remember that it did not catch the eye of Japanese users much in particular.

Was Gemma-2 Actually a Hybrid Model too!?

To name models from famous places we often see, Gemma-2 (2024) and Gemma-3 (2025) released by Google DeepMind are hybrid attention models.

In Gemma-2, Sliding Window Attention handling the role of local attention and Global Attention handling the role of global attention are alternately arranged, and its window width was 4096. Gemma-3 arranged this changing the ratio to 5:1, and its window width was also narrowed to 1024 tokens.

Between Gemma-2 and Gemma-3, it seems there were structural differences and differences in effects expected thereby as follows.

Item Gemma 2 Gemma 3
Context Length 8K (8,192 tokens) Maximum 128K (131,072 tokens)
Supported Modality Text-centric Multimodal (Text + Image)
Local:Global Ratio 1 : 1 (Alternating) 5 : 1 (1 Global layer to 5 Local layers)
Sliding Window Width 4,096 tokens 1,024 tokens
Aim Performance improvement Adaptation to super-long text

Table 2 Comparison of Gemma-2 and Gemma-3

Figure 15 Model Structure of Gemma-2, Gemma-3
Figure 15 Model Structure of Gemma-2, Gemma-3

At the time, I was performing adjustments such as trying to fine-tune Gemma-2 to give it character traits and making it hold memory as internal company terms, but particularly I was made to suffer bitter hardships by the shortness of Gemma-2's context size, and I once investigated desperately how I could expand this.

With that constraint suddenly relaxed in Gemma-3, perhaps it was that in Gemma-2 such long-text contexts would not enter to that extent, so effort was not poured there very much.

However, what quickly supported a super-long context of 1 million characters is, to hide nothing, Google's Gemini series. Perhaps the technology itself was already established in a form like this, and the results of diverting that technology in a different directional orientation are incorporated into Gemma-2.

Conclusion

As we have seen so far, the hybrid attention structure is a form of extremely rational evolution born to break down the definitive walls of "explosive bloating of KV cache" and "increase of computational costs accompanying O(n2)O(n^2) " that the conventional Transformer (GQA) faced.

Rather than referring to the entirety in all layers, by establishing a clear "role division" of dramatically compressing and fixing the majority of computational costs and memory consumption via the "Condensation Layer (GDN, etc.)" and "Local Layer (SWA)," and guaranteeing the integration of overall information and smooth grasp of context via the "Global Layer (GQA)" placed at key points... super-long text processing of the 256k class, which was once hopeless to operate on a single GPU, came to operate nimbly with realistic hardware resources (around a dozen GiB). Now, that context size has indeed entered the territory of 1 million tokens, in other words, 1M tokens.

As open-weight models, this approach, starting from the pioneering challenge by "Jamba" in early 2024, is achieving rapid evolution, such as refinement of ratios in the Gemma series (from 1:1 to 5:1), heightening of peripheral mechanisms like Dual RoPE and embedding sharing, and furthermore the overcoming of associative memory by Gated DeltaNet adopted by the Qwen series.

Currently, when long-text context processing ability and multimodalization have become standard, what governs the true capability and inference efficiency of a model is none other than exactly the design power of such hybrid structures behind the scenes. It is considered that evolution in this field will continue going forward, such as further improvement of computational efficiency and fusion of new state space models.

I would be happy if this article unravels the logical structure of the latest LLM architectures that are becoming complex, and becomes an aid in future model selection and utilization.

References

* Gated DeltaNet-2: Decoupling Erase and Write in Linear Attention - Ali Hatamizadeh, Yejin Choi, Jan Kautz (NVIDIA)

This article is an English adaptation of the original Japanese post published on Zenn: "なぜ最新LLMはハイブリッド構造を選ぶのか?GemmaやQwenから紐解くアテンションの役割分担", by Yuichi Tominaga.

Top comments (0)