[Perf][NPU] Fuse MiniMax H3 Qwen3-VL SwiGLU (#6167)
Signed-off-by: Wenjia Li <wjialish@gmail.com>
This commit is contained in:
1 parent
ffd11c181e
commit
8ecd1f6d5c
3 files changed
+86
-4
No files matched your search
@@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
from vllm_omni.platforms import current_omni_platform
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion]
|
||||
|
||||
|
||||
@pytest.mark.skipif(not current_omni_platform.is_npu(), reason="requires Ascend NPU")
|
||||
@pytest.mark.parametrize("shape", [(1, 16, 256), (2, 1, 256)])
|
||||
def test_qwen3_vl_npu_swiglu_matches_split_reference(
|
||||
shape: tuple[int, int, int],
|
||||
) -> None:
|
||||
from vllm_omni.platforms.npu.models.minimax_h3 import npu_swiglu_from_packed
|
||||
|
||||
packed = torch.randn(*shape, device="npu", dtype=torch.bfloat16)
|
||||
gate, up = packed.chunk(2, dim=-1)
|
||||
|
||||
torch.testing.assert_close(
|
||||
npu_swiglu_from_packed(packed),
|
||||
F.silu(gate) * up,
|
||||
atol=2e-2,
|
||||
rtol=2e-2,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not current_omni_platform.is_npu(), reason="requires Ascend NPU")
|
||||
def test_qwen3_vl_npu_swiglu_matches_two_projection_reference() -> None:
|
||||
from vllm_omni.platforms.npu.models.minimax_h3 import npu_swiglu_from_packed
|
||||
|
||||
x = torch.randn(1, 16, 128, device="npu", dtype=torch.bfloat16)
|
||||
weight = torch.randn(256, 128, device="npu", dtype=torch.bfloat16)
|
||||
packed = F.linear(x, weight)
|
||||
gate = F.linear(x, weight[:128])
|
||||
up = F.linear(x, weight[128:])
|
||||
|
||||
torch.testing.assert_close(
|
||||
npu_swiglu_from_packed(packed),
|
||||
F.silu(gate) * up,
|
||||
atol=2e-2,
|
||||
rtol=2e-2,
|
||||
)
|
||||
Reference in new issue
Block a user