Skip to content

Commit

Permalink
Fix BUG of LazyInterpret FreeEagerTensor memory shared with regst (#5891
Browse files Browse the repository at this point in the history
)

* Fix BUG of LazyInterpret FreeEagerTensor memory shared with regst

* remove note

* remove debug
  • Loading branch information
chengtbf committed Aug 15, 2021
1 parent 924fb9f commit 1b04c60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Maybe<void> AddFreeEagerTensorToVariableOp(const std::shared_ptr<Tensor>& input_
const std::string graph_name = *JUST(JUST(GlobalJobBuildAndInferCtxMgr())->GetCurrentJobName());
const std::string lbn = GenLogicalBlobName(new_op_name, "out");
Global<MultiClientSessionContext>::Get()->StoreFreeEagerTensorWithNameByGraphName(
graph_name, input_tensor, lbn);
graph_name, input_tensor, new_op_name);
// NOTE(chengcheng): MUST record this eager_tensor name as new variable output lbn.
TensorNameScope::Global()->Record(input_tensor, lbn);

Expand Down
14 changes: 6 additions & 8 deletions python/oneflow/test/graph/test_graph_free_eager_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ def __init__(self):

def forward(self, x):
y0 = self.linear(x)
y1 = y0 > 0.5
eager_t = flow.tensor([0.5], dtype=y0.dtype, device=y0.device)
assert eager_t.is_eager
y2 = y0 > eager_t
z = flow.eq(y1, y2)
return z
eager_t = flow.tensor([1.0], dtype=y0.dtype, device=y0.device)
out = y0 + eager_t
return out


@unittest.skipIf(os.getenv("ONEFLOW_TEST_CPU_ONLY"), "only test cpu cases")
Expand All @@ -56,8 +53,9 @@ def build(self, x):
my_g = GraphEagerTensorCaught()
graph_out = my_g(x)
eager_out = my_net_module(x)

test_case.assertTrue(np.array_equal(graph_out.numpy(), eager_out.numpy()))
test_case.assertTrue(
np.allclose(graph_out.numpy(), eager_out.numpy(), 1e-4, 1e-4)
)


if __name__ == "__main__":
Expand Down

0 comments on commit 1b04c60

Please sign in to comment.