[FlashInfer v0.6.12] Support FlashInfer 4over6 NVFP4 (#25239)
This commit is contained in:
@@ -446,6 +446,9 @@ class Envs:
|
||||
SGLANG_FLASHINFER_WORKSPACE_SIZE = EnvInt(384 * 1024 * 1024)
|
||||
# Enable per-token NVFP4 activation scaling path for FlashInfer TRT-LLM MoE.
|
||||
SGLANG_FLASHINFER_NVFP4_PER_TOKEN_ACTIVATION = EnvBool(False)
|
||||
# SGLang needs to know FlashInfer NVFP4 4over6 config to compute the global scale factor.
|
||||
FLASHINFER_NVFP4_4OVER6 = EnvBool(False)
|
||||
FLASHINFER_NVFP4_4OVER6_E4M3_USE_256 = EnvBool(False)
|
||||
# Skip-softmax threshold scale factor for TRT-LLM attention (prefill and decode separately).
|
||||
# None = standard attention. See https://arxiv.org/abs/2512.12087
|
||||
SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTOR = EnvFloat(None)
|
||||
|
||||
@@ -876,9 +876,16 @@ def fused_experts_none_to_flashinfer_trtllm_fp4(
|
||||
if envs.SGLANG_FLASHINFER_NVFP4_PER_TOKEN_ACTIVATION.get():
|
||||
from flashinfer import SfLayout, nvfp4_quantize
|
||||
|
||||
e4m3_max = 448.0
|
||||
if (
|
||||
envs.FLASHINFER_NVFP4_4OVER6.get()
|
||||
and envs.FLASHINFER_NVFP4_4OVER6_E4M3_USE_256.get()
|
||||
):
|
||||
e4m3_max = 256.0
|
||||
|
||||
hs_fp4_bytes, hs_sf_bytes, per_token_scale = nvfp4_quantize(
|
||||
hidden_states,
|
||||
1.0 / (448.0 * 6.0),
|
||||
1.0 / (e4m3_max * 6.0),
|
||||
sfLayout=SfLayout.layout_linear,
|
||||
per_token_activation=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user