Unverified Commit 1e43a28e authored by thatPepe's avatar thatPepe Committed by GitHub
Browse files

Merge pull request #589 from InfiniTensor/issue/566

issue/566: 添加 Python 算子测试
parents 798dc76e 4deec279
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)
# count_nonzero counts number of non-zero elements along dims or overall
_TEST_CASES_DATA = [
((8, 8), None, None),
((8, 8), (16, 1), 1),
((2, 3, 4), None, 0),
((1, 8), None, (0,)),
((16, 64), (128, 1), None),
((4, 5, 6), (60, 12, 2), 2),
]
_TOLERANCE_MAP = {infinicore.int64: {"atol": 0, "rtol": 0}}
_TENSOR_DTYPES = [infinicore.int32, infinicore.float32, infinicore.uint8]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape, strides, dim = data
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(infinicore.int64, {"atol": 0, "rtol": 0})
in_spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if dim is not None:
kwargs["dim"] = dim
test_cases.append(
TestCase(
inputs=[in_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="CountNonZero - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""CountNonZero operator test with simplified implementation"""
def __init__(self):
super().__init__("CountNonZero")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.count_nonzero(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.count_nonzero(*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, correction, fweights, aweights)
_TEST_CASES_DATA = [
((5,), None, 0, None, None),
((3, 5), None, 1, None, None),
((4, 4), (16, 1), 0, None, None),
((2, 8), None, 1, None, None),
((6, 6), None, 0, None, None),
((1, 7), None, 0, None, None),
]
_TOLERANCE_MAP = {infinicore.float32: {"atol": 1e-5, "rtol": 1e-4}}
_TENSOR_DTYPES = [infinicore.float32]
def parse_test_cases():
test_cases = []
for shape, strides, correction, fweights, aweights in _TEST_CASES_DATA:
input_spec = TensorSpec.from_tensor(shape, strides, infinicore.float32)
kwargs = {"correction": correction}
if fweights is not None:
kwargs["fweights"] = fweights
if aweights is not None:
kwargs["aweights"] = aweights
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype)
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"cov - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Cov operator test with simplified implementation"""
def __init__(self):
super().__init__("Cov")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cov(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cov(*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, dim, a_strides_or_None, b_strides_or_None)
# infinicore.cross(a, b, dim=-1)
_TEST_CASES_DATA = [
((8, 3), -1, None, None),
((2, 3, 3), 2, None, (9, 3, 1)),
((4, 3, 5), 1, None, None),
((3, 3), -1, (9, 3), None),
((16, 3), -1, None, None),
((2, 3, 4, 3), 3, None, 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, dim = data[0], data[1]
a_strides = data[2] if len(data) > 2 else None
b_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)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-4})
a_spec = TensorSpec.from_tensor(shape, a_strides, dtype)
b_spec = TensorSpec.from_tensor(shape, b_strides, dtype)
kwargs = {"dim": dim}
# Out-of-place
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"cross - OUT_OF_PLACE",
)
)
# explicit out not supported by infinicore.cross
return test_cases
class OpTest(BaseOperatorTest):
"""Cross operator test with simplified implementation"""
def __init__(self):
super().__init__("Cross")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cross(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cross(*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
# Test cases format: (input_shape_logits_N_C, target_shape_N, input_strides_or_None, weight_present_bool, ignore_index_or_None)
# infinicore.nn.functional.cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean')
_TEST_CASES_DATA = [
((4, 5), (4,), None, False, None),
((8, 10), (8,), None, True, -1),
((1, 3), (1,), None, False, None),
((16, 100), (16,), (1600, 100), True, None),
((3, 7), (3,), None, False, None),
((2, 2), (2,), None, True, -100),
]
_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 (
logits_shape,
target_shape,
logits_strides,
weight_present,
ignore_index,
) in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
logits = TensorSpec.from_tensor(logits_shape, logits_strides, dtype)
target = TensorSpec.from_tensor(
target_shape,
None,
infinicore.int64,
init_mode=TensorInitializer.RANDINT,
low=0,
high=logits_shape[1],
)
inputs = [logits, target]
kwargs = {}
if weight_present:
weight_spec = TensorSpec.from_tensor((logits_shape[1],), None, dtype)
inputs.append(weight_spec)
if ignore_index is not None:
kwargs["ignore_index"] = ignore_index
test_cases.append(
TestCase(
inputs=inputs,
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="cross_entropy - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""cross_entropy operator test with simplified implementation"""
def __init__(self):
super().__init__("cross_entropy")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.cross_entropy(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.cross_entropy(*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, dim, input_strides_or_None, out_strides_or_None)
# cummax returns (values, indices). We will validate the values tensor using the
# comparison_target; indices are returned by PyTorch but the framework compares
# on the primary output (values). Indices tests are not explicitly compared here.
_TEST_CASES_DATA = [
((13, 4), 1, None, None),
((13, 4), 0, (10, 1), None),
((8, 16), 1, None, None),
((2, 3, 4), 2, None, None),
((16, 64), 1, (128, 1), (128, 1)),
((4, 5, 6), 0, 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():
"""
Generate test cases for cummax.
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape, dim = data[0], data[1]
in_strides = data[2] if len(data) > 2 else None
out_strides = data[3] if len(data) > 3 else None
input_supports_inplace = not is_broadcast(in_strides)
out_supports_inplace = not is_broadcast(out_strides)
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_spec = TensorSpec.from_tensor(shape, out_strides, dtype)
# Out-of-place (returns values, indices) - compare values
kwargs = {"dim": dim}
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"cummax - OUT_OF_PLACE",
)
)
# Explicit out for values (if supported) - PyTorch doesn't accept out for cummax, so skip
# Note: PyTorch does not support explicit 'out' for cummax, so we don't add out= cases.
# In-place on input (overwrite) - not supported by PyTorch for cummax
# Note: cummax does not support inplace modification via inplace=True, so no INPLACE cases added.
return test_cases
class OpTest(BaseOperatorTest):
"""Cummax operator test with simplified implementation"""
def __init__(self):
super().__init__("Cummax")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cummax(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cummax(*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, dim, input_strides_or_None, out_strides_or_None)
# cummin returns (values, indices). We validate values similar to cummax.
_TEST_CASES_DATA = [
((13, 4), 1, None, None),
((13, 4), 0, (10, 1), None),
((8, 16), 1, None, None),
((2, 3, 4), 2, None, None),
((16, 64), 1, (128, 1), (128, 1)),
((4, 5, 6), 0, 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, dim = data[0], data[1]
in_strides = data[2] if len(data) > 2 else None
out_strides = data[3] if len(data) > 3 else None
# PyTorch doesn't support inplace/out for cummin op; only out-of-place
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
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=tol,
description=f"cummin- OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Cummin operator test with simplified implementation"""
def __init__(self):
super().__init__("Cummin")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cummin(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cummin(*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, dim, input_strides_or_None, out_strides_or_None)
# cumprod computes cumulative product along dim. PyTorch does not support explicit
# out= or inplace=True for cumprod — we only add out-of-place tests.
_TEST_CASES_DATA = [
((13, 4), 1, None, None),
((13, 4), 0, (10, 1), None),
((8, 16), 1, None, None),
((2, 3, 4), 2, None, None),
((16, 64), 1, (128, 1), None),
((4, 5, 6), 0, 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, dim = data[0], data[1]
in_strides = data[2] if len(data) > 2 else None
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
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=tol,
description=f"cumprod - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Cumprod operator test with simplified implementation"""
def __init__(self):
super().__init__("Cumprod")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cumprod(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cumprod(*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, dim, input_strides_or_None, out_strides_or_None)
# cumsum supports out= in PyTorch? PyTorch provides infinicore.cumsum(input, dim, *, out=None)
# so we include explicit out cases.
_TEST_CASES_DATA = [
((13, 4), 1, None, None),
((13, 4), 0, (10, 1), None),
((8, 16), 1, None, None),
((2, 3, 4), 2, None, None),
((16, 64), 1, (128, 1), (128, 1)),
((4, 5, 6), 0, 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, dim = data[0], data[1]
in_strides = data[2] if len(data) > 2 else None
out_strides = data[3] if len(data) > 3 else None
out_supports_inplace = not is_broadcast(out_strides)
input_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
out_spec = TensorSpec.from_tensor(shape, out_strides, dtype)
# Out-of-place: pass dim as positional argument to match infinicore.cumsum(input, dim, *, dtype=None, out=None)
test_cases.append(
TestCase(
inputs=[input_spec, dim],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"cumsum - OUT_OF_PLACE",
)
)
# Explicit out
if out_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec, dim],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description=f"cumsum - INPLACE(out)",
)
)
# In-place on input (overwrite) - if input supports inplace and op accepts out param
if input_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec, dim],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description=f"cumsum - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Cumsum operator test with simplified implementation"""
def __init__(self):
super().__init__("Cumsum")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.cumsum(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.cumsum(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# =======================================================================
# Test cases format: (shape, input_strides_or_None)
# Test cases format: (in_shape, in_strides_or_None)
# =======================================================================
_TEST_CASES_DATA = [
((13, 4), None),
((13, 4), (10, 1)),
((13, 4), (0, 1)),
((8, 16), None),
((8, 16), (40, 1)),
((16, 5632), None),
((2, 3, 4), 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():
"""
Parse deg2rad test cases.
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
in_strides = data[1] if len(data) > 1 else None
input_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="deg2rad - OUT_OF_PLACE",
)
)
# Explicit out if output supports inplace (same shape and not broadcast)
# We assume out supports inplace for same-shaped dense tensors.
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="deg2rad - INPLACE(out)",
)
)
# In-place overwrite input
if input_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="deg2rad - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Deg2rad operator test with simplified implementation"""
def __init__(self):
super().__init__("Deg2rad")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.deg2rad(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.deg2rad(*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)
# det(input) — only out-of-place (no inplace/out parameter for det)
_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="det - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""det operator test with simplified implementation"""
def __init__(self):
super().__init__("det")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.det(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.det(*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, diagonal_k_or_None)
# infinicore.diag: behavior depends on input dim: 1-D -> returns 2-D diag matrix; 2-D -> returns 1-D diagonal
_TEST_CASES_DATA = [
((4,), None, None),
((3, 3), None, None),
((5,), (0,), None),
((6, 6), (360, 60), 1),
((2, 4), None, -1),
((1,), 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, strides, k in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if k is not None:
kwargs["diagonal"] = k
test_cases.append(
TestCase(
inputs=[spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="diag - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""diag operator test with simplified implementation"""
def __init__(self):
super().__init__("diag")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.diag(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.diag(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (input_shape, input_strides_or_None, offset_or_None)
# diag_embed(input, offset=0, dim1=-2, dim2=-1)
_TEST_CASES_DATA = [
((3,), None, None),
((4,), None, 1),
((2, 5), None, 0),
((6,), (0,), None),
((1,), None, -1),
((8,), None, 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():
test_cases = []
for shape, strides, offset in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if offset is not None:
kwargs["offset"] = offset
test_cases.append(
TestCase(
inputs=[spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="diag_embed - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""diag_embed operator test with simplified implementation"""
def __init__(self):
super().__init__("diag_embed")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.diag_embed(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.diag_embed(*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, offset_or_None)
# diagflat(input, offset=0, dim=0)
_TEST_CASES_DATA = [
((4,), None, None),
((3, 1), None, 1),
((2, 2), (8, 1), 0),
((1,), None, -1),
((6,), None, 2),
((8, 2), 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, strides, offset in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if offset is not None:
kwargs["offset"] = offset
test_cases.append(
TestCase(
inputs=[spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="diagflat - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""diagflat operator test with simplified implementation"""
def __init__(self):
super().__init__("diagflat")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.diagflat(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.diagflat(*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, offset_or_None, dim1_or_None, dim2_or_None)
# infinicore.diagonal(input, offset=0, dim1=0, dim2=1)
_TEST_CASES_DATA = [
((3, 4), None, None, None, None),
((5, 5), (300, 60), 1, None, None),
((2, 3, 3), None, 0, -2, -1),
((4, 4), None, -1, None, None),
((1, 6), None, None, None, None),
((8, 8), (512, 1), 2, 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, strides, offset, d1, d2 in _TEST_CASES_DATA:
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
spec = TensorSpec.from_tensor(shape, strides, dtype)
kwargs = {}
if offset is not None:
kwargs["offset"] = offset
if d1 is not None:
kwargs["dim1"] = d1
if d2 is not None:
kwargs["dim2"] = d2
test_cases.append(
TestCase(
inputs=[spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="diagonal - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""diagonal operator test with simplified implementation"""
def __init__(self):
super().__init__("diagonal")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.diagonal(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.diagonal(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# ===============================================================================
# Operator-specific configuration
# ===============================================================================
# Test cases format: (shape, input_strides, src_strides_or_None, offset)
# diagonal_scatter writes values from src into input along diagonals specified by offset
_TEST_CASES_DATA = [
((6, 6), None, None, 0),
((8, 8), (16, 1), None, 1),
((7, 5), None, (10, 1), -1),
((4, 9), None, None, 2),
((10, 10), (20, 1), (20, 1), 0),
((3, 5), None, None, -2),
]
# Test cases format: (shape, input_strides_or_None, src_strides_or_None, offset, optional_dim1, optional_dim2)
_TEST_CASES_DATA = [
((6, 6), None, None, 0, 0, 1),
((8, 8), (16, 1), None, 1, 0, 1),
((7, 5), None, (4,), -1, 0, 1),
((4, 9), None, None, 2, 0, 1),
((10, 10), (20, 1), (2,), 0, 0, 1),
((3, 5), None, None, -2, 0, 1),
]
# Tolerance configuration
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 0, "rtol": 1e-2},
infinicore.float32: {"atol": 0, "rtol": 1e-3},
infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
# Data types to test for payload tensors
_TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
def parse_test_cases():
"""
Parse diagonal_scatter test cases.
Format: (shape, input_strides, index_strides, src_strides, offset)
"""
test_cases = []
for data in _TEST_CASES_DATA:
shape, in_strides, src_strides, offset, dim1, dim2 = data
# Determine in-place support by checking if input/src are broadcast
in_supports_inplace = not is_broadcast(in_strides)
src_supports_inplace = not is_broadcast(src_strides)
for dtype in _TENSOR_DTYPES:
tolerance = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
dummy = torch.zeros(*shape)
diag = torch.diagonal(dummy, offset=offset, dim1=dim1, dim2=dim2)
diag_len = diag.numel()
src_shape = (diag_len,)
src_spec = TensorSpec.from_tensor(src_shape, src_strides, dtype)
# Out-of-place (return value)
test_cases.append(
TestCase(
inputs=[input_spec, src_spec],
kwargs={"offset": offset, "dim1": dim1, "dim2": dim2},
output_spec=None,
comparison_target=None,
tolerance=tolerance,
description=f"diagonal_scatter - OUT_OF_PLACE",
)
)
# In-place on input (modify input)
if in_supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec, src_spec],
kwargs={"offset": offset, "dim1": dim1, "dim2": dim2},
output_spec=None,
comparison_target=0,
tolerance=tolerance,
description=f"diagonal_scatter - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""DiagonalScatter operator test with simplified implementation"""
def __init__(self):
super().__init__("DiagonalScatter")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.diagonal_scatter(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.diagonal_scatter(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# Test cases format: (shape, n, dim, input_strides_or_None)
_TEST_CASES_DATA = [
((13, 4), 1, 1, None),
((13, 6), 2, 1, (12, 1)),
((8, 16), 1, 0, None),
((2, 3, 5), 1, 2, None),
((16, 64), 3, 1, None),
((4, 5, 6), 2, 0, 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, n, dim = data[0], data[1], data[2]
in_strides = data[3] if len(data) > 3 else None
input_supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 1e-3})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
out_shape = list(shape)
# diff reduces size along dim by n (if valid) — shapes may differ
try:
out_shape[dim] = out_shape[dim] - n
except Exception:
pass
out_spec = TensorSpec.from_tensor(tuple(out_shape), None, dtype)
kwargs = {"n": n, "dim": dim}
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"diff - OUT_OF_PLACE",
)
)
# PyTorch does not support explicit out for diff — skip explicit out tests
# Note: PyTorch diff does not accept out parameter; hence no INPLACE(out) cases.
return test_cases
class OpTest(BaseOperatorTest):
"""Diff operator test with simplified implementation"""
def __init__(self):
super().__init__("Diff")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.diff(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.diff(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
from framework.utils import is_broadcast
# =======================================================================
# Test cases format: (shape, input_strides_or_None)
# =======================================================================
_TEST_CASES_DATA = [
((13, 4), None),
((13, 4), (10, 1)),
((8, 16), None),
((8, 16), (40, 1)),
((2, 3, 4), None),
((16, 5632), None),
]
_TOLERANCE_MAP = {
infinicore.float16: {"atol": 1e-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 = data[0]
in_strides = data[1] if len(data) > 1 else None
supports_inplace = not is_broadcast(in_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 1e-5, "rtol": 1e-4})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
out_spec = TensorSpec.from_tensor(shape, None, dtype)
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="digamma - OUT_OF_PLACE",
)
)
# Explicit out
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=None,
output_spec=out_spec,
comparison_target="out",
tolerance=tol,
description="digamma - INPLACE(out)",
)
)
# In-place on input
if supports_inplace:
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs={"out": 0},
output_spec=None,
comparison_target=0,
tolerance=tol,
description="digamma - INPLACE(input)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Digamma operator test with simplified implementation"""
def __init__(self):
super().__init__("Digamma")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.digamma(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.digamma(*args, **kwargs)
def main():
"""Main entry point"""
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import torch
import infinicore
from framework.base import BaseOperatorTest, TensorSpec, TestCase
from framework.runner import GenericTestRunner
# Test cases format: (shape, a_strides_or_None, b_strides_or_None, p_or_None)
# dist computes p-norm distance between two tensors
_TEST_CASES_DATA = [
((8, 8), None, None, None),
((8, 8), (16, 1), (16, 1), 1.0),
((2, 3, 4), None, None, 2.0),
((1, 8), None, (0, 1), None),
((16, 64), (128, 1), (128, 1), 3.0),
((4, 5, 6), (60, 12, 2), (60, 12, 2), 0.5),
]
_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, a_strides, b_strides, p = data
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 p is not None:
kwargs["p"] = p
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description="Dist - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Dist operator test with simplified implementation"""
def __init__(self):
super().__init__("Dist")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.dist(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.dist(*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)
# infinicore.dot(a, b) — 1-D vectors; returns scalar
_TEST_CASES_DATA = [
((3,), (3,), None, None),
((8,), (8,), None, None),
((1,), (1,), None, None),
((16,), (16,), None, None),
((5,), (5,), None, None),
((32,), (32,), None, None),
((8,), (8,), (2,), (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():
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="dot - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""dot operator test with simplified implementation"""
def __init__(self):
super().__init__("dot")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.dot(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.dot(*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, p, training, in_strides_or_None)
# infinicore.nn.functional.dropout1d(input, p=0.5, training=True)
_TEST_CASES_DATA = [
((8, 16), 0.1, True, None),
((8, 16), 0.2, False, (128, 1)),
((2, 3, 4), 0.5, True, None),
((16, 64), 0.3, True, None),
((4, 5, 6), 0.5, False, None),
((3, 4, 5), 0.4, True, (60, 20, 4)),
]
_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, p, training = 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": 1e-2, "rtol": 1e-2})
input_spec = TensorSpec.from_tensor(shape, in_strides, dtype)
kwargs = {"p": p, "training": training}
# Out-of-place
test_cases.append(
TestCase(
inputs=[input_spec],
kwargs=kwargs,
output_spec=None,
comparison_target=None,
tolerance=tol,
description=f"dropout1d - OUT_OF_PLACE",
)
)
return test_cases
class OpTest(BaseOperatorTest):
"""Dropout1d operator test with simplified implementation"""
def __init__(self):
super().__init__("Dropout1d")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.nn.functional.dropout1d(*args, **kwargs)
# def infinicore_operator(self, *args, **kwargs):
# """InfiniCore implementation (operator not yet available)."""
# return infinicore.nn.functional.dropout1d(*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