[ROCm][DSV4][Perf] Use FP8 WO_A output projection (#54894)
Signed-off-by: Liuyinfeng01 <yinfeliu@amd.com> Co-authored-by: Shanshan Shen <467638484@qq.com>
This commit is contained in:
co-authored by
Shanshan Shen
parent
27b7757f63
commit
0e110f696d
@@ -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
|
||||
Reference in New Issue
Block a user