Image-Text-to-Text
Transformers
Safetensors
English
Retrieval
Multimodal
Embedding
Chain-of-Thought
Reinforcement-Learning
Instructions to use DeepGlint-AI/UniME-R1-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DeepGlint-AI/UniME-R1-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="DeepGlint-AI/UniME-R1-4B")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("DeepGlint-AI/UniME-R1-4B", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use DeepGlint-AI/UniME-R1-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DeepGlint-AI/UniME-R1-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeepGlint-AI/UniME-R1-4B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/DeepGlint-AI/UniME-R1-4B
- SGLang
How to use DeepGlint-AI/UniME-R1-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "DeepGlint-AI/UniME-R1-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeepGlint-AI/UniME-R1-4B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "DeepGlint-AI/UniME-R1-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeepGlint-AI/UniME-R1-4B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use DeepGlint-AI/UniME-R1-4B with Docker Model Runner:
docker model run hf.co/DeepGlint-AI/UniME-R1-4B
Upload folder using huggingface_hub
Browse files- .gitattributes +4 -0
- README.md +160 -0
- figures/intro.png +3 -0
- figures/method.png +3 -0
- figures/mmeb-v2.png +3 -0
- figures/zero-shot.png +3 -0
.gitattributes
CHANGED
|
@@ -35,3 +35,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
adviser/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
embedder/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
adviser/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
embedder/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
figures/intro.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
figures/method.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
figures/mmeb-v2.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
figures/zero-shot.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
datasets:
|
| 4 |
+
- TIGER-Lab/MMEB-train
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
base_model:
|
| 8 |
+
- Qwen/Qwen3-VL-4B-Instruct
|
| 9 |
+
library_name: transformers
|
| 10 |
+
tags:
|
| 11 |
+
- Retrieval
|
| 12 |
+
- Multimodal
|
| 13 |
+
- Embedding
|
| 14 |
+
- Chain-of-Thought
|
| 15 |
+
- Reinforcement-Learning
|
| 16 |
+
pipeline_tag: image-text-to-text
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
<div align="center">
|
| 20 |
+
|
| 21 |
+
<h1>UniME-R1-4B: Learning from Failures for Unified Multimodal Retrieval</h1>
|
| 22 |
+
|
| 23 |
+
<a href="#">Zelong Sun*</a>,</span>
|
| 24 |
+
<a href="#">Jun Wang*</a>,</span>
|
| 25 |
+
<a href="#">Kaicheng Yang</a>,</span>
|
| 26 |
+
<a href="#">Tiancheng Gu</a>,</span>
|
| 27 |
+
Ziyong Feng,</span>
|
| 28 |
+
<a href="#">Zhiwu Lu</a></span>
|
| 29 |
+
|
| 30 |
+
Glint Lab
|
| 31 |
+
|
| 32 |
+
[](https://github.com/deepglint/UniME-R1)
|
| 33 |
+
[]()
|
| 34 |
+
[](https://huggingface.co/DeepGlint-AI)
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
UniME-R1 is an **EmbedderβAdviser** framework that learns to reason over *retrieved candidates* (not the query alone) and generate **Retrieval-Centric Chain-of-Thought (RC-CoT)** to correct retrieval failures. This repository ships the **4B-scale** pair: a Qwen3-VL-4B dual-mode Embedder and the Qwen3-VL-4B retrieval-aware Adviser β the best-performing configuration in the paper.
|
| 38 |
+
|
| 39 |
+
## π‘ Highlights
|
| 40 |
+
|
| 41 |
+
- **Retrieval-Centric CoT (RC-CoT)** β The Adviser analyzes the *actual* top-k retrieved candidates to diagnose model-specific confusion, then emits `<cot_focus>` (which discriminative cues are missing) and `<cot_answer>` (a concise corrected query) to redirect retrieval.
|
| 42 |
+
|
| 43 |
+
<div align="center">
|
| 44 |
+
<img src="figures/intro.png" width="95%">
|
| 45 |
+
</div>
|
| 46 |
+
|
| 47 |
+
- **Dual-Mode Embedder** β A single VLM backbone produces two embeddings via special tokens: `<dis_emb>` for fast discriminative retrieval and `<gen_emb>` for RC-CoT-enhanced re-retrieval. Candidates are encoded **once** with `<dis_emb>` and reused across both paths β no candidate-side CoT, no index rebuilding.
|
| 48 |
+
- **Adaptive Rerank-or-Retrieve** β The Adviser predicts whether a match exists in the top-k set. If yes, it reranks; if not, it appends RC-CoT to the query and re-retrieves over the full corpus.
|
| 49 |
+
- **Retrieval-Oriented GRPO** β The Adviser is optimized with a 4-component reward (format / NDCG rerank / CoT-embedding quality / judge decision) that calls a **frozen Embedder API** to score the Adviser's CoT against mined hard negatives, so the RL signal reflects real end-to-end retrieval quality.
|
| 50 |
+
|
| 51 |
+
<div align="center">
|
| 52 |
+
<img src="figures/method.png" width="100%">
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
## π§± Model Components
|
| 56 |
+
|
| 57 |
+
This release contains two sub-directories:
|
| 58 |
+
|
| 59 |
+
| Component | Backbone | Format | Notes |
|
| 60 |
+
|-----------|----------|--------|-------|
|
| 61 |
+
| **Embedder** (`embedder/`) | Qwen3-VL-4B-Instruct | LoRA (DoRA, r=16, Ξ±=64) + `new_token_embeddings.pt` | Adds `<dis_emb>` / `<gen_emb>` tokens; pooling at the special-token position |
|
| 62 |
+
| **Adviser** (`adviser/`) | Qwen3-VL-4B-Instruct | Full merged weights (bf16) | Outputs 5 structured XML fields; served with vLLM |
|
| 63 |
+
|
| 64 |
+
```
|
| 65 |
+
βββ adviser/ # Qwen3-VL-4B Adviser (full weights, vLLM-ready)
|
| 66 |
+
β βββ model-0000{1,2}-of-00002.safetensors
|
| 67 |
+
β βββ config.json / generation_config.json
|
| 68 |
+
β βββ preprocessor_config.json / video_preprocessor_config.json
|
| 69 |
+
β βββ tokenizer.json / chat_template.jinja
|
| 70 |
+
βββ embedder/ # Qwen3-VL-4B Embedder (LoRA adapter)
|
| 71 |
+
βββ adapter_config.json
|
| 72 |
+
βββ adapter_model.safetensors
|
| 73 |
+
βββ new_token_embeddings.pt # trained <dis_emb>/<gen_emb> embeddings
|
| 74 |
+
βββ config.json
|
| 75 |
+
βββ preprocessor_config.json / video_preprocessor_config.json
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
> The Embedder is released as a **PEFT/LoRA adapter** β load it on top of `Qwen/Qwen3-VL-4B-Instruct`. The two special tokens (`<dis_emb>`=151670, `<gen_emb>`=151669) and their embeddings are provided via `added_tokens.json` + `new_token_embeddings.pt`.
|
| 79 |
+
|
| 80 |
+
The Adviser always emits five structured fields:
|
| 81 |
+
|
| 82 |
+
| Field | Role |
|
| 83 |
+
|-------|------|
|
| 84 |
+
| `<rerank_think>` | Candidate-by-candidate relevance analysis |
|
| 85 |
+
| `<rerank_list>` | Predicted candidate ordering (JSON array, 0-based) |
|
| 86 |
+
| `<rerank_judge>` | Path decision: best-match ID, or `-1` if none matches |
|
| 87 |
+
| `<cot_focus>` | Retrieval-failure diagnosis β which discriminative cues are confused |
|
| 88 |
+
| `<cot_answer>` | Concise refined query text for re-retrieval |
|
| 89 |
+
|
| 90 |
+
## π Quick Start
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
git clone https://github.com/deepglint/UniME-R1.git
|
| 94 |
+
cd UniME-R1
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
conda create -n vlm2vec python=3.10 -y
|
| 99 |
+
conda activate vlm2vec
|
| 100 |
+
|
| 101 |
+
# Install torch matching your CUDA first, e.g.:
|
| 102 |
+
# pip install torch==2.5.1 torchvision --index-url https://download.pytorch.org/whl/cu121
|
| 103 |
+
# pip install flash-attn==2.7.3 --no-build-isolation
|
| 104 |
+
|
| 105 |
+
pip install -r Embedder/requirements.txt
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### π Embedder-only evaluation (direct `<dis_emb>` retrieval)
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
cd Embedder
|
| 112 |
+
bash shell/eval/eval.sh image "../models/UniME-R1-4B/embedder"
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
### π― Full Adviser evaluation (rerank + RC-CoT iterative retrieval)
|
| 116 |
+
|
| 117 |
+
Serve the Adviser via vLLM, then run the unified evaluation:
|
| 118 |
+
|
| 119 |
+
```bash
|
| 120 |
+
vllm serve models/UniME-R1-4B/adviser --tensor-parallel-size 8 --port 9000
|
| 121 |
+
|
| 122 |
+
cd RL/eval
|
| 123 |
+
export EMBEDDER_CHECKPOINT="../../models/UniME-R1-4B/embedder"
|
| 124 |
+
export ADVISER_MODEL="Qwen3-VL-4B-Instruct"
|
| 125 |
+
export ADVISER_URL="http://127.0.0.1:9000/v1"
|
| 126 |
+
bash eval.sh image # image | visdoc | video | uvrb | image_caption
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
## π Results
|
| 130 |
+
|
| 131 |
+
### π MMEB-V2
|
| 132 |
+
|
| 133 |
+
UniME-R1 achieves the best overall performance at both model scales. Notably, the 2B model already outperforms all medium-size (4Bβ7B) baselines, indicating the gains stem from the framework rather than model scale alone.
|
| 134 |
+
|
| 135 |
+
<div align="center">
|
| 136 |
+
<img src="figures/mmeb-v2.png" width="95%">
|
| 137 |
+
</div>
|
| 138 |
+
|
| 139 |
+
### π Zero-shot General Retrieval
|
| 140 |
+
|
| 141 |
+
<div align="center">
|
| 142 |
+
<img src="figures/zero-shot.png" width="90%">
|
| 143 |
+
</div>
|
| 144 |
+
|
| 145 |
+
## ποΈ Citation
|
| 146 |
+
|
| 147 |
+
If you find this repository useful, please use the following BibTeX entry for citation.
|
| 148 |
+
|
| 149 |
+
```bibtex
|
| 150 |
+
@misc{unime-r1,
|
| 151 |
+
title = {Learning from Failures: Retrieval-Centric CoT via Hard Negatives for Unified Multimodal Retrieval},
|
| 152 |
+
author = {Sun, Zelong and Wang, Jun and Yang, Kaicheng and Gu, Tiancheng and Feng, Ziyong and Lu, Zhiwu},
|
| 153 |
+
year = {2025},
|
| 154 |
+
url = {https://github.com/deepglint/UniME-R1}
|
| 155 |
+
}
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
<div align="center">
|
| 159 |
+
β Don't forget to star this repository if you find it helpful!
|
| 160 |
+
</div>
|
figures/intro.png
ADDED
|
Git LFS Details
|
figures/method.png
ADDED
|
Git LFS Details
|
figures/mmeb-v2.png
ADDED
|
Git LFS Details
|
figures/zero-shot.png
ADDED
|
Git LFS Details
|