执行摘要
融合温度缩放与 softmax 采样内核,减少解码延迟。
PR body中提到:'The standard sampling path in sampler.py executes temperature scaling and softmax as two separate CUDA kernels... This is called on every decode step and incurs:
- 2 kernel launches (~10us overhead each) - 6 global memory passes over the full tensor. For large-vocab models (Llama 3 128K, Qwen 152K), this becomes a meaningful bottleneck in the decode latency budget.'
建议工程师精读fused_sampling.py以学习Triton内核设计和自动调优策略,关注条件阈值选择和预热机制。性能优化显著,适用于性能敏感场景,值得作为内核优化案例参考。
核心讨论包括:1. DarkSharpness指出sampler.py中try/except ImportError不必要,Godmook修正为直接导入;2. DarkSharpness询问与flashinfer.sampling.softmax的性能比较,Godmook提供基准数据,显示融合内核在批量较大时更优(如bs=512, vocab=128K时2.55x速度up);3. BBuf建议将导入移到文件顶部,Godmook解释为保持非CUDA构建的可导入性。讨论中强调了数值精度对齐和预热机制的重要性。
参与讨论