perf(vl): optimize HunyuanOCR decoding#159
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces significant performance optimizations for HunyuanOCR, specifically implementing CUDA-graph-based autoregressive decoding and speculative decoding (DFlash). It adds fused CUDA kernels for repetition penalty, argmax, and MLP projections to minimize host-device synchronization overhead, and refactors KV cache management to support exact capacities. The review feedback suggests enhancing the robustness of the dflash_repetition_argmax_stage2 CUDA kernel by using a block-stride loop to handle arbitrary partition counts, and refactoring duplicated PARTITIONS_PER_ROW constants in dynamic_kv.rs into a single module-level constant.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request optimizes the HunyuanOCR model's speculative decoding (DFlash) and autoregressive decoding paths by fusing LM head projection, repetition penalty, and argmax operations directly into CUDA kernels and CUDA graphs, significantly reducing host-device synchronization overhead. Key improvements include fusing gate and up projections in MLP layers, implementing custom CUDA kernels for stable argmax and repetition penalty, introducing an incremental repetition history tracker, and enabling lazy, bucketed CUDA graph capture for the autoregressive decoder. No review comments were provided, so there is no feedback to address.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
Why
HunyuanOCR decoding was dominated by eager kernel launches and repeated full-vocabulary GPU-to-CPU transfers. Plain AR decoding had no CUDA Graph path, while the default repetition penalty forced synchronous CPU processing during both AR generation and DFlash verification.
Impact
On an RTX 4090 with
.oar/images/layout.jpg, the layout prompt,repetition_penalty=1.08, and concurrency 1:d093cc7e76d0c08b)Validation
cargo test --workspacecargo test -p oar-ocr-vl --features cuda,download-binaries --lib— 107 passedcargo check -p oar-ocr-vlcargo check -p oar-ocr-vl --features cuda,download-binariescargo build --release -p oar-ocr-vl --features cuda,download-binariescargo fmt --all -- --checkgit diff --check