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

[Dy2Static] Refactor param_guard logic of @to_static #32867

Merged
merged 5 commits into from
May 18, 2021

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented May 12, 2021

PR types

Function optimization

PR changes

APIs

Describe

1.PR功能

  1. 重构了 param_guard的逻辑@to_static
  2. 重点覆盖解决 self.weight与各种框架容器、Python list、dict等容器搭配使用时的问题。

2. 解决方案

无论上层VarBase如何被各种容器(Python的list、dict、ParameterList)包含,最终在转为静态图时,都是以OpDesc为单位的操作的,对应于framework.py中的append_op,因此只需要在append_op进行统一的转Variable处理即可。

为什么不对Attrs dict 处理?
答:因为在append_op处的Attrs是不支持Tensor类型的。前端Python API对于参数为Tensor类型的支持方案是:将Tensor类型的参数映射一个新的Input,如slice中starts对应StartTensor。

Attr支持的类型:

enum AttrType {
  INT = 0;
  FLOAT = 1;
  STRING = 2;
  INTS = 3;
  FLOATS = 4;
  STRINGS = 5;
  BOOLEAN = 6;
  BOOLEANS = 7;
  BLOCK = 8;
  LONG = 9;
  BLOCKS = 10;
  LONGS = 11;
  FLOAT64S = 12;
}

@paddle-bot-old
Copy link

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

@Aurelius84 Aurelius84 requested a review from zhhsplendid May 17, 2021 08:05
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

inputs = kwargs.get("inputs", None)
outputs = kwargs.get("outputs", None)
with param_guard(inputs), param_guard(outputs):
op = 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.

This will not hurt performance of static graph, because it's only call once in static mode.

Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

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

LGTM for the modification of framework.py

@Aurelius84 Aurelius84 merged commit b8d493d into PaddlePaddle:develop May 18, 2021
Aurelius84 added a commit to Aurelius84/Paddle that referenced this pull request May 19, 2021
)

* Add param_guard in ParameterList to support @to_static

* Refactor param_guard of @to_static

* fix unittest failed

* add more unittest
lanxianghit pushed a commit that referenced this pull request May 20, 2021
… (#32985)

* [Dy2Static]Add param_guard in ParameterList to support @to_static

* [Dy2Static] Refactor param_guard logic of @to_static (#32867)

* Add param_guard in ParameterList to support @to_static

* Refactor param_guard of @to_static

* fix unittest failed

* add more unittest
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.

3 participants