[Perf] Ensure async h2d copies are pinned in more places (#55202)
This commit is contained in:
@@ -49,6 +49,7 @@ from vllm.logger import init_logger
|
||||
from vllm.model_executor.models.interfaces import MixtureOfExperts
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.torch_utils import PIN_MEMORY
|
||||
|
||||
from .async_worker import start_async_worker
|
||||
from .eplb_communicator import EplbCommunicator, create_eplb_communicator
|
||||
@@ -1298,6 +1299,8 @@ def _commit_eplb_maps_for_layer(
|
||||
f"Current number of physical experts: {dst.shape[0]}. New number of physical "
|
||||
f"experts {src.shape[0]}."
|
||||
)
|
||||
if PIN_MEMORY and src.is_cpu:
|
||||
src = src.new_empty(src.shape, pin_memory=True).copy_(src)
|
||||
dst.copy_(src, non_blocking=True)
|
||||
|
||||
num_logical_experts = model_state.logical_to_physical_map.shape[1]
|
||||
@@ -1309,6 +1312,8 @@ def _commit_eplb_maps_for_layer(
|
||||
src = new_replica_count
|
||||
dst = model_state.logical_replica_count[layer]
|
||||
assert src.shape == dst.shape
|
||||
if PIN_MEMORY:
|
||||
src = src.pin_memory()
|
||||
dst.copy_(src, non_blocking=True)
|
||||
|
||||
|
||||
@@ -1326,12 +1331,14 @@ def _commit_eplb_maps(
|
||||
src = new_physical_to_logical_map
|
||||
dst = model_state.physical_to_logical_map
|
||||
|
||||
if PIN_MEMORY and src.is_cpu:
|
||||
src = src.new_empty(src.shape, pin_memory=True).copy_(src)
|
||||
# Rare Case: When the number of physical experts has changed, discard the old
|
||||
# physical to logical expert map and use the new one. This only happens when the
|
||||
# number of GPUs available to vLLM changes while vLLM is running. Otherwise copy the
|
||||
# new map into the old one.
|
||||
if src.shape[1] != dst.shape[1]:
|
||||
model_state.physical_to_logical_map = src.to(dst.device)
|
||||
model_state.physical_to_logical_map = src.to(dst.device, non_blocking=True)
|
||||
else:
|
||||
dst.copy_(src, non_blocking=True)
|
||||
|
||||
@@ -1346,6 +1353,8 @@ def _commit_eplb_maps(
|
||||
# Commit logical_replica_count
|
||||
src = new_replica_count
|
||||
dst = model_state.logical_replica_count
|
||||
if PIN_MEMORY:
|
||||
src = src.pin_memory()
|
||||
dst.copy_(src, non_blocking=True)
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from vllm.distributed.kv_transfer.kv_connector.v1.base import (
|
||||
)
|
||||
from vllm.distributed.parallel_state import get_tensor_model_parallel_rank
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.v1.attention.backend import AttentionMetadata
|
||||
from vllm.v1.core.sched.output import SchedulerOutput
|
||||
|
||||
@@ -377,10 +378,11 @@ class ExampleHiddenStatesConnector(KVConnectorBase_V1, SupportsHMA):
|
||||
with torch.cuda.stream(copy_stream):
|
||||
# Move the CPU slot_mapping to GPU on the copy stream so the
|
||||
# implicit H2D inside fancy indexing doesn't sync the default
|
||||
# stream.
|
||||
slot_mapping_gpu = slot_mapping.to(
|
||||
device=self._kv_cache.device, non_blocking=True
|
||||
)
|
||||
# stream. Deliberate bulk transfer in this reference connector.
|
||||
with gpu_sync_allowed():
|
||||
slot_mapping_gpu = slot_mapping.to(
|
||||
device=self._kv_cache.device, non_blocking=True
|
||||
)
|
||||
hidden_states_gpu = extract_from_kv_cache(
|
||||
self._kv_cache, slot_mapping_gpu, num_tokens
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user