Views
No views yet

See also: ColGemma4-E4B-IT-Base (larger 4.5B-effective variant)
Built following the ColPali architecture pattern, adapted for Gemma 4's multimodal architecture.
| Property | Value |
|---|---|
| Base model | google/gemma-4-E2B-it (5.1B total, 2.3B 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 | 50.7M (1.04% of total) |
| Projection | Random-init linear (hidden_size → 128), not trained |
| Training loss | ColbertLoss (temperature=0.02, in-batch negatives only) |
| Precision | BF16 |
| Task | nDCG@5 | nDCG@10 |
|---|---|---|
| ArxivQA | 78.54 | 80.12 |
| DocVQA | 52.43 | 55.86 |
| InfoVQA | 87.11 | 87.88 |
| ShiftProject | 81.34 | 82.29 |
| SyntheticDocQA - AI | 98.16 | 98.16 |
| SyntheticDocQA - Energy | 92.04 | 92.40 |
| SyntheticDocQA - Government | 94.37 | 94.37 |
| SyntheticDocQA - Healthcare | 93.06 | 93.42 |
| Tabfquad | 84.78 | 86.10 |
| Tatdqa | 69.49 | 72.15 |
| Average | 83.13 | 84.28 |
| Task | nDCG@5 | nDCG@10 |
|---|---|---|
| BioMedical Lectures | 53.06 | 56.30 |
| ESG Reports - HL | 54.96 | 58.39 |
| ESG Reports | 34.19 | 38.38 |
| Economics Reports | 37.19 | 38.86 |
| Average | 44.85 | 47.98 |
| Task | nDCG@5 | nDCG@10 |
|---|---|---|
| Computer Science | 55.80 | 59.61 |
| Energy | 56.03 | 59.09 |
| Finance En | 39.61 | 42.12 |
| Finance Fr | 35.82 | 39.03 |
| HR | 38.62 | 42.01 |
| Industrial | 31.98 | 33.73 |
| Pharmaceuticals | 49.03 | 50.68 |
| Physics | 40.82 | 43.89 |
| Average | 43.46 | 46.27 |
pip install colpali-engine transformers torch peft1import torch
2from colgemma4 import ColGemma4, ColGemma4Processor
3
4# Load base model + LoRA adapter
5model = ColGemma4.from_pretrained(
6 "athrael-soju/ColGemma4-E2B-IT-Base",
7 torch_dtype=torch.bfloat16,
8 device_map="auto",
9 attn_implementation="sdpa",
10 ignore_mismatched_sizes=True, # needed for custom_text_proj
11)
12
13processor = ColGemma4Processor.from_pretrained(
14 "athrael-soju/ColGemma4-E2B-IT-Base",
15 max_num_visual_tokens=1120,
16)1from PIL import Image
2
3images = [Image.open("page1.png"), Image.open("page2.png")]
4batch_doc = processor.process_images(images)
5batch_doc = {k: v.to(model.device) for k, v in batch_doc.items()}
6
7with torch.no_grad():
8 doc_embeddings = model(**batch_doc) # (batch, seq_len, 128)1queries = ["What is the revenue for Q3 2024?"]
2batch_query = processor.process_queries(queries)
3batch_query = {k: v.to(model.device) for k, v in batch_query.items()}
4
5with torch.no_grad():
6 query_embeddings = model(**batch_query) # (batch, seq_len, 128)1scores = processor.score(query_embeddings, doc_embeddings)
2# scores[i][j] = relevance of query i to document j1Base model: google/gemma-4-E2B-it
2Loss: ColbertLoss (temperature=0.02)
3Hard negatives: none
4Batch size per GPU: 64
5GPUs: 7
6Gradient accumulation: 1
7Effective batch size: 448 (64 x 7)
8In-batch negatives: 448
9LoRA:
10 r: 32
11 alpha: 32
12 dropout: 0.1
13 target_modules: "language_model.*(down_proj|gate_proj|up_proj|k_proj|q_proj|v_proj|o_proj)"
14 # custom_text_proj is NOT LoRA-targeted (random init, untrained)
15Learning rate: 2e-4 (cosine schedule, 8% warmup)
16Weight decay: 0.02
17Epochs: 1
18Steps: 1,729
19Visual tokens: 1120
20Attention: Bidirectional (all layers patched)
21Gradient checkpointing: enabled
22Precision: BF16vidore/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_trainF.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.
1# In Gemma4VisionEncoder._position_embeddings:
2# Replace: one_hot = F.one_hot(clamped_positions, num_classes=self.position_embedding_size)
3# With: return F.embedding(clamped_positions, self.position_embedding_table)use_cache - Gemma 4 E2B has 20 of 35 text layers that reuse K/V from earlier layers via the cache. 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.1 for batch 448), and grad norms should be 5-20. If grad norms are in the thousands, weights didn't load correctly.hydra_gemma4.py for the implementation.1@misc{colgemma4,
2 title={ColGemma4: Visual Document Retrieval with Gemma 4},
3 author={Athrael Soju},
4 year={2026},
5 url={https://huggingface.co/athrael-soju/ColGemma4-E2B-IT-Base}
6}