[Core] Ensure memory is pinned prior to async h2d copy (#45424)
Signed-off-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
@@ -36,10 +36,9 @@ def async_copy_to_gpu(
|
||||
assert device is not None
|
||||
out = torch.empty_like(x, device=device)
|
||||
|
||||
# Copy directly to GPU — explicit pin_memory() causes sporadic stalls
|
||||
# under high concurrency due to CUDA driver contention. The driver
|
||||
# handles the transfer efficiently without manual pinning.
|
||||
return out.copy_(x, non_blocking=True)
|
||||
# pin_memory() is no-op if the memory is already pinned.
|
||||
pinned = x.pin_memory()
|
||||
return out.copy_(pinned, non_blocking=True)
|
||||
|
||||
|
||||
class UvaBuffer:
|
||||
@@ -183,7 +182,7 @@ class StagedWriteTensor:
|
||||
|
||||
# Special handling for write_contents
|
||||
write_contents = async_tensor_h2d(
|
||||
self._staged_write_contents, self.dtype, self.device
|
||||
self._staged_write_contents, device=self.device, dtype=self.dtype
|
||||
)
|
||||
|
||||
# Write diffs to the GPU buffer
|
||||
@@ -255,7 +254,7 @@ class FusedStagedWriter:
|
||||
indices_uva = self.indices.copy_to_uva(indices)
|
||||
starts_uva = self.starts.copy_to_uva(starts)
|
||||
cu_lens_uva = self.cu_lens.copy_to_uva(cu_lens)
|
||||
contents_gpu = async_tensor_h2d(contents, torch.int32, self.device)
|
||||
contents_gpu = async_tensor_h2d(contents, device=self.device, dtype=torch.int32)
|
||||
|
||||
_apply_write_kernel[(len(group_ids),)](
|
||||
output_ptrs,
|
||||
|
||||
@@ -49,12 +49,11 @@ class EncoderRunner:
|
||||
|
||||
@torch.inference_mode()
|
||||
def execute_mm_encoder(
|
||||
self,
|
||||
mm_kwargs: list[tuple[str, MultiModalKwargsItem]],
|
||||
self, mm_kwargs: list[tuple[str, MultiModalKwargsItem]]
|
||||
) -> list[torch.Tensor]:
|
||||
encoder_outputs: list[torch.Tensor] = []
|
||||
for modality, num_items, mm_kwargs_batch in group_and_batch_mm_kwargs(
|
||||
mm_kwargs, device=self.device, pin_memory=False
|
||||
mm_kwargs, device=self.device, pin_memory=True
|
||||
):
|
||||
batch_outputs = self.model.embed_multimodal(**mm_kwargs_batch)
|
||||
sanity_check_mm_encoder_outputs(batch_outputs, expected_num_items=num_items)
|
||||
|
||||
@@ -46,8 +46,7 @@ from vllm.sequence import IntermediateTensors
|
||||
from vllm.tasks import SupportedTask
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.utils.mem_utils import DeviceMemoryProfiler, format_gib
|
||||
from vllm.utils.platform_utils import is_pin_memory_available
|
||||
from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE
|
||||
from vllm.utils.torch_utils import PIN_MEMORY, STR_DTYPE_TO_TORCH_DTYPE
|
||||
from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig, MambaSpec
|
||||
from vllm.v1.outputs import DraftTokenIds, ModelRunnerOutput
|
||||
@@ -498,7 +497,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
"""Build KV-block zeroing metadata; invoked from gpu_worker."""
|
||||
self.kv_block_zeroer = KVBlockZeroer(
|
||||
self.device,
|
||||
is_pin_memory_available(),
|
||||
pin_memory=PIN_MEMORY,
|
||||
attn_groups_iter=(g for groups in self.attn_groups for g in groups),
|
||||
kernel_block_sizes=self.kernel_block_sizes,
|
||||
cache_dtype=self.cache_config.cache_dtype,
|
||||
|
||||
@@ -170,7 +170,8 @@ class WhisperModelState(ModelState):
|
||||
for_capture: bool,
|
||||
num_reqs: int,
|
||||
) -> dict[int, tuple[torch.Tensor, np.ndarray]]:
|
||||
encoder_seq_lens_np = np.zeros(num_reqs, dtype=np.int32)
|
||||
encoder_seq_lens = torch.zeros(num_reqs, dtype=torch.int32, pin_memory=True)
|
||||
encoder_seq_lens_np = encoder_seq_lens.numpy()
|
||||
if not for_capture:
|
||||
# During normal execution, use actual encoder lengths.
|
||||
for i, req_id in enumerate(req_ids):
|
||||
@@ -183,9 +184,7 @@ class WhisperModelState(ModelState):
|
||||
# is captured with the correct value for cross-attention.
|
||||
encoder_seq_lens_np[:] = self.max_encoder_len
|
||||
|
||||
self.encoder_seq_lens_gpu[:num_reqs].copy_(
|
||||
torch.from_numpy(encoder_seq_lens_np), non_blocking=True
|
||||
)
|
||||
self.encoder_seq_lens_gpu[:num_reqs].copy_(encoder_seq_lens, non_blocking=True)
|
||||
self.encoder_seq_lens_gpu[num_reqs:].fill_(0)
|
||||
encoder_seq_lens_gpu = self.encoder_seq_lens_gpu[:num_reqs]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user