Views
No views yet

bfloat16 format, use low-rank adapters (LoRA)
with alpha=32 and r=32 on the transformer layers from the language model,
as well as the final randomly initialized projection layer, and use a paged_adamw_8bit optimizer.
We train on an 8 GPU setup with data parallelism, a learning rate of 5e-5 with linear decay with 2.5% warmup steps, and a batch size of 32.1# This model checkpoint is compatible with version 0.1.1, but not more recent versions of the inference lib
2pip install colpali_engine==0.1.11import torch
2import typer
3from torch.utils.data import DataLoader
4from tqdm import tqdm
5from transformers import AutoProcessor
6from PIL import Image
7
8from colpali_engine.models.paligemma_colbert_architecture import ColPali
9from colpali_engine.trainer.retrieval_evaluator import CustomEvaluator
10from colpali_engine.utils.colpali_processing_utils import process_images, process_queries
11from colpali_engine.utils.image_from_page_utils import load_from_dataset
12
13
14def main() -> None:
15 """Example script to run inference with ColPali"""
16
17 # Load model
18 model_name = "akshayballal/colpali-merged"
19 model = ColPali.from_pretrained("google/colpaligemma-3b-mix-448", torch_dtype=torch.bfloat16, device_map="cuda").eval()
20 processor = AutoProcessor.from_pretrained(model_name)
21
22 # select images -> load_from_pdf(<pdf_path>), load_from_image_urls(["<url_1>"]), load_from_dataset(<path>)
23 images = load_from_dataset("vidore/docvqa_test_subsampled")
24 queries = ["From which university does James V. Fiorca come ?", "Who is the japanese prime minister?"]
25
26 # run inference - docs
27 dataloader = DataLoader(
28 images,
29 batch_size=4,
30 shuffle=False,
31 collate_fn=lambda x: process_images(processor, x),
32 )
33 ds = []
34 for batch_doc in tqdm(dataloader):
35 with torch.no_grad():
36 batch_doc = {k: v.to(model.device) for k, v in batch_doc.items()}
37 embeddings_doc = model(**batch_doc)
38 ds.extend(list(torch.unbind(embeddings_doc.to("cpu"))))
39
40 # run inference - queries
41 dataloader = DataLoader(
42 queries,
43 batch_size=4,
44 shuffle=False,
45 collate_fn=lambda x: process_queries(processor, x, Image.new("RGB", (448, 448), (255, 255, 255))),
46 )
47
48 qs = []
49 for batch_query in dataloader:
50 with torch.no_grad():
51 batch_query = {k: v.to(model.device) for k, v in batch_query.items()}
52 embeddings_query = model(**batch_query)
53 qs.extend(list(torch.unbind(embeddings_query.to("cpu"))))
54
55 # run evaluation
56 retriever_evaluator = CustomEvaluator(is_multi_vector=True)
57 scores = retriever_evaluator.evaluate(qs, ds)
58 print(scores.argmax(axis=1))
59
60
61if __name__ == "__main__":
62 typer.run(main)
63gemma license as specified in its model card. The adapters attached to the model are under MIT license.1@misc{faysse2024colpaliefficientdocumentretrieval,
2 title={ColPali: Efficient Document Retrieval with Vision Language Models},
3 author={Manuel Faysse and Hugues Sibille and Tony Wu and Bilel Omrani and Gautier Viaud and Céline Hudelot and Pierre Colombo},
4 year={2024},
5 eprint={2407.01449},
6 archivePrefix={arXiv},
7 primaryClass={cs.IR},
8 url={https://arxiv.org/abs/2407.01449},
9}