Skip to content

Issue/497 优化测试框架#502

Merged
voltjia merged 23 commits into
mainfrom
issue/497
Oct 21, 2025
Merged

Issue/497 优化测试框架#502
voltjia merged 23 commits into
mainfrom
issue/497

Conversation

@wooway777
Copy link
Copy Markdown
Collaborator

@wooway777 wooway777 commented Oct 13, 2025

目前,
先写了一个框架;
加了add和matmul的测试;
加了rms_norm和attention(叫attention_temp)的测试,主要是验证框架对测例的处理,调用姿势跟torch没对齐;

用法跟以前一致python test/infinicore/ops/matmul.py --nvidia --bench
以前的--profile改为--bench,其余不变
test/infinicore/ops.py可以运行所有算子测试

对于一个具体算子的测试,需要:
[区别部分]

  1. 测试用例:
    需要自己定义_TEST_CASES_DATA,包含所有测试用例,格式随意。其中TestCase.BOTHTestCase.IN_PLACETestCase.OUT_OF_PLACE可以区分测试类型
  2. 测试用例的parse方法,需要以TestCase(operation_mode, inputs, output)的形式返回给_TEST_CASES或者get_test_cases(self)
  3. 数据类型表
    _TENSOR_DTYPES = [infinicore.float16, infinicore.bfloat16, infinicore.float32]
    如果需要混合数据类型,templates.py上面给了一些定义方法,可以参考rms_norm.py中_DTYPE_COMBINATIONS的定义方式。
  4. 误差表
_TOLERANCE_MAP = {
    infinicore.float16: {"atol": 0, "rtol": 1e-2},
    infinicore.float32: {"atol": 0, "rtol": 1e-3},
    infinicore.bfloat16: {"atol": 0, "rtol": 5e-2},
}
  1. 测试类,class OpTest(BaseOperatorTest)
    init中字符用算子名。
    get_test_cases, get_tensor_dtype, get_tolerance_map可以复制粘贴。
    torch_operator和infinicore_operator用来定义torch和infinicore的定义方法,原则上应该基本一致。
  2. 如果需要混合类型,则需要:
def get_dtype_combinations(self):
        return _DTYPE_COMBINATIONS

否则不需要定义
[相同部分]

  1. 开头的include
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
  1. 结尾的入口
def main():
    """Main entry point"""
    runner = GenericTestRunner(OpTest)
    runner.run_and_exit()


if __name__ == "__main__":
    main()
image image image

@wooway777 wooway777 marked this pull request as draft October 13, 2025 09:26
@wooway777 wooway777 marked this pull request as ready for review October 15, 2025 09:03
@wooway777 wooway777 force-pushed the issue/497 branch 2 times, most recently from 268dd80 to 99be90d Compare October 16, 2025 08:34
Copy link
Copy Markdown
Collaborator

@voltjia voltjia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前用起来问题不大,描述中给出的命令也都可以顺利运行,可以先合并后面再更新。

有几个小问题,后面可以看看需不需要更改一下:

  1. _TEST_CASES_DATAparse_add_test_case 这俩的命名读起来似乎略有不对劲,但是问题不大。
  2. test/infinicore 下同时存在 ops 文件夹和 ops.py,可能会出现冲突问题,比如后面如果有需要 import 的时候,也许会有问题,但也有可能压根不会需要 import 这些。

@voltjia voltjia merged commit c831cd5 into main Oct 21, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants