Skip to content

Commit a80a15b

Browse files
Add half_precision condition to TensorConfig and refactor specdb tests
ghstack-source-id: 2a8d22a Pull-Request: #38
1 parent aedd5b1 commit a80a15b

File tree

3 files changed

+65
-44
lines changed

3 files changed

+65
-44
lines changed

facto/inputgen/utils/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
from enum import Enum
88

9+
import torch
10+
911

1012
class Condition(str, Enum):
1113
ALLOW_EMPTY = "empty"
1214
ALLOW_TRANSPOSED = "transposed"
1315
ALLOW_PERMUTED = "permuted"
1416
ALLOW_STRIDED = "strided"
1517
DISALLOW_DTYPES = "disallow_dtypes"
18+
HALF_PRECISION = "half_precision"
1619

1720

1821
class TensorConfig:
@@ -23,6 +26,8 @@ def __init__(self, device="cpu", disallow_dtypes=None, **conditions):
2326
for condition, value in conditions.items():
2427
if condition in self.conditions:
2528
self.conditions[condition] = value
29+
if self.conditions[Condition.HALF_PRECISION] is False:
30+
self.disallow_dtypes += [torch.float16, torch.bfloat16]
2631
self.probability = 0.5
2732

2833
def is_allowed(self, condition: Condition) -> bool:

test/specdb/test_specdb_cpu.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@
77
import unittest
88

99
from base_test import BaseSpecDBTest
10+
from facto.inputgen.utils.config import TensorConfig
1011

1112

1213
class TestSpecDBOperationsCPU(BaseSpecDBTest):
1314
"""Test class for validating all specs in SpecDB using gen_errors on CPU."""
1415

16+
SKIP_OPS = [
17+
"_native_batch_norm_legit_no_training.default",
18+
"addmm.default",
19+
"arange.default",
20+
"arange.start_step",
21+
"constant_pad_nd.default",
22+
"split_with_sizes_copy.default",
23+
]
24+
1525
def test_all_ops_cpu(self):
16-
skip_ops = [
17-
"_native_batch_norm_legit_no_training.default",
18-
"addmm.default",
19-
"arange.default",
20-
"arange.start_step",
21-
"constant_pad_nd.default",
22-
"split_with_sizes_copy.default",
23-
]
26+
config = TensorConfig(device="cpu", half_precision=False)
27+
self._run_all_ops(config=config, skip_ops=self.SKIP_OPS)
2428

29+
def test_all_ops_cpu_half(self):
30+
skip_ops = self.SKIP_OPS.copy()
2531
# "cdist" not implemented for 'Half' on CPU
2632
# "pdist" not implemented for 'Half' on CPU
2733
skip_ops += ["_cdist_forward.default", "_pdist_forward.default"]
2834

29-
self._run_all_ops(skip_ops=skip_ops)
35+
config = TensorConfig(device="cpu", half_precision=True)
36+
self._run_all_ops(config=config, skip_ops=skip_ops)
3037

3138

3239
if __name__ == "__main__":

test/specdb/test_specdb_mps.py

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,55 @@
1515
class TestSpecDBOperationsMPS(BaseSpecDBTest):
1616
"""Test class for validating all specs in SpecDB using gen_errors on MPS."""
1717

18+
SKIP_OPS = [
19+
# Calibrate specs (cpu not passing either):
20+
"addmm.default",
21+
"arange.default",
22+
"arange.start_step",
23+
"constant_pad_nd.default",
24+
"split_with_sizes_copy.default",
25+
# https://github.com/pytorch/pytorch/issues/160208
26+
"add.Tensor",
27+
"add.Scalar",
28+
"rsub.Scalar",
29+
"sub.Tensor",
30+
"sub.Scalar",
31+
# crash: https://github.com/pytorch/pytorch/issues/154887
32+
"_native_batch_norm_legit_no_training.default",
33+
# not implemented
34+
"_pdist_forward.default",
35+
# impl: clamp tensor number of dims must not be greater than that of input tensor
36+
"clamp.Tensor",
37+
# crash: https://github.com/pytorch/pytorch/issues/154881
38+
"cumsum.default",
39+
# sparse_grad not supported in MPS yet
40+
"gather.default",
41+
# Dimension specified as -1 but tensor has no dimensions
42+
"index_select.default",
43+
# crash: https://github.com/pytorch/pytorch/issues/154882
44+
"max_pool2d_with_indices.default",
45+
# On-going issue on MPSGraph topk when ndims() - axis > 4, see issue #154890
46+
# https://github.com/pytorch/pytorch/issues/154890
47+
"topk.default",
48+
# var_mps: reduction dim must be in the range of input shape
49+
"var.correction",
50+
"var.dim",
51+
]
52+
1853
def test_all_ops_mps(self):
19-
skip_ops = [
20-
# Calibrate specs (cpu not passing either):
21-
"addmm.default",
22-
"arange.default",
23-
"arange.start_step",
24-
"constant_pad_nd.default",
25-
"split_with_sizes_copy.default",
26-
# https://github.com/pytorch/pytorch/issues/160208
27-
"add.Tensor",
28-
"add.Scalar",
29-
"rsub.Scalar",
30-
"sub.Tensor",
31-
"sub.Scalar",
32-
# crash: https://github.com/pytorch/pytorch/issues/154887
33-
"_native_batch_norm_legit_no_training.default",
34-
# not implemented
35-
"_pdist_forward.default",
36-
# impl: clamp tensor number of dims must not be greater than that of input tensor
37-
"clamp.Tensor",
38-
# crash: https://github.com/pytorch/pytorch/issues/154881
39-
"cumsum.default",
40-
# sparse_grad not supported in MPS yet
41-
"gather.default",
42-
# Dimension specified as -1 but tensor has no dimensions
43-
"index_select.default",
44-
# crash: https://github.com/pytorch/pytorch/issues/154882
45-
"max_pool2d_with_indices.default",
46-
# On-going issue on MPSGraph topk when ndims() - axis > 4, see issue #154890
47-
# https://github.com/pytorch/pytorch/issues/154890
48-
"topk.default",
49-
# var_mps: reduction dim must be in the range of input shape
50-
"var.correction",
51-
"var.dim",
52-
]
54+
config = TensorConfig(
55+
device="mps", disallow_dtypes=[torch.float64], half_precision=False
56+
)
57+
self._run_all_ops(config=config, skip_ops=self.SKIP_OPS)
5358

59+
def test_all_ops_mps_half(self):
60+
skip_ops = self.SKIP_OPS.copy()
5461
# ConvTranspose 3D with BF16 or FP16 types is not supported on MPS
5562
skip_ops += ["convolution.default"]
5663

57-
config = TensorConfig(device="mps", disallow_dtypes=[torch.float64])
64+
config = TensorConfig(
65+
device="mps", disallow_dtypes=[torch.float64], half_precision=True
66+
)
5867
self._run_all_ops(config=config, skip_ops=skip_ops)
5968

6069

0 commit comments

Comments
 (0)