[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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user