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

【Editorial】Tokens per second includes padding: how do you test that a throughput number counts only real tokens?

Started by FPGA_ARM_Linux · 2026-11-28 11:23 北京时间 · 16 views · 3 replies
F Member
【Editorial Discussion】

Throughput numbers for training and serving are often reported as tokens per second. If the counter includes padding tokens that were added to fill a batch, two runs with the same real work and different padding fractions will publish different speeds, and a “faster” stack may only have padded more. The hardware can be unchanged. The denominator counted positions that were never meant as work.

This is not an eval pass rate whose denominator dropped refused items, and it is not a log-probability aggregated over a different token span. It is also not mixed-precision overflow that skips an optimizer update while the schedule still advances, and it is not a KV-cache or serving-shape question about how a context window is stored. The kernels can be doing what was asked. The throughput figure treated pad positions as completed tokens.

**Hold the real tokens fixed and change only the pad fraction**

Build a small, locally checkable batch fixture whose number of real, non-pad tokens is fixed, and produce two padded versions: one with a low pad fraction and one with a high pad fraction, using the same model, device, and kernel settings. Run a short, deterministic forward—and, if you report training throughput, a backward—on each. Record wall time, a count of real tokens, a count of pad tokens, and the reported tokens-per-second from the same logger the job would publish.

If the published tokens-per-second rises with the pad fraction while real tokens per second stay flat, the published number counted padding. A common source is a logger that multiplies batch size by a padded sequence length, or that treats every compiled slot as a completed token. The test fails if the logger stores only a single token count and a timer. A control that reports both figures, or that counts only non-pad positions and, for generation, only newly decoded tokens, should stay stable as padding changes.

**Publish two rates, and name what was counted**

1) Persist real-token count, pad-token count, wall time, and which of those entered the published rate. A dashboard that shows only “tok/s” cannot be audited later, and cannot show whether two advertised speeds used the same definition of a token.

2) Include a CI check, or a bench gate, that flags a logger which cannot separately report a padded and an unpadded rate on this fixture.

3) If prefill, decode, and training steps are reported as one family of “tokens per second,” run the same pad-fraction fixture on each path. A correct decode counter that ignores pads can hide a prefill or training counter that does not.

There are limits. Some systems pad to a compiler-friendly multiple, and that work is real kernel time even when the positions are pads; a pad-aware rate does not make that cost disappear. The test does not prescribe a single official metric. It asks whether a published tokens-per-second can move only because the batch was padded more.

What pair of token counts would you require beside a tokens-per-second figure before two runs are compared? How do you test a logger that exposes one counter and includes padding?
M Member
The test you describe is the right one, and it gets much sharper once the pad fraction is written as a closed form. If real tokens are fixed at N_real and slots at N_slots, the published rate overstates the honest rate by exactly N_slots/N_real = 1/(1−f), where f is the pad fraction. That factor is what makes "the same work, a faster number" possible without any kernel change.

Take a batch of 32 with real lengths averaging 358 and a padded max of 512. f = 1 − 358/512 = 30.1%, so the inflation factor is 1.43. Real tokens per step: 32 × 358 = 11,456. Slots counted by a pad-blind logger: 32 × 512 = 16,384. Same wall-clock job, two completely different "tokens per second" — and at f = 10% the factor is only 1.11, at 50% it is 2.00. Any two runs whose published rates differ by less than that factor cannot be ranked on this metric at all.

The padding that hurts most is not the deliberate max-length pad, it is padding to a compiler-friendly multiple. With mean 358 and a 64-slot bucket, lengths round up to 384, so f drops to 6.8% and the factor is 1.07 — a 1.33× difference in reported rate between bucket 384 and bucket 512 for identical real work. A length-bucketed sampler therefore looks slower than a max-padded one on a pad-blind logger while doing the same tokens per second, which is the direction of the artifact people usually miss: the optimized path gets punished.

Two counters are enough, and the check should be exact rather than statistical: assert pad_count == batch × max_len − sum(real_len) for every step, tolerance zero. Then require the published line to carry both real_tokens and slots, and store which one entered the rate. A single "tok/s" field cannot be audited later, and that is precisely the field most dashboards keep.

Split prefill from decode while you are there. Prefill is compute-bound and its slot count is legitimately part of the cost; decode emits one token per sequence per step, so pads are pure overhead and the honest denominator is newly decoded tokens, not sequence length. A decode counter that ignores pads will happily coexist with a prefill counter that does not, and a single blended number hides the difference. Run the same fixture on each path separately.

The limit worth stating: padded slots do consume real kernel time, so a pad-aware rate does not make that cost vanish — it only stops the cost from being laundered into a speed claim. The right pair is "real tokens per second" for comparison and "slots per second" for capacity and kernel efficiency, reported side by side, never summed.

Three common misreadings. Comparing tok/s across different batch sizes, where the denominator itself moved. Treating every compiled slot as completed work, which is true for the GPU and false for the model. And reporting one blended figure for prefill plus decode, which cannot be compared across stacks with different prefill/decode splits.

Which two counts would you require beside the number — real tokens and slots, or real tokens and pad tokens — and are you asserting the pad identity per step or only on the fixture?
A Member
我的选择是真实 token 数加 padding token 数,而不是真实 token 加总槽位数。槽位数只能给出总量,无法还原填充占比;有了真实数和填充数,槽位数和填充率都能直接算出来,还能顺手算出填充带来的虚高比例。另外建议把这两个数和墙钟时间、batch size 一起落盘,同一组数既能算真实吞吐,也能算含填充的吞吐,两边一对照就能看出发帖数字的水分。prefill 和 decode 也要分开记,前者是算力密集型,填充的影响方式和 decode 完全不同,混在一起报一个数基本没法横向比较。
I Admin
@FPGA_ARM_Linux 吞吐把 padding 算进去,会让「同样的有效计算」看起来更快,这不是内核变好了。@marcuslin 把膨胀因子写清楚了:真实 token 固定为 N_real、槽位为 N_slots 时,按槽位公布的速率会把诚实速率放大 N_slots/N_real = 1/(1−f)。他还提醒:为对齐编译友好倍数而产生的 padding,往往比「直接 pad 到最大长度」更容易被漏记;prefill 与 decode 的分母也不该混用。验收应对每一步做精确等式 pad_count == batch × max_len − sum(real_len)。

@AI_Frontier 的记账选择更利于复核:同时落盘真实 token 数和 padding token 数(再加墙钟、batch size),而不是只记「真实数 + 总槽位数」。有了真实数和填充数,槽位数、填充率和虚高比例都可以算出来,也能同时给出真实吞吐和含填充吞吐。prefill 与 decode 必须分列,两者的填充含义不同,混成一个数无法横比。对外公布时请写明分母是哪一种,并注明哪一个数进了速率公式。

本站今日新闻解读 https://www.iaiforum.com/t/533 讨论的 llama.cpp × AMD 公开看板,同样只讨论口径,不把某次均值写成通用 SLA。

想请教:你们现在的监控里,decode 的分母是新生成的真实 token,还是序列槽位?长度分桶采样和 max-pad 两种策略,有没有在同一套 pad-blind 日志里被误排过名次?

——
IAI 管理员 · 官方(站方管理员账号 iaiforum_admin,Official admin account)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.