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: (in_shape, in_strides_or_None)
# signbit returns boolean-like tensor; tolerances are exact.
_TEST_CASES_DATA = [
((2, 3), None),
((1, 4, 8), (32, 8, 1)),
((3, 2, 5, 7), None),
((2, 1, 16), None),
((1, 8, 9, 11), (792, 99, 11, 1)),
((2, 6, 10), None),
]
_TOLERANCE_MAP = {infinicore.bool: {"atol": 0.0, "rtol": 0.0}}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[infinicore.bool]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
# Out-of-place (returns boolean mask)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="signbit_out_of_place",
)
)
# Explicit out (boolean dtype out)
out_spec = TensorSpec.from_tensor(shape, None, infinicore.bool)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="signbit_explicit_out",
)
)
# In-place on input (not typical for boolean outputs) - skip because in-place would change dtype
# Note: PyTorch does not support in-place signbit that preserves dtype; therefore no in-place case.
return cases
class OpTest(BaseOperatorTest):
"""SignBit operator test with simplified implementation"""
def __init__(self):
super().__init__("SignBit")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.signbit(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.signbit(*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="sinh - OUT_OF_PLACE",
)
)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="sinh - INPLACE(out)",
)
)
if supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="sinh - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Sinh operator test with simplified implementation"""
def __init__(self):
super().__init__("Sinh")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.sinh(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.sinh(*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, src_strides, dim, start, end, step)
# _TEST_CASES_DATA = [
# ((6, 8), None, None, 1, 0, 4, 1),
# ((8, 4), (16, 1), (16, 1), 0, 1, 3, 1),
# ((5, 7), None, (10, 1), 1, -3, None, 1),
# ((3, 9), None, None, 1, 2, 8, 2),
# ((10, 3), (30, 1), (30, 1), 0, None, None, 1),
# ((2, 16), None, None, 1, 0, 2, 1),
# ]
# Format: (input_shape, input_strides, src_shape, src_strides, dim, start, end, step)
_TEST_CASES_DATA = [
((6, 8), None, (6, 4), None, 1, 0, 4, 1),
((8, 4), (16, 1), (2, 4), (16, 1), 0, 1, 3, 1),
((5, 7), None, (5, 3), (10, 1), 1, -3, None, 1),
((3, 9), None, (3, 3), None, 1, 2, 8, 2),
((10, 3), (30, 1), (10, 3), (30, 1), 0, None, None, 1),
((2, 16), None, (2, 2), None, 1, 0, 2, 1),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-3},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
input_shape, in_strides, src_shape, src_strides, dim, start, end, step = data
in_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(input_shape, in_strides, dtype)
src_spec = TensorSpec.from_tensor(src_shape, src_strides, dtype)
kwargs = {"dim": dim}
if start is not None:
kwargs["start"] = start
if end is not None:
kwargs["end"] = end
if step is not None:
kwargs["step"] = step
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec, src_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"slice_scatter - OUT_OF_PLACE",
)
)
if in_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec, src_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=0,
tolerance=tol,
description=f"slice_scatter - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""SliceScatter operator test with simplified implementation"""
def __init__(self):
super().__init__("SliceScatter")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.slice_scatter(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.slice_scatter(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (matrix_shape, strides_or_None)
# slogdet(input) — returns (sign, logabsdet)
_TEST_CASES_DATA = [
((1, 1), None),
((2, 2), None),
((3, 3), (3, 1)),
((4, 4), None),
((8, 8), (512, 1)),
((16, 16), None),
]
_TOLERANCE_MAP = {
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
spec = TensorSpec.from_tensor(shape, strides, dtype)
test_cases.append(
TestCase(
inputs=[spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="slogdet - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""slogdet operator test with simplified implementation"""
def __init__(self):
super().__init__("slogdet")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.slogdet(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.slogdet(*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, target_shape, input_strides_or_None, beta_or_None, reduction_or_None)
# infinicore.nn.functional.smooth_l1_loss(input, target, reduction='mean', beta=1.0)
_TEST_CASES_DATA = [
((4, 5), (4, 5), None, None, None),
((8, 8), (8, 8), (512, 64), 1.0, "sum"),
((1, 10), (1, 10), None, 0.5, "mean"),
((16, 100), (16, 100), None, 0.1, None),
((3, 7), (3, 7), None, None, "none"),
((2, 2), (2, 2), None, 1.5, 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, tgt_shape, strides, beta, 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(tgt_shape, None, dtype)
kwargs = {}
if beta is not None:
kwargs["beta"] = beta
if reduction is not None:
kwargs["reduction"] = reduction
test_cases.append(
TestCase(
inputs=[inp, tgt],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="smooth_l1_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""smooth_l1_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("smooth_l1_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.smooth_l1_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.smooth_l1_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
# Test cases format: (input_shape, target_shape, input_strides_or_None, reduction_or_None)
# infinicore.nn.functional.soft_margin_loss(input, target, reduction='mean')
_TEST_CASES_DATA = [
((4, 5), (4, 5), None, None),
((8, 8), (8, 8), (512, 64), "sum"),
((1, 10), (1, 10), None, "mean"),
((16, 100), (16, 100), None, None),
((3, 7), (3, 7), None, "none"),
((2, 2), (2, 2), None, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-2, "rtol": 1e-1},
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, tgt_shape, strides, 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(tgt_shape, None, dtype)
kwargs = {}
if reduction is not None:
kwargs["reduction"] = reduction
test_cases.append(
TestCase(
inputs=[inp, tgt],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="soft_margin_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""soft_margin_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("soft_margin_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.soft_margin_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.soft_margin_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: (in_shape, in_strides_or_None, dim_or_None)
_TEST_CASES_DATA = [
((4, 10), None, -1),
((2, 5, 8), (40, 8, 1), 1),
((8, 20), None, 1),
]
_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():
"""softmin(input, dim=None, dtype=None)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
dim = data[2] if len(data) > 2 else -1
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"dim": dim}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Softmin - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Softmin operator test with simplified implementation"""
def __init__(self):
super().__init__("Softmin")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.softmin(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.softmin(*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, beta_or_None, threshold_or_None)
_TEST_CASES_DATA = [
((13, 4), None, None, None),
((13, 4), (10, 1), 1.0, 20.0),
((8, 8, 8), None, 0.5, 10.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():
"""softplus(input, beta=1, threshold=20)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
beta = data[2] if len(data) > 2 else 1
threshold = data[3] if len(data) > 3 else 20
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {}
if beta is not None:
kwargs["beta"] = beta
if threshold is not None:
kwargs["threshold"] = threshold
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Softplus - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Softplus operator test with simplified implementation"""
def __init__(self):
super().__init__("Softplus")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.softplus(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.softplus(*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, lambd_or_None)
_TEST_CASES_DATA = [
((13, 4), None, None),
((13, 4), (10, 1), 0.5),
((8, 8, 8), 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():
"""softshrink(input, lambd=0.5)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
lambd = data[2] if len(data) > 2 else 0.5
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {}
if lambd is not None:
kwargs["lambd"] = lambd
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Softshrink - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Softshrink operator test with simplified implementation"""
def __init__(self):
super().__init__("Softshrink")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.softshrink(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.softshrink(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None)
_TEST_CASES_DATA = [
((13, 4), None),
((13, 4), (10, 1)),
((8, 8, 8), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""softsign(input)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Softsign - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Softsign operator test with simplified implementation"""
def __init__(self):
super().__init__("Softsign")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.softsign(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.softsign(*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
# ==============================================================================
# Operator-specific configuration for sort
# ==============================================================================
# Test cases format: (shape, dim, descending, input_strides, values_strides, indices_strides)
_TEST_CASES_DATA = [
# Basic cases
((13, 4), None, False, None, None, None),
((13, 4), 0, False, None, None, None),
((13, 4), 1, False, None, None, None),
((13, 4), -1, False, None, None, None),
# Descending
((13, 4), 1, True, None, None, None),
# Stable flag (PyTorch 1.8+ supports stable sort; include it to match 2.9 signature)
((4, 5, 6), 1, False, None, None, None),
((4, 5, 6), -1, True, None, None, None),
# 3D in-place cases
((4, 5, 6), 1, False, None, (4, 1, 6), (4, 1, 6)),
((4, 5, 6), -1, False, (30, 6, 1), (64, 1, 5), (64, 1, 5)),
# Strided inputs and outputs
((13, 4), None, False, (4, 1), (12, 1), (24, 1)),
((13, 4), 0, False, (1, 4), (64, 1), (1, 4)),
((13, 4), 1, False, (1, 4), (64, 1), (1, 4)),
]
# 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 calculate_output_shape(input_shape, dim):
"""
Calculate the output shape for sort (values and indices share the same shape)
"""
if dim is None:
# Default behavior: sort on last dimension
dim = len(input_shape) - 1 if len(input_shape) > 0 else 0
# normalize negative dim
if dim < 0:
dim = dim + len(input_shape)
output_shape = list(input_shape)
return tuple(output_shape)
def parse_test_cases():
"""
Parse sort test cases including both out-of-place and in-place (out=...) variants.
torch.sort(input, dim=-1, descending=False, stable=False, out=None)
returns (values, indices)
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
dim = data[1] if len(data) > 1 else None
descending = data[2] if len(data) > 2 else False
input_strides = data[3] if len(data) > 3 else None
values_strides = data[4] if len(data) > 4 else None
indices_strides = data[5] if len(data) > 5 else None
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
# Create tensor specs
input_spec = TensorSpec.from_tensor(shape, input_strides, dtype)
# Build description
description_parts = ["sort"]
if dim is not None:
description_parts.append(f"dim={dim}")
if descending:
description_parts.append("descending=True")
if input_strides is not None:
description_parts.append(f"input_strides={input_strides}")
base_description = " - ".join(description_parts)
# Common kwargs
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
kwargs["descending"] = descending
# stable is available in newer PyTorch; keep default False
# ==================================================================
# Test Case 1: Out-of-place (return values)
# ==================================================================
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None, # return values will be compared
comparison_target=None,
tolerance=tolerance,
description=f"{base_description} - OUT_OF_PLACE",
output_count=2, # (values, indices)
)
)
# ==================================================================
# Test Case 2: In-place with explicit output tensors (out=(values, indices))
# ==================================================================
output_shape = calculate_output_shape(shape, dim)
# Create output specs if strides provided; otherwise None
values_spec = TensorSpec.from_tensor(output_shape, values_strides, dtype)
# indices are integer type (long) in PyTorch
indices_spec = TensorSpec.from_tensor(
output_shape, indices_strides, infinicore.int64
)
values_supports_inplace = not is_broadcast(
getattr(values_spec, "strides", None)
)
indices_supports_inplace = not is_broadcast(
getattr(indices_spec, "strides", None)
)
if values_supports_inplace and indices_supports_inplace:
inplace_kwargs = kwargs.copy()
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=inplace_kwargs,
output_specs=[values_spec, indices_spec],
comparison_target="out",
tolerance=tolerance,
description=f"{base_description} - INPLACE(out)",
output_count=2,
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Sort operator test with multiple outputs (values, indices)"""
def __init__(self):
super().__init__("sort")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(
self, x, dim=-1, descending=False, stable=False, out=None, **kwargs
):
# forward to torch.sort; stable kwarg included for compatibility
return torch.sort(x, dim=dim, descending=descending, stable=stable, out=out)
# def infinicore_operator(self, x, dim=-1, descending=False, stable=False, out=None, **kwargs):
# # assume infinicore provides a similar API
# return infinicore.sort(x, dim=dim, descending=descending, stable=stable, out=out)
def main():
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, split_size_or_sections, dim_or_None)
# infinicore.split(tensor, split_size_or_sections, dim=0)
_TEST_CASES_DATA = [
((8, 6), None, 2, 0),
((4, 9), None, [3, 6], 1),
((6, 12, 3), None, 4, 1),
((10,), None, 5, 0),
((3, 8), (24, 8), [2, 1], 0),
((12, 4), None, 3, 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 shape, strides, sections, dim 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)
kwargs = {}
kwargs["split_size_or_sections"] = sections
if dim is not None:
kwargs["dim"] = dim
test_cases.append(
TestCase(
inputs=[inp],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="split - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""split operator test with simplified implementation"""
def __init__(self):
super().__init__("split")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
# infinicore.split signature differs; test runner will map kwargs accordingly
return torch.split(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.split(*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)
# infinicore.sqrt(input)
_TEST_CASES_DATA = [
((2, 3), None),
((1, 4, 8), (32, 8, 1)),
((3, 2, 5, 7), None),
((2, 1, 16), None),
((1, 8, 9, 11), (792, 99, 11, 1)),
((2, 6, 10), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="sqrt_out",
)
)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="sqrt_out_explicit",
)
)
if not is_broadcast(in_spec.strides):
cases.append(
TestCase(
inputs=[in_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="sqrt_inplace",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Sqrt operator test with simplified implementation"""
def __init__(self):
super().__init__("Sqrt")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.sqrt(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.sqrt(*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)
# infinicore.square(input)
_TEST_CASES_DATA = [
((2, 3), None),
((1, 4, 8), (32, 8, 1)),
((3, 2, 5, 7), None),
((2, 1, 16), None),
((1, 8, 9, 11), (792, 99, 11, 1)),
((2, 6, 10), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
cases = []
for shape, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="square_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="square_explicit_out",
)
)
if not is_broadcast(in_spec.strides):
cases.append(
TestCase(
inputs=[in_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="square_inplace_input0",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Square operator test with simplified implementation"""
def __init__(self):
super().__init__("Square")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.square(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.square(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format:
# (in_shape, in_strides_or_None, dim_or_None, correction_or_None, keepdim_or_None, out_strides_or_None)
_TEST_CASES_DATA = [
((8, 8), None, None, None, None, None),
((8, 8), (16, 1), 1, 1, False, None),
((2, 3, 4), None, 0, 0, True, (48, 6, 1)),
((4, 8), None, 0, 1, False, None),
((16, 64), (128, 1), None, 0, None, None),
((4, 5, 6), (60, 12, 2), 2, 1, True, (12, 4, 1)),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def _compute_out_shape(shape, dim, keepdim):
if dim is None:
return ()
if isinstance(dim, tuple):
dims = sorted([(d if d >= 0 else len(shape) + d) for d in dim])
if keepdim:
out = list(shape)
for d in dims:
out[d] = 1
return tuple(out)
else:
return tuple(s for i, s in enumerate(shape) if i not in dims)
else:
d = dim if dim >= 0 else len(shape) + dim
if keepdim:
out = list(shape)
out[d] = 1
return tuple(out)
else:
return tuple(s for i, s in enumerate(shape) if i != d)
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, dim, correction, keepdim, out_strides = data
out_supports_inplace = not is_broadcast(out_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
if correction is not None:
kwargs["correction"] = correction
if keepdim is not None:
kwargs["keepdim"] = keepdim
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Std - OUT_OF_PLACE",
)
)
out_shape = _compute_out_shape(shape, dim, keepdim)
out_spec = TensorSpec.from_tensor(out_shape, out_strides, dtype)
if out_supports_inplace:
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="Std - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Std operator test with simplified implementation"""
def __init__(self):
super().__init__("Std")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.std(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.std(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, dim_or_None, unbiased_or_None, out_strides_or_None)
# std_mean returns (std, mean) along dim(s) or overall
_TEST_CASES_DATA = [
((8, 8), None, None, None, None),
((8, 8), (16, 1), 1, True, None),
((2, 3, 4), None, 0, False, (0, 1, 1)),
((4, 8), None, 0, True, None),
((16, 64), (128, 1), None, False, None),
((4, 5, 6), (60, 12, 2), 2, True, (12, 4, 1)),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def _compute_out_shape(shape, dim, keepdim):
if dim is None:
return ()
if isinstance(dim, tuple):
dims = sorted([(d if d >= 0 else len(shape) + d) for d in dim])
if keepdim:
out = list(shape)
for d in dims:
out[d] = 1
return tuple(out)
else:
return tuple(s for i, s in enumerate(shape) if i not in dims)
else:
d = dim if dim >= 0 else len(shape) + dim
if keepdim:
out = list(shape)
out[d] = 1
return tuple(out)
else:
return tuple(s for i, s in enumerate(shape) if i != d)
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, dim, unbiased, out_strides = data
out_supports_inplace = not is_broadcast(out_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
if unbiased is not None:
kwargs["unbiased"] = unbiased
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="StdMean - OUT_OF_PLACE",
)
)
# Note: std_mean returns a tuple (std, mean) - PyTorch does not support explicit out for tuple returns
return test_cases
class OpTest(BaseOperatorTest):
"""StdMean operator test with simplified implementation"""
def __init__(self):
super().__init__("StdMean")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.std_mean(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.std_mean(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None, dim_or_None, keepdim_or_None, dtype_or_None)
# sum computes the sum along dim(s) or overall
_TEST_CASES_DATA = [
((8, 8), None, None, None, None),
((8, 8), (16, 1), 1, False, None),
((2, 3, 4), None, 0, True, None),
((1, 8), None, (0,), False, None),
((16, 64), (128, 1), None, None, None),
((4, 5, 6), (60, 12, 2), 2, True, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, dim, keepdim, dtype_param = data
# out_supports_inplace = not is_broadcast(out_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
if keepdim is not None:
kwargs["keepdim"] = keepdim
if dtype_param is not None:
kwargs["dtype"] = dtype_param
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Sum - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Sum operator test with simplified implementation"""
def __init__(self):
super().__init__("Sum")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.sum(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.sum(*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: (matrix_shape, strides_or_None, compute_uv_or_None)
# infinicore.svd(a, some=True, compute_uv=True) — different return shapes depending on flags
_TEST_CASES_DATA = [
((3, 3), None, True),
((4, 2), None, True),
((6, 6), (360, 60), True),
((2, 4), None, False),
((8, 8), None, True),
((1, 1), None, True),
]
_TOLERANCE_MAP = {
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides, compute_uv in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if compute_uv is not None:
kwargs["compute_uv"] = compute_uv
test_cases.append(
TestCase(
inputs=[spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="svd - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""svd operator test with simplified implementation"""
def __init__(self):
super().__init__("svd")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.svd(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.svd(*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, indices_shape)
_TEST_CASES_DATA = [
((3, 4), None, (6,)),
((5,), None, (3,)),
((2, 3, 4), (24, 8, 2), (4,)),
((1, 6), None, (2,)),
((4, 4), None, (8,)),
((2, 3, 2), None, (3,)),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides, idx_shape in _TEST_CASES_DATA:
input_spec = TensorSpec.from_tensor(shape, strides, infinicore.float32)
# indices for infinicore.take are flattened indices in [0, input.numel())
prod = 1
for s in shape:
prod *= s
indices_spec = TensorSpec.from_tensor(
idx_shape,
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=max(1, prod),
)
test_cases.append(
TestCase(
inputs=[input_spec, indices_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"take - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Take operator test with simplified implementation"""
def __init__(self):
super().__init__("Take")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.take(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.take(*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="tan - OUT_OF_PLACE",
)
)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="tan - INPLACE(out)",
)
)
if supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="tan - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Tan operator test with simplified implementation"""
def __init__(self):
super().__init__("Tan")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.tan(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.tan(*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