[Core] Check for GPU<->CPU syncs during CI (#43107)
Signed-off-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
7b544ecb52
commit
615d4cfade
@@ -46,6 +46,7 @@ from vllm.utils.flashinfer import (
|
||||
supports_trtllm_attention,
|
||||
use_trtllm_attention,
|
||||
)
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.utils.torch_utils import (
|
||||
PIN_MEMORY,
|
||||
@@ -1408,13 +1409,15 @@ class FlashInferMetadataBuilder(AttentionMetadataBuilder[FlashInferMetadata]):
|
||||
# seq_lens_cpu is not needed since TRTLLM paths use GPU tensors
|
||||
# (block_tables, seq_lens) directly.
|
||||
needs_seq_lens_cpu = self.use_dcp or use_cascade or not all_uses_trtllm
|
||||
seq_lens_cpu = common_attn_metadata.seq_lens_cpu if needs_seq_lens_cpu else None
|
||||
seq_lens_np = seq_lens_cpu.numpy() if seq_lens_cpu is not None else None
|
||||
num_blocks_np = (
|
||||
(seq_lens_np + (page_size - 1)) // page_size
|
||||
if seq_lens_np is not None
|
||||
else None
|
||||
)
|
||||
if needs_seq_lens_cpu:
|
||||
with gpu_sync_allowed():
|
||||
seq_lens_cpu = common_attn_metadata.seq_lens_cpu
|
||||
seq_lens_np = seq_lens_cpu.numpy()
|
||||
num_blocks_np = (seq_lens_np + (page_size - 1)) // page_size
|
||||
else:
|
||||
seq_lens_cpu = None
|
||||
seq_lens_np = None
|
||||
num_blocks_np = None
|
||||
|
||||
# Adjust seq_lens_cpu for DCP
|
||||
if self.use_dcp:
|
||||
|
||||
@@ -20,6 +20,7 @@ import torch.nn.functional as F
|
||||
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.torch_utils import direct_register_custom_op
|
||||
|
||||
|
||||
@@ -50,7 +51,12 @@ def flash_attn_maxseqlen_wrapper(
|
||||
cu_seqlens = torch.arange(
|
||||
0, (batch_size + 1) * q_len, step=q_len, dtype=torch.int32, device=q.device
|
||||
)
|
||||
max_seqlen = q_len if max_seqlen is None else max_seqlen.item()
|
||||
if max_seqlen is None:
|
||||
max_seqlen = q_len
|
||||
else:
|
||||
# `flash_attn_varlen_func` needs a Python int for kernel launch bounds.
|
||||
with gpu_sync_allowed():
|
||||
max_seqlen = max_seqlen.item()
|
||||
|
||||
q, k, v = (einops.rearrange(x, "b s ... -> (b s) ...") for x in [q, k, v])
|
||||
output = flash_attn_varlen_func(
|
||||
@@ -159,7 +165,12 @@ def triton_attn_wrapper(
|
||||
cu_seqlens = torch.arange(
|
||||
0, (batch_size + 1) * q_len, step=q_len, dtype=torch.int32, device=q.device
|
||||
)
|
||||
max_seqlen = q_len if max_seqlen is None else max_seqlen.item()
|
||||
if max_seqlen is None:
|
||||
max_seqlen = q_len
|
||||
else:
|
||||
# `context_attention_fwd` needs a Python int.
|
||||
with gpu_sync_allowed():
|
||||
max_seqlen = max_seqlen.item()
|
||||
|
||||
q, k, v = (einops.rearrange(x, "b s ... -> (b s) ...") for x in [q, k, v])
|
||||
output = torch.empty_like(q)
|
||||
@@ -261,7 +272,9 @@ def torch_sdpa_wrapper(
|
||||
|
||||
outputs = []
|
||||
|
||||
lens = (cu_seqlens[1:] - cu_seqlens[:-1]).tolist()
|
||||
# `torch.split` needs Python int sizes.
|
||||
with gpu_sync_allowed():
|
||||
lens = (cu_seqlens[1:] - cu_seqlens[:-1]).tolist()
|
||||
q_chunks = torch.split(q, lens, dim=1)
|
||||
k_chunks = torch.split(k, lens, dim=1)
|
||||
v_chunks = torch.split(v, lens, dim=1)
|
||||
@@ -337,7 +350,10 @@ def flashinfer_wrapper(
|
||||
batch_offsets_qko = cu_seqlens[:cu_seqlength].view(-1, 1, 1, 1)
|
||||
batch_offsets_v = cu_seqlens[cu_seqlength:].view(-1, 1, 1, 1)
|
||||
sequence_lengths = sequence_lengths.view(-1, 1, 1, 1)
|
||||
max_seqlen = max_seqlen.item()
|
||||
# `cudnn_batch_prefill_with_kv_cache` needs Python ints for the
|
||||
# max-token-per-seq bounds.
|
||||
with gpu_sync_allowed():
|
||||
max_seqlen = max_seqlen.item()
|
||||
|
||||
output, _ = cudnn_batch_prefill_with_kv_cache(
|
||||
q,
|
||||
|
||||
@@ -12,6 +12,7 @@ using Pivot-based Truncation and Selection" By Park et al.
|
||||
import torch
|
||||
|
||||
from vllm.triton_utils import tl, triton
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.math_utils import next_power_of_2
|
||||
from vllm.utils.platform_utils import num_compute_units
|
||||
|
||||
@@ -919,12 +920,13 @@ def apply_top_k_top_p_triton(
|
||||
# Cache lookup table entries on each device.
|
||||
tables = _TRITON_TABLE_CACHE.get(logits.device)
|
||||
if tables is None:
|
||||
normal_cdf_to_sigma_table = logits.new_tensor(_NORMAL_CDF_TO_SIGMA_TABLE)
|
||||
percentile_to_std_table = logits.new_tensor(_PERCENTILE_TO_STD_TABLE)
|
||||
_TRITON_TABLE_CACHE[logits.device] = (
|
||||
normal_cdf_to_sigma_table,
|
||||
percentile_to_std_table,
|
||||
)
|
||||
with gpu_sync_allowed():
|
||||
normal_cdf_to_sigma_table = logits.new_tensor(_NORMAL_CDF_TO_SIGMA_TABLE)
|
||||
percentile_to_std_table = logits.new_tensor(_PERCENTILE_TO_STD_TABLE)
|
||||
_TRITON_TABLE_CACHE[logits.device] = (
|
||||
normal_cdf_to_sigma_table,
|
||||
percentile_to_std_table,
|
||||
)
|
||||
else:
|
||||
normal_cdf_to_sigma_table, percentile_to_std_table = tables
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.config.model import LogprobsMode
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.torch_utils import PIN_MEMORY
|
||||
from vllm.v1.outputs import LogprobsTensors, SamplerOutput
|
||||
from vllm.v1.sample.metadata import SamplingMetadata
|
||||
@@ -342,9 +343,10 @@ class Sampler(nn.Module):
|
||||
# of the compiled batched_count_greater_than. mark_unbacked makes
|
||||
# the size fully symbolic so dynamo doesn't specialize when
|
||||
# batch_size transitions from 1 to >=2.
|
||||
torch._dynamo.decorators.mark_unbacked(logprobs, 0)
|
||||
torch._dynamo.decorators.mark_unbacked(token_logprobs, 0)
|
||||
token_ranks = batched_count_greater_than(logprobs, token_logprobs)
|
||||
with gpu_sync_allowed(first_only=True):
|
||||
torch._dynamo.decorators.mark_unbacked(logprobs, 0)
|
||||
torch._dynamo.decorators.mark_unbacked(token_logprobs, 0)
|
||||
token_ranks = batched_count_greater_than(logprobs, token_logprobs)
|
||||
|
||||
# Concatenate together with the topk.
|
||||
indices = torch.cat((token_ids, topk_indices), dim=1)
|
||||
|
||||
+27
-18
@@ -1,12 +1,15 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from contextlib import nullcontext
|
||||
|
||||
import torch
|
||||
import torch.distributed as dist
|
||||
|
||||
from vllm.config import ParallelConfig
|
||||
from vllm.distributed.parallel_state import get_dp_group
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.v1.worker.ubatch_utils import (
|
||||
check_ubatch_thresholds,
|
||||
is_last_ubatch_empty,
|
||||
@@ -136,27 +139,33 @@ def _synchronize_dp_ranks(
|
||||
parallel_config=parallel_config,
|
||||
)
|
||||
|
||||
# Synchronize cudagraph_mode across ranks first (take min).
|
||||
# This is needed before DP padding decision since we use the synced
|
||||
# cudagraph mode to determine whether DP padding is needed.
|
||||
synced_cudagraph_mode = _post_process_cudagraph_mode(tensor)
|
||||
# Only the NCCL path leaves `tensor` on device. With Gloo -- the default
|
||||
# under async scheduling -- the all-reduce runs on CPU, so the reads below
|
||||
# are host-side and the check should stay armed.
|
||||
with (
|
||||
nullcontext()
|
||||
if parallel_config.disable_nccl_for_dp_synchronization
|
||||
else gpu_sync_allowed()
|
||||
):
|
||||
# Synchronize cudagraph_mode across ranks first (take min).
|
||||
# This is needed before DP padding decision since we use the synced
|
||||
# cudagraph mode to determine whether DP padding is needed.
|
||||
synced_cudagraph_mode = _post_process_cudagraph_mode(tensor)
|
||||
|
||||
# Check conditions for microbatching
|
||||
should_ubatch = _post_process_ubatch(tensor, parallel_config.num_ubatches)
|
||||
# Check conditions for microbatching
|
||||
should_ubatch = _post_process_ubatch(tensor, parallel_config.num_ubatches)
|
||||
|
||||
# DP padding is needed when cudagraph is enabled (synced across ranks)
|
||||
# or when ubatching/DBO is active (ubatching requires uniform batch
|
||||
# sizes across DP ranks currently).
|
||||
# Use the synced runtime cudagraph mode rather than the compilation config
|
||||
# so we can avoid padding when cudagraph is not enabled for this step.
|
||||
should_dp_pad = synced_cudagraph_mode != 0 or should_ubatch
|
||||
# DP padding is needed when cudagraph is enabled (synced across ranks)
|
||||
# or when ubatching/DBO is active (ubatching requires uniform batch
|
||||
# sizes across DP ranks currently).
|
||||
# Use the synced runtime cudagraph mode rather than the compilation
|
||||
# config so we can avoid padding when cudagraph is not enabled for
|
||||
# this step.
|
||||
should_dp_pad = synced_cudagraph_mode != 0 or should_ubatch
|
||||
|
||||
# Pad all DP ranks up to the maximum token count across ranks if
|
||||
# should_dp_pad is True
|
||||
num_tokens_after_padding = _post_process_dp_padding(
|
||||
tensor,
|
||||
should_dp_pad,
|
||||
)
|
||||
# Pad all DP ranks up to the maximum token count across ranks if
|
||||
# should_dp_pad is True
|
||||
num_tokens_after_padding = _post_process_dp_padding(tensor, should_dp_pad)
|
||||
|
||||
return should_ubatch, num_tokens_after_padding, synced_cudagraph_mode
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from vllm.model_executor.models.interfaces import (
|
||||
)
|
||||
from vllm.model_executor.models.utils import scatter_output_slices
|
||||
from vllm.model_executor.models.vision import get_load_balance_assignment
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.v1.worker.encoder_cudagraph_defs import (
|
||||
EncoderCudaGraphConfig,
|
||||
EncoderItemSpec,
|
||||
@@ -298,7 +299,19 @@ class EncoderCudaGraphManager:
|
||||
|
||||
def _get_item_specs(self, mm_kwargs: dict[str, Any]) -> list[EncoderItemSpec]:
|
||||
"""Get item specs from the model."""
|
||||
return self.model.get_encoder_cudagraph_item_specs(mm_kwargs)
|
||||
# Implementations read per-item grid/patch counts off device tensors
|
||||
# to size the cudagraph buffers, so the D2H is inherent here.
|
||||
with gpu_sync_allowed():
|
||||
return self.model.get_encoder_cudagraph_item_specs(mm_kwargs)
|
||||
|
||||
def _select_items(
|
||||
self, mm_kwargs: dict[str, Any], indices: list[int]
|
||||
) -> dict[str, Any]:
|
||||
"""Select the mm kwargs for `indices` from the model."""
|
||||
# Same as `_get_item_specs`: implementations re-read the per-item
|
||||
# grid/patch counts to slice the batch, so the D2H is inherent.
|
||||
with gpu_sync_allowed():
|
||||
return self.model.select_encoder_cudagraph_items(mm_kwargs, indices)
|
||||
|
||||
def _get_per_item_out_tokens(self, mm_kwargs: dict[str, Any]) -> list[int]:
|
||||
"""Get per-item output token counts as plain ints."""
|
||||
@@ -415,9 +428,7 @@ class EncoderCudaGraphManager:
|
||||
|
||||
outputs_by_orig_idx: dict[int, torch.Tensor] = {}
|
||||
for batch_indices, path_budgets in batches:
|
||||
batch_mm_kwargs = self.model.select_encoder_cudagraph_items(
|
||||
mm_kwargs, batch_indices
|
||||
)
|
||||
batch_mm_kwargs = self._select_items(mm_kwargs, batch_indices)
|
||||
graph_outputs: dict[str, torch.Tensor] = {}
|
||||
all_eager = True
|
||||
|
||||
@@ -491,11 +502,9 @@ class EncoderCudaGraphManager:
|
||||
]
|
||||
|
||||
if len(local_indices) > 0:
|
||||
local_mm_kwargs = self.model.select_encoder_cudagraph_items(
|
||||
mm_kwargs, local_indices
|
||||
)
|
||||
local_mm_kwargs = self._select_items(mm_kwargs, local_indices)
|
||||
else:
|
||||
local_mm_kwargs = self.model.select_encoder_cudagraph_items(mm_kwargs, [])
|
||||
local_mm_kwargs = self._select_items(mm_kwargs, [])
|
||||
|
||||
max_output_tokens_per_rank = (
|
||||
max(
|
||||
|
||||
@@ -120,6 +120,7 @@ from vllm.sequence import IntermediateTensors
|
||||
from vllm.tasks import GenerationTask, PoolingTask, SupportedTask
|
||||
from vllm.tracing import instrument
|
||||
from vllm.utils import length_from_prompt_token_ids_or_embeds
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.math_utils import cdiv, round_up
|
||||
from vllm.utils.mem_utils import DeviceMemoryProfiler, format_gib
|
||||
from vllm.utils.nvtx_pytorch_hooks import PytHooks
|
||||
@@ -3848,26 +3849,28 @@ class GPUModelRunner(
|
||||
self.routed_experts_slot_mapping_device[:total],
|
||||
non_blocking=True,
|
||||
)
|
||||
with gpu_sync_allowed():
|
||||
# Get the valid generated tokens.
|
||||
max_gen_len = sampled_token_ids.shape[-1]
|
||||
if max_gen_len == 1:
|
||||
# No spec decode tokens.
|
||||
valid_sampled_token_ids = self._to_list(sampled_token_ids)
|
||||
# Mask out the sampled tokens that should not be sampled.
|
||||
for i in discard_sampled_tokens_req_indices:
|
||||
valid_sampled_token_ids[int(i)].clear()
|
||||
|
||||
# Get the valid generated tokens.
|
||||
max_gen_len = sampled_token_ids.shape[-1]
|
||||
if max_gen_len == 1:
|
||||
# No spec decode tokens.
|
||||
valid_sampled_token_ids = self._to_list(sampled_token_ids)
|
||||
# Mask out the sampled tokens that should not be sampled.
|
||||
for i in discard_sampled_tokens_req_indices:
|
||||
valid_sampled_token_ids[int(i)].clear()
|
||||
|
||||
if logprobs_tensors is not None:
|
||||
logprobs_lists = logprobs_tensors.tolists()
|
||||
else:
|
||||
# Includes spec decode tokens.
|
||||
valid_sampled_token_ids, logprobs_lists = RejectionSampler.parse_output(
|
||||
sampled_token_ids,
|
||||
self.input_batch.vocab_size,
|
||||
discard_sampled_tokens_req_indices,
|
||||
logprobs_tensors=logprobs_tensors,
|
||||
)
|
||||
if logprobs_tensors is not None:
|
||||
logprobs_lists = logprobs_tensors.tolists()
|
||||
else:
|
||||
# Includes spec decode tokens.
|
||||
valid_sampled_token_ids, logprobs_lists = (
|
||||
RejectionSampler.parse_output(
|
||||
sampled_token_ids,
|
||||
self.input_batch.vocab_size,
|
||||
discard_sampled_tokens_req_indices,
|
||||
logprobs_tensors=logprobs_tensors,
|
||||
)
|
||||
)
|
||||
else:
|
||||
valid_sampled_token_ids = []
|
||||
invalid_req_indices = discard_sampled_tokens_req_indices.tolist()
|
||||
@@ -5843,7 +5846,10 @@ class GPUModelRunner(
|
||||
on device instead; see`AsyncGPUModelRunnerOutput`.
|
||||
"""
|
||||
try:
|
||||
counts = [] if logits is None else count_nans_per_row(logits).tolist()
|
||||
# Reporting per-request NaN counts requires them on the host; this
|
||||
# path is opt-in diagnostics, so the D2H is intended.
|
||||
with gpu_sync_allowed():
|
||||
counts = [] if logits is None else count_nans_per_row(logits).tolist()
|
||||
num_nans_in_logits = nans_to_dict(counts, self.input_batch.req_id_to_index)
|
||||
if envs.VLLM_RAISE_ON_LOGIT_NANS:
|
||||
raise_if_nan_logits(num_nans_in_logits)
|
||||
|
||||
@@ -16,6 +16,7 @@ from vllm.model_executor.layers.mamba.mamba_utils import (
|
||||
is_conv_state_dim_first,
|
||||
)
|
||||
from vllm.triton_utils import tl, triton
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.v1.core.sched.output import SchedulerOutput
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig, MambaSpec
|
||||
@@ -754,7 +755,22 @@ class MambaSpecDecodeGPUContext:
|
||||
"""
|
||||
if self.is_initialized:
|
||||
return
|
||||
# This only runs once per worker.
|
||||
with gpu_sync_allowed():
|
||||
self._populate_metadata(
|
||||
kv_cache_config,
|
||||
forward_context,
|
||||
mamba_state_copy_funcs,
|
||||
block_tables,
|
||||
)
|
||||
|
||||
def _populate_metadata(
|
||||
self,
|
||||
kv_cache_config: KVCacheConfig,
|
||||
forward_context: dict[str, Any],
|
||||
mamba_state_copy_funcs: tuple[MambaStateCopyFunc, ...],
|
||||
block_tables: list[torch.Tensor],
|
||||
) -> None:
|
||||
idx = 0
|
||||
for group_local_idx, mamba_group_id in enumerate(self.mamba_group_ids):
|
||||
layer_names = kv_cache_config.kv_cache_groups[mamba_group_id].layer_names
|
||||
|
||||
Reference in New Issue
Block a user