-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[JitLayer]Pybind JitLayer VarBase Function and add python UT #44010
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a0036a3
Pybind JitLayer VarBase Function and add python UT
0x45f dd8c13c
Add multi program load UT
0x45f 64b92d0
Fix UT place error
0x45f e0a3316
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
0x45f e051af3
Update jit.save param name
0x45f c1073aa
Remove some comments
0x45f 5a55f92
Polish cmakelists
0x45f 8face41
Polish JitLayer in Python
0x45f e244533
Fix comments
0x45f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import paddle | ||
import unittest | ||
import tempfile | ||
import numpy as np | ||
from paddle.static import InputSpec | ||
from paddle.fluid.framework import _enable_legacy_dygraph | ||
from paddle.fluid.dygraph.jit import JitLayer | ||
from paddle.fluid.dygraph.dygraph_to_static.program_translator import ProgramTranslator | ||
|
||
_enable_legacy_dygraph() | ||
paddle.seed(1) | ||
|
||
|
||
class Net(paddle.nn.Layer): | ||
|
||
def __init__(self): | ||
super(Net, self).__init__() | ||
self.fc1 = paddle.nn.Linear(4, 4) | ||
self.fc2 = paddle.nn.Linear(4, 4) | ||
self._bias = 0.4 | ||
|
||
@paddle.jit.to_static(input_spec=[InputSpec([None, 4], dtype='float32')]) | ||
def forward(self, x): | ||
out = self.fc1(x) | ||
out = self.fc2(out) | ||
out = paddle.nn.functional.relu(out) | ||
out = paddle.mean(out) | ||
return out | ||
|
||
@paddle.jit.to_static(input_spec=[InputSpec([None, 4], dtype='float32')]) | ||
def infer(self, input): | ||
out = self.fc2(input) | ||
out = out + self._bias | ||
out = paddle.mean(out) | ||
return out | ||
|
||
|
||
class TestMultiLoad(unittest.TestCase): | ||
|
||
def test_multi_load(self): | ||
self.temp_dir = tempfile.TemporaryDirectory() | ||
|
||
x = paddle.full([2, 4], 2) | ||
model = Net() | ||
program_translator = ProgramTranslator() | ||
program_translator.enable(False) | ||
forward_out1 = model.forward(x) | ||
infer_out1 = model.infer(x) | ||
program_translator.enable(True) | ||
|
||
model_path = os.path.join(self.temp_dir.name, 'multi_program') | ||
paddle.jit.save(model, model_path, combine_params=True) | ||
place = paddle.CPUPlace() | ||
if paddle.is_compiled_with_cuda(): | ||
place = paddle.CUDAPlace(0) | ||
jit_layer = JitLayer(model_path, place) | ||
forward_out2 = jit_layer.forward(x) | ||
infer_out2 = jit_layer.infer(x) | ||
self.assertEqual(np.allclose(forward_out1, forward_out2[0]), True) | ||
self.assertEqual(np.allclose(infer_out1, infer_out2[0]), True) | ||
|
||
self.temp_dir.cleanup() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里三个头文件都是不需要的吧?