Skip to content
This repository was archived by the owner on Jul 8, 2026. It is now read-only.

Commit 1d944e3

Browse files
UT
1 parent 5466e4d commit 1d944e3

9 files changed

Lines changed: 40 additions & 14 deletions

File tree

csrc/extensions/include/hip_f8_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,4 @@ T cast_from_f8(uint8_t x) {
264264
}
265265

266266

267-
} // namespace hip_f8_impl
267+
} // namespace hip_f8_impl

csrc/extensions/include/hip_float8.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,3 @@ __device__ hip_float32x4 mfma_f32_16x16x32(hip_f8x8<T_A> a, hip_f8x8<T_B> b, hip
378378

379379
template<hip_f8_type T_A, hip_f8_type T_B>
380380
__device__ hip_float32x16 mfma_f32_32x32x16(hip_f8x8<T_A> a, hip_f8x8<T_B> b, hip_float32x16 c);
381-

csrc/extensions/include/vectorized_pointwise.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ class VectorizedStorer : public VectorizedAccessor<DType, nvec, aligned> {
165165

166166

167167
constexpr int unary_kernel_threads = 512;
168+
169+
#ifndef __HIP_PLATFORM_AMD__
168170
constexpr float e4m3_max = 448.0;
171+
#else
172+
constexpr float e4m3_max = 240.0;
173+
#endif
174+
169175
constexpr float e5m2_max = 57344.0;
170176

171177
extern __device__ msamp::DeviceSyncer device_syncer;

msamp/common/dtype/floating.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import torch
77
import numpy as np
88

9+
from msamp.common.utils import Device, GPUType
910
from msamp.common.dtype import Dtypes
1011

1112

@@ -26,6 +27,8 @@ def _get_fp_max(exp, man, inf_existed=True):
2627
Return:
2728
value (float): The float point value.
2829
"""
30+
if exp == 4 and man == 3 and Device.get_gpu_type() == GPUType.AMD:
31+
return 240.0
2932
e_bias = np.power(2., exp - 1) - 1
3033
if inf_existed:
3134
max_value_exp = (np.power(2.0, exp) - 1) - e_bias - man - 1

msamp/common/utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from msamp.common.utils.logging import MsAmpLogger
77
from msamp.common.utils.lazy_import import LazyImport
88
from msamp.common.utils.dist import DistUtil
9-
from msamp.common.utils.device import Device
9+
from msamp.common.utils.device import Device, GPUType
1010

1111
TransformerEngineWrapper = LazyImport('msamp.common.utils.transformer_engine_wrapper', 'TransformerEngineWrapper')
1212

13-
__all__ = ['MsAmpLogger', 'TransformerEngineWrapper', 'DistUtil', 'Device']
13+
__all__ = ['MsAmpLogger', 'TransformerEngineWrapper', 'DistUtil', 'Device', 'GPUType']

msamp/common/utils/device.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
"""Device module."""
55

6+
from enum import Enum
7+
68
import torch
79

10+
class GPUType(Enum):
11+
NVIDIA=1
12+
AMD=2
13+
UNKNOW=3
814

915
class Device:
1016
"""Device class for different hardwares."""
@@ -20,3 +26,14 @@ def is_fp8_supported():
2026
return True
2127

2228
return False
29+
30+
@staticmethod
31+
def get_gpu_type():
32+
"""Get the GPU type."""
33+
if torch.cuda.device_count() > 0:
34+
device_name = torch.cuda.get_device_name(0)
35+
if "NVIDIA" in device_name:
36+
return GPUType.NVIDIA
37+
elif "AMD" in device_name:
38+
return GPUType.AMD
39+
return GPUType.UNKNOW

tests/common/dtype/test_floating.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44
"""Tests for floating module."""
55

66
import torch
7+
8+
from msamp.common.utils import Device, GPUType
79
from msamp.common.dtype import Floating
810
from msamp.common.dtype import Dtypes
911

1012

1113
def test_fp_max():
1214
"""Test fp_max in Floating class."""
13-
expect_fp_maxs = {torch.fp8e4m3: 448, torch.fp8e5m2: 57344, torch.float16: 65504}
15+
fp8e4m3_max = Device.get_gpu_type() == GPUType.AMD and 240.0 or 448.0
16+
expect_fp_maxs = {torch.fp8e4m3: fp8e4m3_max, torch.fp8e5m2: 57344, torch.float16: 65504}
1417

1518
for k, v in expect_fp_maxs.items():
1619
assert Floating.fp_maxs[k] == v
1720

1821

1922
def test_qfp_max():
2023
"""Test fp_max in Floating class."""
21-
expected_qfp_maxs = {Dtypes.kfloat8_e4m3: 448, Dtypes.kfloat8_e5m2: 57344, Dtypes.kfloat16: 65504}
24+
fp8e4m3_max = Device.get_gpu_type() == GPUType.AMD and 240.0 or 448.0
25+
expected_qfp_maxs = {Dtypes.kfloat8_e4m3: fp8e4m3_max, Dtypes.kfloat8_e5m2: 57344, Dtypes.kfloat16: 65504}
2226

2327
for k, v in expected_qfp_maxs.items():
2428
assert Floating.qfp_max[k] == v

tests/common/tensor/test_meta.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import torch
77
import unittest
88

9+
from msamp.common.utils import Device, GPUType
910
from msamp.common.dtype import Dtypes
1011
from msamp.common.dtype import Floating
1112
from msamp.common.tensor import ScalingMeta
@@ -29,13 +30,15 @@ def test_compute_scaling_factor(self):
2930
amax = torch.tensor(10, device='cuda')
3031
scale = torch.ones((), device='cuda')
3132
scale.copy_(ScalingMeta.compute_scaling_factor(amax, scale, fp_max, margin))
32-
assert scale.item() == 32
33+
expected_scale = 32 if Device.get_gpu_type() == GPUType.NVIDIA else 16
34+
assert scale.item() == expected_scale
3335

3436
# 1/(2^abs(floor(log2(448.0/10000))))
3537
amax = torch.tensor(10000, device='cuda')
3638
scale = torch.ones((), device='cuda')
3739
scale.copy_(ScalingMeta.compute_scaling_factor(amax, scale, fp_max, margin))
38-
assert scale.item() == 1.0 / 32
40+
expected_scale = 1.0 / 32 if Device.get_gpu_type() == GPUType.NVIDIA else 1.0 / 64
41+
assert scale.item() == expected_scale
3942

4043
def test_iswarmup_intime(self):
4144
"""Test is_warmup and is_in_time_scaling i ScalingMeta."""

tests/fake/test_fake.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,3 @@ def tearDown(self):
2626
def test_add(self):
2727
"""Test add."""
2828
self.assertEqual(1 + 2, 3)
29-
30-
@decorator.cuda_test
31-
def test_nvidia_smi(self):
32-
"""Test nvidia-smi."""
33-
smi = os.popen('nvidia-smi').read().strip()
34-
self.assertIn('NVIDIA-SMI', smi)

0 commit comments

Comments
 (0)