PackMonitor: 通过解码时监控实现零包 hallucinations
PackMonitor: Enabling Zero Package Hallucinations Through Decoding-Time Monitoring
AI总结:
PackMonitor通过解码时监控实现零包 hallucinations,通过上下文感知解析器和包名干预者有效消除推荐中的虚假包问题。
摘要:
随着大型语言模型(LLMs)越来越多地融入软件开发工作流程,其可靠性已成为关键关注点。然而,在依赖性推荐场景中,LLMs的可靠性受到广泛包 hallucinations的影响,其中模型经常推荐虚构的包。最近的研究提出了多种方法来缓解这一问题。然而,现有方法通常只是降低hallucination率,而不是消除它们,留下了持续的软件安全风险。在本工作中,我们认为包 hallucinations理论上是可以预防的,基于关键洞察:包的有效性可以通过有限且可枚举的权威包列表来决定。基于此,我们提出了PackMonitor,这是首个能够从根本上消除包 hallucinations的方法,通过持续监控模型的解码过程并在必要时进行干预。为了在实践中实现这一点,PackMonitor解决了三个关键挑战:(1)通过上下文感知解析器确定何时触发干预,该解析器持续监控模型输出,并在生成安装命令时选择性激活干预;(2)通过包名干预者解决如何干预,该干预者严格限制解码空间到权威包列表;(3)通过DFA缓存机制确保监控效率,使该机制能够扩展到数百万个包,而开销极低。在五个广泛使用的LLMs上的大量实验表明,PackMonitor是一种无需训练的即插即用解决方案,能够一致地将包 hallucination率降低到零,同时保持低延迟推理并保留原始模型能力。
英文摘要:
As Large Language Models (LLMs) are increasingly integrated into software development workflows, their trustworthiness has become a critical concern. However, in dependency recommendation scenarios, the reliability of LLMs is undermined by widespread package hallucinations, where models often recommend hallucinated packages. Recent studies have proposed a range of approaches to mitigate this issue. Nevertheless, existing approaches typically merely reduce hallucination rates rather than eliminate them, leaving persistent software security risks. In this work, we argue that package hallucinations are theoretically preventable based on the key insight that package validity is decidable through finite and enumerable authoritative package lists. Building on this, we propose PackMonitor, the first approach capable of fundamentally eliminating package hallucinations by continuously monitoring the model's decoding process and intervening when necessary. To implement this in practice, PackMonitor addresses three key challenges: (1) determining when to trigger intervention via a Context-Aware Parser that continuously monitors model outputs and selectively activates intervening only during installation command generation; (2) resolving how to intervene by employing a Package-Name Intervenor that strictly limits the decoding space to an authoritative package list; and (3) ensuring monitoring efficiency through a DFA-Caching Mechanism that enables scalability to millions of packages with negligible overhead. Extensive experiments on five widely used LLMs demonstrate that PackMonitor is a training-free, plug-and-play solution that consistently reduces package hallucination rates to zero while maintaining low-latency inference and preserving original model capabilities.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。