Fix gfx95 bpreshuffle FP8 activation scale layout (#29275)

Co-authored-by: sunxxuns <126995791+sunxxuns@users.noreply.github.com>
This commit is contained in:
sonle5
2026-07-08 10:55:09 -07:00
committed by GitHub
co-authored by sunxxuns
parent fc378f843e
commit 8d2b66fd90
6 changed files with 127 additions and 13 deletions
@@ -0,0 +1,51 @@
import unittest
import torch
from sglang.srt.layers.quantization.fp8_utils import (
materialize_bpreshuffle_fp8_scale,
materialize_bpreshuffle_fp8_scale_tuple,
)
from sglang.test.ci.ci_register import register_cpu_ci
from sglang.test.test_utils import CustomTestCase
register_cpu_ci(est_time=5, suite="base-a-test-cpu")
class TestBpreshuffleScaleMaterialization(CustomTestCase):
def test_materializes_transposed_physical_storage(self):
scale = torch.arange(12, dtype=torch.float32).reshape(3, 4)
materialized = materialize_bpreshuffle_fp8_scale(scale)
self.assertTrue(torch.equal(materialized, scale))
self.assertEqual(materialized.shape, scale.shape)
self.assertEqual(materialized.stride(), (1, scale.shape[0]))
self.assertTrue(materialized.t().is_contiguous())
def test_materialization_is_idempotent_for_bpreshuffle_layout(self):
scale = torch.arange(12, dtype=torch.float32).reshape(3, 4)
materialized = materialize_bpreshuffle_fp8_scale(scale)
rematerialized = materialize_bpreshuffle_fp8_scale(materialized)
self.assertTrue(torch.equal(rematerialized, scale))
self.assertEqual(rematerialized.stride(), materialized.stride())
def test_tuple_helper_keeps_extra_tuple_payload(self):
q_input = torch.ones((3, 8), dtype=torch.float32)
scale = torch.arange(12, dtype=torch.float32).reshape(3, 4)
bf16_side = torch.ones((3, 8), dtype=torch.bfloat16)
q_out, scale_out, bf16_out = materialize_bpreshuffle_fp8_scale_tuple(
(q_input, scale, bf16_side)
)
self.assertIs(q_out, q_input)
self.assertIs(bf16_out, bf16_side)
self.assertTrue(torch.equal(scale_out, scale))
self.assertEqual(scale_out.stride(), (1, scale.shape[0]))
if __name__ == "__main__":
unittest.main()