Detect and recover from degenerate repeated model output (repetition guard) / 检测并恢复退化的重复模型输出(重复守卫) #3480
filantropo17
started this conversation in
Ideas
Replies: 1 comment
|
The A safe first contract would be:
The proposed 64-character / six repeats / eight-character unit is a useful candidate configuration, not yet a universal default. I wrote up the rc.8 stream and retry boundaries, an evaluation matrix, config example, UI semantics, and acceptance gates here: https://sandbaseai.github.io/deepseek-harness-handbook/degenerate-model-output.html |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem / 问题
Models sometimes degenerate into repeating one word, phrase, or n-gram until the output-token ceiling. The harness currently accepts such responses as an ordinary completed turn: the stream finishes with
stopormax-tokens, neither of which is a failure, so nothing truncates the loop and no retry is triggered. The user is left with a long, unusable, token-wasting reply, and the session log is polluted with the repeated content.模型有时会退化为反复输出同一个单词、短语或 n-gram,直到打满输出 token 上限。当前 harness 会把这类响应当作普通的正常完成 turn:流以
stop或max-tokens结束,两者都不算失败,因此没有任何机制截断循环或触发重试。用户只能得到一段冗长、不可用且浪费 token 的回复,会话日志也被重复内容污染。Proposal / 提议
A stream-level repetition guard: wrap the existing
llm/streamwaterfall, detect when the trailing text is one unit repeated N times, truncate the stream, and fail the request with a new provider-neutral codeDEGENERATE_OUTPUT, so the existingagent/request-error→dsh-llm-retrypath retries it under the provider policy. No agent-loop changes are needed — thellm/streamwaterfall already sits at exactly the right seam.流级重复守卫:包装现成的
llm/stream瀑布,当尾部文本出现同一单元连续重复 N 次时截断流,并以新的 provider 无关错误码DEGENERATE_OUTPUT判失败,从而让现有的agent/request-error→dsh-llm-retry路径按 provider 策略重试。完全不需要改 agent 主循环——llm/stream瀑布正好位于正确的接缝上。I built this as an ecosystem plugin (
dsh-llm-repetition-guard) to prove the approach:我把它实现为生态插件(
dsh-llm-repetition-guard)来验证该方案:每个流一个独立检测器;按块在受限滑动窗口(默认 1024 字符)内累计文本。
检测依据是某单元在所有对齐方式下的最长尾部连续出现——"data data data …" 无论最后一个单元是否恰好落在窗口边界上都能被捕获。
textdeltas are guarded by default;reasoningdeltas are ignored unless opted in (reasoning text is pattern-heavy and would trip conservative thresholds); tool-call argument streams are never guarded (JSON legitimately repeats keys and separators).默认只检测
textdelta;reasoningdelta 默认忽略(推理文本天然模式化,保守阈值容易误伤);工具调用参数流永不检测(JSON 合法地重复键与分隔符)。DEGENERATE_OUTPUTerror finish and truncates the stream; the loop retries under the provider retry policy, and truncated chunks never enter derived messages.检测到时产出终止性的
DEGENERATE_OUTPUTerror finish 并截断流;主循环按 provider 重试策略重试,被截断的 chunk 永不进入派生消息。保守默认值:累计 64 个字符后开始检测,同一 8 字符单元连续出现 ≥6 次即触发。所有阈值均可配置。
What I'd like feedback on / 希望得到反馈
retryableCodes. ShouldDEGENERATE_OUTPUTjoin the default retryable set indsh-llm? The published package currently omits it, so deployments must opt in explicitly. BothEMPTY_RESPONSEandDEGENERATE_OUTPUTare content-quality failures that produced no usable output, so repeating them is safe.默认
retryableCodes。DEGENERATE_OUTPUT是否应该加入dsh-llm的默认可重试集合?当前已发布的包未包含它,部署方必须显式配置。EMPTY_RESPONSE与DEGENERATE_OUTPUT都是未产生可用输出的内容质量类失败,重复它们都是安全的。llm/streamwrapper pattern) rather than relying on ecosystem plugins for this class of checks?核心 vs. 生态。 harness 是否应该在核心中提供内容质量扩展点(
llm/stream包装模式),而不是依赖生态插件来承载这类检查?阈值。 "累计 64 字符后,8 字符单元连续重复 ≥6 次"作为保守默认值是否合理?真实负载下是否有误报经验?
非连续重复。 交替短语或稀疏散布短单元的输出目前无法检测——这一类是否值得覆盖?
The plugin is published as
dsh-llm-repetition-guardand carries an./invariantcompanion that verifies the truncation contract (nothing follows aDEGENERATE_OUTPUTfinish within one attempt).插件以
dsh-llm-repetition-guard发布,并附带./invariant伴随插件,用于验证截断契约(一次 attempt 内DEGENERATE_OUTPUTfinish 之后不得再有内容)。All reactions