Commit 4deec279 authored by thatPepe's avatar thatPepe Committed by MaYuhang
Browse files

Merge pull request #631 from InfiniTensor/issue/630

issue/630 - slightly improved unimplemented messages
parents f3a25b70 2a343a3a
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, weight_shape_or_None)
# Note: PReLU requires a weight parameter of shape (C,) or (1,), we create a per-channel weight when possible.
_TEST_CASES_DATA = [
((4, 4), None, None),
((8, 4, 4), (128, 32, 1), (4,)),
((2, 3, 6), None, (3,)),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""prelu(input, weight)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
weight_shape = data[2] if len(data) > 2 and data[2] is not None else None
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
# Determine default weight shape: channel dimension if available
if weight_shape is None:
if len(shape) >= 2:
c = shape[1]
weight_spec = TensorSpec.from_tensor((c,), None, dtype)
else:
weight_spec = TensorSpec.from_tensor((1,), None, dtype)
else:
weight_spec = TensorSpec.from_tensor(weight_shape, None, dtype)
test_cases.append(
TestCase(
inputs=[input_spec, weight_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"PReLU - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""PReLU operator test with simplified implementation"""
def __init__(self):
super().__init__("PReLU")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.prelu(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.prelu(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, dim_or_None, keepdim_or_None, dtype_or_None)
# prod computes product along dim(s) or overall
_TEST_CASES_DATA = [
((8, 8), None, None, None, None),
((8, 8), (16, 1), 1, False, None),
((2, 3, 4), None, 0, True, None),
((1, 8), None, 0, False, None),
((16, 64), (128, 1), None, None, None),
((4, 5, 6), (60, 12, 2), 2, True, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, dim, keepdim, dtype_param = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
if keepdim is not None:
kwargs["keepdim"] = keepdim
if dtype_param is not None:
kwargs["dtype"] = dtype_param
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Prod - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Prod operator test with simplified implementation"""
def __init__(self):
super().__init__("Prod")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.prod(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.prod(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, q_or_None, dim_or_None, keepdim_or_None, out_strides_or_None)
# quantile computes quantiles along dim or overall. q may be float or tensor
_TEST_CASES_DATA = [
((8, 8), None, 0.5, None, None, None),
((8, 8), (16, 1), 0.25, 1, False, None),
((2, 3, 4), None, 0.75, 2, True, (0, 1, 1)),
((16, 64), (128, 1), 0.5, None, None, None),
((4, 5, 6), (60, 12, 2), 0.5, 2, True, (12, 4, 1)),
]
_TOLERANCE_MAP = {
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float32]
def _compute_out_shape(shape, dim, keepdim, q_is_tensor=False):
# if q is tensor with len>1, output shape may include q dim; keep simple: when q is tensor, return (len(q), ...) prefix
if dim is None:
base = ()
else:
if isinstance(dim, tuple):
dims = sorted([(d if d >= 0 else len(shape) + d) for d in dim])
else:
dims = [dim]
if keepdim:
out = list(shape)
for d in dims:
out[d] = 1
base = tuple(out)
else:
base = tuple(s for i, s in enumerate(shape) if i not in dims)
if q_is_tensor:
# Prepend q-length as first dim
return (2,) + base
return base
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, q, dim, keepdim, out_strides = data
q_is_tensor = isinstance(q, torch.Tensor)
out_supports_inplace = not is_broadcast(out_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {"q": q}
if dim is not None:
kwargs["dim"] = dim
if keepdim is not None:
kwargs["keepdim"] = keepdim
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Quantile - OUT_OF_PLACE",
)
)
out_shape = _compute_out_shape(shape, dim, keepdim, q_is_tensor=q_is_tensor)
out_spec = TensorSpec.from_tensor(out_shape, out_strides, dtype)
if out_supports_inplace:
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="Quantile - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Quantile operator test with simplified implementation"""
def __init__(self):
super().__init__("Quantile")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.quantile(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.quantile(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
......@@ -80,7 +80,7 @@ def parse_test_cases():
),
comparison_target="out",
tolerance=tolerance,
description=f"RandomSample - OUT",
description=f"RandomSample - INPLACE(out)",
)
)
......
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None)
# infinicore.reciprocal(input)
_TEST_CASES_DATA = [
((2, 3), None),
((1, 4, 8), (32, 8, 1)),
((3, 2, 5, 7), None),
((2, 1, 16), None),
((1, 8, 9, 11), (792, 99, 11, 1)),
((2, 6, 10), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="reciprocal_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="reciprocal_explicit_out",
)
)
if not is_broadcast(in_spec.strides):
cases.append(
TestCase(
inputs=[in_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="reciprocal_inplace_input0",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Reciprocal operator test with simplified implementation"""
def __init__(self):
super().__init__("Reciprocal")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.reciprocal(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.reciprocal(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None)
_TEST_CASES_DATA = [
((13, 4), None),
((13, 4), (10, 1)),
((8, 8, 8), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""relu6(input, inplace=False)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
input_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"ReLU6 - OUT_OF_PLACE",
)
)
if input_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={"inplace": True},
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description=f"ReLU6 - INPLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""ReLU6 operator test with simplified implementation"""
def __init__(self):
super().__init__("ReLU6")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.relu6(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.relu6(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (a_shape, a_strides_or_None, b_shape_or_None)
# infinicore.remainder(a, b)
_TEST_CASES_DATA = [
((2, 3, 4), None, None),
((1, 4, 8), (32, 8, 1), None),
((3, 2, 5, 7), None, None),
((2, 1, 16), None, None),
((1, 8, 9, 11), (792, 99, 11, 1), None),
((2, 6, 10), None, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for a_shape, a_strides, b_shape in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
a_spec = TensorSpec.from_tensor(a_shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(
a_shape if b_shape is None else b_shape, None, dtype
)
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="remainder_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(a_shape, None, dtype)
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="remainder_explicit_out",
)
)
if not is_broadcast(a_spec.strides):
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="remainder_inplace_a",
)
)
if not is_broadcast(b_spec.strides):
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="remainder_inplace_b",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Remainder operator test with simplified implementation"""
def __init__(self):
super().__init__("Remainder")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.remainder(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.remainder(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, new_shape)
# reshape can change shape; out parameter is not used in infinicore.reshape API (returns view or tensor)
_TEST_CASES_DATA = [
((2, 6), None, (3, 4)),
((3, 4), (12, 1), (12,)),
((4, 2, 3), None, (2, 12)),
((2, 3, 4), (48, 16, 4), (6, 4)),
((16, 64), None, (64, 16)),
((1, 24), None, (2, 12)),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
in_shape, in_strides, new_shape = data[0], data[1], data[2]
supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-4})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
# Out-of-place (reshape returns tensor)
# Following reference pattern: pass new shape as positional arg to infinicore.reshape
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs={"shape": new_shape},
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"reshape - OUT_OF_PLACE",
)
)
# In-place reshape (view-based) is not an explicit API; skip INPLACE cases.
# Note: infinicore.reshape may return a view; framework will compare returned tensor.
return test_cases
class OpTest(BaseOperatorTest):
"""Reshape operator test with simplified implementation"""
def __init__(self):
super().__init__("Reshape")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.reshape(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.reshape(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (shape, k, dims_tuple, input_strides_or_None)
# infinicore.rot90(input, k=1, dims=(0,1))
_TEST_CASES_DATA = [
((3, 4), 1, (0, 1), None),
((2, 3, 4), 2, (1, 2), (24, 8, 2)),
((4, 5, 6, 7), 3, (2, 3), None),
((6, 7), 1, (0, 1), None),
((2, 2, 3, 4), 2, (1, 3), None),
((5, 6, 7), 1, (0, 2), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, k, dims = data[0], data[1], data[2]
in_strides = data[3] if len(data) > 3 else None
supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-4})
in_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"k": k, "dims": dims}
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"rot90 - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Rot90 operator test with simplified implementation"""
def __init__(self):
super().__init__("Rot90")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.rot90(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.rot90(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# round(input, decimals=0)
# We'll test with various decimals including negative values and None.
_TEST_CASES_DATA = [
((2, 3), None, 0),
((1, 4, 8), None, 1),
((3, 2, 5, 7), None, -1),
((2, 1, 16), None, 2),
((1, 8, 9, 11), None, 0),
((2, 6, 10), None, 3),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides, decimals in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
# out-of-place
kwargs = {"decimals": decimals} if decimals is not None else {}
cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="round_out",
)
)
# explicit out
out_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="round_explicit_out",
)
)
# in-place when not broadcast
if not is_broadcast(strides):
cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=0,
tolerance=tol,
description="round_inplace",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Round operator test with simplified implementation"""
def __init__(self):
super().__init__("Round")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.round(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.round(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, lower_or_None, upper_or_None)
_TEST_CASES_DATA = [
((13, 4), None, 0.125, 0.333),
((13, 4), (10, 1), 0.1, 0.3),
((8, 8, 8), None, 0.05, 0.2),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""rrelu(input, lower=0.125, upper=0.333..., training=False, inplace=False)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
lower = data[2] if len(data) > 2 else 0.125
upper = data[3] if len(data) > 3 else 0.333
input_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"lower": lower, "upper": upper}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"RReLU - OUT_OF_PLACE",
)
)
if input_supports_inplace:
inplace_kwargs = {"lower": lower, "upper": upper, "inplace": True}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=inplace_kwargs,
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description=f"RReLU - INPLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""RReLU operator test with simplified implementation"""
def __init__(self):
super().__init__("RReLU")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.rrelu(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.rrelu(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (q_shape, k_shape, v_shape, attn_mask_or_None, dropout_p, is_causal)
# q/k/v typically have shape (..., seq_len, head_dim) or (batch, seq_len, num_heads, head_dim)
_TEST_CASES_DATA = [
((2, 8, 16), (2, 8, 16), (2, 8, 16), None, 0.0, False),
((1, 4, 32), (1, 4, 32), (1, 4, 32), None, 0.0, False),
((2, 6, 12), (2, 6, 12), (2, 6, 12), None, 0.0, True),
((3, 8, 8), (3, 8, 8), (3, 8, 8), None, 0.0, False),
((2, 4, 16), (2, 4, 16), (2, 4, 16), None, 0.0, True),
((1, 2, 64), (1, 2, 64), (1, 2, 64), None, 0.0, False),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-2, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-4, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for q_shape, k_shape, v_shape, attn_mask, dropout_p, is_causal in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
q_spec = TensorSpec.from_tensor(q_shape, None, dtype)
k_spec = TensorSpec.from_tensor(k_shape, None, dtype)
v_spec = TensorSpec.from_tensor(v_shape, None, dtype)
kwargs = {
"attn_mask": attn_mask,
"dropout_p": dropout_p,
"is_causal": is_causal,
}
# remove None keys
kwargs = {k: v for k, v in kwargs.items() if v is not None}
cases.append(
TestCase(
inputs=[q_spec, k_spec, v_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="ScaledDotProductAttention",
)
)
return cases
class OpTest(BaseOperatorTest):
"""ScaledDotProductAttention operator test with simplified implementation"""
def __init__(self):
super().__init__("ScaledDotProductAttention")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.scaled_dot_product_attention(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.scaled_dot_product_attention(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.tensor import TensorInitializer
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (input_shape, input_strides_or_None, dim, index_shape, src_shape)
_TEST_CASES_DATA = [
((5, 6), None, 1, (5, 2), (5, 2)),
((4, 4), (16, 1), 0, (2, 4), (2, 4)),
((3, 5), None, 1, (3, 3), (3, 3)),
((2, 6), None, 1, (2, 2), (2, 2)),
((6, 3), (18, 1), 0, (3, 3), (3, 3)),
((4, 7), None, 1, (4, 2), (4, 2)),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for tgt_shape, tgt_strides, dim, idx_shape, src_shape in _TEST_CASES_DATA:
tgt_spec = TensorSpec.from_tensor(tgt_shape, tgt_strides, infinicore.float32)
# initialize index tensor within [0, size) for the target dim to avoid OOB
effective_dim = dim if dim >= 0 else (dim + len(tgt_shape))
max_index = tgt_shape[effective_dim]
idx_spec = TensorSpec.from_tensor(
idx_shape,
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=max_index,
)
src_spec = TensorSpec.from_tensor(src_shape, None, infinicore.float32)
out_supports = not is_broadcast(tgt_strides)
# Out-of-place
test_cases.append(
TestCase(
inputs=[tgt_spec, idx_spec, src_spec],
kwargs={"dim": dim},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"scatter - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Scatter operator test with simplified implementation"""
def __init__(self):
super().__init__("Scatter")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
if len(args) < 3:
raise TypeError("scatter requires input, index, src as positional args")
inp, idx, src = args[0], args[1], args[2]
dim = None
if kwargs:
dim = kwargs.get("dim", None)
if dim is None:
raise TypeError("scatter test did not provide 'dim' parameter")
return torch.scatter(inp, dim, idx, src)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.scatter(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.tensor import TensorInitializer
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (shape, input_strides, index_strides, src_strides, dim)
_TEST_CASES_DATA = [
((6, 8), None, None, None, 1),
((8, 4), (16, 1), None, None, 0),
((5, 5), None, None, (10, 1), 1),
((3, 7), None, (14, 1), None, 1),
((10, 3), (30, 1), (30, 1), (30, 1), 0),
((2, 16), None, None, None, 1),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-3},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""Format: (shape, input_strides, index_strides, src_strides, dim)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape, in_strides, idx_strides, src_strides, dim = data
in_supports_inplace = not is_broadcast(in_strides)
out_supports_inplace = not is_broadcast(src_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
# index tensor spec: 必须生成 [0, shape[dim]-1] 的 int64 值
high = max(1, shape[dim])
index_spec = TensorSpec.from_tensor(
shape,
idx_strides,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=high,
)
src_spec = TensorSpec.from_tensor(shape, src_strides, dtype)
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec, src_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"scatter_add - OUT_OF_PLACE",
)
)
# In-place on input
if in_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec, src_spec],
kwargs={},
output_spec=None,
comparison_target=0,
tolerance=tol,
description=f"scatter_add - INPLACE(input)",
)
)
# Out as explicit tensor
if out_supports_inplace:
out_spec = TensorSpec.from_tensor(shape, None, dtype)
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec, src_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description=f"scatter_add - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""ScatterAdd operator test with simplified implementation"""
def __init__(self):
super().__init__("ScatterAdd")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.scatter_add(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.scatter_add(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.tensor import TensorInitializer
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (shape, input_strides, index_strides, src_strides, dim, reduce)
_TEST_CASES_DATA = [
((6, 6), None, None, None, 1, "sum"),
((8, 4), (16, 1), None, None, 0, "amax"),
((5, 5), None, None, (10, 1), 1, "mean"),
((3, 7), None, (14, 1), None, 1, "amin"),
((10, 3), (30, 1), (30, 1), (30, 1), 0, "sum"),
((2, 16), None, None, None, 1, "prod"),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-3},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""Format: (shape, input_strides, index_strides, src_strides, dim, reduce)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape, in_strides, idx_strides, src_strides, dim, reduce = data
in_supports_inplace = not is_broadcast(in_strides)
out_supports_inplace = not is_broadcast(src_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
# index_spec = TensorSpec.from_tensor(shape, idx_strides, infinicore.int64)
# index tensor spec: 必须生成 [0, shape[dim]-1] 的 int64 值
high = max(1, shape[dim])
index_spec = TensorSpec.from_tensor(
shape,
idx_strides,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=high,
)
src_spec = TensorSpec.from_tensor(shape, src_strides, dtype)
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec, src_spec],
kwargs={"reduce": reduce},
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"scatter_reduce - OUT_OF_PLACE",
)
)
# In-place on input
if in_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec, src_spec],
kwargs={"reduce": reduce, "out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description=f"scatter_reduce - INPLACE(input)",
)
)
# Explicit out tensor
if out_supports_inplace:
out_spec = TensorSpec.from_tensor(shape, None, dtype)
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec, src_spec],
kwargs={"reduce": reduce},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description=f"scatter_reduce - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""ScatterReduce operator test with simplified implementation"""
def __init__(self):
super().__init__("ScatterReduce")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.scatter_reduce(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.scatter_reduce(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (input_shape, input_strides_or_None, dim, index)
_TEST_CASES_DATA = [
((3, 4), None, 0, 1),
((5, 6), (30, 1), 1, 2),
((2, 3, 4), None, 2, 0),
((4, 4), None, -1, 1),
((6, 2), (12, 1), 1, 0),
((3, 5), None, 0, 2),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides, dim, idx in _TEST_CASES_DATA:
input_spec = TensorSpec.from_tensor(shape, strides, infinicore.float32)
kwargs = {"dim": dim, "index": idx}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"select - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Select operator test with simplified implementation"""
def __init__(self):
super().__init__("Select")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.select(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.select(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
from framework.tensor import TensorInitializer
# Test cases format: (shape, input_strides, index_strides, src_strides, dim)
_TEST_CASES_DATA = [
((6, 8), None, None, None, 1),
((8, 4), (16, 1), None, None, 0),
((5, 5), None, None, (10, 1), 1),
((3, 7), None, (14, 1), None, 1),
((10, 3), (30, 1), (30, 1), (30, 1), 0),
((2, 16), None, None, None, 1),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-3},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, in_strides, idx_strides, src_strides, dim = data
in_supports_inplace = not is_broadcast(in_strides)
out_supports_inplace = not is_broadcast(src_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
src_shape = tuple(s for i, s in enumerate(shape) if i != dim)
src_strides_for_src = (
src_strides
if (src_strides and len(src_strides) == len(src_shape))
else None
)
src_spec = TensorSpec.from_tensor(src_shape, src_strides_for_src, dtype)
high = max(1, shape[dim])
index_spec = TensorSpec.from_tensor(
shape,
idx_strides,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=high,
)
index_val = 0 if shape[dim] <= 1 else (shape[dim] // 2)
test_cases.append(
TestCase(
inputs=[input_spec, src_spec, dim, index_val],
kwargs=None,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"select_scatter - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""SelectScatter operator test with simplified implementation"""
def __init__(self):
super().__init__("SelectScatter")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.select_scatter(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.select_scatter(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None)
_TEST_CASES_DATA = [
((13, 4), None),
((13, 4), (10, 1)),
((8, 8, 8), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""selu(input)
SELU functional API does not accept inplace; only out-of-place.
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"SELU - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""SELU operator test with simplified implementation"""
def __init__(self):
super().__init__("SELU")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.selu(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.selu(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (in_shape, in_strides_or_None)
# sgn is an alias for sign on many platforms; we provide similar coverage.
_TEST_CASES_DATA = [
((2, 3), None),
((1, 4, 8), (32, 8, 1)),
((3, 2, 5, 7), None),
((2, 1, 16), None),
((1, 8, 9, 11), (792, 99, 11, 1)),
((2, 6, 10), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0.0, "rtol": 0.0},
infinicore.float32: {"atol": 0.0, "rtol": 0.0},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="sgn_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="sgn_explicit_out",
)
)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="sgn_inplace_out0",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Sgn operator test with simplified implementation"""
def __init__(self):
super().__init__("Sgn")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.sgn(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.sgn(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (in_shape, in_strides_or_None)
_TEST_CASES_DATA = [
((2, 3), None),
((1, 4, 8), (32, 8, 1)),
((3, 2, 5, 7), None),
((2, 1, 16), None),
((1, 8, 9, 11), (792, 99, 11, 1)),
((2, 6, 10), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0.0, "rtol": 0.0},
infinicore.float32: {"atol": 0.0, "rtol": 0.0},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="sign_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="sign_explicit_out",
)
)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="sign_inplace_out0",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Sign operator test with simplified implementation"""
def __init__(self):
super().__init__("Sign")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.sign(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.sign(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment