Skip to content

feat(sglang): add image number limitation to prevent OOM (#8540) - #44078

Closed
Asthenia0412 wants to merge 1 commit into
sgl-project:mainfrom
Asthenia0412:feat/8540-image-number-limitation
Closed

Asthenia0412 wants to merge 1 commit into
sgl-project:mainfrom
Asthenia0412:feat/8540-image-number-limitation

Conversation

@Asthenia0412

@Asthenia0412 Asthenia0412 commented Oct 13, 2026 •

Copy link
Copy Markdown

Summary

Fix #8540.

Adds a per-request image-count bound across the multimodal processor
pipeline. Each 4K image costs roughly 1 GiB GPU memory with the fast
image processor, so unbounded multi-image requests can easily OOM the
serving instance.

Changes

Three layers of validation to fail fast before any heavy image preprocessing:

  1. Rust ingress prefetch (config.py): the default
    {"image": 5} is propagated to the Rust side so early requests can be
    rejected there too.
  2. Python TokenizerManager (tokenizer_manager.py):
    _validate_mm_limits() now falls back to
    BaseMultimodalProcessor.DEFAULT_IMAGE_NUM_LIMITATION = 5 instead of
    skipping validation when no limit is configured.
  3. BaseMultimodalProcessor (base_processor.py): a defensive check in
    validate_mm_data() that honours the ServerArg override if set, or the
    class-level constant otherwise.

Operators can tune the bound or disable it:

# default: 5 images
sglang serve ...

# custom bound
sglang serve ... --limit-mm-data-per-request '{"image": 10}'

# disable all limits
sglang serve ... --limit-mm-data-per-request '{}'

Test Plan

  • Code inspection: validation runs before preprocess in all 3 layers
  • Covered by CI

/cc @merrymercy


DCO: Signed-off-by: yancy yancy@users.noreply.github.com


CI States

Latest PR Test (Base): ❌ Run #38414303599
Latest PR Test (Extra): ❌ Run #38414304356
Latest PR Test (AMD ROCm 10): ❌ Run #38414304566

Add a per-request default image-count bound (default 5) that is enforced
at three entry points to prevent OOM when users submit dozens of 4K
images in a single request (~1 GiB GPU memory per image with the fast
image processor).

Changes:
- BaseMultimodalProcessor: add DEFAULT_IMAGE_NUM_LIMITATION = 5 class
  constant that subclasses may override; enforce the bound in
  validate_mm_data() as a defensive safeguard
- TokenizerManager._validate_mm_limits: when the user did not explicitly
  set --limit-mm-data-per-request, default to {"image": 5} instead of
  skipping all limits; user-provided values take precedence and an empty
  dict disables all limits
- rust_server/config: mirror the default when building the Rust ingress
  launch config so Rust-side requests get the same OOM protection

Operators can tune or disable the bound via --limit-mm-data-per-request,
e.g. --limit-mm-data-per-request '{"image": 10}' or '{}' to disable.

Ref: #8540

Signed-off-by: yancy <yancy@users.noreply.github.com>
@Asthenia0412

Copy link
Copy Markdown
Author

@mickqian @JustinTong0323 @merrymercy @HaiShaw — Hi folks, #8540 asked for a per-request image-count bound to prevent OOM from 4K images (roughly 1 GiB each). This PR adds a default limit of 5 with override via the existing --limit-mm-data-per-request ServerArg. Validation runs at three layers — Rust ingress, Python TokenizerManager, BaseProcessor — so bad requests fail fast. 73/4 across 3 files. Mind taking a look? Thanks!

@Asthenia0412

Copy link
Copy Markdown
Author

Same — needs 'run-ci' label to trigger CI tests.

@Asthenia0412

Copy link
Copy Markdown
Author

🤖 CI gating notice: This PR's checks (call-gate/pr-gate, pr-test-*-finish) fail because this repo requires a run-ci label to trigger the actual test matrix. The failed jobs are just CI gating placeholders — real tests haven't run yet.

@hnyls2002

Copy link
Copy Markdown
Collaborator

Thanks for your interest in SGLang. This account opened 16 PRs in about eight hours, across unrelated subsystems (attention backends, speculative decoding, diffusion loading, scheduler IPC, KV-cache compression, docs), including two PRs for the same change (#44073 and #44117, both for #28808) and a fix for #43929 that is already on main. We can't review contributions at this volume, so we are closing the ones still open. If you want to pursue one, please pick a single change, verify it on a real run (a repro, a test, or numbers), and open a fresh PR.

@hnyls2002 hnyls2002 closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Implement Image Number Limitation for Image Processors

3 participants