Memorilla-Gemma4-26B-A4B
Latent memory module for quantized Gemma 4
3 min read
An unofficial port of the Memorilla architecture from Stanford SNAP, adapted for the frozen decoder google/gemma-4-26B-A4B-it with 4-bit expert quantization (MoE). Weighing in at around 190M parameters, the module transforms a question and document embeddings (vector representations from Qwen/Qwen3-Embedding-4B) into 16 special soft tokens (trainable continuous vectors) that are prepended to the prompt without modifying the weights of the language model itself. Unlike the original Stanford port for Qwen3-8B, which was trained on four H100 GPUs, this port was trained on a single AMD Strix Halo workstation using 10% of the data and initialized from the second-stage weights of memorilla/Memorilla-Qwen3-8B. It is well-suited for RAG (retrieval-augmented generation) and latent memory researchers looking to compress context for local MoE models.
Key features
- Compactness: The memory module itself takes up only ~190M parameters (183M for Perceiver and 7.2M for the output projection) and generates 16 tokens of dimension 2816 for each question.
- 4-bit MoE compatibility: Trained specifically alongside
gemma-4-26B-A4B-it, which features routed experts compressed to 4 bits. - Rigorous metric breakdown: The author evaluated the model not only in closed-book mode and with correct documents, but also with random documents, revealing where the performance boost comes from context versus question encoding alone.
- Gemma scaling factored in: The √2816 multiplier is already baked into the output projection weights, so tokens are output at the exact scale needed right away.
What you can do
- Explore context compression for RAG: Replace long text chunks with 16 latent tokens when handling factual questions (FactKG, TriviaQA) and summarization (NarrativeQA).
- Run on consumer hardware: Reproduce training or evaluation on unified memory systems like AMD Strix Halo without server clusters.
- Test latent memory hypotheses: Use the evaluation scripts from the author's repository to check the robustness of memory tokens against irrelevant documents.
Example
from memorilla.memory import MemoryModule
memory = MemoryModule.from_pretrained("checkpoints/memorilla_gemma4")
# doc_embeds: [batch, num_docs, 2560] от Qwen3-Embedding-4B
# question_embeds: [batch, 2560]
tokens = memory(doc_embeds, doc_padding_mask, question_embeds) # [batch, 16, 2816]Read more
DetailsBenchmarks (Memory vs Closed book): FactKG — 79.8% vs 67.0% (+12.8), TriviaQA — 63.2% vs 54.0% (+9.2), PubMedQA — 46.0% vs 23.0% (+23.0, though unrelated documents yield a similar increase).
Hardware and training: A single AMD Strix Halo GPU (Radeon 8060S, 64 GB unified memory, Windows ROCm), with peak PyTorch memory usage of 24–26 GB.
Limitations: The repository contains only the module weights (
memory.pt); the Gemma 4 decoder and Qwen3-Embedding-4B encoder must be downloaded separately. It is not suitable for personalization based on user history and has not been tested in full precision.









Comments