Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper • 2101.06983 • Published • 2
How to use tomaarsen/ColQwen3-VL-Embedding-2B-vdr with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("tomaarsen/ColQwen3-VL-Embedding-2B-vdr")
sentences = [
"The weather is lovely today.",
"It's so sunny outside!",
"He drove to the stadium."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]This is a Multi-Vector Encoder model finetuned from Qwen/Qwen3-VL-Embedding-2B on the llamaindex-vdr-en-train-preprocessed dataset using the sentence-transformers library. It maps inputs to sequences of 128-dimensional token-level vectors and scores them with late interaction (MaxSim), useful for semantic search with late interaction.
MultiVectorEncoder(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'image': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'video': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'message': {'method': 'forward', 'method_output_name': 'last_hidden_state', 'format': 'structured'}}, 'module_output_name': 'token_embeddings', 'processing_kwargs': {'chat_template': {'add_generation_prompt': True}}, 'unpad_inputs': False, 'architecture': 'Qwen3VLModel'})
(1): Dense({'in_features': 2048, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'module_input_name': 'token_embeddings', 'module_output_name': 'token_embeddings'})
(2): MultiVectorMask({'skiplist_words': [], 'keep_only_token_ids': None})
(3): Normalize({'module_input_name': 'token_embeddings', 'module_output_name': 'token_embeddings'})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import MultiVectorEncoder
# Download from the 🤗 Hub
model = MultiVectorEncoder("tomaarsen/ColQwen3-VL-Embedding-2B-vdr")
# Run inference: each input becomes a sequence of per-token vectors (variable length).
queries = [
'What are the new anthropological perspectives on development as discussed by Quarles Van Ufford and Giri in 2003?',
]
documents = [
'https://huggingface.co/tomaarsen/ColQwen3-VL-Embedding-2B-vdr/resolve/main/assets/image_0.jpg',
'https://huggingface.co/tomaarsen/ColQwen3-VL-Embedding-2B-vdr/resolve/main/assets/image_1.jpg',
'https://huggingface.co/tomaarsen/ColQwen3-VL-Embedding-2B-vdr/resolve/main/assets/image_2.jpg',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings[0].shape, document_embeddings[0].shape)
# (48, 128) (352, 128)
# Get the MaxSim similarity scores
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[37.0712, 33.5348, 23.2705]])
vdr-eval-hardMultiVectorInformationRetrievalEvaluator| Metric | Value |
|---|---|
| maxsim_accuracy@1 | 0.8467 |
| maxsim_accuracy@3 | 0.9567 |
| maxsim_accuracy@5 | 0.98 |
| maxsim_accuracy@10 | 0.9967 |
| maxsim_precision@1 | 0.8467 |
| maxsim_precision@3 | 0.3189 |
| maxsim_precision@5 | 0.196 |
| maxsim_precision@10 | 0.0997 |
| maxsim_recall@1 | 0.8467 |
| maxsim_recall@3 | 0.9567 |
| maxsim_recall@5 | 0.98 |
| maxsim_recall@10 | 0.9967 |
| maxsim_ndcg@10 | 0.9278 |
| maxsim_mrr@10 | 0.905 |
| maxsim_map@100 | 0.9053 |
query, image, and negative_0| query | image | negative_0 | |
|---|---|---|---|
| type | string | image | image |
| modality | text | image | image |
| details |
|
|
|
| query | image | negative_0 |
|---|---|---|
What are the new anthropological perspectives on development as discussed by Quarles Van Ufford and Giri in 2003? |
![]() |
![]() |
What are the three main positions anthropologists have taken in relation to development, as discussed by David Lewis? |
![]() |
![]() |
Who are the three sisters known as the Fates in Greek mythology? |
![]() |
![]() |
CachedMultiVectorMultipleNegativesRankingLoss with these parameters:{
"score_metric": "colbert_scores",
"mini_batch_size": 1,
"mini_batch_num_tokens": null,
"score_mini_batch_size": 1,
"scale": 1.0,
"size_average": true,
"gather_across_devices": false
}
per_device_train_batch_size: 64num_train_epochs: 1learning_rate: 2e-05warmup_steps: 0.1max_grad_norm: 30.0bf16: Truelearning_rate_mapping: {'^(model\.)?1\.linear': 0.0002}per_device_train_batch_size: 64num_train_epochs: 1max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 30.0label_smoothing_factor: 0.0bf16: Truefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 8prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Falseignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {'^(model\.)?1\.linear': 0.0002}max_length: None| Epoch | Step | Training Loss | vdr-eval-hard_maxsim_ndcg@10 |
|---|---|---|---|
| -1 | -1 | - | 0.8244 |
| 0.0510 | 8 | 2.2737 | - |
| 0.1019 | 16 | 0.6985 | 0.9132 |
| 0.1529 | 24 | 0.3765 | - |
| 0.2038 | 32 | 0.3179 | 0.9133 |
| 0.2548 | 40 | 0.2909 | - |
| 0.3057 | 48 | 0.2984 | 0.9184 |
| 0.3567 | 56 | 0.2649 | - |
| 0.4076 | 64 | 0.2771 | 0.9232 |
| 0.4586 | 72 | 0.2404 | - |
| 0.5096 | 80 | 0.2456 | 0.9271 |
| 0.5605 | 88 | 0.2933 | - |
| 0.6115 | 96 | 0.2549 | 0.9224 |
| 0.6624 | 104 | 0.2636 | - |
| 0.7134 | 112 | 0.2815 | 0.9202 |
| 0.7643 | 120 | 0.2829 | - |
| 0.8153 | 128 | 0.2592 | 0.9206 |
| 0.8662 | 136 | 0.2180 | - |
| 0.9172 | 144 | 0.2647 | 0.9206 |
| 0.9682 | 152 | 0.2411 | - |
| 1.0 | 157 | - | 0.9278 |
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
@misc{gao2021scaling,
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
year={2021},
eprint={2101.06983},
archivePrefix={arXiv},
primaryClass={cs.LG}
}