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
# Test cases format: (input_shape, input_strides_or_None, weight_present_bool, pos_weight_present_bool, reduction_or_None)
_TEST_CASES_DATA = [
((4, 5), None, False, False, None),
((8, 8), (512, 64), True, False, "sum"),
((1, 10), None, False, True, "mean"),
((16, 100), None, False, True, "mean"),
((3, 7), (21, 7), True, False, None),
((2, 2), None, False, False, "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 (
shape,
strides,
weight_present,
pos_weight_present,
reduction,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
inp = TensorSpec.from_tensor(shape, strides, dtype)
tgt = TensorSpec.from_tensor(shape, None, dtype)
inputs = [inp, tgt]
kwargs = {}
if weight_present:
weight_spec = TensorSpec.from_tensor(shape, None, dtype)
inputs.append(weight_spec)
if pos_weight_present:
pos_weight_spec = TensorSpec.from_tensor(
(shape[1],) if len(shape) > 1 else (shape[0],), None, dtype
)
inputs.append(pos_weight_spec)
if reduction is not None:
kwargs["reduction"] = reduction
test_cases.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="binary_cross_entropy_with_logits - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""binary_cross_entropy_with_logits operator test with simplified implementation"""
def __init__(self):
super().__init__("binary_cross_entropy_with_logits")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.binary_cross_entropy_with_logits(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.binary_cross_entropy_with_logits(*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
# Test cases format: (input_shape, input_strides_or_None, weights_present_bool, minlength)
_TEST_CASES_DATA = [
((10,), None, False, 0),
((6,), None, True, 0),
((8,), None, False, 5),
((12,), None, True, 3),
((1,), None, False, 0),
((20,), None, True, 0),
]
_TOLERANCE_MAP = {infinicore.int64: {"atol": 0, "rtol": 0}}
_TENSOR_DTYPES = [infinicore.int64]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, weights_present, minlength = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 0})
# bincount requires 1-D non-negative integer inputs; use RANDINT with low=0
high = max(1, shape[0])
input_spec = TensorSpec.from_tensor(
shape,
strides,
dtype,
init_mode=TensorInitializer.RANDINT,
low=0,
high=high,
)
if weights_present:
weights_spec = TensorSpec.from_tensor(shape, None, infinicore.float32)
else:
weights_spec = None
kwargs = (
{"minlength": minlength}
if minlength is not None and minlength != 0
else {}
)
inputs = [input_spec] if not weights_present else [input_spec, weights_spec]
test_cases.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="bincount - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Bincount operator test with simplified implementation"""
def __init__(self):
super().__init__("Bincount")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.bincount(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.bincount(*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, a_strides_or_None, b_strides_or_None, out_strides_or_None)
# ==============================================================================
# Operator-specific configuration
# ==============================================================================
_TEST_CASES_DATA = [
# small shapes
((8, 8), None, None, None),
((8, 8), (16, 1), None, None),
# different shapes (broadcasting second operand)
((8, 8), None, (0, 1), None),
((4, 1), None, None, (8, 1)),
# 3D tensor
((2, 3, 4), None, None, None),
# large but strided
((16, 512), (1024, 1), (0, 1), None),
]
# Integers require exact comparison
_TOLERANCE_MAP = {
infinicore.int32: {"atol": 0, "rtol": 0},
infinicore.int64: {"atol": 0, "rtol": 0},
infinicore.uint8: {"atol": 0, "rtol": 0},
}
# Data types to test (integer types)
_TENSOR_DTYPES = [infinicore.int32, infinicore.int64, infinicore.uint8]
def parse_test_cases():
"""
Parse test case data and return list of TestCase objects for bitwise_left_shift.
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
a_strides = data[1] if len(data) > 1 else None
b_strides = data[2] if len(data) > 2 else None
out_strides = data[3] if len(data) > 3 else None
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:
tolerance = _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)
# Out-of-place
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description="Bitwise left shift - OUT_OF_PLACE",
)
)
# explicit out
if out_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tolerance,
description="Bitwise left shift - INPLACE(out)",
)
)
# in-place into first input
if a_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description="Bitwise left shift - INPLACE(a)",
)
)
# in-place into second input
if b_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tolerance,
description="Bitwise left shift - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""BitwiseLeftShift operator test with simplified implementation"""
def __init__(self):
super().__init__("BitwiseLeftShift")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.bitwise_left_shift(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.bitwise_left_shift(*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, 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()
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