Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加单测调用多样性检测工具 Validate Unittest #328

Merged
merged 14 commits into from
Nov 14, 2023

Conversation

RedContritio
Copy link
Contributor

@RedContritio RedContritio commented Nov 6, 2023

PR Docs

无对应映射文档

  • 添加单测调用多样性检测工具 Validate Unittest
  • 修复大约 50 个不符合规范的单测
  • 完善了部分 api 的 api_mapping.json 映射数据

PR APIs

torch.Tensor.absolute
torch.Tensor.add
torch.Tensor.add_
torch.Tensor.addbmm
torch.Tensor.addcdiv
torch.Tensor.addcmul
torch.Tensor.addmm
torch.Tensor.addmm_
torch.Tensor.addmv
torch.Tensor.addr
torch.Tensor.all
torch.Tensor.allclose
torch.Tensor.amax
torch.Tensor.amin
torch.Tensor.aminmax
torch.Tensor.any
torch.Tensor.arccos
torch.Tensor.argmax
torch.Tensor.argmin
torch.Tensor.argsort
torch.Tensor.as_strided
torch.Tensor.atan2
torch.Tensor.baddbmm
torch.Tensor.bitwise_and
torch.Tensor.bitwise_or
torch.Tensor.bitwise_xor
torch.Tensor.cholesky_inverse
torch.Tensor.clamp
torch.Tensor.clamp_
torch.Tensor.clip_
torch.Tensor.clone
torch.Tensor.count_nonzero
torch.Tensor.cov
torch.Tensor.cross
torch.Tensor.cumprod
torch.Tensor.cumsum
torch.Tensor.diag
torch.Tensor.diag_embed
torch.Tensor.diagonal
torch.Tensor.dist
torch.Tensor.div
torch.Tensor.divide
torch.Tensor.eq
torch.Tensor.unfold
torch.count.nonzero

torch.fft.ifftshift
torch.is.nonzero
torch.nn.NLLLoss
torch.nn.NLLLoss2d
torch.nn.Softmax2d
torch.normal
torch.trapezoid
torch.trapz

......

现存不符合规范的 api

注1:当前规则仅检查以下四种情况:

  1. 所有关键字不指定
  2. 所有关键字都指定
  3. 关键字乱序
  4. 存在 min_input_args 且不指定所有默认参数

注2:当 api_mapping.json 不含对应信息或找不到 'args_list' 时,暂时跳过对应 api,不做检查

当前大约有 800 unittests 不符合规范

api all args all kwargs kwargs out of order all default
torch.Tensor.fill_diagonal_
torch.Tensor.flatten
torch.Tensor.float
torch.Tensor.fmax
torch.Tensor.fmin
torch.Tensor.gather
torch.Tensor.greater_equal
torch.Tensor.half
torch.Tensor.histc
torch.Tensor.index_add
torch.Tensor.index_copy_
torch.Tensor.index_select
torch.Tensor.int
torch.Tensor.isclose
torch.Tensor.istft
torch.Tensor.kthvalue
torch.Tensor.le
torch.Tensor.lerp
torch.Tensor.lerp_
torch.Tensor.less
torch.Tensor.less_equal
torch.Tensor.logit
torch.Tensor.logsumexp
torch.Tensor.long
torch.Tensor.lt
torch.Tensor.lu
……

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Nov 6, 2023

'min_input_args' 和默认参数的数量有关,如果不进行 默认参数全部不指定 的检查,就不影响其他三项的检查。

'min_input_args' 应该就可以用来做 默认参数全部不指定 的检查吧,所有API也需要补上'min_input_args' ,测试用例须包含有 'min_input_args' 个参数且不指定关键字,你看这个方案能否可行

@@ -0,0 +1,2 @@
callvariety_report.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

validate_unittest
validation

改成这样命名吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已更新

@RedContritio RedContritio changed the title 添加单测调用多样性检测工具 Call variety check 添加单测调用多样性检测工具 Validate Unittest Nov 6, 2023
@RedContritio
Copy link
Contributor Author

RedContritio commented Nov 6, 2023

'min_input_args' 和默认参数的数量有关,如果不进行 默认参数全部不指定 的检查,就不影响其他三项的检查。

'min_input_args' 应该就可以用来做 默认参数全部不指定 的检查吧,所有API也需要补上'min_input_args' ,测试用例须包含有 'min_input_args' 个参数且不指定关键字,你看这个方案能否可行

好的我试试

已更新,现在有大约 800 个不符合规范的单测

@paddle-bot paddle-bot bot added the contributor External developers label Nov 6, 2023
@@ -69,14 +69,3 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result", "out"], check_value=False)


def test_case_6():
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个case为什么删除,尽量新增case不减少case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

因为这个 case 测试的是 torch.randint,我倾向于和 torch.normal 毫不相关

r"^test_hub_download_url_to_file\.py", # 要下载,费时间,先跳过了
r"^test_(\w*)Tensor\.py", # 特殊类构造函数,api_mapping.json 不合用,跳过
r"^test_Size\.py", # api_mapping.json 不合用
r"^test_nn_ParameterList\.py", # 该文件没有测试 torch.nn.ParameterList
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个测试后面需要补充上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个里面有两个测试,有一个是之前改,但是没有使用 torch.nn.ParameterList,而是使用 list[Parameter] 的,这种不清楚是不是合理的。

tools/validate_unittest/validate_unittest.py Show resolved Hide resolved
tools/validate_unittest/validate_unittest.py Outdated Show resolved Hide resolved
tools/validate_unittest/validate_unittest.py Outdated Show resolved Hide resolved
with open(test_data_path, "w") as f:
json.dump(test_data, f)

for k, v in api_alias_mapping.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个的目的是为了检查api_alias_mapping,是否在api_mapping里吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的

tools/validate_unittest/validate_unittest.py Outdated Show resolved Hide resolved
tools/validate_unittest/validate_unittest.py Outdated Show resolved Hide resolved
tools/validate_unittest/validate_unittest.py Outdated Show resolved Hide resolved
test_data.update(newtest_data)
with open(test_data_path, "w") as f:
json.dump(test_data, f)

Copy link
Collaborator

Choose a reason for hiding this comment

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

我觉得下面这个for循环里的逻辑还要再优化下,if-else嵌套过深,变量命名也需要设计下,提升下可读性。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

Copy link
Contributor Author

@RedContritio RedContritio Nov 9, 2023

Choose a reason for hiding this comment

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

已更新,重写了 alias 的检查逻辑

zhwesky2010
zhwesky2010 previously approved these changes Nov 14, 2023
Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -42,7 +42,8 @@ def forward(self, x):
obj.run(pytorch_code, ["result"])


def test_case_2():
# this is test case for named_buffers
def _test_case_2():
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个是否要移动到对应位置去?或者改写为相应的新写法?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已移动

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants