Downloads · 30 days
0
athrael-soju/ColGemma4-E4B-IT-Base
ColGemma4-E4B-IT-Base is a visual document retrieval model from athrael-soju. Use it for the visual document retrieval task on the model card, and read the license before you ship it in a product. It is set up for colpali_engine. The card lists the license as apache-2.0.
<p align="center" <img src="colgemma.png" alt="ColGemma-4" width="500"/ </p
Downloads · 30 days
0
Access
Public
Updated May 4, 2026
Repo size
1.7 GB
Likes
2
Public
Click a slice to open those files.
.pt1.3 GB · 80%
From the Hugging Face model README
See also: ColGemma4-E2B-IT-Base (smaller 2.3B-effective variant)
ColGemma4 is a visual document retrieval model built on Google's Gemma 4 E4B (9B params, 4.5B effective). It generates ColBERT-style multi-vector representations of document images and text queries for late-interaction retrieval.
Single-seed LoRA adapter trained with ColbertLoss, no hard negatives, no model merging.
Built following the ColPali architecture pattern, adapted for Gemma 4's multimodal architecture.
| Property | Value |
|---|---|
| Base model | google/gemma-4-E4B-it (9B total, 4.5B effective) |
| Architecture | ColBERT late-interaction over Gemma 4 VLM |
| Embedding dim | 128 |
| Visual tokens | 1120 (max soft tokens) |
| Fine-tuning | LoRA (r=32, alpha=32, dropout=0.1) |
| Trainable params | 73.4M (0.95% of total) |
| Projection | Random-init linear (hidden_size -> 128), not trained |
| Training loss | ColbertLoss (temperature=0.02, in-batch negatives only) |
| Precision | BF16 |
All scores are nDCG@5 on the ViDoRe benchmark.
| Task | nDCG@5 | nDCG@10 |
|---|---|---|
| ArxivQA | 84.53 | 85.57 |
| DocVQA | 57.70 | 59.87 |
| InfoVQA | 90.84 | 91.12 |
| ShiftProject | 84.45 | 85.17 |
| SyntheticDocQA - AI | 97.89 | 97.89 |
| SyntheticDocQA - Energy | 94.40 | 95.01 |
| SyntheticDocQA - Government | 96.58 | 96.58 |
| SyntheticDocQA - Healthcare | 97.89 | 97.89 |
| Tabfquad | 92.37 | 92.84 |
| Tatdqa | 76.72 | 78.93 |
| Average | 87.34 | 88.09 |
| Task | nDCG@5 | nDCG@10 |
|---|---|---|
| BioMedical Lectures | 57.06 | 59.48 |
| ESG Reports - HL | 57.96 | 61.07 |
| ESG Reports | 47.51 | 51.59 |
| Economics Reports | 39.76 | 42.46 |
| Average | 50.57 | 53.65 |
| Task | nDCG@5 | nDCG@10 |
|---|---|---|
| Computer Science | 63.55 | 67.76 |
| Energy | 59.64 | 62.55 |
| Finance En | 51.05 | 53.96 |
| Finance Fr | 41.05 | 44.64 |
| HR | 52.60 | 55.17 |
| Pharmaceuticals | 55.98 | 57.42 |
| Physics | 43.37 | 46.11 |
| Industrial | 41.52 | 42.98 |
| Average | 51.10 | 53.82 |
pip install colpali-engine transformers torch peft
import torch
from colgemma4 import ColGemma4, ColGemma4Processor
model = ColGemma4.from_pretrained(
"athrael-soju/ColGemma4-E4B-IT-Base",
torch_dtype=torch.bfloat16,
device_map="auto",
attn_implementation="sdpa",
ignore_mismatched_sizes=True,
)
processor = ColGemma4Processor.from_pretrained(
"athrael-soju/ColGemma4-E4B-IT-Base",
max_num_visual_tokens=1120,
)
from PIL import Image
images = [Image.open("page1.png"), Image.open("page2.png")]
batch_doc = processor.process_images(images)
batch_doc = {k: v.to(model.device) for k, v in batch_doc.items()}
with torch.no_grad():
doc_embeddings = model(**batch_doc)
queries = ["What is the revenue for Q3 2024?"]
batch_query = processor.process_queries(queries)
batch_query = {k: v.to(model.device) for k, v in batch_query.items()}
with torch.no_grad():
query_embeddings = model(**batch_query)
scores = processor.score(query_embeddings, doc_embeddings)
Base model: google/gemma-4-E4B-it
Loss: ColbertLoss (temperature=0.02)
Hard negatives: none
Batch size per GPU: 64
GPUs: 8
Gradient accumulation: 1
Effective batch size: 512 (64 x 8)
In-batch negatives: 512
LoRA:
r: 32
alpha: 32
dropout: 0.1
target_modules: "language_model.*(down_proj|gate_proj|up_proj|k_proj|q_proj|v_proj|o_proj)"
Learning rate: 2e-4 (cosine schedule, 8% warmup)
Weight decay: 0.02
Epochs: 1
Steps: 1,512
Visual tokens: 1120
Attention: Bidirectional (all 42 layers patched)
Gradient checkpointing: enabled
Precision: BF16
Trained on ~774K query-document pairs from publicly available datasets:
vidore/colpali_train_setopenbmb/VisRAG-Ret-Train-Synthetic-dataopenbmb/VisRAG-Ret-Train-In-domain-datallamaindex/vdr-multilingual-train (en/de/es/fr/it subsets)vidore/tatdqa_trainvidore/tabfquad_train_setIf you're building on this model or training your own ColGemma4, here's what we learned along the way.
F.one_hot(positions, num_classes=10240) which allocates ~314 GB at batch=32 with 1120 tokens. Replacing with F.embedding is mathematically identical and saves ~106 GB/GPU. Required for batch sizes above 8.
# In Gemma4VisionEncoder._position_embeddings:
# Replace: one_hot = F.one_hot(clamped_positions, num_classes=self.position_embedding_size)
# With: return F.embedding(clamped_positions, self.position_embedding_table)
use_cache - Gemma 4 E4B has 18 of 42 text layers (24-41) that reuse K/V from 2 donor layers (22 and 23) when caching is enabled. During training, always set use_cache=False to ensure every layer computes its own K/V and all LoRA weights are active. At inference time, set use_cache=True so the KV-sharing architecture works as designed.attn_implementation="sdpa" instead.custom_text_proj alone - The 128-dim projection is randomly initialized and works best untrained. Both LoRA-targeting and modules_to_save caused regressions in our experiments. The random projection provides a consistent mapping without overfitting.grad_accum=1 with contrastive losses - all_gather only collects the current micro-batch, so accumulation steps halve your in-batch negatives. Training loss looks deceptively good but eval regresses. Use the largest batch that fits with grad_accum=1.torch.compile - It adds _orig_mod. to weight keys, breaking PEFT adapter loading at eval time. Scores drop to near-zero despite healthy training loss.ignore_mismatched_sizes=True will initialize mismatched weights to random without any error. Sanity check: loss at step 0 should be near log(batch_size) (~6.2 for batch 512), and grad norms should be 5-20. If grad norms are in the thousands, weights didn't load correctly.This repo includes lm_head.pt, the saved language model head from the base model. Combined with the LoRA adapter, this enables the HydraGemma4 dual-head architecture supporting both retrieval (ColBERT embeddings) and generation (text output) from the same base model.
@misc{colgemma4,
title={ColGemma4: Visual Document Retrieval with Gemma 4},
author={Athrael Soju},
year={2026},
url={https://huggingface.co/athrael-soju/ColGemma4-E4B-IT-Base}
}