vllm.v1.spec_decode.utils ¶
copy_and_expand_eagle_inputs_kernel ¶
copy_and_expand_eagle_inputs_kernel(
target_token_ids_ptr,
target_positions_ptr,
next_token_ids_ptr,
out_input_ids_ptr,
out_positions_ptr,
out_is_rejected_token_mask_ptr,
out_is_masked_token_mask_ptr,
out_new_token_indices_ptr,
out_hidden_state_mapping_ptr,
query_start_loc_ptr,
query_end_loc_ptr,
padding_token_id,
parallel_drafting_token_id,
total_input_tokens,
num_padding_slots_per_request,
shift_input_ids,
BLOCK_SIZE_TOKENS: constexpr,
)
Copy and expand inputs from the target model to the drafting buffers for Eagle speculative decoding. This kernel handles padding slots and parallel drafting tokens, if enabled.
Source code in vllm/v1/spec_decode/utils.py
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 | |
create_vllm_config_for_draft_model ¶
create_vllm_config_for_draft_model(
target_model_vllm_config: VllmConfig,
) -> VllmConfig
The vllm_config is configured for the target model, e.g. its quant_config and parallel_config. But the draft model is potentially quantized differently, and has potentially different tensor_parallel_size. This function creates a new vllm_config configured for the drafter. The vllm_config is useful when loading the draft model with get_model().
Source code in vllm/v1/spec_decode/utils.py
eagle_prepare_inputs_padded_kernel ¶
eagle_prepare_inputs_padded_kernel(
cu_num_draft_tokens_ptr,
valid_sampled_tokens_count_ptr,
query_start_loc_gpu_ptr,
token_indices_to_sample_ptr,
num_rejected_tokens_gpu_ptr,
num_reqs,
)
Fused kernel for Eagle prepare_input_padded. This kernel computes the token index to sample for each request, taking into account the number of draft tokens and the number of valid sampled tokens (which is one more than the number of accepted tokens).
Source code in vllm/v1/spec_decode/utils.py
eagle_prepare_next_token_padded_kernel ¶
eagle_prepare_next_token_padded_kernel(
sampled_token_ids_ptr,
discard_request_mask_ptr,
backup_next_token_ids_ptr,
next_token_ids_ptr,
valid_sampled_tokens_count_ptr,
vocab_size,
num_sampled_tokens_per_req,
num_reqs,
stride_sampled_token_ids,
BLOCK_SIZE_TOKENS: constexpr,
)
Fused kernel for Eagle prepare_next_token_ids_padded. This kernel computes the number of valid (1 + accepted) tokens for each request, and the corresponding "next" token id to sample from during speculative decoding. This is the "last accepted token" from the sampled tokens, or the backup token if no tokens were accepted or if the request is marked as discarded.
Source code in vllm/v1/spec_decode/utils.py
eagle_step_slot_mapping_metadata_kernel ¶
eagle_step_slot_mapping_metadata_kernel(
positions_ptr,
block_table_ptr,
block_table_stride,
seq_lens_ptr,
out_clamped_positions_ptr,
out_slot_mapping_ptr,
block_size: constexpr,
max_model_len: constexpr,
n_blocks_per_req: constexpr,
PAD_ID: constexpr,
batch_size,
)
Fused kernel for EAGLE autoregressive step: updates positions, slot mapping, and sequence lengths in a single kernel to reduce launch overhead.
Launched with input_batch_size threads. Threads with req_idx >= batch_size are cudagraph padding slots and only write PADDING_SLOT_ID.
Each real thread handles one request in the batch. Computes: - new_position = position + 1, clamped if exceeds max_model_len - slot_mapping from block table lookup - seq_lens += 1, or 1 if position exceeds max
Source code in vllm/v1/spec_decode/utils.py
eagle_step_update_slot_mapping_and_metadata ¶
eagle_step_update_slot_mapping_and_metadata(
positions_1d: Tensor,
block_table_tensor: Tensor,
seq_lens: Tensor,
block_size: int,
max_model_len: int,
out_clamped_positions: Tensor,
out_slot_mapping: Tensor,
input_batch_size: int | None = None,
) -> None
Fused update of slot mapping and metadata for one EAGLE autoregressive step. Updates seq_lens in place. Writes to out_clamped_positions and out_slot_mapping.
When input_batch_size > batch_size, threads beyond batch_size write PADDING_SLOT_ID to out_slot_mapping for cudagraph padding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions_1d | Tensor | [batch_size] current positions (use positions[0] for M-RoPE) | required |
block_table_tensor | Tensor | [batch_size, n_blocks_per_req] | required |
seq_lens | Tensor | [batch_size] updated in place | required |
block_size | int | KV cache block size | required |
max_model_len | int | max model length for clamping | required |
out_clamped_positions | Tensor | [batch_size] output buffer for clamped positions | required |
out_slot_mapping | Tensor | [input_batch_size] output buffer for slot mapping | required |
input_batch_size | int | None | total batch size including cudagraph padding; defaults to batch_size (no padding) | None |
Source code in vllm/v1/spec_decode/utils.py
extend_all_queries_by_N ¶
extend_all_queries_by_N(
common_attn_metadata: CommonAttentionMetadata,
N: int,
arange: Tensor,
new_slot_mapping: Tensor,
) -> CommonAttentionMetadata
Creates a new CommonAttentionMetadata with all query lengths increased by N. Also all seq lens are increased by N. This is useful e.g. in speculative decoding with parallel drafting, where we extend each sequence by N tokens and predict all tokens in one pass. The slot mapping is computed externally, as it requires more information.