Merge remote-tracking branch 'origin/main' into sync/lesj/qwen4exp-bugfixes

Signed-off-by: lesj0610 <lesj0610@users.noreply.github.com>
This commit is contained in:
lesj0610
2026-09-20 22:55:38 +09:00
83 changed files with 4549 additions and 1058 deletions
@@ -1,11 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Focused unit tests for the GLM decode top-k dispatch."""
"""Tests for the GLM kpool indexer's top-k backend wiring."""
import pytest
import torch
from vllm.models.glm5next.nvidia.sparse_indexer import _use_cooperative_topk
from vllm.config import VllmConfig, set_current_vllm_config
from vllm.platforms import current_platform
pytestmark = pytest.mark.skipif(
@@ -13,29 +13,31 @@ pytestmark = pytest.mark.skipif(
)
@pytest.mark.parametrize("num_rows", [1, 64], ids=["1row", "64rows"])
@torch.inference_mode()
def test_cooperative_topk_is_selected_for_supported_batch(num_rows: int):
logits = torch.empty(num_rows, 8192, dtype=torch.float32, device="cuda")
assert _use_cooperative_topk(logits, 512, num_rows)
def _require_deep_gemm() -> None:
from vllm.utils.deep_gemm import has_deep_gemm
if not has_deep_gemm():
pytest.skip("kpool indexer requires DeepGEMM")
@pytest.mark.parametrize(
("num_rows", "select_k", "stride_padding"),
[
(65, 512, 0),
(1, 256, 0),
(1, 512, 1),
],
ids=["too_many_rows", "unsupported_k", "unaligned_stride"],
)
@torch.inference_mode()
def test_cooperative_topk_falls_back_on_unsupported_batch(
num_rows: int, select_k: int, stride_padding: int
):
logits = torch.empty(
num_rows, 8192 + stride_padding, dtype=torch.float32, device="cuda"
)
if stride_padding:
logits = logits[:, :8192]
assert not _use_cooperative_topk(logits, select_k, num_rows)
@pytest.mark.parametrize("backend", ["auto", "persistent", "cooperative", "torch"])
def test_kpool_indexer_dispatches_through_shared_topk_backend(backend: str) -> None:
"""The kpool indexer must read kernel_config.sparse_indexer_topk_backend
and hand it to the shared SparseIndexerTopk dispatcher, rather than
hard-coding its own cooperative/persistent/per_row choice."""
_require_deep_gemm()
from vllm.models.glm5next.nvidia.sparse_indexer import SparseAttnIndexerKpool
cfg = VllmConfig(kernel_config={"sparse_indexer_topk_backend": backend})
with set_current_vllm_config(cfg):
op = SparseAttnIndexerKpool(
k_cache=None,
quant_block_size=128,
scale_fmt="ue8m0",
topk_tokens=2048,
head_dim=128,
max_pool_len=4096,
max_total_seq_len=8192,
topk_indices_buffer=torch.empty(8, 2176, dtype=torch.int32, device="cuda"),
)
assert op.topk_backend == backend
@@ -55,6 +55,10 @@ def kimi_vl_chat_template(content: str) -> str:
)
def deepseek_v41_chat_template(content: str) -> str:
return f"<|begin▁of▁sentence|><|User|>{content}<|Assistant|></think>"
def step3_vl_chat_template(content: str) -> str:
return (
"<|begin▁of▁sentence|> You are a helpful assistant.<|BOT|>user\n "
@@ -221,6 +225,25 @@ MODEL_CONFIGS: dict[str, VitCudagraphTestConfig] = {
vllm_runner_kwargs={"gpu_memory_utilization": 0.80},
marks=[pytest.mark.core_model],
),
"deepseek_v41": VitCudagraphTestConfig(
model="deepseek-ai/DeepSeek-V4.1-Flash",
modalities=["image"],
image_prompt=deepseek_v41_chat_template(
"<|deepseek_image|>\n\nWhat is in this image?"
),
compilation_config_overrides={
"encoder_cudagraph_token_budgets": [1024],
},
vllm_runner_kwargs={
"load_format": "dummy",
"attention_backend": "FLASHMLA_SPARSE_DSV41",
"hf_overrides": partial(
dummy_hf_overrides,
model_arch="DeepseekV41ForCausalLM",
exist_overrides={"vision_n_layers": 1},
),
},
),
"step3_vl": VitCudagraphTestConfig(
model="stepfun-ai/Step3-VL-10B",
modalities=["image"],
@@ -218,8 +218,14 @@ def test_model_tensor_schema(model_id: str):
factories = model_cls._processor_factory
# Capture helpers return capture-buffer containers (e.g.
# EncoderCudaGraphCaptureInputs), not TensorSchema mm inputs.
capture_helpers = {"prepare_encoder_cudagraph_capture_inputs"}
inputs_parse_methods = []
for attr_name in dir(model_cls):
if attr_name in capture_helpers:
continue
attr = getattr(model_cls, attr_name)
if hasattr(attr, "__annotations__"):
return_type = attr.__annotations__.get("return", None)
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
import torch
from vllm.models.deepseek_v4.amd.rocm import _wo_a_block_scale_to_e8m0
def test_wo_a_block_scale_to_e8m0_from_float():
scale = torch.tensor([[0.5, 1.0, 2.0, 4.0]], dtype=torch.float32)
encoded = _wo_a_block_scale_to_e8m0(scale)
assert encoded is not None
torch.testing.assert_close(
encoded,
torch.tensor([[126, 127, 128, 129]], dtype=torch.uint8),
)
assert encoded.is_contiguous()
def test_wo_a_block_scale_to_e8m0_preserves_encoded_scales():
raw = torch.tensor([[125, 127, 131]], dtype=torch.uint8)
encoded = raw.view(torch.float8_e8m0fnu)
converted = _wo_a_block_scale_to_e8m0(encoded)
assert converted is not None
torch.testing.assert_close(converted, raw)
@pytest.mark.parametrize(
"scale",
[
torch.tensor([[0.0, 1.0]]),
torch.tensor([[-1.0, 1.0]]),
torch.tensor([[0.75, 1.0]]),
torch.tensor([[float("inf"), 1.0]]),
torch.ones(1, dtype=torch.int32),
],
)
def test_wo_a_block_scale_to_e8m0_rejects_invalid_scales(scale: torch.Tensor):
assert _wo_a_block_scale_to_e8m0(scale) is None