Views
No views yet

[!NOTE] This version is similar tovidore/colpali-v1.3, except that the LoRA adapter was merged into the base model. Thus, loading ColPali from this checkpoint saves you the trouble of merging the pre-trained adapter yourself.This can be useful if you want to train a new adpter from scratch.
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.colpali-engine:pip install colpali-engine>=0.3.0,<0.4.01from typing import cast
2
3import torch
4from PIL import Image
5
6from colpali_engine.models import ColPali, ColPaliProcessor
7
8model_name = "vidore/colpali-v1.2-merged"
9
10model = ColPali.from_pretrained(
11 model_name,
12 torch_dtype=torch.bfloat16,
13 device_map="cuda:0", # or "mps" if on Apple Silicon
14).eval()
15processor = ColPaliProcessor.from_pretrained(model_name)
16
17# Your inputs
18images = [
19 Image.new("RGB", (32, 32), color="white"),
20 Image.new("RGB", (16, 16), color="black"),
21]
22queries = [
23 "Is attention really all you need?",
24 "Are Benjamin, Antoine, Merve, and Jo best friends?",
25]
26
27# Process the inputs
28batch_images = processor.process_images(images).to(model.device)
29batch_queries = processor.process_queries(queries).to(model.device)
30
31sess = ort.InferenceSession("AndrewOgn/colpali-v1.3-merged-onnx")
32image_embeddings = sess.run([sess.get_outputs()[0].name],{"input_ids":batch_images['input_ids'].numpy(),"pixel_values":batch_images['pixel_values'].numpy(),"attention_mask":batch_images['attention_mask'].numpy()})[0]
33
34pixel_values = np.zeros((batch_queries['input_ids'].shape[0],3,448,448), dtype=np.float32)
35# Dummy pixel values
36query_embeddings = sess.run([sess.get_outputs()[0].name],{"input_ids":batch_queries['input_ids'].numpy(),"pixel_values":pixel_values,"attention_mask":batch_queries['attention_mask'].numpy()})[0]
37query_embeddings = np.array(query_embeddings)gemma license as specified in its model card.
Because the pre-trained adapter got merged in this model, the license for these weights are also under the gemma license1@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}