AdaDec: A Uncertainty-Guided Lookahead Decoding Framework for LLM-Based Code Generation

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: He, Kaifeng, Liu, Mingwei, Wang, Chong, Li, Zike, Wang, Yanlin, Peng, Xin, Zheng, Zibin
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917431867342848
author He, Kaifeng
Liu, Mingwei
Wang, Chong
Li, Zike
Wang, Yanlin
Peng, Xin
Zheng, Zibin
author_facet He, Kaifeng
Liu, Mingwei
Wang, Chong
Li, Zike
Wang, Yanlin
Peng, Xin
Zheng, Zibin
contents Code generation with large language models (LLMs) is highly sensitive to token selection during decoding, particularly at uncertain decision points that influence program logic. While standard strategies such as greedy decoding treat all tokens uniformly, they overlook code-specific uncertainty patterns, leading to suboptimal performance. This paper presents an empirical study revealing that many generation errors stem from token ranking mistakes at high-uncertainty steps, where the correct token is present but not top-ranked. Motivated by these findings, we propose AdaDec, a lookahead-based uncertainty-guided adaptive decoding framework that integrates a token-level pause-then-rerank mechanism driven by token uncertainty. AdaDec learns model-specific uncertainty thresholds and applies a lookahead-based reranking strategy when uncertainty is high. Experiments on HumanEval+, MBPP+, and DevEval benchmarks show that AdaDec improves Pass@1 accuracy by up to 20.9% in absolute terms over greedy decoding. More importantly, it consistently outperforms both competitive baselines like Beam Search and state-of-the-art adaptive decoding methods such as AdapT, while maintaining high efficiency through selective, uncertainty-triggered pausing. Our results highlight the promise of uncertainty-aware adaptive decoding for improving both the reliability and efficiency of LLM-based code generation.
format Preprint
id arxiv_https___arxiv_org_abs_2506_08980
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle AdaDec: A Uncertainty-Guided Lookahead Decoding Framework for LLM-Based Code Generation
He, Kaifeng
Liu, Mingwei
Wang, Chong
Li, Zike
Wang, Yanlin
Peng, Xin
Zheng, Zibin
Software Engineering
I.2.7; I.2.2
Code generation with large language models (LLMs) is highly sensitive to token selection during decoding, particularly at uncertain decision points that influence program logic. While standard strategies such as greedy decoding treat all tokens uniformly, they overlook code-specific uncertainty patterns, leading to suboptimal performance. This paper presents an empirical study revealing that many generation errors stem from token ranking mistakes at high-uncertainty steps, where the correct token is present but not top-ranked. Motivated by these findings, we propose AdaDec, a lookahead-based uncertainty-guided adaptive decoding framework that integrates a token-level pause-then-rerank mechanism driven by token uncertainty. AdaDec learns model-specific uncertainty thresholds and applies a lookahead-based reranking strategy when uncertainty is high. Experiments on HumanEval+, MBPP+, and DevEval benchmarks show that AdaDec improves Pass@1 accuracy by up to 20.9% in absolute terms over greedy decoding. More importantly, it consistently outperforms both competitive baselines like Beam Search and state-of-the-art adaptive decoding methods such as AdapT, while maintaining high efficiency through selective, uncertainty-triggered pausing. Our results highlight the promise of uncertainty-aware adaptive decoding for improving both the reliability and efficiency of LLM-based code generation.
title AdaDec: A Uncertainty-Guided Lookahead Decoding Framework for LLM-Based Code Generation
topic Software Engineering
I.2.7; I.2.2
url https://arxiv.org/abs/2506.08980