vllm.models.deepseek_v41.nvidia.model_state
¶
Classes:
-
DeepseekV41ModelState–DefaultModelState plus the engram lookback window and SWA bounded replay.
-
ReplayAttnMetadata–Hands the batch's replay starts to the sliding-window builders.
DeepseekV41ModelState
¶
Bases: DefaultModelState
DefaultModelState plus the engram lookback window and SWA bounded replay.
The engram n-gram hash needs the ids of the depth tokens preceding
each request's chunk start (see common/engram.py). The runner keeps
the full token history on device, so the window is gathered there every
step: exact for prompt and generated tokens alike, whatever instance
produced their KV.
SWA bounded replay (CacheConfig.swa_bounded_replay) keeps the
sliding-window KV out of prefix caching and rebuilds it after a prefix hit
by recomputing the hit's last window; the scheduler tells each request the
position from which it holds window KV (NewRequestData.replay_start).
prepare_attn gathers those per batch, pads the replayed tokens' slots
in the prefix-cacheable groups so the cached KV stays as is, and hands the
starts to the sliding-window metadata builders, whose kernels read no
window KV below them. With the decoder side on
(model.decoder_replay_layers) it also prepares the replay layers'
batch in eager steps: each prefill's last window rows as a sub-batch
with metadata and a forward context of its own, like a microbatch.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
_agree_across_dp(trims, num_tokens)
¶
Whether any rank trims and, then, the replay layers' DP metadata from every rank's replay token count.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
_kept_input_batch(input_batch, slot_mappings, replay_start, kept_lens)
¶
Build the sub-InputBatch of each request's last kept_lens
rows, and its slot mappings.
The kept rows follow the device boundaries minus the rows trimmed before them: adaptive verification resizes the decodes on the GPU alone, and decodes never trim. Like a microbatch's, the sub-batch describes the forward only; its sampling fields are carried over and must not be read.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
_prepare_replay_batch(input_batch, cudagraph_mode, block_tables, slot_mappings, attn_groups, kv_cache_config, replay_start)
¶
Set the replay layers' batch for this forward, or none when nothing trims. Only eager steps trim: a CUDA graph keeps the layers on the whole batch, and ranks share the graph mode. Under data parallelism every rank replays if any does.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
_replay_groups(attn_groups)
¶
The attention groups with metadata builders of their own, like each microbatch's: a builder keeps the metadata it built, and the runner's hold the batch's.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
_warm_up_replay_kernels(input_batch, slot_mappings)
¶
Compile the replay kernels on the buffers they run on: the startup dummy batches never replay or trim, so they would not launch them.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
ReplayAttnMetadata
¶
Bases: ModelSpecificAttnMetadata
Hands the batch's replay starts to the sliding-window builders.
Source code in vllm/models/deepseek_v41/nvidia/model_state.py
_gather_replay_batch_kernel(query_start_loc_ptr, dropped_before_ptr, seq_lens_ptr, replay_start_ptr, positions_ptr, slot_mappings_ptr, slot_mappings_stride, rows_ptr, kept_query_start_loc_ptr, kept_positions_ptr, kept_slot_mappings_ptr, kept_slot_mappings_stride, kept_kv_start_ptr, window, NUM_GROUPS, BLOCK)
¶
One program per request: its kept rows are the last ones before its boundary, and land at that boundary minus the rows trimmed before it.