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

supplet several interface of static Variable to consistent with dygraph Tensor #33330

Merged
merged 36 commits into from
Jun 24, 2021

Conversation

CtfGo
Copy link
Contributor

@CtfGo CtfGo commented Jun 3, 2021

PR types

New features

PR changes

APIs

Describe

supplet several interface of static Variable to consistent with dygraph Tensor,including 1 property(ndim) and 4 methods( ndimension,dim,size,matmul,detach), the preview of api document listed below:
image
image
image
image

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jun 3, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@CtfGo CtfGo force-pushed the variable-keeping-with-ensor branch from a3a6cf6 to e684e65 Compare June 3, 2021 12:50
CtfGo added 17 commits June 4, 2021 08:56
Aurelius84
Aurelius84 previously approved these changes Jun 15, 2021
Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM

Aurelius84
Aurelius84 previously approved these changes Jun 17, 2021
zhhsplendid
zhhsplendid previously approved these changes Jun 21, 2021
Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

I gave some comments, but you can change in next PR since you already passed some CIs.

I will approve this PR.

@@ -0,0 +1,25 @@
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

You can change in next PR:

2019 -> 2021

Returns a new Variable, detached from the current graph.
It will share data with origin Variable and always doesn't have a Tensor copy.
Copy link
Member

Choose a reason for hiding this comment

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

"and always doesn't have a Tensor copy" -> "without tensor copy"


@prog_scope()
def test_matmul(self):
a = fluid.layers.data(name='a', shape=[2, 3], dtype='float32')
Copy link
Member

Choose a reason for hiding this comment

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

You can change in next PR:

use 2.0 api instead of fluid API for the new code.

@@ -345,6 +344,52 @@ def _test():

self.assertRaises(Exception, _test)

def test_size(self):
prog = paddle.static.Program()
with fluid.program_guard(prog):
Copy link
Member

Choose a reason for hiding this comment

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

You can change in next PR:

use 2.0 api instead of fluid API for the new code.

x = fluid.data(name='x', shape=[3, 2, 1], dtype='float32')
x.persistable = True
feed_data = np.ones(shape=[3, 2, 1], dtype=np.float32)
detach_x = x.detach()
Copy link
Member

Choose a reason for hiding this comment

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

Could we also test:

  1. Change to detach_x would also change x
  2. Change to x would also change detach_x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated code with these tips, thank you.

zhhsplendid
zhhsplendid previously approved these changes Jun 23, 2021
Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM


Examples:
.. code-block:: python
:name: code-example1
Copy link
Contributor

Choose a reason for hiding this comment

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

有文档预览的结果吗?麻烦将结果截图放到PR里

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

class ShareDataOpMaker : public framework::OpProtoAndCheckerMaker {
public:
void Make() override {
AddInput("Input", "The input tensor.");
Copy link
Contributor

Choose a reason for hiding this comment

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

The input tensor of ShareData operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, used on static.Variable.detach

Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@zhangting2020 zhangting2020 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM

@zhhsplendid zhhsplendid merged commit af9dcb2 into PaddlePaddle:develop Jun 24, 2021
Aurelius84 pushed a commit to Aurelius84/Paddle that referenced this pull request Jul 26, 2021
lanxianghit pushed a commit that referenced this pull request Jul 27, 2021
…o consistent with dygraph Tensor (#33330) #34401

As the title

[cherry-pick][Dy2Stat]supplet several interface of static Variable to consistent with dygraph Tensor (#33330)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants