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

[BUG] test_add.py 跑graph 测试报错 #7283

Closed
grybd opened this issue Jan 18, 2022 · 1 comment · Fixed by #7458
Closed

[BUG] test_add.py 跑graph 测试报错 #7283

grybd opened this issue Jan 18, 2022 · 1 comment · Fixed by #7458
Assignees
Labels

Comments

@grybd
Copy link
Contributor

grybd commented Jan 18, 2022

背景信息

将test_add.py中的test_0dim_inplace_add(test_case) 打开check_graph=True ,再跑test_add.py报错,报错信息如下:

======================================================================
FAIL: test_0dim_inplace_add (__main__.TestAddModule)
----------------------------------------------------------------------
assert (
AssertionError: Check graph failed: graph result [[1.392592  1.2263045 1.4627435]
 [1.3013713 1.7706606 1.7302301]] not equals to eager result [[0.788282  0.6219945 0.8584335]
 [0.6970614 1.1663506 1.12592  ]].

合并lixiang 的#7276 分支(解决inplace op 跑graph 测试参数deepcopy的分支Fix_autotest_inplace_bug)再跑测试还是会报错,报错信息:

Traceback (most recent call last):
  File "/home/fengdaochao/fdz/oneflow/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py", line 757, in new_f
    res = f(test_case)
  File "/home/fengdaochao/fdz/oneflow/python/oneflow/test/modules/test_add.py", line 180, in test_0dim_inplace_add
    x += y.mean()
  File "/home/fengdaochao/fdz/oneflow/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py", line 500, in dual_method
    check_eager_graph_tensor(oneflow_res, test_g_res)
  File "/home/fengdaochao/fdz/oneflow/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py", line 232, in check_eager_graph_tensor
    assert (
AssertionError: Check graph failed: graph result [[1.8136338  1.1563476  0.9524027 ]
 [1.8796235  0.99145484 1.845683  ]] not equals to eager result [[1.3421042  0.684818   0.4808731 ]
 [1.4080939  0.51992524 1.3741534 ]].

在oneflow下做了测试eager 和graph的结果是不对齐的

import oneflow as flow
import numpy as np 

a=flow.randn(2,3)
b=flow.randn(1,10)

x = flow.Tensor(a).to("cpu")
print("x :",x)
y = flow.Tensor(b).to("cpu")
print("y: ",y)

x_1 = x
x_2 = x
y_1 = y
y_2 = y

x_1 = flow.add(x_1,y_1.mean())
print("eager, 非inplace")
print("-------------------------------------")
print(x_1)

x_2 = flow.add(x_2,y_2.mean(),inplace=True)
print("eager, inplace")
print("-------------------------------------")
print(x_2)

def model(x,y):
    return flow.add(x,y.mean(),inplace=True)

class Graph(flow.nn.Graph):
    def __init__(self):
        super().__init__()
        self.m=model

    def build(self,x,y):
        out = self.m(x,y)
        return out

graph=Graph()
out_=graph(x,y.mean())

print("graph, inplace")
print("-------------------------------------")
print(out_)

输出结果:

x : tensor([[ 0.3299, -0.2933,  0.3413],
        [-2.1822,  0.5900, -0.3539]], dtype=oneflow.float32)
y:  tensor([[-0.1691, -0.9497,  1.6760],
        [-0.4748, -0.7713, -2.3149]], dtype=oneflow.float32)
eager, 非inplace
-------------------------------------
tensor([[ 0.1608, -1.2430,  2.0173],
        [-2.6569, -0.1812, -2.6687]], dtype=oneflow.float32)
eager, inplace
-------------------------------------
tensor([[ 0.1608, -1.2430,  2.0173],
        [-2.6569, -0.1812, -2.6687]], dtype=oneflow.float32)
graph, inplace
-------------------------------------
tensor([[-0.0082, -2.1926,  3.6933],
        [-3.1317, -0.9525, -4.9836]], dtype=oneflow.float32)

@strint

@grybd grybd added the bug label Jan 18, 2022
@grybd grybd self-assigned this Jan 18, 2022
@grybd grybd linked a pull request Feb 10, 2022 that will close this issue
1 task
@strint
Copy link
Contributor

strint commented Feb 10, 2022

fixed in #7458

@strint strint closed this as completed Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants