TIGER-AI-Lab / TIGER-AI-Lab/VLM2Vec

Batch inference: The representation results of a sample repeated k times and n times are different?

Open
#124 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
684
Forks
64
Avg merge
8m
Merged PRs (30d)
1

Description

I tested it using the following code in demo.py
processor_inputs = { "text": ['<|image_pad|> Represent the given image.\n', '<|image_pad|> Represent the given image.\n', '<|image_pad|> Represent the given image.\n'], "images": [Image.open('assets/example.jpg'), Image.open('assets/example.jpg'), Image.open('assets/example.jpg')], } inputs = Qwen2_VL_process_fn( processor_inputs, processor) inputs = batch_to_device(inputs, "cuda") with torch.autocast(device_type="cuda", dtype=torch.bfloat16): tgt_output = model(tgt=inputs)["tgt_reps"] print(tgt_output)

The greater the gap between n and k, the greater the gap in the representation obtained through inference. Theoretically, without the influence of padding, the results should be consistent.
k=1

Image

n=8

Image

In the actual model inference process, due to the influence of padding within the batch, the calculated similarity differs significantly from the result of single-sample inference.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in demo.py, including Qwen2_VL_process_fn, batch_to_device, and the model(tgt=inputs) call; compare k=1 with n=8 under the shown autocast settings. Trace how batch padding reaches representation computation and verify that repeated identical samples produce consistent representations and similarity results within expected numerical tolerance.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.