[Perf] Read VidCom2 frame budgets once - #55331
Conversation
Co-authored-by: Codex <codex@openai.com> Signed-off-by: levius <2114377220@qq.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughThe retention mask computation now materializes frame budgets with one ChangesFrame Budget Optimization
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to VidCom2 now transfers frame budgets once while preserving retention-mask behavior. Existing validation covers the optimized read path and mask shape, with no remaining merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/ci run |
|
✅ Triggered Buildkite CI #87262 for commit |
Signed-off-by: levius <2114377220@qq.com> Signed-off-by: Jyotirmoy Roy <jyotirmoyroy649@gmail.com>
Purpose
VidCom2 currently reads each dynamic per-frame Top-K budget with
ks[i].item(), then reads the selected-token count with another scalarreduction. For
Tframes this introducesT + 1host-visible scalar reads inthe token-selection path.
This PR copies the small budget vector to a Python list once, preserves the
original one-dimensional unsorted
torch.topkoperation for every frame, andreuses the budget sum during count reconciliation:
The budgets are already clamped to at least one, so the previous non-positive
budget branch was unreachable. The change keeps one portable PyTorch path with
no custom kernel, architecture gate, device branch, or device-specific tuning.
This is not duplicating existing work. The following open-PR searches returned
no matching VidCom2 optimization:
VidCom2 topk,VidCom2 frame budget, andvideo prune synchronization.Test Plan
Regression test
The new test runs the complete mask function, rejects any per-element
Tensor.item()read, and verifies exactly one vector budget transfer. Existingtests cover retained counts, dynamic frame budgets, empty input, and first-frame
behavior.
Lint and pre-commit
RTX 4090 complete-function benchmark
Hardware/software: NVIDIA RTX 4090, driver 580.76.05, CUDA 13.2,
PyTorch 2.13.0+cu132. Baseline commit:
c615b1fd.Across all 288 configurations, the raw geometric-mean speedup was 1.181x and
the median was 1.142x. All masks matched bit-for-bit. One T=1 sample was a raw
timing outlier; five alternating-order trials with 500 iterations reproduced a
1.041x median speedup (1.037–1.041x), leaving no stable regression beyond 3%.
The profiler confirms that Top-K and scatter counts are unchanged while the
per-frame scalar reads disappear:
itemcalls, old → newEach profiler row contains 20 complete mask calls. Other reconciliation-path
copies remain; the removed difference is exactly
20 * Tper-frame budgetreads.
The standalone benchmark, raw CSV, profiler output, outlier recheck, and paired
model-evaluation output are available in the
benchmark artifact Gist.
Qwen3-VL paired evaluation
The offline evaluation used
Qwen/Qwen3-VL-2B-Instructrevision89644892e4d85e24eaac8bacfd4f463576704203. Baseline and candidate requestswere interleaved in one process, prefix caching was disabled, and both mask
functions were also run on the same visual embeddings.
[4, 8, 8][16, 4, 4]All ten timed baseline/candidate outputs had identical generated token IDs,
text, and cumulative log probability.
Test Result
ruff-format,ruff-check, typo, SPDX-header, forbidden-import,new-
torch.cudaAPI, andgit diff --checkchecks passed locally.Limitations
The broad performance matrix uses synthetic post-ViT embeddings on one RTX
4090. The two Qwen3-VL cases validate output stability but do not establish an
end-to-end throughput improvement; the optimized helper is a small fraction of
total inference latency. No performance claim is made for other architectures
or backends.
AI assistance
AI assistance was used during implementation, testing, benchmarking, model
evaluation, and PR drafting. The human contributor reviewed and takes
responsibility for the change and evidence.