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

[Frontend][PaddlePaddle] Remove unused parameters and fix doc string #9283

Merged
merged 38 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5b39c79
Merge pull request #2 from apache/main
jiangjiajun Aug 3, 2021
74cc942
Merge pull request #8 from apache/main
jiangjiajun Aug 13, 2021
e0420bd
Merge branch 'apache:main' into main
jiangjiajun Sep 23, 2021
f181b0a
Merge branch 'apache:main' into main
jiangjiajun Sep 24, 2021
800b187
Merge branch 'apache:main' into main
jiangjiajun Sep 26, 2021
87c6d3d
add part of operators
jiangjiajun Sep 26, 2021
39b96fc
remove part of operators
jiangjiajun Sep 26, 2021
50e3c41
add lookup
jiangjiajun Sep 26, 2021
555406e
add test
jiangjiajun Sep 26, 2021
75956db
Update paddlepaddle.py
jiangjiajun Sep 27, 2021
a3aa170
modify error message for SAME padding
jiangjiajun Sep 27, 2021
326383a
Remove some function and old version operator
jiangjiajun Sep 28, 2021
6e275c2
Remove some function and old version operator
jiangjiajun Sep 28, 2021
f8e93cb
Remove some function and old version operator
jiangjiajun Sep 28, 2021
cd4ef59
Remove some function and old version operator
jiangjiajun Sep 28, 2021
56f4ccb
Merge pull request #55 from jiangjiajun/pr001_1
jiangjiajun Sep 28, 2021
67e9816
add dot test
jiangjiajun Sep 28, 2021
98fb38a
modify doc
jiangjiajun Sep 28, 2021
201be45
remove unreviewed code
jiangjiajun Sep 29, 2021
8d865b7
Update paddlepaddle.py
jiangjiajun Sep 29, 2021
96afd3d
Update test_forward.py
jiangjiajun Sep 29, 2021
ef7a003
Update paddlepaddle.py
jiangjiajun Sep 29, 2021
43ae5ab
Update paddlepaddle.py
jiangjiajun Sep 29, 2021
8d0af49
Update test_forward.py
jiangjiajun Sep 29, 2021
509e023
Update test_forward.py
jiangjiajun Sep 29, 2021
4139fb3
Merge pull request #57 from jiangjiajun/unreviewed
jiangjiajun Sep 29, 2021
2a5e30d
Merge branch 'apache:main' into pr001
jiangjiajun Oct 4, 2021
3c34b5a
add more cases for tests
jiangjiajun Oct 4, 2021
e600036
add more cases for tests
jiangjiajun Oct 4, 2021
4887e96
Merge pull request #60 from jiangjiajun/add-more-cases
jiangjiajun Oct 4, 2021
ef4c84b
remove annotation
jiangjiajun Oct 4, 2021
5d1aa7c
reduce test case sizes
jiangjiajun Oct 5, 2021
69ddea7
Merge branch 'apache:main' into pr001
jiangjiajun Oct 8, 2021
89bf515
Merge branch 'apache:main' into paddle_frontend_1008
jiangjiajun Oct 11, 2021
c87a22e
Remove unused parameters and fix doc string for paddle frontend
jiangjiajun Oct 13, 2021
5dde918
remove blank line
jiangjiajun Oct 13, 2021
2a528ab
fix code error
jiangjiajun Oct 14, 2021
19c6b9a
modify test_forward.py
jiangjiajun Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions python/tvm/relay/frontend/paddlepaddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tvm
from tvm.ir import IRModule

from ... import nd as _nd
from .. import analysis
from .. import ty as _ty
from .. import expr as _expr
Expand Down Expand Up @@ -954,10 +955,12 @@ def extract_parameters(self, program, scope=None):
if not var.persistable:
continue
if isinstance(scope, dict):
self.params[name] = scope[name]
self.params[name] = _nd.array(scope[name])
else:
self.params[name] = np.array(scope.var(name).get_tensor())
self.nodes[name] = _expr.const(self.params[name])
self.params[name] = _nd.array(np.array(scope.var(name).get_tensor()))
shape = self.params[name].shape
dtype = self.params[name].dtype
self.nodes[name] = new_var(name, shape=shape, dtype=dtype)

def check_input_shape(self, op, block):
"""Check the shape information of model's inputs, fixed shape is recommended."""
Expand Down Expand Up @@ -1048,6 +1051,12 @@ def from_translated_layer(self, layer, shape_dict):
free_vars = analysis.free_vars(outputs)
func = _function.Function(free_vars, outputs)
mod = IRModule.from_expr(func)
# remove unused parameters
final_params = dict()
for var in free_vars:
if var.name_hint in self.params:
final_params[var.name_hint] = self.params[var.name_hint]
self.params = final_params
return mod, self.params


Expand All @@ -1056,6 +1065,24 @@ def from_paddle(program_or_layer, shape_dict=None, scope=None):

PaddlePaddle Program/TranslatedLayer represent the computation graph of PaddlePaddle model,
and PaddlePaddle scope stores all the weights of PaddlePaddle model.

Parameters
----------
program_or_layer : object of `paddle.static.Program` or `paddle.jit.TranslatedLayer`
Loaded model by `paddle.static.load_inference_model` or `paddle.jit.load`

shape_dict : dict of str to tuple/list, optional
The input shape of model

scope : object of `paddle.static.Scope`, optional
The scope that saves all the weights of model, use `paddle.static.global_scope` by default

Returns
-------
mod : tvm.IRModule
The relay module for compilation

params : dict of str to tvm.nd.NDArray
"""

import paddle
Expand Down
3 changes: 1 addition & 2 deletions tests/python/frontend/paddlepaddle/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def verify_model(func, input_data, rtol=1e-5, atol=1e-5):
baseline_outputs = (baseline_outputs.numpy(),)

mod, params = relay.frontend.from_paddle(baseline_model, input_shape_dict)
parms_num = min(len(input_names), len(mod["main"].params))
compiled_names = []
for arg in mod["main"].params[:parms_num]:
for arg in mod["main"].params:
assert arg.name_hint in input_names or arg.name_hint in params
if arg.name_hint in input_names:
compiled_names.append(arg.name_hint)
Expand Down