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

[Dy2stat]Add naming rule if not specific InputSpec.name #26997

Merged
merged 4 commits into from
Sep 9, 2020

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented Sep 3, 2020

PR types

New features

PR changes

Others

Describe

Add naming rule if not specific InputSpec.name.

Naming rule

1. Already specific name

If InputSpec.name is not None, do nothing.

2. Single argument single InputSpec

If each argument x corresponds to an InputSpec, using the argument name like x

def foo(x, y):
    return x + y

foo = to_static(foo, input_spec=[InputSpec([None, 10]), InputSpec([None])])
print([in_var.name for in_var in foo.inputs])  # [x, y]

3. Argument with list

If the arguments inputs corresponds to a list(InputSpec), using name like inputs_0, inputs_1

def foo(inputs):
    return inputs[0] + inputs[1]

foo = to_static(foo, input_spec=[[InputSpec([None, 10]), InputSpec([None])]])
print([in_var.name for in_var in foo.inputs])  # [inputs_0, inputs_1]

4. Argument with dict

If the arguments input_dic corresponds to a dict(InputSpec), using key as name.

def foo(inputs):
    return inputs['x'] + inputs['y']

 foo = to_static(foo, input_spec=[{'x': InputSpec([None, 10]), 'y': InputSpec([None])}])
print([in_var.name for in_var in foo.inputs])  # [x, y]

@paddle-bot-old
Copy link

paddle-bot-old bot commented Sep 3, 2020

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

@Aurelius84 Aurelius84 closed this Sep 7, 2020
@Aurelius84 Aurelius84 reopened this Sep 7, 2020
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Sep 7, 2020
@PaddlePaddle PaddlePaddle unlocked this conversation Sep 7, 2020
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Sep 7, 2020
@PaddlePaddle PaddlePaddle unlocked this conversation Sep 7, 2020
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

Adds default name according to argument name from decorated function
if without specificing InputSpec.name

The naming rule are as followed:
Copy link
Member

Choose a reason for hiding this comment

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

Tiny English grammar issue:

"The naming rule is" or "The naming rules are".

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

@Aurelius84 Aurelius84 merged commit 252aeb1 into PaddlePaddle:develop Sep 9, 2020
@Aurelius84 Aurelius84 deleted the default_input_name branch April 12, 2021 03:37
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.

None yet

3 participants