Support inverse transform ue8m0 scale (#13285)
This commit is contained in:
@@ -75,6 +75,7 @@ suites = {
|
||||
TestFile("test_eval_fp8_accuracy.py", 303),
|
||||
TestFile("test_fa3.py", 420),
|
||||
TestFile("test_flashmla.py", 230),
|
||||
TestFile("test_fp8_utils.py", 5),
|
||||
TestFile("rotary_embedding/test_mrope.py", 10),
|
||||
TestFile("test_function_call_parser.py", 10),
|
||||
TestFile("test_fused_moe.py", 80),
|
||||
|
||||
44
test/srt/test_fp8_utils.py
Normal file
44
test/srt/test_fp8_utils.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import unittest
|
||||
|
||||
import torch
|
||||
|
||||
from sglang.srt.layers.quantization.fp8_utils import (
|
||||
inverse_transform_scale_ue8m0,
|
||||
quant_weight_ue8m0,
|
||||
transform_scale_ue8m0,
|
||||
)
|
||||
from sglang.test.test_utils import CustomTestCase
|
||||
|
||||
|
||||
class TestInverseTransformScaleUe8m0(CustomTestCase):
|
||||
def test_round_trip(self):
|
||||
for _ in range(100):
|
||||
weight_bf16 = torch.randn(
|
||||
# DeepSeek V3 kv_b_proj
|
||||
(32768, 512),
|
||||
dtype=torch.bfloat16,
|
||||
device="cuda",
|
||||
)
|
||||
|
||||
weight_block_size = [128, 128]
|
||||
|
||||
qweight, sf_fp32_original = quant_weight_ue8m0(
|
||||
weight_bf16, weight_block_size=weight_block_size
|
||||
)
|
||||
mn = qweight.shape[-2]
|
||||
|
||||
sf_packed_original = transform_scale_ue8m0(sf_fp32_original, mn=mn)
|
||||
sf_fp32_recreated = inverse_transform_scale_ue8m0(sf_packed_original, mn=mn)
|
||||
|
||||
sf_packed_recreated = transform_scale_ue8m0(sf_fp32_recreated, mn=mn)
|
||||
|
||||
assert torch.all(
|
||||
sf_packed_original == sf_packed_recreated
|
||||
), f"{sf_packed_original=} {sf_packed_recreated}"
|
||||
assert torch.all(
|
||||
sf_fp32_original == sf_fp32_recreated
|
||||
), f"{sf_fp32_original=} {sf_fp32_recreated}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user