What is Nomic Contrastors?
Nomic Contrastors is Train and evaluate contrastive text and multimodal embedding models. It sits in the Embedding Models & Inference category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python. To get started: create and activate a virtual environment.
Overview
Contrastors is Nomic AI's contrastive learning toolkit. It holds the training code and recipes behind the fully open nomic-embed family of long-context text and multimodal embedding models, so researchers and engineers can train and evaluate contrastive models themselves.
It is aimed at teams who want to build their own embedding models rather than only consume a hosted API. It is built on Flash Attention, supports multi-GPU training, and uses GradCache so you can train with large batch sizes even when GPU memory is limited.
Within the embedding-models category, it sits on the training side: it covers masked language modeling pretraining, contrastive pretraining and finetuning, Matryoshka representation learning for flexible embedding sizes, and CLIP/LiT style training for vision.
What it does
- Built on Flash Attention for fast, memory-efficient training
- Multi-GPU training with DeepSpeed and torchrun
- GradCache support for large batch sizes in limited GPU memory
- Matryoshka Representation Learning for flexible embedding sizes
- CLIP and LiT style contrastive learning for vision, plus ViT/timm model loading
- Hugging Face support for common models (Pythia/GPTNeoX, BERT) and MLM pretraining
Getting started
Contrastors relies on custom CUDA kernels from Flash Attention, so set up a Python environment with CUDA 11.8+ before installing. Verify your CUDA version with nvcc --version.
Create and activate a virtual environment
Use a clean Python venv to keep the CUDA and Flash Attention dependencies isolated.
python3 -m venv env
source env/bin/activateInstall torch and build tools
Install torch (see the PyTorch docs for the right command for your system), then the build helpers Flash Attention needs.
pip3 install torch torchvision torchaudio
pip install wheel packaging ninja setuptoolsInstall Flash Attention kernels and the package
Install Flash Attention with its custom kernels, then install contrastors itself in editable mode.
pip install --no-cache-dir flash-attn --no-build-isolation git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/rotary git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/layer_norm git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/fused_dense_lib git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/xentropy
pip install -e .Run contrastive pretraining
Launch a training run with torchrun across your GPUs, pointing at one of the provided configs.
cd src/contrastors
torchrun --nproc-per-node=8 train.py --config=configs/train/contrastive_pretrain.yaml --dtype=bf16Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Train your own BERT-based text embedding model from scratch with MLM pretraining followed by contrastive pretraining and finetuning
- Reproduce or adapt the nomic-embed-text-v1 training recipe on your own corpus
- Fit large effective batch sizes on memory-limited GPUs using GradCache
- Train CLIP/LiT style multimodal embeddings and produce Matryoshka embeddings with flexible output sizes
How Nomic Contrastors compares
Nomic Contrastors alongside other open-source embedding models & inference tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Sentence Transformers | ★ 19.3k | The standard Python framework for loading, training, and computing embeddings with sentence and reranking models. |
| OpenCLIP | ★ 14.3k | An open implementation of CLIP for training and running image-text embedding models, with a large catalogue of pretrained checkpoints for zero-shot classification and retrieval. |
| PyTorch Metric Learning | ★ 6.3k | PyTorch library of losses, miners, distances, samplers, trainers and accuracy testers for training embedding models with deep metric and self-supervised learning. |
| EmbeddingGemma (Gemma) | ★ 5.9k | Google DeepMind's Gemma repo, home to EmbeddingGemma, a 308M multilingual embedding model small enough to run on-device for RAG and semantic search. |
| Text Embeddings Inference (TEI) | ★ 5.1k | Hugging Face's Rust-based server for deploying embedding, reranking, and sequence-classification models with high throughput on GPU or CPU. |
| text2vec | ★ 5k | Python library for sentence embeddings and text similarity, implementing Word2Vec, BM25, Sentence-BERT, CoSENT and BGE with Chinese and multilingual models. |
| Infinity (Embeddings) | ★ 3k | A high-throughput serving engine for text embeddings, rerankers, CLIP, and ColPali models, exposing an OpenAI-compatible API. |
| Nomic Contrastors | ★ 807 | Train and evaluate contrastive text and multimodal embedding models |

