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)
# infinicore.floor(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": 0.0, "rtol": 0.0},
infinicore.float32: {"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[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="floor - 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="floor - INPLACE(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="floor - INPLACE(a)",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Floor operator test with simplified implementation"""
def __init__(self):
super().__init__("Floor")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.floor(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.floor(*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.floor_divide(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.int32: {"atol": 0.0, "rtol": 0.0},
infinicore.int64: {"atol": 0.0, "rtol": 0.0},
}
_TENSOR_DTYPES = [infinicore.int32, infinicore.int64]
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="floor_divide - 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="floor_divide - INPLACE(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="floor_divide - 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="floor_divide - INPLACE(b)",
)
)
return cases
class OpTest(BaseOperatorTest):
"""FloorDivide operator test with simplified implementation"""
def __init__(self):
super().__init__("FloorDivide")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.floor_divide(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.floor_divide(*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, b_strides)
_TEST_CASES_DATA = [
((6, 8), None, None),
((8, 4), (16, 1), None),
((5, 5), None, (10, 1)),
((3, 7), (14, 1), (14, 1)),
((10, 3), None, None),
((2, 16), (32, 1), (32, 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:
shape, a_strides, b_strides = data
a_inplace = not is_broadcast(a_strides)
b_inplace = not is_broadcast(b_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-of-place
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="fmax - OUT_OF_PLACE",
)
)
# In-place variations
if a_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="fmax - INPLACE(a)",
)
)
if b_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="fmax - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""FMax operator test with simplified implementation"""
def __init__(self):
super().__init__("FMax")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.fmax(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.fmax(*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, b_strides)
_TEST_CASES_DATA = [
((6, 8), None, None),
((8, 4), (16, 1), None),
((5, 5), None, (10, 1)),
((3, 7), (14, 1), (14, 1)),
((10, 3), None, None),
((2, 16), (32, 1), (32, 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:
shape, a_strides, b_strides = data
a_inplace = not is_broadcast(a_strides)
b_inplace = not is_broadcast(b_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)
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="fmin - OUT",
)
)
if a_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="fmin - INPLACE(a)",
)
)
if b_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="fmin - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""FMin operator test with simplified implementation"""
def __init__(self):
super().__init__("FMin")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.fmin(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.fmin(*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, other_shape_or_None)
# infinicore.fmod(input, other)
_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 in_shape, in_strides, other_shape in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
a_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
b_spec = TensorSpec.from_tensor(
in_shape if other_shape is None else other_shape, None, dtype
)
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="fmod_out_of_place",
)
)
out_spec = TensorSpec.from_tensor(in_shape, None, dtype)
cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="fmod_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="fmod_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="fmod_inplace_b",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Fmod operator test with simplified implementation"""
def __init__(self):
super().__init__("Fmod")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.fmod(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.fmod(*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, output_size, kernel_size, dilation, padding, stride)
# For fold/unfold: input is the output of unfold; fold reconstructs image from patches.
_TEST_CASES_DATA = [
# ((2, 6, 9), None, (4, 4), (2, 2), 1, 0, (2, 2)),
# ((1, 8, 16), None, (8, 8), (4, 4), 1, 0, (2, 2)),
# ((3, 4, 12), None, (6, 6), (3, 2), 1, 1, (1, 2)),
# ((2, 2, 20), None, (10, 2), (2, 2), 1, 0, (2, 1)),
# ((1, 3, 25), None, (5, 5), (5, 5), 1, 0, (5, 5)),
# ((2, 5, 18), (90, 18, 1), (9, 2), (3, 2), 1, 0, (2, 1)),
# 原来对应 ((2,3,8,8), None, (3,3), 1, 0, (1,1))
# 计算得到 L=6*6=36, channels_for_fold = 3*3*3 = 27
((2, 27, 36), None, (8, 8), (3, 3), 1, 0, (1, 1)),
# 原来对应 ((1,4,10,12), None, (5,3), 1, 1, (2,1))
# L = 4 * 12 = 48, channels = 4*5*3 = 60
((1, 60, 48), None, (10, 12), (5, 3), 1, 1, (2, 1)),
# 原来对应 ((2,2,16,16), (512,256,16,1), (4,4), 1, 0, (4,4))
# L = 4 * 4 = 16, channels = 2*4*4 = 32
((2, 32, 16), None, (16, 16), (4, 4), 1, 0, (4, 4)),
# 原来对应 ((3,6,7,9), None, (3,2), 1, 0, (1,1))
# L = 5 * 8 = 40, channels = 6*3*2 = 36
((3, 36, 40), None, (7, 9), (3, 2), 1, 0, (1, 1)),
# 原来对应 ((1,8,9,11), None, (2,3), 1, 1, (1,2))
# L = 10 * 6 = 60, channels = 8*2*3 = 48
((1, 48, 60), None, (9, 11), (2, 3), 1, 1, (1, 2)),
# 原来对应 ((2,5,12,6), (360,72,6,1), (3,3), 1, 0, (2,1))
# L = 5 * 4 = 20, channels = 5*3*3 = 45
((2, 45, 20), None, (12, 6), (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,
output_size,
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 = {
"output_size": output_size,
"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="Fold - OUT_OF_PLACE",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Fold operator test with simplified implementation"""
def __init__(self):
super().__init__("Fold")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.fold(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.fold(*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.frac(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="frac_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="frac_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="frac_inplace",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Frac operator test with simplified implementation"""
def __init__(self):
super().__init__("Frac")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.frac(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.frac(*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, output_size_or_None, return_indices)
# Note: fractional_max_pool may return values and indices; PyTorch accepts optional random samples. We avoid
# explicit _random_samples and focus on default behavior. Indices (if returned) form a separate output; tests
# here exercise the value-returning path.
_TEST_CASES_DATA = [
((2, 3, 15, 15), None, (3, 3), (5, 5), False),
((1, 4, 16, 14), (896, 224, 14, 1), (4, 3), (4, 5), False),
((2, 2, 17, 19), None, (5, 5), (7, 6), False),
((3, 6, 9, 11), None, (2, 2), (4, 5), False),
((1, 8, 20, 20), (3200, 400, 20, 1), (3, 3), (6, 6), False),
((2, 5, 12, 10), None, (4, 3), (3, 3), False),
]
_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, out_size, return_indices in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
kwargs = {
"kernel_size": kernel_size,
"output_size": out_size,
"return_indices": return_indices,
}
cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="FractionalMaxPool2d - OUT_OF_PLACE",
)
)
return cases
class OpTest(BaseOperatorTest):
"""FractionalMaxPool2d operator test with simplified implementation"""
def __init__(self):
super().__init__("FractionalMaxPool2d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.fractional_max_pool2d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.fractional_max_pool2d(*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, output_size_or_None, return_indices)
# Note: PyTorch fractional_max_pool3d behaves similarly to fractional_max_pool2d; we avoid _random_samples.
_TEST_CASES_DATA = [
((2, 3, 9, 9, 9), None, (3, 3, 3), (4, 4, 4), False),
((1, 4, 8, 10, 12), None, (2, 3, 2), (4, 4, 6), False),
((2, 2, 7, 11, 5), (770, 110, 55, 5, 1), (3, 2, 3), (3, 4, 2), False),
((3, 6, 5, 6, 7), None, (2, 2, 2), (3, 3, 4), False),
((1, 8, 10, 10, 10), None, (4, 3, 2), (5, 4, 5), False),
((2, 5, 12, 8, 6), None, (3, 3, 2), (4, 3, 2), False),
]
_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, out_size, return_indices in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP[dtype]
in_spec = TensorSpec.from_tensor(in_shape, in_strides, dtype)
kwargs = {
"kernel_size": kernel_size,
"output_size": out_size,
"return_indices": return_indices,
}
cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="FractionalMaxPool3d - OUT_OF_PLACE",
)
)
return cases
class OpTest(BaseOperatorTest):
"""FractionalMaxPool3d operator test with simplified implementation"""
def __init__(self):
super().__init__("FractionalMaxPool3d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.fractional_max_pool3d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.fractional_max_pool3d(*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)
_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)
# Return-value tests only
cases.append(
TestCase(
inputs=[in_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="frexp_out_tuple",
)
)
return cases
class OpTest(BaseOperatorTest):
"""Frexp operator test with simplified implementation"""
def __init__(self):
super().__init__("Frexp")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.frexp(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.frexp(*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.datatypes import to_torch_dtype
# Test cases format: (shape, fill_value, dtype)
_TEST_CASES_DATA = [
((3, 4), 0.0, infinicore.float32),
((6, 2), 1.5, infinicore.float16),
((5, 5), -2.0, infinicore.float32),
((1, 7), 3.14, infinicore.bfloat16),
((8, 3), 42.0, infinicore.float32),
((2, 2, 2), 0.5, infinicore.float16),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32, infinicore.float16, infinicore.bfloat16]
def parse_test_cases():
test_cases = []
for shape, val, dtype in _TEST_CASES_DATA:
out_spec = TensorSpec.from_tensor(shape, None, dtype)
# kwargs = {"fill_value": val, "size": shape, "dtype": to_torch_dtype(dtype)}
kwargs = {"fill_value": val, "size": shape, "dtype": dtype}
test_cases.append(
TestCase(
inputs=[],
kwargs=kwargs,
output_spec=out_spec,
comparison_target="out",
tolerance=_TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4}),
description=f"full - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Full operator test with simplified implementation"""
def __init__(self):
super().__init__("Full")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
if "fill_value" not in kwargs:
raise TypeError("full test did not provide 'fill_value' parameter")
fill_value = kwargs.pop("fill_value")
if "size" not in kwargs:
raise TypeError("full test did not provide 'size' parameter")
size = kwargs.pop("size")
if "dtype" not in kwargs:
raise TypeError("full test did not provide 'dtype' parameter")
dtype_torch = to_torch_dtype(kwargs.pop("dtype"))
if dtype_torch is None:
raise TypeError("full test provided unsupported 'dtype' parameter")
# 支持测试框架通过 kwargs 注入 out 参数
out = kwargs.pop("out", None)
if out is not None:
return torch.full(tuple(size), fill_value, dtype=dtype_torch, out=out)
else:
return torch.full(tuple(size), fill_value, dtype=dtype_torch)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.full(*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.datatypes import to_torch_dtype
# Test cases format: (base_shape, base_strides_or_None, fill_value, dtype_or_None)
_TEST_CASES_DATA = [
((3, 4), None, 0.0, None),
((6, 2), (12, 1), 1.5, infinicore.float16),
((5, 5), None, -2.0, infinicore.float32),
((1, 7), None, 3.14, infinicore.bfloat16),
((8, 3), (24, 1), 42.0, None),
((2, 2, 2), None, 0.5, infinicore.float16),
]
_TOLERANCE_MAP = {
infinicore.float32: {"atol": 0, "rtol": 0},
infinicore.float16: {"atol": 1e-3, "rtol": 1e-3},
infinicore.bfloat16: {"atol": 1e-2, "rtol": 1e-2},
}
_TENSOR_DTYPES = [infinicore.float32, infinicore.float16, infinicore.bfloat16]
def parse_test_cases():
test_cases = []
for base_shape, base_strides, val, dtype in _TEST_CASES_DATA:
for input_dtype in _TENSOR_DTYPES:
base_spec = TensorSpec.from_tensor(base_shape, base_strides, input_dtype)
kwargs = {"fill_value": val}
if dtype is not None:
kwargs["dtype"] = dtype
# torch.full_like does not accept an `out=` kwarg in most PyTorch
# versions; call out-of-place and compare the return value instead.
test_cases.append(
TestCase(
inputs=[base_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4}),
description=f"full_like - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""FullLike operator test with simplified implementation"""
def __init__(self):
super().__init__("FullLike")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
if "fill_value" not in kwargs:
raise TypeError("full_like test did not provide 'fill_value' parameter")
fill_value = kwargs.pop("fill_value")
if "dtype" not in kwargs:
dtype_torch = None
else:
dtype_torch = to_torch_dtype(kwargs.pop("dtype"))
return torch.full_like(*args, fill_value=fill_value, dtype=dtype_torch)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore full_like implementation (operator not yet available)."""
# # Mirror the torch_operator signature/behavior but call infinicore implementation.
# if "fill_value" not in kwargs:
# raise TypeError("full_like test did not provide 'fill_value' parameter")
# fill_value = kwargs.pop("fill_value")
#
# if "dtype" not in kwargs:
# dtype_infinicore = None
# else:
# # tests pass infinicore dtypes directly, so forward as-is
# dtype_infinicore = kwargs.pop("dtype")
# return infinicore.full_like(*args, fill_value=fill_value, dtype=dtype_infinicore)
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: (input_shape, input_strides_or_None, dim, index_shape)
_TEST_CASES_DATA = [
((3, 4), None, 1, (3, 2)),
((5, 6), (30, 1), 0, (2, 6)),
((2, 3, 4), None, 2, (2, 3, 2)),
((4, 4), None, -1, (4, 2)),
((6, 2), (12, 1), 1, (6, 1)),
((3, 5), None, 0, (1, 5)),
]
_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)
input_ndim = len(shape)
if dim < 0:
actual_dim = input_ndim + dim
else:
actual_dim = dim
size_dim = shape[actual_dim]
# index tensor spec:值必须在 [0, size_dim)
index_spec = TensorSpec.from_tensor(
idx_shape,
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=size_dim, # exclusive bound
)
# gather returns same dtype as input
kwargs = {"dim": dim}
test_cases.append(
TestCase(
inputs=[input_spec, index_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=_TOLERANCE_MAP[infinicore.float32],
description=f"gather - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Gather operator test with simplified implementation"""
def __init__(self):
super().__init__("Gather")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
if "dim" not in kwargs:
raise TypeError("gather test did not provide 'dim' parameter")
dim = kwargs.pop("dim")
input = args[0]
index = args[1]
return torch.gather(input, dim, index)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.gather(*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, var_present_bool, full_or_None, eps_or_None, input_strides_or_None)
# infinicore.nn.functional.gaussian_nll_loss(input, target, var, full=False, eps=1e-6, reduction='mean')
_TEST_CASES_DATA = [
((4, 5), True, None, None, None),
((8, 8), True, True, 1e-6, (512, 64)),
((1, 10), True, False, 1e-3, None),
((16, 100), True, None, None, None),
((3, 7), True, True, 1e-5, None),
((2, 2), True, False, 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, var_present, full, eps, strides in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
inp = TensorSpec.from_tensor(shape, strides, dtype)
tgt = TensorSpec.from_tensor(shape, None, dtype)
var = TensorSpec.from_tensor(shape, None, dtype) if var_present else None
inputs = [inp, tgt]
if var is not None:
inputs.append(var)
kwargs = {}
if full is not None:
kwargs["full"] = full
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="gaussian_nll_loss - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""gaussian_nll_loss operator test with simplified implementation"""
def __init__(self):
super().__init__("gaussian_nll_loss")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.gaussian_nll_loss(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.gaussian_nll_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: (shape, a_strides, b_strides)
_TEST_CASES_DATA = [
((6, 8), None, None),
((8, 4), (16, 1), None),
((5, 5), None, (10, 1)),
((3, 7), (14, 1), (14, 1)),
((10, 3), None, None),
((2, 16), (32, 1), (32, 1)),
]
_TOLERANCE_MAP = {infinicore.int64: {"atol": 0, "rtol": 0}}
_TENSOR_DTYPES = [infinicore.int64]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, a_strides, b_strides = data
a_inplace = not is_broadcast(a_strides)
b_inplace = not is_broadcast(b_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
a_spec = TensorSpec.from_tensor(shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(shape, b_strides, dtype)
# Out-of-place
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="gcd - OUT",
)
)
if a_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="gcd - INPLACE(a)",
)
)
if b_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="gcd - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""GCD operator test with simplified implementation"""
def __init__(self):
super().__init__("GCD")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.gcd(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.gcd(*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 = [
((13, 4), None, -1),
((8, 6), (48, 1), -1), # last dim divisible by 2
((4, 8, 6), (48, 8, 1), 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():
"""GLU: infinicore.nn.functional.glu(input, dim=-1)
GLU splits last dimension in half; ensure last dim is even in test shapes.
No inplace argument in functional API, so 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
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"GLU - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""GLU operator test with simplified implementation"""
def __init__(self):
super().__init__("GLU")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.glu(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.glu(*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, num_groups, weight_bias_present_bool, eps_or_None)
# infinicore.nn.functional.group_norm(input, num_groups, weight=None, bias=None, eps=1e-5)
_TEST_CASES_DATA = [
((4, 8, 16, 16), None, 4, True, None),
((2, 6, 8, 8), (768, 128, 1, 1), 3, False, 1e-3),
((1, 3, 10, 10), None, 3, True, None),
((8, 12, 6, 6), None, 6, True, 1e-4),
((6, 4, 7, 7), None, 2, False, None),
((3, 2, 9, 9), None, 1, True, 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, num_groups, wb_present, 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)
# infinicore.nn.functional.group_norm(input, num_groups, weight=None, bias=None, eps=1e-5)
# pass num_groups as positional argument to avoid duplicate kwarg issue
inputs = [inp, num_groups]
kwargs = {}
if wb_present:
weight = TensorSpec.from_tensor((C,), None, dtype)
bias = TensorSpec.from_tensor((C,), None, dtype)
inputs.append(weight)
inputs.append(bias)
else:
# explicit None placeholders for weight and bias
inputs.append(None)
inputs.append(None)
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="group_norm - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""group_norm operator test with simplified implementation"""
def __init__(self):
super().__init__("group_norm")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.group_norm(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.group_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, a_strides_or_None, b_strides_or_None, out_strides_or_None)
# greater-than comparison
_TEST_CASES_DATA = [
((8, 8), None, None, None),
((8, 8), (16, 1), (16, 1), None),
((8, 8), None, (0, 1), None),
((1, 8), None, None, (8, 1)),
((2, 3, 4), None, None, None),
((32, 64), (128, 1), (128, 1), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-3},
infinicore.int32: {"atol": 0, "rtol": 0},
}
_TENSOR_DTYPES = [infinicore.float16, infinicore.float32, infinicore.int32]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, a_strides, b_strides, out_strides = data[0], data[1], data[2], data[3]
a_supports_inplace = not is_broadcast(a_strides)
b_supports_inplace = not is_broadcast(b_strides)
out_supports_inplace = not is_broadcast(out_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 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, infinicore.bool)
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="GT - OUT_OF_PLACE",
)
)
if out_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="GT - INPLACE(out)",
)
)
if a_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="GT - INPLACE(a)",
)
)
if b_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={"out": 1},
output_spec=None,
comparison_target=1,
tolerance=tol,
description="GT - INPLACE(b)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""GT operator test with simplified implementation"""
def __init__(self):
super().__init__("GT")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.gt(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.gt(*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, tau_or_None, hard_or_None, dim_or_None)
_TEST_CASES_DATA = [
((4, 10), None, 1.0, False, -1),
((8, 20), (160, 1), 0.5, False, -1),
((2, 5, 6), None, 1.5, True, 2),
]
_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():
"""
gumbel_softmax: infinicore.nn.functional.gumbel_softmax(input, tau=1, hard=False, eps=1e-10, dim=-1)
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
tau = data[2] if len(data) > 2 else 1.0
hard = data[3] if len(data) > 3 else False
dim = data[4] if len(data) > 4 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 = {"tau": tau, "hard": hard, "dim": dim}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"GumbelSoftmax - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""GumbelSoftmax operator test with simplified implementation"""
def __init__(self):
super().__init__("GumbelSoftmax")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.gumbel_softmax(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.gumbel_softmax(*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():
"""
hardshrink(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"Hardshrink - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Hardshrink operator test with simplified implementation"""
def __init__(self):
super().__init__("Hardshrink")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.hardshrink(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.hardshrink(*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