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

Merge pull request #631 from InfiniTensor/issue/630

issue/630 - slightly improved unimplemented messages
parents f3a25b70 2a343a3a
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (in_shape, in_strides_or_None)
_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():
"""tanhshrink(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"Tanhshrink - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Tanhshrink operator test with simplified implementation"""
def __init__(self):
super().__init__("Tanhshrink")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.tanhshrink(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.tanhshrink(*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, threshold, value)
_TEST_CASES_DATA = [
((13, 4), None, 0.0, 0.0),
((13, 4), (10, 1), 0.5, -1.0),
((8, 8, 8), None, 1.0, 2.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():
"""threshold(input, threshold, value, inplace=False)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
thr = data[2] if len(data) > 2 else 0.0
val = data[3] if len(data) > 3 else 0.0
input_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"threshold": thr, "value": val}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Threshold - OUT_OF_PLACE",
)
)
if input_supports_inplace:
inplace_kwargs = {"threshold": thr, "value": val, "inplace": True}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=inplace_kwargs,
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description=f"Threshold - INPLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Threshold operator test with simplified implementation"""
def __init__(self):
super().__init__("Threshold")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.threshold(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.threshold(*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, k, dim, largest, sorted)
_TEST_CASES_DATA = [
((6, 8), None, 1, 1, True, True),
((8, 4), (16, 1), 2, 0, True, False),
((5, 5), None, 3, -1, False, True),
((3, 7), (14, 1), 2, 1, True, True),
((10, 3), None, 2, 1, True, False),
((2, 16), (32, 1), 5, 1, False, True),
]
_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, in_strides, k, dim, largest, sorted_ = data
out_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)
kwargs = {"k": k, "dim": dim, "largest": largest, "sorted": sorted_}
# Out-of-place returns (values, indices)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"topk - OUT_OF_PLACE",
)
)
# topk returns (values, indices) - in-place/out variant requires tuple of outputs
# The current test harness expects a single TensorSpec for `output_spec`, so
# we avoid creating an in-place test for topk here and only test out-of-place.
return test_cases
class OpTest(BaseOperatorTest):
"""TopK operator test with simplified implementation"""
def __init__(self):
super().__init__("TopK")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.topk(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.topk(*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, dim0, dim1, input_strides_or_None)
# infinicore.transpose(input, dim0, dim1)
_TEST_CASES_DATA = [
((13, 4), 0, 1, None),
((8, 16), 0, 1, (128, 1)),
((2, 3, 4), 0, 2, None),
((4, 5, 6), 1, 2, None),
((16, 64), 0, 1, None),
((2, 2, 3, 4), 1, 3, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, dim0, dim1 = data[0], data[1], data[2]
in_strides = data[3] if len(data) > 3 else None
supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-4})
in_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
out_shape = list(shape)
out_shape[dim0], out_shape[dim1] = out_shape[dim1], out_shape[dim0]
out_spec = TensorSpec.from_tensor(tuple(out_shape), None, dtype)
# Out-of-place
kwargs = {"dim0": dim0, "dim1": dim1}
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs={"dim0": dim0, "dim1": dim1},
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"transpose - OUT_OF_PLACE",
)
)
# In-place via out param not supported; skip explicit out tests.
return test_cases
class OpTest(BaseOperatorTest):
"""Transpose operator test with simplified implementation"""
def __init__(self):
super().__init__("Transpose")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
# dim0 = kwargs.pop("dim0", None)
# dim1 = kwargs.pop("dim1", None)
# if dim0 is not None and dim1 is not None:
# return infinicore.transpose(*args, dim0, dim1)
return torch.transpose(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# dim0 = kwargs.pop("dim0", None)
# dim1 = kwargs.pop("dim1", None)
# if dim0 is not None and dim1 is not None:
# return infinicore.transpose(*args, dim0, dim1)
# return infinicore.transpose(*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: (anchor_shape, positive_shape, negative_shape, strides_or_None, margin_or_None, p_or_None, eps_or_None, swap_or_None)
# infinicore.nn.functional.triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-6, swap=False, reduction='mean')
_TEST_CASES_DATA = [
((4, 3), (4, 3), (4, 3), None, None, None, None, None),
((8, 5), (8, 5), (8, 5), (40, 5), 1.0, 2, 1e-6, False),
((1, 10), (1, 10), (1, 10), None, 0.5, 1, 1e-3, None),
((16, 12), (16, 12), (16, 12), None, 2.0, 2, None, True),
((3, 7), (3, 7), (3, 7), None, None, None, None, None),
((2, 4), (2, 4), (2, 4), None, None, None, 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 a_shape, p_shape, n_shape, strides, margin, p, eps, swap in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
a = TensorSpec.from_tensor(a_shape, strides, dtype)
pos = TensorSpec.from_tensor(p_shape, strides, dtype)
neg = TensorSpec.from_tensor(n_shape, strides, dtype)
kwargs = {}
if margin is not None:
kwargs["margin"] = margin
if p is not None:
kwargs["p"] = p
if eps is not None:
kwargs["eps"] = eps
if swap is not None:
kwargs["swap"] = swap
test_cases.append(
TestCase(
inputs=[a, pos, neg],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="triplet_margin_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""triplet_margin_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("triplet_margin_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.triplet_margin_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.triplet_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
# Test cases format: (anchor_shape, positive_shape, negative_shape, strides_or_None, margin_or_None, swap_or_None)
# infinicore.nn.functional.triplet_margin_with_distance_loss(anchor, positive, negative, distance_function=None, margin=1.0, swap=False, reduction='mean')
_TEST_CASES_DATA = [
((4, 3), (4, 3), (4, 3), None, None, None),
((8, 5), (8, 5), (8, 5), (40, 5), 1.0, False),
((1, 10), (1, 10), (1, 10), None, 0.5, None),
((16, 12), (16, 12), (16, 12), None, 2.0, True),
((3, 7), (3, 7), (3, 7), None, None, None),
((2, 4), (2, 4), (2, 4), None, 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 a_shape, p_shape, n_shape, strides, margin, swap in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
a = TensorSpec.from_tensor(a_shape, strides, dtype)
pos = TensorSpec.from_tensor(p_shape, strides, dtype)
neg = TensorSpec.from_tensor(n_shape, strides, dtype)
kwargs = {}
if margin is not None:
kwargs["margin"] = margin
if swap is not None:
kwargs["swap"] = swap
# distance_function is optional; test harness can supply default if needed
test_cases.append(
TestCase(
inputs=[a, pos, neg],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="triplet_margin_with_distance_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""triplet_margin_with_distance_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("triplet_margin_with_distance_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.triplet_margin_with_distance_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.triplet_margin_with_distance_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
# trunc(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), None),
((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)
# out-of-place
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="trunc_out",
)
)
# explicit out
out_spec = TensorSpec.from_tensor(shape, strides, dtype)
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="trunc_explicit_out",
)
)
# in-place when not broadcast
if not is_broadcast(strides):
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="trunc_inplace",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Trunc operator test with simplified implementation"""
def __init__(self):
super().__init__("Trunc")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.trunc(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.trunc(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (in_shape, in_strides_or_None, kernel_size, dilation, padding, stride)
# Unfold extracts sliding local blocks from a batched input tensor.
_TEST_CASES_DATA = [
((2, 3, 8, 8), None, (3, 3), 1, 0, (1, 1)),
((1, 4, 10, 12), None, (5, 3), 1, 1, (2, 1)),
((2, 2, 16, 16), (512, 256, 16, 1), (4, 4), 1, 0, (4, 4)),
((3, 6, 7, 9), None, (3, 2), 1, 0, (1, 1)),
((1, 8, 9, 11), None, (2, 3), 1, 1, (1, 2)),
((2, 5, 12, 6), (360, 72, 6, 1), (3, 3), 1, 0, (2, 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 parse_test_cases():
cases = []
for (
in_shape,
in_strides,
kernel_size,
dilation,
padding,
stride,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
kwargs = {
"kernel_size": kernel_size,
"dilation": dilation,
"padding": padding,
"stride": stride,
}
cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Unfold - OUT_OF_PLACE",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Unfold operator test with simplified implementation"""
def __init__(self):
super().__init__("Unfold")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.unfold(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.unfold(*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, sorted_or_None, return_inverse_or_None, return_counts_or_None)
# unique returns unique values and optionally inverse indices and counts
_TEST_CASES_DATA = [
((8,), None, True, False, False),
((8, 8), None, False, True, False),
((2, 3, 4), (24, 8, 2), True, False, True),
((1, 8), None, None, True, True),
((16, 64), (128, 1), False, False, True),
((4, 5), (20, 4), True, True, False),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.int32: {"atol": 0, "rtol": 0},
}
_TENSOR_DTYPES = [infinicore.int32, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, sorted_flag, return_inverse, return_counts = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if sorted_flag is not None:
kwargs["sorted"] = sorted_flag
if return_inverse:
kwargs["return_inverse"] = True
if return_counts:
kwargs["return_counts"] = True
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Unique - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Unique operator test with simplified implementation"""
def __init__(self):
super().__init__("Unique")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.unique(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.unique(*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, size_or_scale_factor, mode, align_corners_or_None, input_strides_or_None)
_TEST_CASES_DATA = [
((1, 3, 16, 16), (32, 32), "bilinear", True, None),
((2, 3, 8, 8), (16, 16), "nearest", None, (384, 128, 16, 1)),
((1, 1, 10), 20, "linear", False, None),
((2, 3, 6, 6), (12, 12), "area", None, None),
((1, 3, 4, 4, 4), (8, 8, 8), "trilinear", True, None),
((4, 3, 7, 7), 2.0, "bilinear", False, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-2, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, size_or_scale, mode, align, in_strides = data
supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
in_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"mode": mode}
if isinstance(size_or_scale, tuple):
kwargs["size"] = size_or_scale
else:
kwargs["scale_factor"] = size_or_scale
if align is not None:
kwargs["align_corners"] = align
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"upsample - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Upsample operator test with simplified implementation"""
def __init__(self):
super().__init__("Upsample")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
# Map deprecated upsample to interpolate
return torch.nn.functional.interpolate(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.interpolate(*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, size_or_scale_factor, align_corners_or_None, input_strides_or_None)
# infinicore.nn.functional.upsample_bilinear is deprecated in favor of interpolate(mode='bilinear')
_TEST_CASES_DATA = [
((1, 3, 16, 16), (32, 32), True, None),
((2, 3, 8, 8), (16, 16), None, (384, 128, 16, 1)),
((1, 1, 10, 10), (20, 20), False, None),
((2, 3, 6, 6), (12, 12), None, None),
((4, 3, 7, 7), 2.0, False, None),
((3, 3, 5, 5), (10, 10), True, None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-2, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, size_or_scale, align, in_strides = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
in_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"mode": "bilinear"}
if isinstance(size_or_scale, tuple):
kwargs["size"] = size_or_scale
else:
kwargs["scale_factor"] = size_or_scale
if align is not None:
kwargs["align_corners"] = align
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"upsample_bilinear - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""UpsampleBilinear operator test with simplified implementation"""
def __init__(self):
super().__init__("UpsampleBilinear")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
# Use interpolate with bilinear mode
return torch.nn.functional.interpolate(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.interpolate(*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, size_or_scale_factor, input_strides_or_None)
# infinicore.nn.functional.upsample_nearest is deprecated in favor of interpolate(mode='nearest')
_TEST_CASES_DATA = [
((1, 3, 16, 16), (32, 32), None),
((2, 3, 8, 8), (16, 16), (384, 128, 16, 1)),
((1, 1, 10), 20, None),
((2, 3, 6, 6), (12, 12), None),
((4, 3, 7, 7), 2.0, None),
((3, 3, 5, 5), (10, 10), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-2, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, size_or_scale, in_strides = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
in_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"mode": "nearest"}
if isinstance(size_or_scale, tuple):
kwargs["size"] = size_or_scale
else:
kwargs["scale_factor"] = size_or_scale
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"upsample_nearest - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""UpsampleNearest operator test with simplified implementation"""
def __init__(self):
super().__init__("UpsampleNearest")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.interpolate(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.interpolate(*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, N)
_TEST_CASES_DATA = [
((5,), None, None),
((6,), None, 3),
((4,), None, 5),
((7,), None, None),
((8,), None, 4),
((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, N = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if N is not None:
kwargs["N"] = N
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"vander - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Vander operator test with simplified implementation"""
def __init__(self):
super().__init__("Vander")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.vander(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.vander(*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, keepdim_or_None)
# var computes variance along dim(s) or overall
_TEST_CASES_DATA = [
((8, 8), None, None, None, None),
((8, 8), (16, 1), 1, True, False),
((2, 3, 4), None, 0, False, True),
((4, 8), None, 0, True, False),
((16, 64), (128, 1), None, False, None),
((4, 5, 6), (60, 12, 2), 2, True, True),
]
_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, unbiased, keepdim = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
if unbiased is not None:
kwargs["unbiased"] = unbiased
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="Var - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Var operator test with simplified implementation"""
def __init__(self):
super().__init__("Var")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.var(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.var(*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, keepdim_or_None)
# var_mean returns (var, mean)
_TEST_CASES_DATA = [
((8, 8), None, None, None, None),
((8, 8), (16, 1), 1, True, False),
((2, 3, 4), None, 0, False, True),
((4, 8), None, 0, True, False),
((16, 64), (128, 1), None, False, None),
((4, 5, 6), (60, 12, 2), 2, True, True),
]
_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, unbiased, keepdim = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
if unbiased is not None:
kwargs["unbiased"] = unbiased
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="VarMean - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""VarMean operator test with simplified implementation"""
def __init__(self):
super().__init__("VarMean")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.var_mean(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.var_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
# Test cases format: (vec1_shape, vec2_shape, vec1_strides_or_None, vec2_strides_or_None)
# vdot(a, b) — conjugate dot product for 1-D vectors
_TEST_CASES_DATA = [
((3,), (3,), None, None),
((8,), (8,), (0,), None),
((1,), (1,), None, None),
((16,), (16,), None, (256,)),
((5,), (5,), None, None),
((32,), (32,), (64,), (64,)),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-3, "rtol": 1e-2},
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 5e-2},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
test_cases = []
for s1, s2, st1, st2 in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
a = TensorSpec.from_tensor(s1, st1, dtype)
b = TensorSpec.from_tensor(s2, st2, dtype)
test_cases.append(
TestCase(
inputs=[a, b],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="vdot - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""vdot operator test with simplified implementation"""
def __init__(self):
super().__init__("vdot")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.vdot(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.vdot(*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: (condition_shape, cond_strides_or_None, x_shape_or_None, y_shape_or_None)
# infinicore.where can be used as where(condition, x, y) or where(condition) returning indices.
_TEST_CASES_DATA = [
((3, 4), None, (3, 4), (3, 4)),
((5,), None, (5,), (5,)),
((2, 2, 3), (12, 6, 2), None, None),
((1, 6), None, (1, 6), (1, 6)),
((4, 4), None, None, None),
((2, 3, 2), None, (2, 3, 2), (2, 3, 2)),
]
_TOLERANCE_MAP = {
infinicore.float32: {"atol": 1e-5, "rtol": 1e-4},
infinicore.int64: {"atol": 0, "rtol": 0},
}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for cond_shape, cond_strides, x_shape, y_shape in _TEST_CASES_DATA:
cond_spec = TensorSpec.from_tensor(cond_shape, cond_strides, infinicore.bool)
if x_shape is None or y_shape is None:
# where(condition) -> returns indices
test_cases.append(
TestCase(
inputs=[cond_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.int64],
description=f"where - condition_only shape={cond_shape}",
)
)
else:
x_spec = TensorSpec.from_tensor(x_shape, None, infinicore.float32)
y_spec = TensorSpec.from_tensor(y_shape, None, infinicore.float32)
test_cases.append(
TestCase(
inputs=[cond_spec, x_spec, y_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"where - select shape={cond_shape}",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Where operator test with simplified implementation"""
def __init__(self):
super().__init__("Where")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.where(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.where(*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