perf(vl): accelerate GLM-OCR, MinerU, and PaddleOCR-VL#160
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces shared CUDA kernels (stable argmax, sparse token masking, and sampling with confidence) and decoder CUDA-graph plumbing to optimize single-token decoding across multiple VLM backends, including GLM-OCR, HunyuanOCR, MinerU, MinerU-Diffusion, and PaddleOCR-VL. It also integrates a Multi-Token Predictor (MTP) for speculative decoding in GLM-OCR. The review feedback highlights several potential underflow vulnerabilities across the codebase where subtracting from sequence lengths or token counts (e.g., seq_len - 1, prompt_len - 1, max_seq_len - 1) could cause panics in debug mode if the values are zero, and suggests adding appropriate validation guards.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Why
After the HunyuanOCR optimization, the other VL backends still spent substantial decode time in eager kernel launches, per-row LM-head calls, CPU-side token processing, and repeated per-token CUDA allocations.
This change moves those hot paths onto reusable CUDA Graphs and shared GPU kernels while preserving eager semantics. In particular, single-token graph replay now uses non-causal attention just like the eager decoder, while multi-token speculative verification remains causal. This fixes the numerical drift that could otherwise prevent EOS on long or degenerate PaddleOCR-VL generations.
Correctness and safety
Representative results
Warm batch-1 runs on an RTX 4090:
The canonical HunyuanOCR page case remains unchanged at 1,393 tokens with the same fingerprint; DFlash remains about 1.20 s.
These are representative local regression runs rather than a formal benchmark suite.
Review guide
cuda_kernels.rsanddecoder_graph.rs: shared GPU selection/sampling and graph lifecycle primitivesglmocr/mtp.rsplusglmocr/model.rs: MTP proposal, verification, acceptance, and KV rollbackglmocr/text.rs,mineru/text.rs, andpaddleocr_vl/ernie.rs: backend graph capture/replay and eager parityValidation
cargo fmt --all -- --checkcargo clippy --all-targets --all -- -D warningscargo clippy --all-targets -p oar-ocr-vl -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depscargo test --allcargo test -p oar-ocr-vl --lib --features cuda,download-binaries— 117 passedcargo build --release -p oar-ocr-vl --examples --features cuda,download-binariesgit diff --check