vllm.models.beam.nvidia.dflash2
¶
DFlash2 draft model for Beam targets.
A DFlash2 drafter predicts a block of tokens at once from hidden states the
Beam target captures at dflash_config.target_layer_ids, then a low-rank
candidate selector rescores the top-k tokens at each block position against
the token before it. The drafter shares the target's embeddings and LM head.
Nothing here is torch-compiled. The DFlash speculator captures the whole draft step (decoder layers, candidate head and selector) in its own CUDA graphs, and the context K/V precompute runs eagerly as a few fused kernels.
Classes:
-
DFlash2BeamCandidateSelector–Scores each candidate token against every candidate one position back.
-
DFlash2BeamForCausalLM– -
DFlash2BeamModel–
DFlash2BeamCandidateSelector
¶
Bases: Module
Scores each candidate token against every candidate one position back.
For block position p, candidate c and predecessor q, the score is the
candidate's own logit plus <predecessor[q] * h_p, successor[c]>, where
h_p is the drafter's hidden state projected to the codebook rank. The
predecessor of the first position is the anchor token.
Methods:
-
forward–Edge scores
[requests, steps, top_k (predecessor), top_k].
Source code in vllm/models/beam/nvidia/dflash2.py
forward(candidate_ids, unary_logits, hidden_states, anchor_token_ids)
¶
Edge scores [requests, steps, top_k (predecessor), top_k].
Source code in vllm/models/beam/nvidia/dflash2.py
DFlash2BeamForCausalLM
¶
Bases: Module
Methods:
-
combine_hidden_states–Project the concatenated target-layer states to the drafter's width.
-
compute_candidates–The selector's top-k candidate ids and their logits at each position.
-
get_draft_attn_causal–Per-layer causality, aligned with
get_draft_kv_cache_layer_names.
Source code in vllm/models/beam/nvidia/dflash2.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
combine_hidden_states(hidden_states)
¶
Project the concatenated target-layer states to the drafter's width.
Source code in vllm/models/beam/nvidia/dflash2.py
compute_candidates(hidden_states)
¶
The selector's top-k candidate ids and their logits at each position.
Source code in vllm/models/beam/nvidia/dflash2.py
get_draft_attn_causal()
¶
Per-layer causality, aligned with get_draft_kv_cache_layer_names.
DFlash2BeamModel
¶
Bases: Module
Methods:
-
build_context_kv_weights–Stack every layer's K/V projection and K-norm weight.
-
precompute_and_store_context_kv–Project the combined target states to each layer's K/V and cache them.
Source code in vllm/models/beam/nvidia/dflash2.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
build_context_kv_weights()
¶
Stack every layer's K/V projection and K-norm weight.
The context K/V for all layers then comes from one GEMM and one grouped norm. Must run after the weights are loaded, since it copies them.
Source code in vllm/models/beam/nvidia/dflash2.py
precompute_and_store_context_kv(context_states, context_positions, context_slot_mapping=None)
¶
Project the combined target states to each layer's K/V and cache them.
The drafter's queries attend to these context keys, which carry the
layer's K-norm and RoPE like the queries' own keys. Profiling uses a
None slot mapping to run the projection without writing the cache.
Source code in vllm/models/beam/nvidia/dflash2.py
_forward_normalized(layer, positions, hidden_states, residual, next_norm)
¶
Carry normalized activations across layers to fuse both convolutions.