[None][perf] Optimize Video Hashing Speed#16340
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by CodeRabbit
Description
Current Video hashing iterates over every decoded frame's pixel data (~100 MB for a 30s @ fps=8 374x374 request) inside apply_mm_hashes, adding ~145 ms per request to the OpenAI serve entry path.
The decoded frame content is a deterministic function of (source mp4 bytes) + (media IO num_frames/fps kwargs),
and the latter is already captured in metadata["frames_indices"] (a lossless projection of the kwargs into the effective sampling result). So the same content identity can be obtained by hashing the source bytes once at media-load time and using them as the anchor in update_hash.
Measured on a real 30s @ fps=8 374x374 mp4 (147 KB, 240 decoded frames) inside the tensorrt-llm/release:1.3.0rc20 container with the patch overlaid, 50 iterations per path:
Coverage preserved:
metadata["frames_indices"]is still hashed on both paths, so media IOnum_frames/fpskwargs land in the hash implicitly.AudioData.update_hash) is unchanged.Known pre-existing gap NOT addressed here: HF processor kwargs (
mm_processor_kwargs) are still not in the hash. Two requests with identical decoded frames but different per-request HF kwargs share a cache entry, which can produce wrong embeddings. Tracked separately.Perf improvement
e2e benchmarks
Benchmark is with the cosmos3-reasoner Nano FP8 model ran on a single H200 node. 256 concurrent requests each with 128x128 30s @ 8 fps mp4 videos + 50 token text prompt. KV reuse enabled:
enable_block_reuse: trueIsolated test for just the hashing function
Total hashing cost drops ~1250x. Load-time hashing runs inside the existing async media-I/O threadpool, so almost all of the 145 ms comes off the synchronous request-handling path when KV-reuse is enabled.
Test Coverage
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.