Unverified Commit 1e43a28e authored by thatPepe's avatar thatPepe Committed by GitHub
Browse files

Merge pull request #589 from InfiniTensor/issue/566

issue/566: 添加 Python 算子测试
parents 798dc76e 4deec279
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, a_strides_or_None, b_strides_or_None, out_strides_or_None)
_TEST_CASES_DATA = [
((8, 8), None, None, None),
((8, 8), (16, 1), None, None),
((8, 8), None, (0, 1), None),
((4, 1), None, None, (8, 1)),
((2, 3, 4), None, None, None),
((16, 512), (1024, 1), (0, 1), None),
]
_TOLERANCE_MAP = {
infinicore.int32: {"atol": 0, "rtol": 0},
infinicore.int64: {"atol": 0, "rtol": 0},
infinicore.uint8: {"atol": 0, "rtol": 0},
}
_TENSOR_DTYPES = [infinicore.int32, infinicore.int64, infinicore.uint8]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, a_strides, b_strides, out_strides = data[0], data[1], data[2], data[3]
a_supports_inplace = not is_broadcast(a_strides)
b_supports_inplace = not is_broadcast(b_strides)
out_supports_inplace = not is_broadcast(out_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 0})
a_spec = TensorSpec.from_tensor(shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(shape, b_strides, dtype)
out_spec = TensorSpec.from_tensor(shape, out_strides, dtype)
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Bitwise right shift - OUT_OF_PLACE",
)
)
if out_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="Bitwise right shift - INPLACE(out)",
)
)
if a_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="Bitwise right shift - INPLACE(a)",
)
)
if b_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="Bitwise right shift - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""BitwiseRightShift operator test with simplified implementation"""
def __init__(self):
super().__init__("BitwiseRightShift")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.bitwise_right_shift(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.bitwise_right_shift(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
......@@ -31,7 +31,7 @@ _TEST_CASES_DATA = [
((16, 5632), (13312, 1), (13312, 1), None),
]
# Tolerance configuration - exact match required for bitwise operations
# Tolerance configuration
_TOLERANCE_MAP = {
infinicore.int8: {"atol": 0, "rtol": 0},
infinicore.int16: {"atol": 0, "rtol": 0},
......@@ -41,14 +41,14 @@ _TOLERANCE_MAP = {
infinicore.bool: {"atol": 0, "rtol": 0},
}
# Data types to test - integer types for bitwise operations
# Data types to test
_TENSOR_DTYPES = [
infinicore.int8,
infinicore.int16,
infinicore.int32,
infinicore.int64,
infinicore.uint8,
infinicore.bool, # XOR also supports boolean tensors
infinicore.bool,
]
......
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: (list_of_matrix_shapes, list_of_strides_or_None, dtype)
_TEST_CASES_DATA = [
([(3, 4), (2, 2)], [None, None], None),
([(1, 1), (1, 1), (1, 1)], [None, None, None], None),
([(4, 4), (2, 3), (3, 2)], [None, (6, 1), (0, 3)], None),
([(8, 8)], [None], None),
([(5, 2), (2, 5)], [(10, 1), None], None),
([(6, 6), (6, 6), (6, 6)], [None, None, None], None),
]
_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 shapes, strides_list, _ in _TEST_CASES_DATA:
# prepare TensorSpec list for inputs
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_specs = []
for s, st in zip(shapes, strides_list):
input_specs.append(TensorSpec.from_tensor(s, st, dtype))
test_cases.append(
TestCase(
inputs=input_specs,
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="block_diag - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""block_diag operator test with simplified implementation"""
def __init__(self):
super().__init__("block_diag")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.block_diag(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.block_diag(*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: (input_shape, input_strides_or_None, target_shape)
_TEST_CASES_DATA = [
((3, 1), None, (3, 4)),
((1,), None, (5,)),
((2, 1, 4), (8, 1, 1), (2, 3, 4)),
((4, 1), None, (4, 6)),
((1, 1), None, (2, 3)),
((2,), None, (2, 2)),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, target = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {"size": target}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="broadcast_to - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""BroadcastTo operator test with simplified implementation"""
def __init__(self):
super().__init__("BroadcastTo")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.broadcast_to(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.broadcast_to(*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, boundaries_len)
_TEST_CASES_DATA = [
((5,), None, 3),
((4, 3), None, 4),
((2,), None, 5),
((6,), None, 2),
((3, 3), None, 6),
((1,), None, 1),
]
_TOLERANCE_MAP = {infinicore.int64: {"atol": 0, "rtol": 0}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides, b_len in _TEST_CASES_DATA:
input_spec = TensorSpec.from_tensor(shape, strides, infinicore.float32)
boundaries_spec = TensorSpec.from_tensor((b_len,), None, infinicore.float32)
test_cases.append(
TestCase(
inputs=[input_spec, boundaries_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.int64],
description="bucketize - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Bucketize operator test with simplified implementation"""
def __init__(self):
super().__init__("Bucketize")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.bucketize(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.bucketize(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
......@@ -89,7 +89,7 @@ def parse_test_cases():
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Cat - OUT_OF_PLACE",
description="Cat - OUT_OF_PLACE",
)
)
......@@ -102,7 +102,7 @@ def parse_test_cases():
output_spec=output_spec,
comparison_target="out",
tolerance=tolerance,
description=f"Cat - INPLACE(out)",
description="Cat - 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
# Test cases format: (x1_shape, x2_shape, x1_strides_or_None, x2_strides_or_None, p_or_None)
_TEST_CASES_DATA = [
((5, 3), (6, 3), None, None, None),
((1, 4), (2, 4), None, None, 1.0),
((8, 16), (8, 16), (128, 16), (128, 16), 2.0),
((3, 2), (4, 2), None, (0, 2), None),
((10, 5), (7, 5), None, None, float("inf")),
((2, 1), (3, 1), None, None, None),
]
_TOLERANCE_MAP = {
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for x1_shape, x2_shape, x1_strides, x2_strides, p in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
x1_spec = TensorSpec.from_tensor(x1_shape, x1_strides, dtype)
x2_spec = TensorSpec.from_tensor(x2_shape, x2_strides, dtype)
kwargs = {}
if p is not None:
kwargs["p"] = p
test_cases.append(
TestCase(
inputs=[x1_spec, x2_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="cdist - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""cdist operator test with simplified implementation"""
def __init__(self):
super().__init__("cdist")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cdist(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cdist(*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, alpha_or_None)
# ==============================================================================
# Operator-specific configuration
# ==============================================================================
_TEST_CASES_DATA = [
((13, 4), None, None),
((13, 4), (10, 1), None),
((8, 8), None, 0.5),
((16, 16), (256, 1), 1.5),
((32, 8), None, 1.0),
]
# Tolerance configuration
_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},
}
# Data types to test
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
alpha = data[2] if len(data) > 2 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)
# Out-of-place
kwargs = {}
if alpha is not None:
kwargs["alpha"] = alpha
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"CELU - OUT_OF_PLACE",
)
)
# In-place
if input_supports_inplace:
inplace_kwargs = {"inplace": True}
if alpha is not None:
inplace_kwargs["alpha"] = alpha
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=inplace_kwargs,
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description=f"CELU - INPLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""CELU operator test with simplified implementation"""
def __init__(self):
super().__init__("CELU")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.celu(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.celu(*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: (shape, input_strides_or_None)
_TEST_CASES_DATA = [
((3, 4), None),
((6, 2), (12, 1)),
((5, 5), None),
((1, 7), None),
((8, 3), (24, 1)),
((2, 2, 2), None),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
# clone is out-of-place; also test clone with memory_format not None if supported
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"clone - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Clone operator test with simplified implementation"""
def __init__(self):
super().__init__("Clone")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.clone(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.clone(*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, r)
# combinations operates on 1-D inputs (combinations of elements). We keep inputs small.
_TEST_CASES_DATA = [
((5,), None, 2),
((6,), None, 3),
((4,), None, 1),
((7,), None, 2),
((8,), None, 3),
((3,), None, 2),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, r = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {"r": r}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"combinations - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Combinations operator test with simplified implementation"""
def __init__(self):
super().__init__("Combinations")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.combinations(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.combinations(*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: (in_shape, in_strides_or_None, weight_shape, bias_shape_or_None, stride, padding, dilation, groups)
_TEST_CASES_DATA = [
((2, 4, 16), None, (8, 4, 3), None, 1, 0, 1, 1),
((1, 6, 15), (90, 15, 1), (4, 6, 5), (4,), 2, 2, 1, 1),
((2, 16, 32), None, (8, 8, 1), None, 1, 0, 1, 2),
((3, 3, 7), (21, 7, 1), (6, 3, 3), None, 1, 0, 1, 1),
((2, 2, 31), None, (4, 2, 4), (4,), 2, 1, 1, 1),
((1, 8, 9), (72, 9, 1), (8, 8, 3), None, 1, 1, 2, 1),
]
_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():
tests = []
for (
in_shape,
in_strides,
w_shape,
b_shape,
stride,
padding,
dilation,
groups,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
weight_spec = TensorSpec.from_tensor(w_shape, None, dtype)
if b_shape is not None:
bias_spec = TensorSpec.from_tensor(b_shape, None, dtype)
else:
bias_spec = None
kwargs = {
"stride": stride,
"padding": padding,
"dilation": dilation,
"groups": groups,
}
inputs = [in_spec, weight_spec]
if bias_spec is not None:
inputs.append(bias_spec)
tests.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Conv1d - OUT_OF_PLACE",
)
)
return tests
class OpTest(BaseOperatorTest):
"""Conv1d operator test with simplified implementation"""
def __init__(self):
super().__init__("Conv1d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.conv1d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.conv1d(*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: (in_shape, in_strides_or_None, weight_shape, bias_shape_or_None, stride, padding, dilation, groups)
_TEST_CASES_DATA = [
((2, 4, 16, 16), None, (8, 4, 3, 3), None, (1, 1), (0, 0), (1, 1), 1),
((1, 6, 15, 17), (1530, 255, 17, 1), (4, 6, 5, 3), (4,), (2, 2), (2, 1), (1, 1), 1),
((2, 8, 32, 32), None, (8, 8, 1, 1), None, (1, 1), (0, 0), (1, 2), 1),
((3, 3, 7, 9), (189, 63, 9, 1), (6, 3, 3, 3), None, 1, (1, 1), (1, 1), 1),
((2, 2, 31, 29), None, (4, 2, 4, 3), (4,), (2, 1), (1, 0), (1, 1), 1),
((1, 8, 9, 11), (792, 99, 11, 1), (8, 8, 3, 3), None, (1, 1), (1, 1), (1, 1), 1),
]
_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():
tests = []
for (
in_shape,
in_strides,
w_shape,
b_shape,
stride,
padding,
dilation,
groups,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
weight_spec = TensorSpec.from_tensor(w_shape, None, dtype)
if b_shape is not None:
bias_spec = TensorSpec.from_tensor(b_shape, None, dtype)
else:
bias_spec = None
kwargs = {
"stride": stride,
"padding": padding,
"dilation": dilation,
"groups": groups,
}
inputs = [in_spec, weight_spec]
if bias_spec is not None:
inputs.append(bias_spec)
tests.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Conv2d - OUT_OF_PLACE",
)
)
return tests
class OpTest(BaseOperatorTest):
"""Conv2d operator test with simplified implementation"""
def __init__(self):
super().__init__("Conv2d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.conv2d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.conv2d(*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: (in_shape, in_strides_or_None, weight_shape, bias_shape_or_None, stride, padding, dilation, groups)
_TEST_CASES_DATA = [
((1, 2, 8, 8, 8), None, (4, 2, 3, 3, 3), None, (1, 1, 1), (0, 0, 0), (1, 1, 1), 1),
(
(2, 3, 7, 9, 5),
(756, 252, 36, 4, 1),
(6, 3, 3, 3, 1),
(6,),
(2, 2, 1),
(1, 1, 0),
(1, 1, 1),
1,
),
(
(1, 4, 16, 16, 6),
None,
(8, 4, 1, 1, 2),
None,
(1, 1, 2),
(0, 1, 0),
(1, 1, 1),
1,
),
(
(2, 1, 9, 11, 7),
(693, 77, 77, 7, 1),
(6, 1, 3, 3, 3),
None,
1,
(1, 0, 1),
(1, 1, 1),
1,
),
((3, 2, 5, 6, 4), None, (4, 2, 2, 2, 2), (4,), (1, 1, 1), (0, 1, 0), (1, 1, 1), 1),
(
(2, 6, 10, 9, 8),
(4320, 720, 72, 8, 1),
(8, 6, 3, 3, 2),
None,
(2, 1, 2),
(1, 0, 1),
(1, 1, 1),
1,
),
]
_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():
tests = []
for (
in_shape,
in_strides,
w_shape,
b_shape,
stride,
padding,
dilation,
groups,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
weight_spec = TensorSpec.from_tensor(w_shape, None, dtype)
if b_shape is not None:
bias_spec = TensorSpec.from_tensor(b_shape, None, dtype)
else:
bias_spec = None
kwargs = {
"stride": stride,
"padding": padding,
"dilation": dilation,
"groups": groups,
}
inputs = [in_spec, weight_spec]
if bias_spec is not None:
inputs.append(bias_spec)
tests.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Conv3d - OUT_OF_PLACE",
)
)
return tests
class OpTest(BaseOperatorTest):
"""Conv3d operator test with simplified implementation"""
def __init__(self):
super().__init__("Conv3d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.conv3d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.conv3d(*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: (in_shape, in_strides_or_None, weight_shape, bias_shape_or_None, stride, padding, output_padding, groups)
_TEST_CASES_DATA = [
((2, 4, 16), None, (4, 4, 3), None, 1, 0, 0, 1),
((1, 6, 15), (90, 15, 1), (6, 6, 5), (6,), 2, 1, 1, 1),
((2, 8, 32), None, (8, 4, 1), None, 1, 0, 0, 2),
((3, 3, 7), (21, 7, 1), (3, 3, 3), None, 1, 0, 0, 1),
((2, 2, 31), None, (2, 2, 4), (2,), 2, 1, 1, 1),
((1, 8, 9), (72, 9, 1), (8, 4, 3), None, 1, 1, 0, 1),
]
_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():
tests = []
for (
in_shape,
in_strides,
w_shape,
b_shape,
stride,
padding,
out_pad,
groups,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
weight_spec = TensorSpec.from_tensor(w_shape, None, dtype)
if b_shape is not None:
bias_spec = TensorSpec.from_tensor(b_shape, None, dtype)
else:
bias_spec = None
kwargs = {
"stride": stride,
"padding": padding,
"output_padding": out_pad,
"groups": groups,
}
inputs = [in_spec, weight_spec]
if bias_spec is not None:
inputs.append(bias_spec)
tests.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="ConvTranspose1d - OUT_OF_PLACE",
)
)
return tests
class OpTest(BaseOperatorTest):
"""ConvTranspose1d operator test with simplified implementation"""
def __init__(self):
super().__init__("ConvTranspose1d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.conv_transpose1d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.conv_transpose1d(*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: (in_shape, in_strides_or_None, weight_shape, bias_shape_or_None, stride, padding, output_padding, groups)
_TEST_CASES_DATA = [
((2, 4, 16, 16), None, (4, 4, 3, 3), None, (1, 1), (0, 0), (0, 0), 1),
((1, 6, 15, 17), (1530, 255, 17, 1), (6, 6, 5, 3), (6,), (2, 2), (2, 1), (1, 1), 1),
((2, 8, 32, 32), None, (8, 4, 1, 1), None, (1, 1), (0, 0), (0, 0), 1),
((3, 3, 7, 9), (189, 63, 9, 1), (3, 3, 3, 3), None, 1, (1, 1), (0, 0), 1),
((2, 2, 31, 29), None, (2, 2, 4, 3), (2,), (2, 1), (1, 0), (1, 0), 1),
((1, 8, 9, 11), (792, 99, 11, 1), (8, 4, 3, 3), None, (1, 1), (1, 1), (0, 0), 1),
]
_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():
tests = []
for (
in_shape,
in_strides,
w_shape,
b_shape,
stride,
padding,
out_pad,
groups,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
weight_spec = TensorSpec.from_tensor(w_shape, None, dtype)
if b_shape is not None:
bias_spec = TensorSpec.from_tensor(b_shape, None, dtype)
else:
bias_spec = None
kwargs = {
"stride": stride,
"padding": padding,
"output_padding": out_pad,
"groups": groups,
}
inputs = [in_spec, weight_spec]
if bias_spec is not None:
inputs.append(bias_spec)
tests.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="ConvTranspose2d - OUT_OF_PLACE",
)
)
return tests
class OpTest(BaseOperatorTest):
"""ConvTranspose2d operator test with simplified implementation"""
def __init__(self):
super().__init__("ConvTranspose2d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.conv_transpose2d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.conv_transpose2d(*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: (in_shape, in_strides_or_None, weight_shape, bias_shape_or_None, stride, padding, output_padding, groups)
_TEST_CASES_DATA = [
((1, 2, 8, 8, 8), None, (2, 2, 3, 3, 3), None, (1, 1, 1), (0, 0, 0), (0, 0, 0), 1),
(
(2, 3, 7, 9, 5),
(756, 252, 36, 4, 1),
(3, 3, 3, 3, 1),
(3,),
(2, 2, 1),
(1, 1, 0),
(0, 0, 0),
1,
),
(
(1, 4, 16, 16, 6),
None,
(4, 2, 1, 1, 2),
None,
(1, 1, 2),
(0, 1, 0),
(0, 0, 0),
1,
),
(
(2, 1, 9, 11, 7),
(693, 77, 77, 7, 1),
(1, 6, 3, 3, 3),
None,
1,
(1, 0, 1),
(0, 0, 0),
1,
),
((3, 2, 5, 6, 4), None, (2, 2, 2, 2, 2), (2,), (1, 1, 1), (0, 1, 0), (0, 0, 0), 1),
(
(2, 6, 10, 9, 8),
(4320, 720, 72, 8, 1),
(6, 8, 3, 3, 2),
None,
(2, 1, 2),
(1, 0, 1),
(1, 0, 1),
1,
),
]
_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():
tests = []
for (
in_shape,
in_strides,
w_shape,
b_shape,
stride,
padding,
out_pad,
groups,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
weight_spec = TensorSpec.from_tensor(w_shape, None, dtype)
if b_shape is not None:
bias_spec = TensorSpec.from_tensor(b_shape, None, dtype)
else:
bias_spec = None
kwargs = {
"stride": stride,
"padding": padding,
"output_padding": out_pad,
"groups": groups,
}
inputs = [in_spec, weight_spec]
if bias_spec is not None:
inputs.append(bias_spec)
tests.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="ConvTranspose3d - OUT_OF_PLACE",
)
)
return tests
class OpTest(BaseOperatorTest):
"""ConvTranspose3d operator test with simplified implementation"""
def __init__(self):
super().__init__("ConvTranspose3d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.conv_transpose3d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.conv_transpose3d(*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)
# corrcoef accepts 1-D or 2-D inputs; we include both shapes.
_TEST_CASES_DATA = [
((5,), None),
((3, 5), None),
((4, 4), (16, 1)),
((2, 8), None),
((6, 6), None),
((1, 7), None),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"corrcoef - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Corrcoef operator test with simplified implementation"""
def __init__(self):
super().__init__("Corrcoef")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.corrcoef(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.corrcoef(*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, input_strides_or_None)
# =======================================================================
_TEST_CASES_DATA = [
((13, 4), None),
((13, 4), (10, 1)),
((8, 16), None),
((8, 16), (40, 1)),
((2, 3, 4), None),
((16, 5632), 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():
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="cosh - OUT_OF_PLACE",
)
)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="cosh - INPLACE(out)",
)
)
if supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="cosh - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Cosh operator test with simplified implementation"""
def __init__(self):
super().__init__("Cosh")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cosh(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cosh(*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: (input1_shape, input2_shape, target_shape, input1_strides_or_None, input2_strides_or_None, target_strides_or_None, margin_or_None)
# infinicore.nn.functional.cosine_embedding_loss(x1, x2, y, margin=0.0, reduction='mean')
_TEST_CASES_DATA = [
((4, 3), (4, 3), (4,), None, None, None, None),
((8, 5), (8, 5), (8,), (40, 5), None, None, 0.5),
((1, 10), (1, 10), (1,), None, None, None, 0.2),
((16, 20), (16, 20), (16,), None, None, None, 0.0),
((3, 7), (3, 7), (3,), None, (21, 7), None, None),
((2, 2), (2, 2), (2,), None, None, None, 1.0),
]
_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():
test_cases = []
for s1, s2, st, st1, st2, stt, margin in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
a = TensorSpec.from_tensor(s1, st1, dtype)
b = TensorSpec.from_tensor(s2, st2, dtype)
y = TensorSpec.from_tensor(st, stt, dtype)
kwargs = {}
if margin is not None:
kwargs["margin"] = margin
test_cases.append(
TestCase(
inputs=[a, b, y],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="cosine_embedding_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""cosine_embedding_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("cosine_embedding_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.cosine_embedding_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.cosine_embedding_loss(*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, dim, eps, a_strides_or_None, b_strides_or_None)
# infinicore.nn.functional.cosine_similarity(x1, x2, dim=1, eps=1e-8)
_TEST_CASES_DATA = [
((8, 16), 1, 1e-8, None, None),
((8, 16), 1, 1e-6, (128, 1), (128, 1)),
((2, 3, 4), 2, 1e-8, None, None),
((16, 64), 1, 1e-8, None, None),
((4, 5, 6), 0, 1e-8, None, None),
((3, 4, 5), 1, 1e-7, (60, 20, 4), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-2, "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():
test_cases = []
for data in _TEST_CASES_DATA:
shape, dim, eps = data[0], data[1], data[2]
a_strides = data[3] if len(data) > 3 else None
b_strides = data[4] if len(data) > 4 else None
a_supports_inplace = not is_broadcast(a_strides)
b_supports_inplace = not is_broadcast(b_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
a_spec = TensorSpec.from_tensor(shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(shape, b_strides, dtype)
kwargs = {"dim": dim, "eps": eps}
# Out-of-place
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"cosine_similarity - OUT_OF_PLACE",
)
)
# PyTorch cosine_similarity does not support explicit out param; skip out tests
return test_cases
class OpTest(BaseOperatorTest):
"""CosineSimilarity operator test with simplified implementation"""
def __init__(self):
super().__init__("CosineSimilarity")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.cosine_similarity(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.cosine_similarity(*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