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():
"""hardsigmoid(input)
No inplace arg on functional API; only out-of-place tests.
"""
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"Hardsigmoid - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Hardsigmoid operator test with simplified implementation"""
def __init__(self):
super().__init__("Hardsigmoid")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.hardsigmoid(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.hardsigmoid(*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),
((8, 8), (64, 1)),
((2, 3, 6), 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():
"""
hardswish(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"Hardswish - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Hardswish operator test with simplified implementation"""
def __init__(self):
super().__init__("Hardswish")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.hardswish(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.hardswish(*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, min_val_or_None, max_val_or_None)
_TEST_CASES_DATA = [
((13, 4), None, -1.0, 1.0),
((13, 4), (10, 1), -0.5, 0.5),
((8, 8, 8), None, -2.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():
"""hardtanh(input, min_val=-1.0, max_val=1.0, inplace=False)"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
minv = data[2] if len(data) > 2 else -1.0
maxv = data[3] if len(data) > 3 else 1.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 = {"min_val": minv, "max_val": maxv}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"Hardtanh - OUT_OF_PLACE",
)
)
if input_supports_inplace:
inplace_kwargs = {"min_val": minv, "max_val": maxv, "inplace": True}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=inplace_kwargs,
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description=f"Hardtanh - INPLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Hardtanh operator test with simplified implementation"""
def __init__(self):
super().__init__("Hardtanh")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.hardtanh(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.hardtanh(*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)
# heaviside is binary: heaviside(input, values)
# =======================================================================
_TEST_CASES_DATA = [
((13, 4), None, None, None),
((13, 4), (10, 1), None, None),
((13, 4), None, (10, 1), None),
((8, 16), (40, 1), (40, 1), None),
((2, 3, 4), None, None, None),
((16, 5632), 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 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:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
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=tol,
description="heaviside - 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=tol,
description="heaviside - INPLACE(out)",
)
)
# In-place on 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=tol,
description="heaviside - INPLACE(a)",
)
)
# In-place on 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=tol,
description="heaviside - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Heaviside operator test with simplified implementation"""
def __init__(self):
super().__init__("Heaviside")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.heaviside(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.heaviside(*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, target_strides_or_None, margin_or_None)
# infinicore.nn.functional.hinge_embedding_loss(input, target, margin=1.0, reduction='mean')
_TEST_CASES_DATA = [
((4,), (4,), None, None, None),
((8,), (8,), None, None, 0.5),
((1,), (1,), None, None, None),
((16,), (16,), (4,), None, 1.0),
((3,), (3,), None, None, 0.2),
((2,), (2,), None, None, 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, s1, s2, margin 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, s1, dtype)
tgt = TensorSpec.from_tensor(tgt_shape, s2, dtype)
kwargs = {}
if margin is not None:
kwargs["margin"] = margin
test_cases.append(
TestCase(
inputs=[inp, tgt],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="hinge_embedding_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""hinge_embedding_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("hinge_embedding_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.hinge_embedding_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.hinge_embedding_loss(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (input_shape, input_strides_or_None, bins, min_val, max_val)
_TEST_CASES_DATA = [
((100,), None, 10, 0.0, 1.0),
((50,), None, 5, -1.0, 1.0),
((20,), None, 8, 0.0, 2.0),
((10,), None, 4, 0.0, 1.0),
((1,), None, 3, 0.0, 1.0),
((200,), None, 20, -2.0, 2.0),
]
_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, bins, minv, maxv = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {"bins": bins, "min": minv, "max": maxv}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"histc - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""HistC operator test with simplified implementation"""
def __init__(self):
super().__init__("HistC")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.histc(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.histc(*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, bins_or_sequence, range_or_None)
_TEST_CASES_DATA = [
((100,), None, 10, (0.0, 1.0)),
((20,), None, 5, (0.0, 2.0)),
((10,), None, 4, (0.0, 1.0)),
((200,), None, 20, (-1.0, 1.0)),
((1,), None, 3, (0.0, 1.0)),
]
_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, bins, rng = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
input_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {"bins": bins}
if rng is not None:
kwargs["range"] = rng
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"histogram - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Histogram operator test with simplified implementation"""
def __init__(self):
super().__init__("Histogram")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.histogram(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.histogram(*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, sections_or_None)
# infinicore.hsplit(input, sections)
# Note: PyTorch hsplit is a convenience wrapper around split/reshape. We include both int and list sections.
_TEST_CASES_DATA = [
((4, 8), None, 2),
((4, 9), None, [3, 6]),
((2, 6, 12), None, 3),
((1, 10), (10, 1), 5),
((8, 4), None, [1, 3]),
((6, 12), None, 4),
]
_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 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)
# infinicore.hsplit expects positional second arg (sections) rather than kw in this API;
# put sections into inputs when present. Convert list -> tuple.
if sections is not None:
# wrap sections in a small wrapper so TestCase.__init__ does not
# interpret the tuple as a Tensor shape
class Sections:
def __init__(self, v):
self.v = v
def as_tuple(self):
return tuple(self.v) if isinstance(self.v, list) else self.v
def __repr__(self):
return f"sections({self.v})"
sec = Sections(sections)
test_inputs = [inp, sec]
else:
test_inputs = [inp]
test_cases.append(
TestCase(
inputs=test_inputs,
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="hsplit - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""hsplit operator test with simplified implementation"""
def __init__(self):
super().__init__("hsplit")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
# unwrap Sections wrapper if present
args = list(args)
if len(args) >= 2 and hasattr(args[1], "as_tuple"):
args[1] = args[1].as_tuple()
return torch.hsplit(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.hsplit(*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, target_strides_or_None, delta_or_None)
# infinicore.nn.functional.huber_loss(input, target, reduction='mean', delta=1.0)
_TEST_CASES_DATA = [
((4, 5), (4, 5), None, None, None),
((8, 8), (8, 8), (512, 64), None, 1.0),
((1, 10), (1, 10), None, None, 0.5),
((16, 100), (16, 100), None, None, 2.0),
((3, 7), (3, 7), None, (21, 7), None),
((2, 2), (2, 2), None, None, 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, s1, s2, delta 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, s1, dtype)
tgt = TensorSpec.from_tensor(tgt_shape, s2, dtype)
kwargs = {}
if delta is not None:
kwargs["delta"] = delta
test_cases.append(
TestCase(
inputs=[inp, tgt],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="huber_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""huber_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("huber_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.huber_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.huber_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: (a_shape, a_strides_or_None, b_shape_or_None)
# infinicore.hypot(a, b)
_TEST_CASES_DATA = [
((2, 3, 4), None, None),
((1, 4, 8), (32, 8, 1), None),
((3, 2, 5, 7), None, None),
((2, 1, 16), None, None),
((1, 8, 9, 11), (792, 99, 11, 1), None),
((2, 6, 10), None, 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 a_shape, a_strides, b_shape in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
a_spec = TensorSpec.from_tensor(a_shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(
a_shape if b_shape is None else b_shape, None, dtype
)
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="hypot_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(a_shape, None, dtype)
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="hypot_explicit_out",
)
)
if not is_broadcast(a_spec.strides):
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="hypot_inplace_a",
)
)
if not is_broadcast(b_spec.strides):
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="hypot_inplace_b",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Hypot operator test with simplified implementation"""
def __init__(self):
super().__init__("Hypot")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.hypot(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.hypot(*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: (target_shape, target_strides_or_None, dim, index_shape, src_shape)
_TEST_CASES_DATA = [
((5, 6), None, 1, (5, 2), (5, 2)),
((4, 4), (16, 1), 0, (2, 4), (2, 4)),
((3, 5), None, 1, (3, 3), (3, 3)),
((2, 6), None, 1, (2, 2), (2, 2)),
((6, 3), (18, 1), 0, (3, 3), (3, 3)),
((4, 7), None, 1, (4, 2), (4, 2)),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for target_shape, t_strides, dim, idx_shape, src_shape in _TEST_CASES_DATA:
target_spec = TensorSpec.from_tensor(
target_shape, t_strides, infinicore.float32
)
# index for index_add should be 1-D with length equal to source.size(dim)
index_len = src_shape[dim]
from framework.tensor import TensorInitializer
index_spec = TensorSpec.from_tensor(
(index_len,),
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=target_shape[dim],
)
src_spec = TensorSpec.from_tensor(src_shape, None, infinicore.float32)
# out parameter can be used (explicit out)
out_supports = not is_broadcast(t_strides)
# Out-of-place (return value)
# Use positional dim to match infinicore.index_add(input, dim, index, tensor)
test_cases.append(
TestCase(
inputs=[target_spec, dim, index_spec, src_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_add - OUT_OF_PLACE",
)
)
# In-place on target (out=target)
if out_supports:
test_cases.append(
TestCase(
inputs=[target_spec, dim, index_spec, src_spec],
kwargs=None,
output_spec=target_spec,
comparison_target="out",
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_add - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""IndexAdd operator test with simplified implementation"""
def __init__(self):
super().__init__("IndexAdd")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.index_add(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.index_add(*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.tensor import TensorInitializer
from framework.utils import is_broadcast
# Test cases format: (target_shape, target_strides_or_None, dim, index_shape, src_shape)
_TEST_CASES_DATA = [
((5, 6), None, 1, (5, 2), (5, 2)),
((4, 4), (16, 1), 0, (2, 4), (2, 4)),
((3, 5), None, 1, (3, 3), (3, 3)),
((2, 6), None, 1, (2, 2), (2, 2)),
((6, 3), (18, 1), 0, (3, 3), (3, 3)),
((4, 7), None, 1, (4, 2), (4, 2)),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for target_shape, t_strides, dim, idx_shape, src_shape in _TEST_CASES_DATA:
target_spec = TensorSpec.from_tensor(
target_shape, t_strides, infinicore.float32
)
# index for index_copy should be 1-D with length equal to source.size(dim)
index_len = src_shape[dim]
index_spec = TensorSpec.from_tensor(
(index_len,),
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=target_shape[dim],
)
src_spec = TensorSpec.from_tensor(src_shape, None, infinicore.float32)
out_supports = not is_broadcast(t_strides)
# Out-of-place: infinicore.index_copy(input, dim, index, source)
test_cases.append(
TestCase(
inputs=[target_spec, dim, index_spec, src_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_copy - OUT_OF_PLACE",
)
)
# Explicit out: same ordering, output will be provided by framework
if out_supports:
test_cases.append(
TestCase(
inputs=[target_spec, dim, index_spec, src_spec],
kwargs=None,
output_spec=target_spec,
comparison_target="out",
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_copy - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""IndexCopy operator test with simplified implementation"""
def __init__(self):
super().__init__("IndexCopy")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.index_copy(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.index_copy(*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: (target_shape, target_strides_or_None, dim, index_shape, reduce)
_TEST_CASES_DATA = [
((5, 6), None, 1, (5, 2), "prod"),
((4, 4), (16, 1), 0, (2, 4), "amax"),
((3, 5), None, 1, (3, 3), "amin"),
((2, 6), None, 1, (2, 2), "prod"),
((2, 6), None, 1, (2, 2), "amin"),
((6, 3), (18, 1), 0, (3, 3), "mean"),
((4, 7), None, 1, (4, 2), "prod"),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for tgt_shape, tgt_strides, dim, idx_shape, reduce in _TEST_CASES_DATA:
target_spec = TensorSpec.from_tensor(tgt_shape, tgt_strides, infinicore.float32)
# idx_shape here represents the source shape for index_reduce; index itself must be 1-D
src_shape = idx_shape
# determine index length from source along the reduction dim
index_len = src_shape[dim]
from framework.tensor import TensorInitializer
index_spec = TensorSpec.from_tensor(
(index_len,),
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=tgt_shape[dim],
)
src_spec = TensorSpec.from_tensor(src_shape, None, infinicore.float32)
out_supports = not is_broadcast(tgt_strides)
kwargs = {"reduce": reduce}
test_cases.append(
TestCase(
inputs=[target_spec, dim, index_spec, src_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_reduce - OUT_OF_PLACE",
)
)
if out_supports:
test_cases.append(
TestCase(
inputs=[target_spec, dim, index_spec, src_spec],
kwargs=kwargs,
output_spec=target_spec,
comparison_target="out",
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_reduce - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""IndexReduce operator test with simplified implementation"""
def __init__(self):
super().__init__("IndexReduce")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.index_reduce(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.index_reduce(*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, dim, index_shape)
_TEST_CASES_DATA = [
((3, 4), None, 1, (2,)),
((5, 6), (30, 1), 0, (3,)),
((2, 3, 4), None, 2, (2,)),
((4, 4), None, -1, (1,)),
((6, 2), (12, 1), 1, (2,)),
((3, 5), None, 0, (1,)),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides, dim, idx_shape in _TEST_CASES_DATA:
input_spec = TensorSpec.from_tensor(shape, strides, infinicore.float32)
# index_select requires a 1-D index tensor
index_len = idx_shape[0]
from framework.tensor import TensorInitializer
index_spec = TensorSpec.from_tensor(
(index_len,),
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=shape[dim],
)
# Use positional dim to match infinicore.index_select(input, dim, index)
test_cases.append(
TestCase(
inputs=[input_spec, dim, index_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"index_select - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""IndexSelect operator test with simplified implementation"""
def __init__(self):
super().__init__("IndexSelect")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.index_select(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.index_select(*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: (a_shape, b_shape, a_strides_or_None, b_strides_or_None)
# infinicore.inner(a, b)
_TEST_CASES_DATA = [
((3,), (3,), None, None),
((2, 3), (3,), None, None),
((4, 5), (4, 5), (20, 5), (20, 5)),
((6,), (6,), None, (0,)),
((2, 3, 4), (4,), None, None),
((8, 8), (8, 8), None, 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 a_shape, b_shape, a_strides, b_strides 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, a_strides, dtype)
b = TensorSpec.from_tensor(b_shape, b_strides, dtype)
test_cases.append(
TestCase(
inputs=[a, b],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="inner - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""inner operator test with simplified implementation"""
def __init__(self):
super().__init__("inner")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.inner(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.inner(*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, running_mean_present_bool, running_var_present_bool, weight_bias_present_bool, use_input_stats_or_None, momentum_or_None, eps_or_None)
# infinicore.nn.functional.instance_norm(input, running_mean=None, running_var=None, weight=None, bias=None, use_input_stats=False, momentum=0.1, eps=1e-5)
_TEST_CASES_DATA = [
((4, 3, 8, 8), None, True, True, True, False, None, None),
((2, 6, 4, 4), None, True, True, True, True, 0.2, 1e-5),
((1, 3, 16, 16), None, True, True, False, False, None, None),
((8, 5, 2, 2), None, True, True, False, True, 0.1, 1e-3),
((6, 4, 7, 7), None, True, True, True, False, None, 1e-4),
((3, 2, 9, 9), None, True, True, True, True, 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,
strides,
mean_p,
var_p,
wb_p,
use_stats,
momentum,
eps,
) in _TEST_CASES_DATA:
C = shape[1]
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
inp = TensorSpec.from_tensor(shape, strides, dtype)
running_mean = TensorSpec.from_tensor((C,), None, dtype) if mean_p else None
running_var = TensorSpec.from_tensor((C,), None, dtype) if var_p else None
inputs = [inp]
# instance_norm signature expects running_mean, running_var next
inputs.append(running_mean)
inputs.append(running_var)
if wb_p:
weight = TensorSpec.from_tensor((C,), None, dtype)
bias = TensorSpec.from_tensor((C,), None, dtype)
inputs.append(weight)
inputs.append(bias)
else:
inputs.append(None)
inputs.append(None)
kwargs = {}
if use_stats is not None:
kwargs["use_input_stats"] = use_stats
if momentum is not None:
kwargs["momentum"] = momentum
if eps is not None:
kwargs["eps"] = eps
test_cases.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="instance_norm - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""instance_norm operator test with simplified implementation"""
def __init__(self):
super().__init__("instance_norm")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.instance_norm(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.instance_norm(*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)
# infinicore.nn.functional.interpolate(input, size=None, scale_factor=None, mode='nearest', align_corners=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"interpolate - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Interpolate operator test with simplified implementation"""
def __init__(self):
super().__init__("Interpolate")
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: (matrix_shape, strides_or_None)
# inverse(input) — only out-of-place (no out parameter)
_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="inverse - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""inverse operator test with simplified implementation"""
def __init__(self):
super().__init__("inverse")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.inverse(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.inverse(*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, extra_kwargs_or_None)
# isclose compares two tensors with atol/rtol; we include kwargs combinations
_TEST_CASES_DATA = [
((8, 8), None, None, {"rtol": 1e-05, "atol": 1e-08}),
((8, 8), (16, 1), (16, 1), {"rtol": 1e-03, "atol": 1e-05}),
((8, 8), None, (0, 1), {"rtol": 1e-02, "atol": 1e-03}),
((2, 3, 4), None, None, {"rtol": 1e-02, "atol": 1e-03}),
((1, 8), None, None, {"equal_nan": True}),
((16, 64), (128, 1), (128, 1), 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.float32, infinicore.bfloat16]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, a_strides, b_strides, extra = data[0], data[1], data[2], data[3]
a_supports_inplace = not is_broadcast(a_strides)
b_supports_inplace = not is_broadcast(b_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-3})
a_spec = TensorSpec.from_tensor(shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(shape, b_strides, dtype)
kwargs = {}
if extra is not None:
kwargs.update(extra)
# Out-of-place not support 'out='
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="IsClose - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""IsClose operator test with simplified implementation"""
def __init__(self):
super().__init__("IsClose")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.isclose(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.isclose(*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)
# isfinite checks each element for finiteness and returns boolean tensor
_TEST_CASES_DATA = [
((8, 8), None),
((8, 8), (16, 1)),
((8, 8), None),
((2, 3, 4), None),
((1, 8), None),
((16, 128), (256, 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.float32, infinicore.bfloat16]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, in_strides = data[0], data[1]
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="IsFinite - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""IsFinite operator test with simplified implementation"""
def __init__(self):
super().__init__("IsFinite")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.isfinite(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.isfinite(*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