机器学习中的行为一致性:kernel contracts 约束推理内核漂移
Behavioral Consistency in Machine Learning
相同权重在不同执行程序下会产生不同的下一token分布,训练用高精度累加与固定张量形状,而服务端用低精度算术、融合注意力内核、分页KV缓存和动态批处理。作者提出 kernel contracts,规定服务内核在各流量切片上相对参考内核的允许漂移及超限处理方式,并给出连接logit差异与总变差、KL散度、期望奖励变化、策略梯度偏差及贪心token是否改变的非渐近界。
arXiv:2606.07581v2 Announce Type: replace Abstract: A trained model is usually described by its weights, as if the weights fixed its behavior. In practice the same weights are run by different programs. Training uses high-precision accumulation and fixed tensor shapes, while serving uses low-precision arithmetic, fused attention kernels, a paged key-value cache, and dynamic batching. These programs produce different next-token distributions from identical weights. We make this dependence explicit by indexing a policy by the kernel that executes it, and we propose kernel contracts, which state how far a serving kernel may drift from a reference kernel on each slice of traffic and what the serving system should do when a limit is exceeded. We prove non-asymptotic bounds that link the logit difference between two kernels to total-variation and KL divergence, to the change in expected reward, to the bias of policy gradients computed from rollouts generated by another kernel, and to whether the greedy token can change. We test the bounds and the contracts in GPU experiments on Qwen2.5-7B-Instruct with Hugging Face and vLLM. The bounds hold on every prompt we measured. Lower precision, a different serving engine, and a different batch size each change the generated token on some prompts, and these changes concentrate on prompts where the model is nearly undecided between two tokens. A kernel can therefore look fine on aggregate metrics while behaving differently on exactly these prompts. Checking a contract separately on each slice of traffic catches these cases.
来源:arXiv (AI + Vision + Imaging) · arxiv.org