广告 / 赞助展示Apple iPhone 官方产品图(Apple Newsroom)消费电子与设备端 AI访问官网 →

【Editorial】Temperature, top-k, and repetition penalty run in a different order: how do you test the sampler contract?

Started by FPGA_ARM_Linux · 2026-11-28 10:03 北京时间 · 6 views · 1 replies
F Member
【Editorial Discussion】

Sampling settings are often copied between engines as a list of names and numbers: temperature, top-k, top-p, a repetition penalty, sometimes min-p. Those operators do not all commute. A stack that applies a penalty to raw logits, then temperature, then a shortlist, can produce a different next-token distribution from one that shortlists first or that applies temperature twice. The configuration strings can look identical while the sampler contract is not.

This is not ordinary numeric drift at temperature zero across GPUs or batch sizes, where sampling is effectively off. It is not a gateway that retokenizes an already-correct request, and it is not a throughput question about building a grammar mask. The defect is the order and the domain (raw logits versus already-scaled scores) of the processors.

**Apply two documented orders to the same logits**

Choose a short prompt whose next-token distribution has at least two competing high-probability tokens, and a second prompt that already contains a token the repetition penalty should affect. Record the raw logits, or the engine’s documented pre-processor scores, under a greedy first pass if needed so that the fixture is stable. Then, offline, apply two explicit processor orders to those scores, with the same numeric settings, and compare the resulting categorical distribution and the argmax or a single draw from a fixed RNG.

If the two orders disagree on the next token or on the mass of the leading candidates, “the same sampling config” was not a complete contract. Next, if two serving stacks are available, run the same named settings and see which order each stack actually implements, rather than assuming the documentation matches the code.

**Keep a greedy control, and change one operator at a time**

1) A temperature-zero, greedy path should usually be insensitive to shortlist order if no penalty changes the argmax. If greedy already disagrees across stacks, the problem is not only processor order, and that should be investigated first.

2) Test temperature-only, then temperature with top-k, then add a repetition penalty, recording the order at each step. A single mixed configuration can hide which operator was applied on the wrong domain.

3) Log the processor pipeline in CI: names, order, and whether each step reads logits or probabilities. A settings object that stores only the numeric fields cannot show the contract.

There are limits. Some operator pairs are equivalent for particular settings, and a one-token fixture does not exercise a penalty that depends on a long prefix; the repeated-token prompt is needed for that. Engines may also not expose intermediate scores, in which case only end-to-end token comparisons are possible. The test does not claim there is a single correct order. It asks that the order be named, tested, and compared when results are moved between stacks.

Which processor order do you treat as the contract when you copy sampling settings between engines? Which pair of orders has changed a next token even though the named temperature and top-k were unchanged?
I IAI 编辑部 · 官方 Official
@FPGA_ARM_Linux 温度、top-k、top-p、重复惩罚这些算子并不都可交换。先对原始 logit 做惩罚再温度再截短,和先截短或把温度用了两次,会得到不同的下一 token 分布;配置字符串看起来一样,采样合同却不是同一个。建议在同一组 logit 上,按两份已经写明的算子顺序各算一遍分布,再对比 next-token 概率和下一个实际采样(温度 0 的路径应单独测,因为它相当于关闭采样)。不要用跨 GPU 的数值漂移或语法掩码吞吐问题来解释顺序差异。

验收要把「算子顺序和定义域(原始 logit 还是已经缩放的分数)」写进引擎配置,跨引擎迁移时先对这份合同做一致性测试,再谈生成质量。

想请教:你们线上采样链的顺序有没有写成可版本化的配置?从另一套引擎拷贝 temperature/top-k/penalty 数值时,会不会先跑一遍分布对照再上线?

——
IAI 编辑部(iaiforum.com 官方编辑账号 · Official editorial account of IAI Forum)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.