Skip to content

[Core] Keep attention backends eligible for text-only serving of prefix-LM models - #48796

Merged
vllm-bot merged 14 commits into
vllm-project:mainfrom
qtris123:fix/mm-prefix-text-only-gate
Jul 25, 2026
Merged

vllm-bot merged 14 commits into
vllm-project:mainfrom
qtris123:fix/mm-prefix-text-only-gate

Conversation

@qtris123

@qtris123 qtris123 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Prefix-LM multimodal models set is_mm_prefix_lm=True from static model configuration (e.g. Gemma 4, Gemma 3, Molmo2). This flag is evaluated at server startup and tells backend selection that some multimodal tokens may need bidirectional (prefix) attention, so backends without supports_mm_prefix() are rejected.

That constraint is correct while vision inputs can still appear. The problem is that it is applied unconditionally β€” even when the deployment is configured so that vision inputs can never occur. In that case the gate rejects otherwise-valid attention backends for no reason:

  • Automatic selection is over-constrained. With vision disabled, backends without mm_prefix support are still filtered out. On Blackwell (B200) this can leave only TRITON_ATTN eligible.
  • Manual override is also blocked. Even an explicit --attention-backend FLASHINFER fails validation with "partial multimodal token full attention not supported", so the operator cannot opt into a backend that is actually usable for a text-only deployment.

This PR does not force any backend or claim a particular backend is always faster. It simply stops disabling backends that are valid once vision cannot occur, by clearing is_mm_prefix_lm when:

  • --language-model-only is set, or
  • --limit-mm-per-prompt sets limit 0 for every supported vision modality (image / video).

The check reads allowed_mm_limits and supported_mm_limits from MULTIMODAL_REGISTRY.get_processing_info():

  • image-only models (e.g. Gemma 3) need only image=0
  • image-and-video models (e.g. Gemma 4, Molmo2) need both image=0 and video=0
  • leaving any supported vision modality enabled keeps mm_prefix on

Logic lives in ModelConfig._apply_mm_prefix_lm_limits(). Selection stays startup/config-based, not per-request.

Example: Gemma 4 text-only serving

vllm serve nvidia/Gemma-4-31B-IT-NVFP4 \
  --quantization modelopt \
  --limit-mm-per-prompt '{"image": 0, "video": 0}'

Example: Gemma 3 text-only serving

vllm serve google/gemma-3-4b-it \
  --limit-mm-per-prompt '{"image": 0}'

Test Plan

  • Unit coverage in tests/config/test_multimodal_config.py
  • --language-model-only disables mm_prefix
  • All supported vision limits at zero disable mm_prefix
  • Any supported vision modality left enabled keeps mm_prefix
  • Non-prefix causal models are unchanged
  • Gemma 4 NVFP4 on B200
  • Molmo2-8B on B200
  • Gemma 3 4B-IT on B200

Test Results

Unit tests

pytest tests/config/test_multimodal_config.py -k mm_prefix

Backend eligibility on B200

The change restores backend candidates only when vision is disabled. The normal selector still chooses among those candidates.

Vision disabled β€” eligibility restored

Model and configuration Eligible before this PR Eligible with this PR Selected with this PR
Gemma 4 NVFP4, image=0,video=0 TRITON_ATTN FLASHINFER, TRITON_ATTN FLASHINFER + TRT-LLM
Molmo2-8B, image=0,video=0 FLASH_ATTN, TRITON_ATTN, FLEX_ATTENTION FLASHINFER, FLASH_ATTN, TRITON_ATTN, FLEX_ATTENTION FLASHINFER + TRT-LLM
Gemma 3 4B-IT, image=0 TRITON_ATTN, FLEX_ATTENTION FLASHINFER, FLASH_ATTN, TRITON_ATTN, FLEX_ATTENTION FLASHINFER

--language-model-only follows the same restored-eligibility path because no vision inputs can occur.

Vision remains possible β€” eligibility unchanged

Model and configuration Eligible before this PR Eligible with this PR Selected with this PR
Gemma 4 NVFP4, image=0 but video enabled TRITON_ATTN TRITON_ATTN TRITON_ATTN
Molmo2-8B, image=0 but video enabled FLASH_ATTN, TRITON_ATTN, FLEX_ATTENTION FLASH_ATTN, TRITON_ATTN, FLEX_ATTENTION FLASH_ATTN
Gemma 3 4B-IT, image enabled TRITON_ATTN, FLEX_ATTENTION TRITON_ATTN, FLEX_ATTENTION TRITON_ATTN

Disabled-path startup log:

Disabled mm_prefix attention mode because all supported vision modalities are limited to zero via --limit-mm-per-prompt. Attention backends without mm_prefix support may now be selected.

Throughput

For Gemma 4 NVFP4 on a long-context text-only workload, restoring backend eligibility (Triton β†’ FlashInfer + TRT-LLM) gives a large aggregate-throughput improvement and substantially lower TTFT. For the other models, short-request smoke checks show neutral-to-modest differences; this PR does not claim a universal backend speedup β€” it removes an eligibility restriction so the normal selector can pick the best available backend.

Notes for Reviewers

  • Attention backend choice is fixed at engine startup. This intentionally does not change behavior based on an individual text-only request.
  • AI-assisted change. The author reviewed the implementation and confirms ownership, licensing, and absence of secrets.

@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.

PRs do not trigger a full CI run by default. 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.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

πŸš€

@qtris123 qtris123 changed the title [Perf] Disable mm_prefix attention when vision inputs are disabled [Core] Keep attention backends eligible for text-only serving of prefix-LM models Jul 18, 2026
@qtris123
qtris123 marked this pull request as ready for review July 18, 2026 11:34
@qtris123
qtris123 force-pushed the fix/mm-prefix-text-only-gate branch from a55359b to 97c4a55 Compare July 18, 2026 11:34

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork β€” automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Use the registry's deployment-level multimodal eligibility in architecture conversion so regenerated text subconfigs preserve the correct attention mode.

Signed-off-by: qtris123 <voquangtri2021@gmail.com>
Comment thread vllm/config/model.py Resolved
@mergify

mergify Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Hi @qtris123, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Document that the cached decision is required for correctness on the with_hf_config regeneration path, not merely to avoid repeated registry lookups.

Signed-off-by: qtris123 <voquangtri2021@gmail.com>
@mergify

mergify Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Hi @qtris123, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Signed-off-by: qtris123 <voquangtri2021@gmail.com>

@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.

Please fix the test failures

qtris123 added 2 commits July 22, 2026 03:28
Architecture inspection helpers call get_model_arch_config on a duck-typed DummyConfig class; expose the new support probe so they keep the default multimodal conversion path.

Signed-off-by: qtris123 <voquangtri2021@gmail.com>
Bring in CI timeout bumps and latest main without changing the mm_prefix gate.
@qtris123 qtris123 closed this Jul 22, 2026
@qtris123 qtris123 reopened this Jul 22, 2026
qtris123 added 2 commits July 22, 2026 19:41
Pick up pytorch-compilation-unit-tests timeout bump (vllm-project#49450) to re-run CI.
Pick up topk_softplus_sqrt CUDA fix (vllm-project#49452) and re-trigger CI.
@qtris123

Copy link
Copy Markdown
Contributor Author

Hi @DarkLight1337, most of the ci tests pass, including multimodal / mm_prefix-related suites. The remaining failed cases don't seem to relate to this PR. Should we proceed with this, or would you prefer a CI retry first?

@DarkLight1337

Copy link
Copy Markdown
Member

Rebasing

@DarkLight1337
DarkLight1337 enabled auto-merge (squash) July 23, 2026 04:10
@DarkLight1337
DarkLight1337 disabled auto-merge July 23, 2026 04:10
@DarkLight1337
DarkLight1337 enabled auto-merge (squash) July 23, 2026 04:10
@qtris123

Copy link
Copy Markdown
Contributor Author

Hi @DarkLight1337 β€” gentle ping. Auto-merge has been blocked for ~2 days on Buildkite #79597.

Most of the reds is either "permission denied error" or the kernel moe tess. I don’t have Buildkite SSO to retry. Maybe could you retry the failed jobs (or kick a fresh CI run) to unblock these test cases?

@vllm-bot
vllm-bot merged commit fe51457 into vllm-project:main Jul 25, 2026
5 checks passed
@qtris123

Copy link
Copy Markdown
Contributor Author

I see the updates, thanks for the support @DarkLight1337 🫑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants