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