Skip to content

Commit cdba045

Browse files
committed
Refactor vLLM attention orchestration
Signed-off-by: Kai Xu <kaix@nvidia.com>
1 parent 04418af commit cdba045

8 files changed

Lines changed: 1025 additions & 668 deletions

File tree

examples/vllm_serve/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is a simple example to demonstrate calibrating and serving ModelOpt fakequa
55
Compared with realquant, fakequant is 2-5x slower, but doesn't require dedicated kernel support and facilitates research.
66

77
The general fakequant example is tested with vLLM 0.9.0 and 0.19.1. The compact
8-
NVFP4 attention worker documented below requires vLLM 0.14.0 or newer.
8+
NVFP4 attention worker documented below requires vLLM 0.15.0 or newer.
99

1010
## Prepare environment
1111

@@ -115,9 +115,19 @@ Workflow:
115115
python vllm_serve_sparse_attn.py <EXPORT_DIR> --enforce-eager -tp 8 --host 0.0.0.0 --port 8000
116116
```
117117

118-
If the checkpoint has no `sparse_attention_config`, the worker logs a message and passes through vLLM runs unchanged. Whole-model fakequant flows remain handled by `vllm_serve_fakequant.py`; the compact attention-only path is below.
118+
If the checkpoint has no `sparse_attention_config`, the sparse-only installer passes through and vLLM runs unchanged. Whole-model fakequant flows remain handled by `vllm_serve_fakequant.py`; the compact attention-only path is below.
119119

120-
Both explicit serving policies live in `sparse_attn_worker.py`: `SparseAttnWorker` is checkpoint-driven sparse-only, while `QuantSparseAttnWorker` uses fixed NVFP4 Q/K/P/V plus optional checkpoint sparsity. The launcher keeps `SparseAttnWorker` as its default.
120+
The reusable serving policies live in `modelopt/torch/sparsity/attention_sparsity/plugins/vllm_runtime.py`. `install_vllm_sparse_attention_from_checkpoint` installs checkpoint-driven sparse-only attention, while `install_vllm_nvfp4_attention` installs fixed NVFP4 Q/K/P/V with optional checkpoint sparsity. Both validate every selected layer before publishing any replacement implementation and return a `VllmAttentionInstallReport` with the installed layer names and backend counts.
121+
122+
`sparse_attn_worker.py` only invokes these APIs after vLLM loads the model. It retains `SparseAttnWorker` as the launcher's default and provides `QuantSparseAttnWorker` for the compact NVFP4 policy. Other vLLM integrations can invoke the same library APIs directly:
123+
124+
```python
125+
from modelopt.torch.sparsity.attention_sparsity.plugins.vllm_runtime import (
126+
install_vllm_nvfp4_attention,
127+
)
128+
129+
report = install_vllm_nvfp4_attention(model_runner, sparse_cfg="checkpoint")
130+
```
121131

122132
Limitations:
123133

@@ -126,7 +136,7 @@ Limitations:
126136

127137
### Compact NVFP4 attention worker
128138

129-
vLLM 0.14.0 or newer is checked when `QuantSparseAttnWorker` is selected. Importing or using `SparseAttnWorker` does not resolve quant-only APIs.
139+
vLLM 0.15.0 or newer is required when either worker activates a ModelOpt attention transform. Importing `SparseAttnWorker`, or using it with no checkpoint sparse metadata, does not resolve quant-only APIs.
130140

131141
Use the same launcher with the compact worker. By default, vLLM selects the backend for the model and platform; NemotronH on Blackwell selects FlashInfer:
132142

@@ -136,9 +146,9 @@ python vllm_serve_sparse_attn.py <MODEL_PATH> -tp 8 \
136146
--worker-cls sparse_attn_worker.QuantSparseAttnWorker
137147
```
138148

139-
The worker supports both FlashInfer and FlashAttention and prints the installed adapter counts. Pass `--attention-backend FLASHINFER` or `--attention-backend FLASH_ATTN` only when an explicit override is needed.
149+
The installer supports both FlashInfer and FlashAttention, and the worker prints the installed adapter counts. Pass `--attention-backend FLASHINFER` or `--attention-backend FLASH_ATTN` only when an explicit override is needed.
140150

141-
This attention-only path applies a fixed dynamic block-16 NVFP4 fakequant recipe to Q/K/P/V. Q is dynamic, K/V use global scale 1.0, and P uses amax 1.0; calibrated attention amax restore is not part of this fixed path. It does not re-quantize realquant Linear or MoE weights. An optional checkpoint `sparse_attention_config` is still honored.
151+
This attention-only path applies a fixed dynamic block-16 NVFP4 fakequant format to Q/K/P/V. Q is dynamic; missing K/V scales default to global scale 1.0, and P defaults to amax 1.0. Existing scalar attention amax values are preserved, but this path does not calibrate or restore them itself. It does not re-quantize realquant Linear or MoE weights. An optional checkpoint `sparse_attention_config` is still honored.
142152

143153
Decode uses a fixed 32-split, 128-key-tile schedule. P QDQ consumes split-local,
144154
unnormalized online-softmax probabilities, so changing that schedule can change

0 commit comments

Comments
 (0)