-
-
Notifications
You must be signed in to change notification settings - Fork 20.1k
[offloader] v2: Hide weight onloading latency via prefetching #29941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a3dfa47
9bf4097
152af73
67cd6cc
c21063e
f43b577
975e972
0ed3570
b07eb3f
ac5fb49
80e764e
9436a66
21e0813
5bc88d8
719af1b
91c180e
20db2a1
2debd78
20ef9d8
f536bc4
021acc1
0525c42
6506706
55a9934
8478e55
4520428
fcaa9da
79ec7d5
5fe6d7c
08bab8a
0d18ec2
e5d375e
1d3d404
3c3ba9b
96301e3
6c6600d
ff52cd4
2a77385
20696cd
f537f21
18b576e
3df4d98
150dc9f
9f49711
0478a6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Test V2 offloading correctness with DeepSeek V2 model.""" | ||
|
|
||
| from ..utils import compare_two_settings | ||
|
|
||
|
|
||
| def test_v2_offload_deepseek(): | ||
| """Test V2 CPU offloading with DeepSeek-V2-Lite. | ||
|
|
||
| Compares outputs between: | ||
| 1. Baseline (no offloading) | ||
| 2. V2 offloading (group_size=8, num_in_group=2, prefetch_step=1) | ||
|
|
||
| This tests the advanced offloading with prefetching on a MoE model. | ||
| """ | ||
| compare_two_settings( | ||
| "deepseek-ai/DeepSeek-V2-Lite", | ||
| [], # Baseline: no offloading | ||
| [ | ||
| # V2 offloading configuration | ||
| "--offload-group-size", | ||
| "8", | ||
| "--offload-num-in-group", | ||
| "2", | ||
| "--offload-prefetch-step", | ||
| "1", | ||
| # currently not compatible with torch.compile | ||
| "--enforce-eager", | ||
| ], | ||
| ) | ||
|
minosfuture marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,14 @@ class LLM: | |
| the model weights. This virtually increases the GPU memory space | ||
| you can use to hold the model weights, at the cost of CPU-GPU data | ||
| transfer for every forward pass. | ||
| offload_group_size: Advanced CPU offloading: Group every N layers | ||
| together. Offload last `offload_num_in_group` layers of each group. | ||
| Default is 0 (disabled). | ||
| offload_num_in_group: Advanced CPU offloading: Number of layers to | ||
| offload per group. Default is 1. | ||
| offload_prefetch_step: Advanced CPU offloading: Number of layers to | ||
| prefetch ahead. Higher values hide more latency but use more GPU | ||
| memory. Default is 1. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we are missing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. Thanks! |
||
| enforce_eager: Whether to enforce eager execution. If True, we will | ||
| disable CUDA graph and always execute the model in eager mode. | ||
| If False, we will use CUDA graph and eager execution in hybrid. | ||
|
|
@@ -202,6 +210,9 @@ def __init__( | |
| gpu_memory_utilization: float = 0.9, | ||
| swap_space: float = 4, | ||
| cpu_offload_gb: float = 0, | ||
| offload_group_size: int = 0, | ||
| offload_num_in_group: int = 1, | ||
| offload_prefetch_step: int = 1, | ||
| enforce_eager: bool = False, | ||
| disable_custom_all_reduce: bool = False, | ||
| hf_token: bool | str | None = None, | ||
|
|
@@ -317,6 +328,9 @@ def __init__( | |
| kv_cache_memory_bytes=kv_cache_memory_bytes, | ||
| swap_space=swap_space, | ||
| cpu_offload_gb=cpu_offload_gb, | ||
| offload_group_size=offload_group_size, | ||
| offload_num_in_group=offload_num_in_group, | ||
| offload_prefetch_step=offload_prefetch_step, | ||
| enforce_eager=enforce_eager, | ||
| disable_custom_all_reduce=disable_custom_all_reduce, | ||
| hf_token=hf_token, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1275,6 +1275,31 @@ def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""): | |
| vllm_config, prefix, topk_indices_buffer=topk_indices_buffer | ||
| ), | ||
| prefix=f"{prefix}.layers", | ||
| offloader_kwargs=dict( | ||
| # Extract the MLP submodule - for MoE layers, go deeper to the experts | ||
| submodule_accessor=lambda layer: ( | ||
| layer.mlp.experts | ||
| if isinstance(layer.mlp, DeepseekV2MoE) | ||
| else layer.mlp | ||
| ), | ||
|
minosfuture marked this conversation as resolved.
Outdated
|
||
| # Specify which parameters to offload | ||
| whitelist_param_names_creator=lambda module: ( | ||
| [ | ||
| # Core MoE expert weights | ||
| "w13_weight", | ||
| "w2_weight", | ||
| # NVFP4 quantization scales (if present) | ||
| *( | ||
| ["w13_blockscale_swizzled", "w2_blockscale_swizzled"] | ||
| if hasattr(module, "w13_blockscale_swizzled") | ||
| else [] | ||
| ), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there harm in offloading "too many" params? I feel like I'd prefer a general "w13" or "w2" match rather than specializing on specific quant methods
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid overheads, onloading latency needs to be hidden by overlap with computation. This requires careful check on latencies of H2D ops and layer latency. We probably shouldn't blindly offload too many weights. I removed quantization scales that are not needed. |
||
| ] | ||
| # Only offload from MoE experts (SharedFusedMoE/FusedMoE) | ||
| if hasattr(module, "w13_weight") | ||
| else [] | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| if get_pp_group().is_last_rank: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Model parameter offloading infrastructure.""" | ||
|
|
||
| from vllm.model_executor.offloader.base import ( | ||
| BaseOffloader, | ||
| NoopOffloader, | ||
| create_offloader, | ||
| get_offloader, | ||
| set_offloader, | ||
| ) | ||
| from vllm.model_executor.offloader.uva import UVAOffloader | ||
| from vllm.model_executor.offloader.v2 import OffloaderV2 | ||
|
|
||
| __all__ = [ | ||
| "BaseOffloader", | ||
| "NoopOffloader", | ||
| "UVAOffloader", | ||
| "OffloaderV2", | ||
| "create_offloader", | ||
| "get_offloader", | ||
| "set_offloader", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use an fp8 model here to make it faster like RedHatAI/DeepSeek-Coder-V2-Lite-Instruct-FP8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serving "RedHatAI/DeepSeek-Coder-V2-Lite-Instruct-FP8" failed at flashinfer autotuning stage on GB200. 😿
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched to llama as we support any model now.