How AI Models Change Architecture Without Full Retraining

Image for Can we change an AI model’s architecture without retraining it from scratch?

After studying this material, you should be able to:

  1. Explain the memory limitations of standard Transformer architectures
  2. Distinguish between eidetic and fading memory in AI models
  3. Describe how the "Priming" method converts Transformers into hybrid architectures
  4. Compare different state space models (Mamba-2, GDN, GKA) and their trade-offs
  5. Evaluate why hybrid architectures outperform sliding-window attention
  6. Understand how hybrid models can extend beyond their training context window

Step-by-Step Study Material

Step 1: The Core Problem — Why Transformers Are Expensive

The Memory Tax

Imagine reading a very long book and having to remember every single word perfectly before answering a question. That is essentially what a Transformer does.

Token 1 → Token 2 → Token 3 → ... → Token 100,000
         ↑           ↑                    ↑
    remembered   remembered           remembered
    perfectly    perfectly            perfectly

The KV Cache Explained:

When a Transformer processes text, for each token it creates three vectors:

VectorRoleAnalogy
Query (Q)What this token is looking forA search question
Key (K)What this token offersA file label
Value (V)The actual informationThe file contents

The model stores every Key and Value in a KV Cache to avoid recomputation.

The problem: As context grows, the KV cache grows linearly. More tokens = more memory = slower processing.

Why This Matters Now

AI agents are being asked to:

  • Handle longer conversations
  • Perform deeper reasoning chains
  • Operate more autonomously

Each of these demands more tokens, which means more memory cost.


Step 2: Two Types of Memory — Eidetic vs. Fading

This is the conceptual foundation of the entire article.

Eidetic Memory (Standard Attention)

Definition: Perfect, verbatim recall of every past token

Past tokens:  [T1][T2][T3][T4]...[T10,000]
                ↓   ↓   ↓   ↓        ↓
              ALL stored perfectly in KV cache
              Cache size grows with every new token

Advantages:

  • Enables in-context learning
  • Supports long-document reasoning
  • Powers retrieval-augmented generation (RAG)

Disadvantages:

  • Memory cost scales with input length
  • Becomes prohibitively expensive at 100K+ tokens

Fading Memory (State Space Models)

Definition: A compressed, fixed-size summary of the past

Past tokens:  [T1][T2][T3][T4]...[T10,000]
                         ↓
              Compressed into fixed-size STATE
              State size stays CONSTANT regardless of input length

Advantages:

  • Fixed memory footprint
  • Faster processing

Disadvantages:

  • Lossy compression — some details are forgotten
  • Cannot do perfect verbatim recall

The Key Insight

Not all attention layers need eidetic memory.

Some layers perform long-range retrieval (need eidetic memory). Other layers perform local operations like tracking the current clause (fading memory is sufficient).

Layer Type          | Memory Needed | Example Task
--------------------|---------------|---------------------------
Long-range attention| Eidetic       | "What did the user say 50,000 tokens ago?"
Local attention     | Fading        | "What word comes next in this sentence?"

Step 3: Hybrid Architectures — The Best of Both Worlds

The Design Space Concept

Think of sequence model architectures as points on a map:

PURE TRANSFORMER ←————————————————→ PURE SSM
(all eidetic)    hybrid zone        (all fading)
                 ↑
         Best balance of:
         - Memory efficiency
         - Speed
         - Quality

Three Approaches to Efficient Attention

Before hybrids, researchers tried:

MethodHow It WorksLimitation
Sparse AttentionOnly looks at a subset of past tokensMay miss important tokens
Sliding-Window Attention (SWA)Only keeps the most recent N tokensForgets everything before the window
State Space Models (SSMs)Compresses all history into fixed stateLossy compression

The Hybrid Solution

Hybrid Model Architecture:

Layer 1:  [ATTENTION]  ← eidetic, for long-range retrieval
Layer 2:  [SSM]        ← fading, for local operations  
Layer 3:  [SSM]        ← fading, for local operations
Layer 4:  [ATTENTION]  ← eidetic, for long-range retrieval
Layer 5:  [SSM]        ← fading, for local operations
...

Result: Smaller memory footprint + preserved recall where it actually matters


Step 4: The Priming Method — Converting Without Retraining

The Old Problem

Previously, testing each hybrid configuration required:

  • Training from scratch
  • Trillions of tokens
  • Hundreds of thousands of GPU-hours

This made systematic comparison practically impossible.

The Core Insight Behind Priming

A Transformer is actually a special case of a state space model.

Both attention layers and SSM layers can be expressed as:

Output = (Mixing Matrix) × (Value Sequence)

Attention:  Mixing Matrix = Q × K  (computed dynamically)
SSM:        Mixing Matrix = recurrent state (fixed dimension)

Because of this structural similarity, the learned knowledge in a Transformer's weights can be transferred to an SSM.

The Three Stages of Priming

STAGE 1: LAYER SELECTION
┌─────────────────────────────────────────┐
│ Test each layer: replace with SWA       │
│ If quality drops → needs eidetic memory │
│ If quality holds → candidate for SSM   │
└─────────────────────────────────────────┘
              ↓
STAGE 2: WEIGHT TRANSFER & ALIGNMENT
┌─────────────────────────────────────────┐
│ Copy Q, K, V projections from attention │
│ to SSM input projections                │
│ Run short distillation to align behavior│
└─────────────────────────────────────────┘
              ↓
STAGE 3: END-TO-END ADAPTATION
┌─────────────────────────────────────────┐
│ Fine-tune the full hybrid model         │
│ All layers coadapt together             │
│ Uses <0.5% of original training budget  │
└─────────────────────────────────────────┘

The Hankel Rank Concept

To formally determine if a layer can be converted, researchers use Hankel rank:

Hankel rank measures how much information must pass through the state bottleneck — essentially, the minimum SSM state size needed to perfectly replicate what an attention layer does.

  • Low Hankel rank → Layer does simple, local operations → Good SSM candidate
  • High Hankel rank → Layer does complex, long-range retrieval → Keep as attention

Step 5: Comparing State Space Models

Three SSM types were tested. They differ in how they update their fixed-size state.

Mamba-2 — Uniform Decay

State update:
New State = (decay_factor × Old State) + New Token

Example:
Old State: [0.8, 0.6, 0.9, 0.7]  ← all past information
Decay:     × 0.9 applied to ALL
New State: [0.72, 0.54, 0.81, 0.63] + new token contribution

Analogy: Like a camera with a uniform fade — everything gets dimmer at the same rate.

Limitation: Cannot selectively remember important things and forget unimportant ones.

Gated DeltaNet (GDN) — Targeted Updates

State update:
1. Find the slot associated with current key
2. ERASE that specific slot
3. Write new information there
4. Rest of state is unchanged (no uniform decay)

Analogy: Like a whiteboard where you can erase and rewrite specific sections without affecting others.

Advantage over Mamba-2: Can revise specific associations without degrading everything else.

Gated KalmaNet (GKA) — History-Aware Updates

State update:
1. Consider statistics of ALL past keys
2. Use this cumulative history to determine what to erase
3. Write new information with history-informed precision

Analogy: Like an expert editor who understands the entire document's themes before deciding what to revise.

Unique feature: Variable computation at inference time (adjustable iteration count).

Performance Hierarchy

Quality:  GKA > GDN > Mamba-2

The gap WIDENS on long-context tasks
The gap NARROWS on short-context tasks

This matches the theoretical expressiveness hierarchy — more sophisticated state management = better performance when compression quality matters most.


Step 6: Surprising Finding — Fading Beats Windowed Memory

The Intuitive Expectation (Wrong)

"Surely keeping recent tokens perfectly (SWA) is better than compressing everything (SSM)?"

What Actually Happened

Test: Long-context benchmarks
Memory budget: SWA given 2-4× MORE memory than SSM state

Result:
SSM hybrid:  ████████████████████  (better)
SWA hybrid:  ████████████          (worse, despite more memory)

Why This Happens

SWA's problem: It has a hard cutoff. Anything outside the window is completely gone.

SWA with window=1000:
Tokens 1-9000:   [COMPLETELY FORGOTTEN]
Tokens 9001-10000: [PERFECTLY REMEMBERED]

SSM's advantage: It compresses everything, even if imperfectly.

SSM with equivalent memory:
Tokens 1-9000:   [DIMLY REMEMBERED - some signal preserved]
Tokens 9001-10000: [CLEARLY REMEMBERED - recent = stronger signal]

Key principle: A good lossy summary of everything beats a perfect recording of only the recent past.


Step 7: Practical Performance Gains

Throughput Improvements

Context Length | Speedup (32B model) | Speedup (8B model)
16K tokens     | 1.50×               | 1.94×
128K tokens    | 2.06×               | 2.29×

Why does speedup grow with context length?

At long context, reading the KV cache dominates computation time. Halving the cache size roughly doubles how many sequences can be processed simultaneously.

Real-World Reasoning Speed

On AIME 2025 math competition problems:

Standard Transformer:  ████████████████████  (baseline)
GKA Hybrid:           ████████████████████  (same accuracy)
                      but reaches accuracy thresholds 1.2-1.6× faster

Both models generate similarly long reasoning traces (~14,000 tokens median), meaning the hybrid isn't cutting corners — it's genuinely faster at the same quality level.

GKA's Variable Computation Knob

Iterations | Accuracy Loss | Speed Gain
30 (full)  | 0%           | baseline
10 (fast)  | ~1%          | +10% faster decoding

Practical implication: One trained model can serve multiple use cases:

High-accuracy deployment:  run 30 iterations
Balanced deployment:       run 20 iterations  
Low-latency deployment:    run 10 iterations

No need to maintain separate model variants.


Step 8: Extending Beyond the Training Window

The Challenge

Primed hybrids natively support 128K tokens. But real-world use cases often exceed this:

  • Long legal documents
  • Large codebases
  • Extended agent sessions

The State Composition Method

Long document (256K tokens):
┌──────────────────────────────────────────────────┐
│                  Full Document                    │
└──────────────────────────────────────────────────┘
              ↓ Split into chunks
┌─────────────┐  ┌─────────────┐
│  Chunk 1    │  │  Chunk 2    │
│ (128K)      │  │ (128K)      │
└─────────────┘  └─────────────┘
       ↓ Process independently in parallel
┌─────────────┐  ┌─────────────┐
│ KV Cache 1  │  │ KV Cache 2  │
│ SSM State 1 │  │ SSM State 2 │
└─────────────┘  └─────────────┘
       ↓ Combine
┌──────────────────────────────┐
│ Concatenated KV Caches       │
│ Weighted-averaged SSM States │
└──────────────────────────────┘

Result: 128K → 256K context with no additional training, while preserving the GKA > GDN > Mamba-2 quality hierarchy.


Concept Summary Map

PROBLEM: Transformers have growing memory cost
              ↓
INSIGHT: Not all layers need perfect recall
              ↓
SOLUTION: Hybrid architectures (eidetic + fading)
              ↓
BARRIER: Testing hybrids requires full retraining
              ↓
BREAKTHROUGH: Priming (reuse Transformer weights)
              ↓
FINDING 1: GKA > GDN > Mamba-2 for SSM layers
FINDING 2: SSM fading memory > SWA windowed memory
FINDING 3: 2× throughput at 128K context, same quality
FINDING 4: GKA offers variable speed-accuracy trade-off
FINDING 5: Context can extend to 256K without retraining

Self-Check Questions

  1. Why does the KV cache grow with context length, and why is this a problem?
  2. What is the difference between eidetic and fading memory? Give an example of when each is appropriate.
  3. Explain in your own words why a Transformer's weights can be transferred to an SSM (the structural similarity argument).
  4. What are the three stages of priming, and what happens in each?
  5. Why does GKA outperform Mamba-2 on long-context tasks specifically?
  6. Why does SSM-based fading memory outperform sliding-window attention, even with less memory budget?
  7. How does GKA's variable computation enable a single model to serve multiple latency tiers?

More to study