[RL] DSV4: add env to quantize SWA KV cache from bf16-rounded values (#31086)

Signed-off-by: zhihaow6 <zhihaow6@illinois.edu>
This commit is contained in:
Zhihao Wang
2026-07-24 15:52:00 -07:00
committed by GitHub
parent 4ececf2b1d
commit 0a212c6119
3 changed files with 17 additions and 0 deletions
+3
View File
@@ -1018,6 +1018,9 @@ class Envs:
# Default reasoning_effort for dsv4 chat encoder when request doesn't set it.
# Accepts "", "max", "high" (empty string means unset); other values filtered to None.
SGLANG_DSV4_REASONING_EFFORT = EnvStr("")
# Quantize the SWA fp8 KV cache from bf16-rounded values (matches
# trainer-side QAT and the DSA-CP path) instead of fp32 registers.
SGLANG_DSV4_USE_BF16_KV_QUANT_SOURCE = EnvBool(False)
# CUDA kernels
SGLANG_OPT_DEEPGEMM_HC_PRENORM = EnvBool(True)
+9
View File
@@ -722,6 +722,15 @@ class MQALayer(MqaAttentionBase):
Replaces the bf16-kv-intermediate path. Used everywhere except the DSA
prefill-CP case (which needs bf16 kv for the cross-rank all-gather).
"""
if envs.SGLANG_DSV4_USE_BF16_KV_QUANT_SOURCE.get():
# Quantize the nope payload from bf16-rounded values (the fused
# kernel quantizes from fp32 registers; the bf16 rounding moves
# values across fp8 bins relative to bf16-sourced consumers).
kv = self._compute_kv_bf16(x, positions, qkv_a=qkv_a)
attn_backend.store_cache(
layer_id=self.layer_id, swa_k=kv, forward_batch=forward_batch
)
return
if qkv_a is not None:
kv = qkv_a[..., self.q_lora_rank :]
else: