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

Add flow xxx and tensor xxx autotest #5386

Merged
merged 90 commits into from
Jul 7, 2021

Conversation

BBuf
Copy link
Contributor

@BBuf BBuf commented Jul 5, 2021

给flow.xxx 和 flow.Tensor.xxx 添加Pytorch自动测试测试。

test_module_against_pytorch 测试module
test_flow_against_pytorch 测试flow.xxx
test_tensor_against_pytorch 测试flow.Tensor.xxx

BBuf added 30 commits May 25, 2021 11:01
device: str = "cuda",
training: bool = True,
backward: bool = True,
rtol=1e-4,
atol=1e-5,
n=20,
pytorch_module_class_name=None,
api_flag: int = 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

还有一些 0 1 2 没有改成 TEST_MODULE 等常量

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

def has_full_args_spec(args):
if args == set():
return False
return True
Copy link
Contributor

@daquexian daquexian Jul 6, 2021

Choose a reason for hiding this comment

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

啊不是的,是这样:

def has_full_args_spec(callable):
    try:
        spec = inspect.getfullargspec(callable)
        return True
    except Exception:
        return False

然后 164 行-169 行可以一起改成

torch_module_class = eval(f"torch.{pytorch_module_class_name}")
if has_full_arg_spec(torch_module_class):
    spec = inspect.getfullargspec(torch_module_class)
else:
    spec = xxxx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

try:
torch_module_class = eval(f"torch.{pytorch_module_class_name}")
spec = inspect.getfullargspec(torch_module_class)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

这里 as e 可以去掉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

args = (set(spec.args) | set(spec.kwonlyargs)) - {"self"}
if has_full_args_spec(args) == False:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if has_full_args_spec(args) == False:
if not has_full_args_spec(args):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

if has_default(name):
if rng.random() < 1 / 3:
continue
if api_flag == TEST_MODULE:
Copy link
Contributor

Choose a reason for hiding this comment

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

那这个 if 是不是也没有必要,不管测试什么都需要处理 default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的, 已删除

test_case,
module_class_name,
extra_annotations: Optional[Dict[str, Any]] = None,
extra_generators: Optional[Dict[str, Any]] = None,
extra_defaults: Optional[Dict[str, Any]] = None,
device: str = "cuda",
training: bool = True,
backward: bool = True,
rtol=1e-4,
atol=1e-5,
n=20,
pytorch_module_class_name=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里和 165 行的变量名需要改

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return True
except Exception:
return False

torch_module_class = eval(f"torch.{pytorch_module_class_name}")
Copy link
Contributor

Choose a reason for hiding this comment

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

api_flag 是 TEST_TENSOR 的时候,这里是不是要改,先生成一个 torch tensor,再获取函数对象、拿到 spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

@@ -183,9 +209,6 @@ def generate(name):
flow_attr_dict = {}
torch_attr_dict = {}
for name in args:
if has_default(name):
if rng.random() < 1 / 3:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

这为什么删掉了😂

@@ -127,18 +132,20 @@ def generator(_):
return generator


def test_module_against_pytorch(
def test_against_pytorch(
test_case,
module_class_name,
Copy link
Contributor

Choose a reason for hiding this comment

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

这个参数名也要改,不能出现 module 字样

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

@BBuf BBuf requested a review from oneflow-ci-bot July 7, 2021 05:47
@BBuf BBuf added the automerge label Jul 7, 2021
assert args == set(
annotations.keys()
annotations.keys() | extra_defaults.keys()
Copy link
Contributor

Choose a reason for hiding this comment

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

这行改动是不需要的

@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot July 7, 2021 06:37
@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot July 7, 2021 06:43
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot July 7, 2021 07:33
@BBuf BBuf mentioned this pull request Jul 7, 2021
3 tasks
@oneflow-ci-bot oneflow-ci-bot merged commit 41786ad into master Jul 7, 2021
@oneflow-ci-bot oneflow-ci-bot deleted the add_flow_xxx_and_tensor_xxx_autotest branch July 7, 2021 09:46
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.

3 participants