Merge remote-tracking branch 'upstream/main' into patches

Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-09-29 12:54:18 +07:00
264 changed files with 13095 additions and 1541 deletions
+30
View File
@@ -4,11 +4,13 @@
import pytest
import torch
from vllm.models.qwen4_exp.nvidia.ops.cute_dsl.hc_down_silu import hc_down_silu
from vllm.models.qwen4_exp.nvidia.ops.hc import (
grouped_gemma_rmsnorm,
hc_combine,
hc_combine_norm,
hc_gate_mix,
hc_silu,
)
from vllm.platforms import current_platform
from vllm.triton_utils import HAS_TRITON
@@ -22,6 +24,13 @@ HC = 4
HIDDEN_SIZE = 2560
HYPER_HIDDEN_SIZE = HC * HIDDEN_SIZE
EPS = 1e-6
LORA_RANK = 320
DOWN_N = LORA_RANK + HC + 12 # merged down+inject weight, 16-row padded
requires_sm90 = pytest.mark.skipif(
not current_platform.has_device_capability(90),
reason="fused HC down+SiLU requires SM90+",
)
def test_grouped_gemma_rmsnorm() -> None:
@@ -125,3 +134,24 @@ def test_hc_combine_norm_unit_injection(num_tokens: int) -> None:
expected_norm = grouped_gemma_rmsnorm(expected, weight, EPS, HC)
assert torch.equal(actual, expected)
torch.testing.assert_close(actual_norm, expected_norm)
@requires_sm90
@pytest.mark.parametrize("num_tokens", [1, 3, 5, 17, 48])
def test_hc_down_silu_fused(num_tokens: int) -> None:
# Compare computed columns with the unfused ll_bf16 + hc_silu reference.
from vllm.model_executor.kernels.linear.cute_dsl.ll_bf16 import ll_bf16_gemm
torch.manual_seed(0)
x = torch.randn(num_tokens, HYPER_HIDDEN_SIZE, dtype=torch.bfloat16, device="cuda")
weight = torch.randn(DOWN_N, HYPER_HIDDEN_SIZE, dtype=torch.bfloat16, device="cuda")
lora, injection = hc_down_silu(x, weight, LORA_RANK, HC)
down = ll_bf16_gemm(x, weight).to(torch.bfloat16)
torch.testing.assert_close(
lora, hc_silu(down[:, :LORA_RANK], HC), rtol=0.01, atol=0.01
)
torch.testing.assert_close(
injection, down[:, LORA_RANK : LORA_RANK + HC], rtol=0.01, atol=0.01
)
+125
View File
@@ -20,6 +20,9 @@ import vllm.model_executor.layers.vocab_parallel_embedding as embedding_module
import vllm.model_executor.parameter as parameter_module
import vllm.models.qwen4_exp.common.ngram_embedding as ngram_embedding_module
import vllm.models.qwen4_exp.nvidia.ngram_embedding as nvidia_ngram_embedding_module
from tests.v1.attention.utils import BatchSpec, create_common_attn_metadata
from vllm.config import SpeculativeConfig, VllmConfig
from vllm.config.compilation import CUDAGraphMode
from vllm.config.quantization import QuantizationConfigArgs
from vllm.model_executor.layers.quantization.fp8 import Fp8Config
from vllm.model_executor.layers.quantization.modelopt import (
@@ -50,8 +53,125 @@ from vllm.models.qwen4_exp.nvidia.ple_layer import Qwen4ExpPLELayer
from vllm.utils.torch_utils import weak_ref_tensor
from vllm.v1.attention.backends.short_conv_attn import (
PleShortConvAttentionMetadata,
PleShortConvAttentionMetadataBuilder,
)
from vllm.v1.attention.backends.utils import NULL_BLOCK_ID
from vllm.v1.kv_cache_interface import MambaSpec
@pytest.mark.parametrize("device", ["cpu", "cuda"])
@pytest.mark.parametrize("full_graph", [False, True])
@pytest.mark.parametrize(
"query_lens,drafts,spec_rows,non_spec_rows,token_order",
[
pytest.param([4, 2, 0], [3, 1, -1], [0, 1], [], None, id="spec-padding"),
pytest.param(
[3, 1, 2, 5, 0],
[2, -1, 1, -1, -1],
[0, 2],
[1, 3],
[0, 1, 2, 4, 5, 3, 6, 7, 8, 9, 10],
id="mixed-padding",
),
pytest.param([1, 5], [-1, -1], [], [0, 1], None, id="non-spec"),
],
)
def test_ple_metadata_preserves_request_and_token_order(
device, full_graph, query_lens, drafts, spec_rows, non_spec_rows, token_order
):
"""Preserve state routing, acceptance and prefill offsets without GPU sync."""
if device == "cuda" and not torch.cuda.is_available():
pytest.skip("CUDA required")
device = torch.device(device)
config = VllmConfig()
config.speculative_config = SpeculativeConfig(
method="ngram", num_speculative_tokens=3
)
config.compilation_config.cudagraph_mode = (
CUDAGraphMode.FULL if full_graph else CUDAGraphMode.NONE
)
config.compilation_config.max_cudagraph_capture_size = 32
builder = PleShortConvAttentionMetadataBuilder(
MambaSpec(block_size=16, shapes=((16, 64),), dtypes=(torch.float32,)),
["ple"],
config,
device,
)
common = create_common_attn_metadata(
BatchSpec(seq_lens=[q + 16 for q in query_lens], query_lens=query_lens),
16,
device,
arange_block_indices=True,
)
common.is_prefilling = torch.tensor(
[q > 1 and d < 0 for q, d in zip(query_lens, drafts)]
)
# Token padding is independent of the sum of per-request query lengths.
common.num_actual_tokens += 3
accepted = torch.arange(1, len(query_lens) + 1, dtype=torch.int32, device=device)
drafts_cpu = torch.tensor(drafts, dtype=torch.int32)
sync_mode = torch.cuda.get_sync_debug_mode() if device.type == "cuda" else None
if sync_mode is not None:
torch.cuda.set_sync_debug_mode("error")
try:
metadata = builder.build(
0,
common,
num_accepted_tokens=accepted,
num_decode_draft_tokens_cpu=drafts_cpu,
)
finally:
if sync_mode is not None:
torch.cuda.set_sync_debug_mode(sync_mode)
def check(actual, expected):
torch.testing.assert_close(
actual, torch.tensor(expected, dtype=actual.dtype, device=device)
)
assert metadata.num_spec_decodes == len(spec_rows)
assert metadata.num_decodes == sum(query_lens[i] == 1 for i in non_spec_rows)
assert metadata.num_prefills == sum(query_lens[i] > 1 for i in non_spec_rows)
if spec_rows:
torch.testing.assert_close(
metadata.spec_state_indices_tensor[: len(spec_rows)],
common.block_table_tensor[spec_rows, 0],
)
torch.testing.assert_close(
metadata.num_accepted_tokens[: len(spec_rows)], accepted[spec_rows]
)
check(
metadata.spec_query_start_loc[: len(spec_rows) + 1],
[0, *accumulate(query_lens[i] for i in spec_rows)],
)
if full_graph and not non_spec_rows:
check(metadata.spec_state_indices_tensor[len(spec_rows) :], [NULL_BLOCK_ID])
check(metadata.num_accepted_tokens[len(spec_rows) :], [1])
check(
metadata.spec_query_start_loc[len(spec_rows) + 1 :], [sum(query_lens)]
)
assert (
metadata.spec_state_indices_tensor.data_ptr()
== builder.spec_state_indices_tensor.data_ptr()
)
if non_spec_rows:
torch.testing.assert_close(
metadata.state_indices_tensor, common.block_table_tensor[non_spec_rows, 0]
)
prefill_lens = [query_lens[i] for i in non_spec_rows if query_lens[i] > 1]
check(metadata.query_start_loc_p, [0, *accumulate(prefill_lens)])
check(metadata.has_initial_states_p, [True] * len(prefill_lens))
if token_order is not None:
check(
torch.cat((metadata.spec_token_indx, metadata.non_spec_token_indx)),
token_order,
)
else:
assert metadata.spec_token_indx is None
assert metadata.non_spec_token_indx is None
assert metadata.nums_dict is None
assert metadata.batch_ptr is None
assert metadata.token_chunk_offset_ptr is None
def _mock_etp_group(
@@ -1892,6 +2012,11 @@ def _make_conv_metadata(
else None
),
non_spec_query_start_loc=(non_spec_query_start_loc if has_non_spec else None),
query_start_loc_p=(
non_spec_query_start_loc[case.num_decodes :] - case.num_decodes
if num_prefills
else None
),
has_initial_states_p=(
torch.arange(num_prefills, device=device) % 2 == 0 if num_prefills else None
),
+22 -1
View File
@@ -17,6 +17,7 @@ from vllm.models.qwen4_exp.nvidia.ops import qsa as qsa_ops
from vllm.models.qwen4_exp.nvidia.ops import qsa_indexer as qsa_indexer_ops
from vllm.platforms import current_platform
from vllm.triton_utils import HAS_TRITON
from vllm.v1.worker.utils import clear_layer_kv_caches
requires_qsa_kernels = pytest.mark.skipif(
not current_platform.is_cuda() or not HAS_TRITON,
@@ -365,7 +366,9 @@ def test_qsa_circular_buffer_survives_one_speculative_step(chunk_start: int) ->
assert set(slots.tolist()).isdisjoint((committed % capacity).tolist())
def _qsa_key_cache(block_size: int, compress_ratio: int) -> qsa_cache.QSAKeyStateCache:
def _qsa_key_cache(
block_size: int, compress_ratio: int, **kwargs
) -> qsa_cache.QSAKeyStateCache:
return qsa_cache.QSAKeyStateCache(
head_size=64,
dtype=torch.bfloat16,
@@ -375,6 +378,7 @@ def _qsa_key_cache(block_size: int, compress_ratio: int) -> qsa_cache.QSAKeyStat
compilation_config=SimpleNamespace(static_forward_context={})
),
compress_ratio=compress_ratio,
**kwargs,
)
@@ -402,6 +406,23 @@ def test_qsa_state_caches_adapt_the_unified_logical_layout() -> None:
assert compressed_cache.kv_cache.data_ptr() == compressed_view.data_ptr()
def test_clearing_qsa_key_cache_releases_its_storage() -> None:
"""Profiling teardown clears `kv_cache`; no derived view may keep it alive."""
raw_cache = _qsa_key_cache(
block_size=32, compress_ratio=4, cache_rope_positions=True
)
kv = torch.zeros(2, 1, 8, raw_cache.head_size, dtype=torch.bfloat16)
references_before_bind = torch._C._storage_Use_Count(kv.untyped_storage()._cdata)
raw_cache.bind_kv_cache(kv)
assert raw_cache.key_cache.shape[-1] == 64
assert raw_cache.rope_position_cache.dtype == torch.int64
clear_layer_kv_caches([raw_cache])
references = torch._C._storage_Use_Count(kv.untyped_storage()._cdata)
assert references == references_before_bind
@pytest.mark.parametrize(
("compress_ratio", "num_spec", "expected"),
[(4, 0, 4), (4, 1, 8), (4, 3, 8), (4, 4, 8), (4, 5, 12), (2, 3, 6)],