@@ -94,6 +94,7 @@ class _InstallPlan:
9494 layers : tuple [_AttentionPlan , ...]
9595 quantize : bool
9696 sparse_algorithm : str | None
97+ bmm2 : str = "nvfp4"
9798
9899
99100def _unwrapped_model (model_runner ):
@@ -315,7 +316,9 @@ def _raise_unsupported(errors: list[str], policy: str) -> None:
315316 )
316317
317318
318- def _plan_vllm_attention (model_runner , * , quantize : bool , sparse_cfg ) -> _InstallPlan :
319+ def _plan_vllm_attention (
320+ model_runner , * , quantize : bool , sparse_cfg , bmm2 : str = "nvfp4"
321+ ) -> _InstallPlan :
319322 model = _unwrapped_model (model_runner )
320323 resolved_sparse_cfg , sparse_algorithm = _resolve_sparse_config (model_runner , sparse_cfg )
321324 candidates = []
@@ -329,7 +332,7 @@ def _plan_vllm_attention(model_runner, *, quantize: bool, sparse_cfg) -> _Instal
329332 candidates .append ((name , module , sparse_kw ))
330333
331334 if not candidates and not quantize :
332- return _InstallPlan (model_runner , (), False , sparse_algorithm )
335+ return _InstallPlan (model_runner , (), False , sparse_algorithm , bmm2 )
333336
334337 _require_supported_vllm ()
335338 errors = _global_errors (model_runner ) if quantize else []
@@ -373,7 +376,7 @@ def _plan_vllm_attention(model_runner, *, quantize: bool, sparse_cfg) -> _Instal
373376 if quantize and attention_count == 0 :
374377 errors .append ("no regular attention layers were found" )
375378 _raise_unsupported (errors , "NVFP4 attention" if quantize else "sparse attention" )
376- return _InstallPlan (model_runner , tuple (plans ), quantize , sparse_algorithm )
379+ return _InstallPlan (model_runner , tuple (plans ), quantize , sparse_algorithm , bmm2 )
377380
378381
379382def _build_report (plan : _InstallPlan ) -> VllmAttentionInstallReport :
@@ -405,15 +408,28 @@ def _apply_vllm_attention_plans(plan: _InstallPlan) -> VllmAttentionInstallRepor
405408 for layer in plan .layers :
406409 layer .new_impl .sparse_kw = layer .sparse_kw
407410 if plan .quantize :
411+ # Pass cfg only for the non-default recipe: keeps the default call
412+ # signature stable for callers/fakes that predate the cfg parameter.
413+ _cfg_kwargs = (
414+ {"cfg" : quant_plugin ._VLLM_NVFP4_BMM1_FP8_BMM2_QUANT_CFG }
415+ if plan .bmm2 == "fp8"
416+ else {}
417+ )
408418 converted = quant_plugin .configure_vllm_nvfp4_attention_quantizers (
409419 layer .module ,
410420 device = layer .device ,
411421 dtype = layer .dtype ,
422+ ** _cfg_kwargs ,
412423 )
413424 if converted is not None and converted is not layer .module :
414425 raise RuntimeError ("vLLM attention quantization must convert modules in place" )
415426 p_qdq , p_qdq_amax = attention_plugin ._p_qdq_from_layer (layer .module )
416427 v_qdq , v_qdq_amax = attention_plugin ._v_qdq_from_layer (layer .module )
428+ if plan .bmm2 == "fp8" :
429+ # Per-tensor FP8 V is quantized module-level BEFORE the cache
430+ # write (each token is self-contained; no block geometry), so
431+ # the kernel sees pre-QDQ'd V and needs no V transform at all.
432+ v_qdq , v_qdq_amax = None , None
417433 layer .new_impl .quant_kw = {
418434 "p_qdq" : p_qdq ,
419435 "p_qdq_amax" : p_qdq_amax ,
@@ -426,7 +442,7 @@ def _apply_vllm_attention_plans(plan: _InstallPlan) -> VllmAttentionInstallRepor
426442 old_value_flag = getattr (layer .module , "_value_quant_in_kernel" , missing )
427443 if plan .quantize :
428444 layer .module ._query_quant_in_kernel = True
429- layer .module ._value_quant_in_kernel = True
445+ layer .module ._value_quant_in_kernel = plan . bmm2 != "fp8"
430446 try :
431447 # Publish the adapter last so a native impl never runs with in-kernel
432448 # quantization flags that only the ModelOpt adapter understands.
@@ -463,6 +479,7 @@ def install_vllm_nvfp4_attention(
463479 model_runner ,
464480 * ,
465481 sparse_cfg = "checkpoint" ,
482+ bmm2 : str = "nvfp4" ,
466483) -> VllmAttentionInstallReport :
467484 """Install fixed NVFP4 attention with optional checkpoint sparsity.
468485
@@ -471,6 +488,8 @@ def install_vllm_nvfp4_attention(
471488 sparse_cfg: ``"checkpoint"`` to consume optional exported metadata, a
472489 resolved sparse config dict, or ``None`` for NVFP4-only attention.
473490 """
491+ if bmm2 not in ("nvfp4" , "fp8" ):
492+ raise ValueError (f"bmm2 must be 'nvfp4' or 'fp8', got { bmm2 !r} " )
474493 return _apply_vllm_attention_plans (
475- _plan_vllm_attention (model_runner , quantize = True , sparse_cfg = sparse_cfg )
494+ _plan_vllm_attention (model_runner , quantize = True , sparse_cfg = sparse_cfg , bmm2 = bmm2 )
476495 )
0 commit comments