扩展想法:llama-server 与自定义采样器

Reddit r/LocalLLaMA 工具

摘要

一个为 llama-server 设计的原型扩展,支持自定义采样逻辑,并附带一个循环检测器示例,无需维护独立分支。

这只是一个想法和一个原型(由 Qwen3.6-27B-UD-Q6\_K\_XL 通过 OpenCode 生成),旨在允许用户向 llama-server 添加自定义采样逻辑,无需维护自己的完整分支,也无需重写包装器来实现 llama-server 的所有功能。其中包含一个示例扩展,用于检测并打断一种常见于重度量化模型中的循环问题——模型会陷入重复相同 1-3 个 token 的死循环。其他采样想法(目前 llama.cpp 尚未实现)包括:在思考、工具调用和正常生成过程中使用不同的采样参数;根据上下文切换语法;非 GBNF 语法;确保生成的 SQL 查询中只引用实际存在的表;在采样器内部进行 PII 脱敏;以及其他实验性通用采样方法。该扩展基于 MTP 合并后的最新主分支;也兼容推测解码。在此处投票:[https://github.com/ggml-org/llama.cpp/discussions/23028](https://github.com/ggml-org/llama.cpp/discussions/23028) 分支:[https://github.com/dpmm99/llama.cpp/tree/master-with-sampling-extensions](https://github.com/dpmm99/llama.cpp/tree/master-with-sampling-extensions) 示例采样器扩展是一个相当短的文件:[https://github.com/dpmm99/llama.cpp/blob/master-with-sampling-extensions/examples/sampling-ext/loop-detector.cpp](https://github.com/dpmm99/llama.cpp/blob/master-with-sampling-extensions/examples/sampling-ext/loop-detector.cpp) 为了方便尝试,此处提供一个 Vulkan Windows x64 发布版副本:[https://github.com/dpmm99/llama.cpp/releases/tag/dpmm99-0.1](https://github.com/dpmm99/llama.cpp/releases/tag/dpmm99-0.1) 但请记住每日提醒:不要相信来自互联网的随机可执行文件。;) 示例命令:llama-server -np 1 -c 32768 --temp 0.1 -m Qwen3.6-27B-UD-Q6_K_XL-MTP.gguf --spec-type draft-mtp --spec-draft-n-max 3 --sampling-ext-path sampling-ext-loop-detector.dll [扩展在 llama-server 中与 Qwen3.6-27B 搭配 MTP 工作的截图](https://preview.redd.it/1pwpo5p9mi1h1.png?width=773&format=png&auto=webp&s=e9d8bda72bbc127f0b9cc5dcbaa4a73e62096b36)
查看原文

相似文章

llama.cpp 的粒子散射采样器

Reddit r/LocalLLaMA

本文介绍了一个 llama.cpp 的实验性采样器,名为 'scatter',它对按等级排序的令牌应用局部扩散,以平滑顶级候选之间的概率分布,从而在不增加尾部概率的情况下实现更具创造性的文本生成。