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

Fix handle_size_arg when len(size) == 0 #9975

Merged
merged 6 commits into from
Mar 21, 2023

Conversation

Pang-GJ
Copy link
Contributor

@Pang-GJ Pang-GJ commented Mar 10, 2023

修复两个问题:

flow.full

>>> import oneflow as flow
>>> flow.full([], 8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/home/pangguojian/oneflow/python/oneflow/nn/modules/constant.py", line 396, in full_op
    size = _handle_size_arg(size)
  File "/data/home/pangguojian/oneflow/python/oneflow/nn/modules/utils.py", line 50, in _handle_size_arg
    assert len(size) > 0, "size of tensor doesn't exists"
AssertionError: size of tensor doesn't exists

torch中:

# torch.full
>>> import torch
>>> torch.full([],8)
tensor(8)

修改方法当len(size)==0时直接返回size

new_full

在torch中:

>>> import torch
>>> tensor = torch.ones((2,))
>>> tensor.new_full([], 2)
tensor(2.)

oneflow中:

>>> import oneflow as flow
>>> tensor = flow.ones((2,))
>>> tensor.new_full([], 8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/home/pangguojian/oneflow/python/oneflow/framework/tensor.py", line 210, in _new_full
    return flow.new_full(
  File "/data/home/pangguojian/oneflow/python/oneflow/nn/modules/constant.py", line 531, in new_full_op
    size = _handle_size_arg(size)
  File "/data/home/pangguojian/oneflow/python/oneflow/nn/modules/utils.py", line 50, in _handle_size_arg
    assert len(size) > 0, "size of tensor doesn't exists"
AssertionError: size of tensor doesn't exists

应用问题一的修改后,问题变为:

>>> import oneflow as flow
>>> tensor = flow.ones((2,))
>>> tensor.new_full([], 2)
tensor([2., 2.], dtype=oneflow.float32)

这是由于_handle_meta_args

if size is None or len(size) == 0:
        new_size = input.shape

所以返回的new_size是shape,导致了不一致

@Pang-GJ Pang-GJ requested review from BBuf and daquexian as code owners March 10, 2023 08:47
@CLAassistant
Copy link

CLAassistant commented Mar 10, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@BBuf BBuf left a comment

Choose a reason for hiding this comment

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

测试加一下吧

@@ -47,6 +47,8 @@ def parse(x):


def _handle_size_arg(size):
if len(size) == 0:
return size
Copy link
Contributor

Choose a reason for hiding this comment

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

补下测试,验证之前不能通过的 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.

done

@Pang-GJ
Copy link
Contributor Author

Pang-GJ commented Mar 16, 2023

测试已加

@xiezipeng-ML xiezipeng-ML requested review from oneflow-ci-bot and daquexian and removed request for daquexian March 20, 2023 03:03
@xiezipeng-ML xiezipeng-ML requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 20, 2023 07:36
@xiezipeng-ML xiezipeng-ML requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 21, 2023 01:32
@xiezipeng-ML xiezipeng-ML enabled auto-merge (squash) March 21, 2023 01:34
@xiezipeng-ML xiezipeng-ML requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 21, 2023 02:43
@xiezipeng-ML xiezipeng-ML merged commit 8913829 into Oneflow-Inc:master Mar 21, 2023
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.

5 participants