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()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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