Repository navigation
[https://nvbugs/6992761][fix] Bound decoded video memory per request in trtllm-serve - #21675
Conversation
trtllm-agent-review
left a comment
There was a problem hiding this comment.
Thanks for the PR. This PR caps the decoded frame buffers a trtllm-serve chat request may allocate for its videos with one per-request budget (8 GiB by default, set or disabled via --media_io_kwargs video.max_decoded_frame_bytes) and rejects requests that try to set that limit themselves.
Reviewed at commit 4d275aa04b (4 files, +196/−10).
#21366 is an open competing fix for the same issue; this review covers only this PR.
Approve: no Blocker found. 2 possible blockers below need a measurement or a closer look. 5 suggestions below are nice to have.
Possible blockers (2)
- (B5: User-visible switch behavior) The new 8 GiB default rejects video requests main serves: Cosmos3 clips over ~23 s of 1080p30, the Nemotron README's 128-frame config above 1080p, and four 4K videos at the loader defaults. (chat_utils.py:104)
- (B5: User-visible switch behavior) On the EPD encoder (
mm_embedding_serve) the cap is fixed at 8 GiB: the command has no--media_io_kwargs, so videos main encodes (e.g. four 4K videos for Qwen2.5-VL) now get a 400 with nothing to raise it. (chat_utils.py:584)
Nice to have (5): 4 inline, 1 below
- (R5: Input and config validation) A bad
video.max_decoded_frame_bytes(0, -1, "8GiB", true) starts the server fine and then fails every video request with a 400. (chat_utils.py:113) - (N7: Robustness hardening) When one video of a request fails, its other videos keep decoding after the 400, and a single oversized video's error does not name the setting. (chat_utils.py:125)
- (R3: Repository rules) The reserver is typed with
Any, the new tests are unannotated, and the two edited files have no NVIDIA header (CODING_GUIDELINES.md). (utils.py:362) - (R6: Required documentation) The
media_io_kwargsrequest-field docs still say the request wins per key, and the help text does not say the cap bounds one request, not the server. (chat_utils.py:188) - [Nice to have] (R1: PR process) #21366 (open) also fixes #20988: it rewrites
_make_media_iointensorrt_llm/serve/chat_utils.pyand adds tests toTestMakeMediaIointests/unittest/llmapi/apps/test_chat_utils.py, with a different policy (a 4 GiB per-video cap). Whichever merges second conflicts in both files, and a mechanical resolution can leave two caps on the same path. Its review already raised the default rejecting Cosmos3 clips and per-video versus per-request. Please link the PRs and agree with its author on one; if this one stays, carry over #21366'smedia_io_kwargsdescription update intensorrt_llm/serve/openai_protocol.py.
What this review checked
- The server-only keys are rejected while the messages are parsed, before any fetch or decode starts:
_make_media_ioruns synchronously fromparse_chat_message_content_part(tensorrt_llm/serve/chat_utils.py:276-279), and theValueErrorbecomes a 400 (tensorrt_llm/serve/openai_server.py:2526-2527). - The budget follows the reservation protocol
_load_video_by_cv2uses:reserve()checks and charges under one lock (tensorrt_llm/serve/chat_utils.py:154-161), a failed decode's reservation is refunded throughrelease()(tensorrt_llm/inputs/media_io.py:1020-1023) and a committed one stays charged, sovideos_share_limitfails on the second video whatever the decode order. - The new tests fail on the base and run pre-merge:
_DecodedVideoBudgetand_DEFAULT_MAX_DECODED_VIDEO_FRAME_BYTESdo not exist there and_make_media_ioaccepted the keys;tests/unittest/llmapi/apps/test_chat_utils.pyiscpu_onlyand listed inl0_cpu.yml(CPU-Generic x86 and arm stages). - Not covered: No GPU or server run; the new CPU tests were not run locally.
- Not covered: Reviewed at the PR's merge base; the head conflicts with current main in
tensorrt_llm/inputs/utils.pyandtests/unittest/llmapi/apps/test_chat_utils.py, so the rebased code was not reviewed.
Automated review by trtllm-agent-review. If a point is wrong, reply in its thread. Once you have pushed code changes and replied in every Blocker thread, the bot re-checks the Blockers within a few hours.
|
|
||
| # Counted peak frame buffers (see `_load_video_by_cv2`) that the videos of one | ||
| # request may allocate when the server sets no `video.max_decoded_frame_bytes`. | ||
| _DEFAULT_MAX_DECODED_VIDEO_FRAME_BYTES = 8 * 1024**3 |
There was a problem hiding this comment.
[Possible blocker] (B5: User-visible switch behavior) This default turns the cap on for every server that sets no video.max_decoded_frame_bytes, and the cap counts each video's conversion peak at source resolution (_load_video_by_cv2, tensorrt_llm/inputs/media_io.py:936-953: 9 bytes per pixel channel for pt on CPU, 2 for np/pil), summed over the request's videos. Requests that main decodes now get a 400:
- Cosmos3 and Cosmos3-Edge decode every frame (
num_frames=-1, fps=-1on top of Qwen3-VL'snp,modeling_cosmos3.py:60-65,modeling_cosmos3_edge.py:971-976, merged into the server config atopenai_server.py:656-668) and let the HF processor resample. A 1080p frame counts 12,441,600 bytes, so a request fits about 23 s of 1080p30 (52 s of 720p30); a 30 s 1080p clip getsDecoded video frame buffers require 11197440000 bytes, exceeding the limit of 8589934592 bytes. examples/models/core/nemotron/README_nano-v2-vl.md:65,77(fps 2,num_frames 128,pt): a 1440p clip of 43.5 s or longer, a 4K clip of 19.5 s or longer, or 1080p clips that together reach 154 sampled frames.- The loader defaults (
pt, 10 frames): a request with four 4K, nine 1440p or sixteen 1080p videos.
The help text documents the key, but nothing in the tree that relied on the old default sets it (the same concern came up on #21366 for its 4 GiB default). The cap can stay; please migrate what depends on it:
- List in the PR description (and the release note, if there is one) which requests now get a 400 and how to raise or disable the cap: the cases above, MuseSpark Open Omni at 173 sampled 4K frames per request, and requests that raise
num_frames/fpspast the cap or setmax_decoded_frame_bytesthemselves. - In the README's two
--media_io_kwargsexamples, setmax_decoded_frame_bytesto at least the 8 GiB default and enough for the largest source the deployment accepts (one 4K clip at 128ptframes needs 28,665,446,400), and say it bounds one request, not the server. - In the
--media_io_kwargshelp, say the value is a positive integer number of bytes ornull, and what is counted: each video's conversion peak at source resolution (9 bytes per pixel channel forpton CPU, 13 on another device, 2 fornp/pil), summed over the request's videos, audio extracted from them included.
Two related gaps are raised separately: the error a single oversized video gets does not name the setting, and some entry points cannot set it at all.
There was a problem hiding this comment.
The PR description now lists the requests that need a higher limit and how to raise it or turn it off, the Nemotron README examples set 32 GiB, and the --media_io_kwargs help says what is counted and that the limit is per request.
| mm_placeholder_counts = [] | ||
| model_type = model_type_override or resolve_top_level_model_type( | ||
| model_config) | ||
| video_decode_limit = _video_decode_limit(multimodal_server_config) |
There was a problem hiding this comment.
[Possible blocker] (B5: User-visible switch behavior) multimodal_server_config carries a limit only when the process was started with trtllm-serve serve --media_io_kwargs. The EPD encoder cannot set one: mm_embedding_serve has no such option, and launch_mm_encoder_server (tensorrt_llm/commands/serve.py:806-823) builds OpenAIServer without a multimodal_server_config, so the encoder's /v1/chat/completions (openai_server.py:2883-2898) always gets the 8 GiB default, and requests can no longer set the limit themselves. For Qwen2.5-VL and Nemotron Nano VL V2 (EPD = Yes in the support matrix; pt, 10 frames), a request with four 4K videos, or one that asks for 128 frames at 2 fps of a 4K clip of 19.5 s or longer, is now rejected on the encoder although main encodes it (the np Qwen3-VL and Qwen3.5 families reach the cap at 173 sampled 4K frames per request). The 400 then tells the operator to use --media_io_kwargs (chat_utils.py:156-160), which the encoder does not have.
Suggested fix: add --media_io_kwargs to mm_embedding_serve (status prototype, and in the mm_embedding_serve options of tests/unittest/api_stability/references/trtllm_serve_cli.yaml) and pass the MultimodalServerConfig through launch_mm_encoder_server to OpenAIServer(multimodal_server_config=...). Parse and validate it in one helper that both commands call before the model loads (today serve.py:1706-1715 only runs json.loads): a mapping of modality to mapping or null, and video.max_decoded_frame_bytes a positive non-bool int or null. Add an in-process test that a larger value and null reach the encoder's chat route.
Two other entry points get the same fixed default:
- The resource-governor truncate routes call
parse_chat_messages_coroutines(messages, self.model_config, None)(resource_governor.py:144-146) and then discard the decoded media (rendered, _ = ...,resource_governor.py:158); passingresolve_media=Falsethere, asrender/chat.pydoes, drops both the decode and the cap. - Context servers started by
disaggregated_mpi_workercalllaunch_serverwithoutmultimodal_server_config(serve.py:2880-2883) and have nothing to carry the setting. Either add a carrier (a disagg-config key means regeneratingtensorrt_llm/schemas/trtllm-serve-disagg-config.schema.json, andtest_launch_disaggregated_server_sets_worker_rolepinslaunch_server's kwargs) or document that the default applies there.
There was a problem hiding this comment.
mm_embedding_serve now takes --media_io_kwargs and passes it to its server, the KV cache truncation routes use the server's setting and only decode media when the model's renderer reads it, and the help text says disaggregated_mpi_worker context workers use the default.
4d275aa to
4dd3043
Compare
|
/bot run |
|
PR_Github #87044 [ run ] triggered by Bot. Commit: |
|
PR_Github #87044 [ run ] completed with state
|
trtllm-agent-review
left a comment
There was a problem hiding this comment.
Threads for the findings that the bot's review of 2026-11-24 listed only in its body: each finding is now a thread of its own, so it can be answered where it is. Nothing new is raised here.
- #21366 is an open, competing fix for #20988 that rewrites the same
_make_media_ioand test class; please link the two and settle on one. (its thread)
There was a problem hiding this comment.
[Nice to have] (R1: PR process) tensorrt_llm/serve/chat_utils.py:2: #21366 (open) also fixes #20988: it rewrites _make_media_io in tensorrt_llm/serve/chat_utils.py and adds tests to TestMakeMediaIo in tests/unittest/llmapi/apps/test_chat_utils.py, with a different policy (a 4 GiB per-video cap). Whichever merges second conflicts in both files, and a mechanical resolution can leave two caps on the same path. Its review already raised the default rejecting Cosmos3 clips and per-video versus per-request. Please link the PRs and agree with its author on one; if this one stays, carry over #21366's media_io_kwargs description update in tensorrt_llm/serve/openai_protocol.py.
|
/bot run |
90045b4 to
40c74ac
Compare
|
/bot run |
|
PR_Github #87281 [ run ] triggered by Bot. Commit: |
|
PR_Github #87281 [ run ] completed with state
|
…serve Signed-off-by: Aswin Visva <[email protected]>
…video limit, check the setting at startup, and cancel a request's other media loads when one fails Signed-off-by: Aswin Visva <[email protected]>
… governor that the render callers test builds without its constructor Signed-off-by: Aswin Visva <[email protected]>
40c74ac to
fb90a34
Compare
|
/bot run |
|
PR_Github #87359 [ run ] triggered by Bot. Commit: |
|
PR_Github #87359 [ run ] completed with state
|
@coderabbitai summary
Description
Fixes #20988.
trtllm-servepassed a request'smedia_io_kwargsto the video loader with no limit, so a 1.2 MB video sent with{"video": {"num_frames": 500, "fps": 1000}}decoded into 5 GiB of float32 frames (13.6 GiB peak memory) before main switched to uint8 frames, and a request could setmax_decoded_frame_bytesitself to remove any limit the server had. Now all videos in a chat request share one decoded video budget,video.max_decoded_frame_bytes(default 8 GiB,nullturns it off), checked before the frames are allocated, and a request that tries to setmax_decoded_frame_bytesordecoded_memory_reservergets a 400 error. When one media load of a request fails, its other loads are cancelled.Setting the limit
mm_embedding_servenow takes--media_io_kwargstoo, and both commands reject avideo.max_decoded_frame_bytesthat is not a positive integer ornullat startup. The limit applies to each request, so the worst case on one host is about the limit x--num_serve_frontendsx--num_media_load_workers. The KV cache truncation routes use the server's setting and only decode media for models whose renderer reads it. Context workers started bydisaggregated_mpi_workercannot pass the setting and use the default.Requests that need a higher limit
num_framesorfpspast the limit, or that setmax_decoded_frame_bytesthemselves.Related PR
#21366 also fixes #20988, with a 4 GiB limit per video instead of one per request. Whichever merges second conflicts with the other in
chat_utils.pyandtest_chat_utils.py, so only one of them should go in.Test Coverage
CPU tests in
tests/unittest/llmapi/apps/test_chat_utils.pydecode a real mp4 throughparse_chat_messages_coroutinesand cover the default limit, a server limit, a disabled limit, videos sharing the limit, requests that try to set the limit keys, and cancelling the other loads when one fails. The newtests/unittest/serve/test_media_io_kwargs_option.pychecks that both commands reject bad values before launch and hand good ones to their servers,test_serve_cli.pypins the encoder's new option, and the resource governor test checks that it uses the server's setting. All of these are fast CPU-only checks of request memory and CLI behavior, so they run in pre-merge through the existingl0_cpuentries for their directories. On the first revision of this change, the request from the issue made a Qwen2.5-VL-3Btrtllm-servein a 64 GiB container get killed for running out of memory on main, and got a 400 in about 0.05 s with the fix while the server kept serving.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.