vllm.worker.multi_step_model_runner
DeferredLogprobsReturnType
module-attribute
¶
DeferredLogprobsReturnType = Tuple[
Optional[List[Optional[PromptLogprobs]]],
Optional[List[SampleLogprobs]],
]
MULTI_STEP_ATTENTION_BACKENDS
module-attribute
¶
MULTI_STEP_CHUNKED_PREFILL_ATTENTION_BACKENDS
module-attribute
¶
ModelOutput
dataclass
¶
The output of a single model forward pass.
The sampler_output_ready_event is set when the tensors in sampler_output are ready (the model+sampler forward pass has completed). We use the event to synchronize the GPU->CPU transfer, which we want to only run when the data has been written to the GPU tensors. Until the event is ready, the tensors in sampler_output will have garbage data.
There are two scenarios: 1. The output tensors are ready and we can pythonize them immediately. 2. The output tensors are not ready and we need to wait for the event to be ready.
Source code in vllm/worker/multi_step_model_runner.py
pythonization_cache
class-attribute
instance-attribute
¶
pythonization_cache: Optional[PythonizationCache] = None
__init__
¶
__init__(
sampler_output: SamplerOutput,
sampler_output_ready_event: Event,
sampled_token_ids: Optional[Tensor] = None,
pythonized: bool = False,
logprobs: Optional[Tensor] = None,
pythonization_cache: Optional[
PythonizationCache
] = None,
) -> None
_pythonize_sampler_output
¶
_pythonize_sampler_output(
input_metadata: StatefulModelInput,
copy_stream: Stream,
pinned_sampled_token_buffer: Tensor,
blocking: bool,
) -> bool
If blocking is set, will block until the forward pass for the output is ready and pythonize the output. Upon completing Pythonization, erases self.logprobs (note that a non-blocking call that is performed when the sampler output is not yet ready, will not erase self.logprobs.)
Source code in vllm/worker/multi_step_model_runner.py
maybe_pythonize
¶
maybe_pythonize(
input_metadata: StatefulModelInput,
copy_stream: Stream,
pinned_sampled_token_buffer: Tensor,
) -> None
Pythonize the output if ready, else return None. Non-blocking.
Source code in vllm/worker/multi_step_model_runner.py
pythonize
¶
pythonize(
input_metadata: StatefulModelInput,
copy_stream: Stream,
pinned_sampled_token_buffer: Tensor,
) -> None
Pythonize the output. Blocking.
Source code in vllm/worker/multi_step_model_runner.py
MultiStepModelRunner
¶
Bases: GPUModelRunnerBase[StatefulModelInput]
Source code in vllm/worker/multi_step_model_runner.py
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 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
pythonization_cache
instance-attribute
¶
pythonization_cache = (
PythonizationCache()
if pipeline_parallel_size == 1
else None
)
__init__
¶
__init__(
base_model_runner: GPUModelRunnerBase, *args, **kwargs
)
Source code in vllm/worker/multi_step_model_runner.py
_advance_step
¶
_advance_step(
model_input: StatefulModelInput, out: SamplerOutput
) -> StatefulModelInput
Source code in vllm/worker/multi_step_model_runner.py
_async_process_outputs
¶
_async_process_outputs(
model_input: StatefulModelInput,
output_proc_callback: Callable,
)
Source code in vllm/worker/multi_step_model_runner.py
_final_process_outputs
¶
_final_process_outputs(
model_input: StatefulModelInput,
output_proc_callback: Optional[Callable],
) -> List[SamplerOutput]
Source code in vllm/worker/multi_step_model_runner.py
_update_sampling_metadata
¶
_update_sampling_metadata(
sampling_metadata: SamplingMetadata,
num_seqs: Optional[int],
num_queries: int,
)
Source code in vllm/worker/multi_step_model_runner.py
capture_model
¶
execute_model
¶
execute_model(
model_input: StatefulModelInput,
kv_caches: List[Tensor],
intermediate_tensors: Optional[
IntermediateTensors
] = None,
num_steps: int = 1,
) -> Optional[
Union[List[SamplerOutput], IntermediateTensors]
]
Execute the model for a single step and update multi-step metadata
Source code in vllm/worker/multi_step_model_runner.py
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 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
load_model
¶
make_model_input_from_broadcasted_tensor_dict
¶
make_model_input_from_broadcasted_tensor_dict(
tensor_dict: Dict[str, Any],
) -> StatefulModelInput
Source code in vllm/worker/multi_step_model_runner.py
prepare_model_input
¶
prepare_model_input(
seq_group_metadata_list: List[SequenceGroupMetadata],
virtual_engine: int = 0,
finished_requests_ids: Optional[List[str]] = None,
) -> StatefulModelInput
Source code in vllm/worker/multi_step_model_runner.py
profile_run
¶
remove_all_loras
¶
save_sharded_state
¶
save_tensorized_model
¶
save_tensorized_model(
tensorizer_config: TensorizerConfig,
) -> None
PythonizationCache
¶
Source code in vllm/worker/multi_step_model_runner.py
cached_completion_seq_group_output
instance-attribute
¶
cached_completion_seq_group_output = PyObjectCache(
completion_seq_group_output_builder
)
__init__
¶
StatefulModelInput
dataclass
¶
Bases: BroadcastableModelInput
Source code in vllm/worker/multi_step_model_runner.py
146 147 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 |
|
base_output_proc_callback
class-attribute
instance-attribute
¶
cached_outputs
class-attribute
instance-attribute
¶
cached_outputs: List[ModelOutput] = field(
default_factory=list
)
frozen_model_input
class-attribute
instance-attribute
¶
frozen_model_input: Optional[
ModelInputForGPUWithSamplingMetadata
] = None
last_sampled_token_ids
class-attribute
instance-attribute
¶
step_cuda_events
class-attribute
instance-attribute
¶
__init__
¶
__init__(
frozen_model_input: Optional[
ModelInputForGPUWithSamplingMetadata
] = None,
cached_outputs: List[ModelOutput] = list(),
last_sampled_token_ids: Optional[Tensor] = None,
current_step: int = 0,
is_multi_step: bool = True,
is_last_step: bool = False,
is_first_multi_step: bool = False,
base_output_proc_callback: Optional[Callable] = None,
step_cuda_events: List[Event] = lambda: [
Event(blocking=True)
]
* 2(),
num_seqs: int = -1,
num_queries: int = -1,
num_single_step_prefills: int = 0,
) -> None
add_sampler_output
¶
add_sampler_output(
sampler_output: SamplerOutput,
sampled_token_ids: Optional[Tensor] = None,
)
Source code in vllm/worker/multi_step_model_runner.py
as_broadcastable_tensor_dict
¶
Source code in vllm/worker/multi_step_model_runner.py
from_broadcasted_tensor_dict
classmethod
¶
from_broadcasted_tensor_dict(
tensor_dict: Dict[str, Any],
attn_backend: Optional[AttentionBackend] = None,
) -> StatefulModelInput
Source code in vllm/worker/multi_step_model_runner.py
maybe_advance_frozen_model_input
¶
Advancing the datastructures of StatefulModelInput::frozen_model_input is only required when prefills are scheduled with decodes to run in multi-step. This advancement/correction is required to account for the conversion of Prefills to Decodes after the first multi-step.
Source code in vllm/worker/multi_step_model_runner.py
maybe_advance_sampling_metadata
¶
sampling_metadata.selected_token_indices is constructed for the first-step in Multi-Step. However, when chunked-prefill is enabled with multi-step, the scheduled prompts are fully processed in the first-step and are processed as decodes in the rest of the steps. This function updates the sampling_metadata.selected_token_indices to account for this conversion.
Example: Let 2 prompts and 2 decodes be scheduled together. Let the num-tokens to process for the 2 prompts be 5 and 8 respectively.
In that case, sampling_metadata.sampled_token_indices will be, [4, 12, 13, 14] as it is constructed for the first-step in multi-step. However, the prompts turns to decodes after the first-step and the num-tokens for the previously-prompt sequences will be 1 and 1 as they are decodes now. The self.sampled_token_indices must be updated to [0,1,2,3].
Source code in vllm/worker/multi_step_model_runner.py
record_step_event
¶
record_step_event(current_stream: Stream)
Source code in vllm/worker/multi_step_model_runner.py
wait_previous_step
¶
Source code in vllm/worker/multi_step_model_runner.py
_get_supported_attention_backends
¶
_pythonize_sampler_output
¶
_pythonize_sampler_output(
model_input: StatefulModelInput,
output: SamplerOutput,
pinned_sampled_token_buffer: Tensor,
sampled_token_ids: Tensor,
logprobs_tensor: Optional[Tensor],
cache: Optional[PythonizationCache],
) -> None
This function is only called when the output tensors are ready.
See ModelOutput
.
Modifies output.outputs
and pinned_sampled_token_buffer
in-place,
adding a Pythonized output data structure
(CompletionSequenceGroupOutput
)
for each SequenceGroup
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
SamplerOutput
|
sampler output |
required |
pinned_sampled_token_token_buffer
|
CPU-side pinned memory (receives copy of GPU-side token buffer.) |
required | |
sampled_token_ids
|
Tensor
|
GPU-side token buffer |
required |
logprobs_tensor
|
Optional[Tensor]
|
GPU-side tensor containing logprobs computed during sampling |
required |
Source code in vllm/worker/multi_step_model_runner.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
|
completion_seq_group_output_builder
¶
deferred_pythonize_logprobs
¶
deferred_pythonize_logprobs(
output: SamplerOutput,
sampling_metadata: SamplingMetadata,
logprobs_tensor: Optional[Tensor],
) -> DeferredLogprobsReturnType
Perform deferred logprob Pythonization.
- Pythonize GPU-side sampler result tensors into CPU-side sampler result.
- Pythonize GPU-side logprobs tensor into CPU-side logprobs lists, utilizing the Pythonized sampler result computed in step 1.
These deferred computations are not required for single-step scheduling
or the profile_run()
phase of multi-step scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
SamplerOutput
|
sampler output (under deferred Pythonization) |
required |
Returns:
Type | Description |
---|---|
DeferredLogprobsReturnType
|
prompt_logprobs (CPU), sample_logprobs (CPU) |