Skip to content

[Bugfix] Fix Nemotron VL image processing - #22739

Merged
vllm-bot merged 1 commit into
vllm-project:mainfrom
ducviet00:fix-nemotronvl
Aug 13, 2025
Merged

vllm-bot merged 1 commit into
vllm-project:mainfrom
ducviet00:fix-nemotronvl

Conversation

@ducviet00

@ducviet00 ducviet00 commented Aug 12, 2025 •

Copy link
Copy Markdown
Contributor

Purpose

Correct image processing for Nemotron VL:

  • Do not normalize images like InternVL
  • Use a correct method to find_closest_aspect_ratio

Test Plan

Using this script to test vLLM

Nemotron VL test script
import requests
from transformers import AutoTokenizer
from PIL import Image

from vllm import LLM, SamplingParams


if __name__ == "__main__":
    model_path = "nvidia/Llama-3.1-Nemotron-Nano-VL-8B-V1"

    tokenizer = AutoTokenizer.from_pretrained(model_path)

    image_url = (
        "https://huggingface.co/nvidia/Llama-3.1-Nemotron-Nano-VL-8B-V1/resolve/main/images/table.png"
    )
    image = Image.open(requests.get(image_url, stream=True).raw).convert("RGB")
    image = image.resize((image.width * 2, image.height * 2), Image.BILINEAR)

    question = "<image>\nExtract the table in this image as HTML."

    engine_args = {
        "model": "nvidia/Llama-3.1-Nemotron-Nano-VL-8B-V1",
        "trust_remote_code": True,
        "max_model_len": 8192,
        "limit_mm_per_prompt": {"image": 1, "video": 0, "audio": 0},
    }
    llm = LLM(**engine_args)


    messages = [[{"role": "user", "content": question}]]
    prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)


    stop_token_ids = [tokenizer.eos_token_id]
    sampling_params = SamplingParams(temperature=0, max_tokens=8192, stop_token_ids=stop_token_ids)

    inputs = {
        "prompt": prompts[0],
        "multi_modal_data": {"image": image},
    }

    outputs = llm.generate(
        inputs,
        sampling_params=sampling_params,
    )

    for output in outputs:
        print("vLLM output:\n", output.outputs[0].text)

Test Result

On main branch: repeated nonsense:

<table>
 <tr>
    <td>Intel</td>
    <td>Intel</td>
    <td>Intel</td>
    <td>Intel</td>
    <td>Intel</td
....

This branch correctly extracted table from the image and matches HF outputs

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements the specific image processing pipeline for Nemotron VL models, addressing a bug in the previous implementation. The changes, which include removing image normalization and adopting a model-specific method for finding the closest aspect ratio, align well with the reference implementation. My review identifies a potential ZeroDivisionError if an image with zero width or height is processed. I've suggested adding input validation to prevent this potential crash, which would improve the robustness of the new logic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The calculation of aspect_ratio can lead to a ZeroDivisionError if orig_height is 0. Similarly, the find_closest_aspect_ratio function called later can also face a division by zero if width * height (area) is zero. It's safer to validate that both orig_width and orig_height are positive at the beginning of this function to prevent potential crashes from invalid image inputs.

Suggested change
aspect_ratio = orig_width / orig_height
if orig_width <= 0 or orig_height <= 0:
raise ValueError("Image dimensions must be positive.")
aspect_ratio = orig_width / orig_height

@ducviet00

Copy link
Copy Markdown
Contributor Author

Hi @simon-mo, could you please re-invite me to the vLLM Slack? I missed the invitation email, and it’s now expired

@mergify mergify Bot added the multi-modality Related to multi-modality (#4194) label Aug 12, 2025
@ducviet00 ducviet00 changed the title [Bugfix]: Fix Nemotron VL image processing [Bugfix] Fix Nemotron VL image processing Aug 12, 2025

@DarkLight1337 DarkLight1337 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can you add a correctness test under tests/models/multimodal/generation/test_common.py to avoid future regressions?

@mgoin mgoin added the bug Something isn't working label Aug 13, 2025
@ducviet00

ducviet00 commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor Author

@DarkLight1337 unfortunately, the config can’t be auto-loaded — it requires patching tests.conftest.HfRunner. I suspect it’s the same issue as OpenGVLab/Mono-InternVL-2B

# FIXME: Config cannot be loaded in transformers 4.52
# "OpenGVLab/Mono-InternVL-2B",

Minimal reproduce script:

from transformers import AutoConfig

model_path = "nvidia/Llama-3.1-Nemotron-Nano-VL-8B-V1"

# Fails without attn_implementation
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
## TypeError: argument of type 'NoneType' is not iterable

# Works with attn_implementation explicitly set
config = AutoConfig.from_pretrained(
    model_path, trust_remote_code=True, attn_implementation="flash_attention_2"
)
print("WORK!!")

Environment:

uv pip show transformers
Name: transformers
Version: 4.55.0
Location: /data1/workspace/viet.d.hoang/vllm/.venv/lib/python3.12/site-packages
Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm
Required-by: compressed-tensors, vllm, xgrammar

I plan to add Nemotron to the Hugging Face Transformers repo soon, so no worries about that.

@DarkLight1337 DarkLight1337 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright let's just merge this first then, thanks

@DarkLight1337
DarkLight1337 enabled auto-merge (squash) August 13, 2025 07:11
@DarkLight1337 DarkLight1337 added this to the v0.10.1 milestone Aug 13, 2025
@github-actions github-actions Bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 13, 2025
@vllm-bot
vllm-bot merged commit a01e001 into vllm-project:main Aug 13, 2025
51 of 58 checks passed
diegocastanibm pushed a commit to diegocastanibm/vllm that referenced this pull request Aug 15, 2025
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
Signed-off-by: Diego-Castan <diego.castan@ibm.com>
yiliu30 pushed a commit to yiliu30/vllm-fork that referenced this pull request Aug 19, 2025
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
divakar-amd pushed a commit to divakar-amd/vllm_upstream that referenced this pull request Aug 20, 2025
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
Signed-off-by: Xiao Yu <xiao.yu@amd.com>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
mystous pushed a commit to mystous/vllm_hybrid that referenced this pull request May 10, 2026
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
my-other-github-account pushed a commit to my-other-github-account/vllm that referenced this pull request May 15, 2026
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
0826joyce pushed a commit to 0826joyce/vllm-serving-optimization that referenced this pull request May 19, 2026
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
plasticchris pushed a commit to plasticchris/vllm that referenced this pull request Jul 20, 2026
Co-authored-by: ducviet00-h2 <viet.d.hoang@h2corporation.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working multi-modality Related to multi-modality (#4194) ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants