arXiv:2605.17626 · 中英对照阅读
循环中的验证器:代码翻译的解码时验证(DTV)
Verifiers in the Loop: Decoding Time Verification for Code Translation
中文速览
代码翻译中,编译器和类型检查器能准确发现错误,但等整段代码生成完再检查,错误往往已经影响后续内容。论文提出解码时验证(Decoding Time Verification,DTV):让模型每写完一条语句、一个代码块等结构边界,就暂停检查;通过的部分先固定下来,失败则按范围回退,并把错误信息交给模型重写。在 C 转 Rust 和 JavaScript 转 TypeScript 的测试中,DTV 比同等生成预算下的自我修正方法通过率更高、生成 token 更少,效果也大体能迁移到其他模型。它说明,代码任务可以把可靠的外部检查直接放进生成过程,及早拦住错误,从而更有效地利用推理算力。
摘要
Test-time scaling is an important mechanism for improving large language models, especially on tasks with deterministic verifiers. Code translation is a canonical example: the source program constrains valid outputs, while compilers, type checkers, and behavioral checks provide exact pass/fail feedback. Outcome-only approaches apply these verifiers only after generation, which is inefficient because early errors corrupt the autoregressive context and are rarely corrected later. We introduce Decoding Time Verification (DTV), a framework that treats structural boundaries as meta steps for verifier-guided decoding. DTV interleaves generation with verifier calls under a state-machine controller that commits verified prefixes, using structural-boundary checks and structure-aware rollback to prevent error propagation while reducing wasted tokens. We evaluate DTV on C-to-Rust and JavaScript-to-TypeScript translation. Using Qwen3-4B as the primary generator under matched token budgets, DTV improves pass rates from 72.3% to 82.0% on C-to-Rust and from 33.3% to 46.0% on JavaScript-to-TypeScript relative to matched self-refinement baselines, while using fewer tokens per case; the same trend largely transfers to Gemma-4-E4B and Qwen3-30B-A3B. In the evaluated cost-matched grid, DTV achieves a more favorable tradeoff between pass rate and generated-token cost than post-hoc verification or sampling-based scaling. These results show that verifier-guided decoding is an effective use of inference-time compute for code translation.
术语表
- test-time scaling
- 测试时扩展
- large language model (LLM)
- 大语言模型(LLM)
- inference-time compute
- 推理时计算
- Decoding Time Verification (DTV)
- 解码时验证(DTV)
- verifier-guided decoding
- 验证器引导解码
- deterministic verifier
- 确定性验证器
- outcome-only approach
- 仅基于结果的方法
- autoregressive context
- 自回归上下文
- structural boundary
- 结构边界
- state-machine controller
- 状态机控制器
- verified prefix
- 已验证前缀
- structure-aware rollback
- 结构感知回滚
- structural-boundary verification
- 结构边界验证
- legal prefix invariant
- 合法前缀不变式
- unanimous-pass commit condition
- 全体通过提交条件
- diagnostic feedback
- 诊断反馈
- prompt augmentation
- 提示增强
- self-refinement
- 自我迭代
- post-hoc verification
- 事后验证
- best-of-N
- best-of-N
- C-to-Rust
- C 到 Rust
- JavaScript-to-TypeScript
- JavaScript 到 TypeScript
- differential testing
- 差分测试
- static type checking
- 静态类型检查
- compile-pass rate
- 编译通过率
- Qwen3-4B
- Qwen3-4B
- Gemma-4-E4B
- Gemma-4-E4B
- Qwen3-30B-A3B
- Qwen3-30B-A3B