forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NPU] Support npu save load (PaddlePaddle#31893)
* support save load for NPU * add save load npu unittest * support np.array transform in NPU * fix errors * delete dygraph in unittest * add Wait * fix unittest * fix review comment * fix unittest problem * fix little problem
- Loading branch information
Showing
9 changed files
with
355 additions
and
40 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Copyright (c) 2021 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. */ | ||
|
||
#include "paddle/fluid/operators/load_combine_op.h" | ||
|
||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OP_NPU_KERNEL( | ||
load_combine, | ||
ops::LoadCombineOpKernel<paddle::platform::NPUDeviceContext, float>, | ||
ops::LoadCombineOpKernel<paddle::platform::NPUDeviceContext, double>, | ||
ops::LoadCombineOpKernel<paddle::platform::NPUDeviceContext, int>, | ||
ops::LoadCombineOpKernel<paddle::platform::NPUDeviceContext, int8_t>, | ||
ops::LoadCombineOpKernel<paddle::platform::NPUDeviceContext, int64_t>); |
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,24 @@ | ||
/* Copyright (c) 2021 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. */ | ||
|
||
#include "paddle/fluid/operators/load_op.h" | ||
|
||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OP_NPU_KERNEL( | ||
load, ops::LoadOpKernel<paddle::platform::NPUDeviceContext, float>, | ||
ops::LoadOpKernel<paddle::platform::NPUDeviceContext, double>, | ||
ops::LoadOpKernel<paddle::platform::NPUDeviceContext, int>, | ||
ops::LoadOpKernel<paddle::platform::NPUDeviceContext, int8_t>, | ||
ops::LoadOpKernel<paddle::platform::NPUDeviceContext, int64_t>); |
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,24 @@ | ||
/* Copyright (c) 2021 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. */ | ||
|
||
#include "paddle/fluid/operators/save_combine_op.h" | ||
|
||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OP_NPU_KERNEL( | ||
save_combine, | ||
ops::SaveCombineOpKernel<paddle::platform::NPUDeviceContext, float>, | ||
ops::SaveCombineOpKernel<paddle::platform::NPUDeviceContext, double>, | ||
ops::SaveCombineOpKernel<paddle::platform::NPUDeviceContext, int>, | ||
ops::SaveCombineOpKernel<paddle::platform::NPUDeviceContext, int64_t>); |
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,28 @@ | ||
/* Copyright (c) 2021 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. */ | ||
|
||
#include "paddle/fluid/operators/save_op.h" | ||
#include "paddle/fluid/platform/float16.h" | ||
|
||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OP_NPU_KERNEL( | ||
save, ops::SaveOpKernel<paddle::platform::NPUDeviceContext, float>, | ||
ops::SaveOpKernel<paddle::platform::NPUDeviceContext, double>, | ||
ops::SaveOpKernel<paddle::platform::NPUDeviceContext, int>, | ||
ops::SaveOpKernel<paddle::platform::NPUDeviceContext, uint8_t>, | ||
ops::SaveOpKernel<paddle::platform::NPUDeviceContext, int8_t>, | ||
ops::SaveOpKernel<paddle::platform::NPUDeviceContext, int64_t>, | ||
ops::SaveOpKernel<paddle::platform::NPUDeviceContext, | ||
paddle::platform::float16>); |
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
108 changes: 108 additions & 0 deletions
108
python/paddle/fluid/tests/unittests/npu/test_save_load_npu.py
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,108 @@ | ||
# Copyright (c) 2021 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. | ||
|
||
from __future__ import print_function | ||
|
||
import unittest | ||
import sys | ||
sys.path.append("..") | ||
import paddle | ||
import paddle.fluid as fluid | ||
import paddle.fluid.core as core | ||
from paddle.nn import Embedding | ||
import paddle.fluid.framework as framework | ||
from paddle.fluid.optimizer import Adam | ||
from paddle.fluid.dygraph.base import to_variable | ||
from test_imperative_base import new_program_scope | ||
from paddle.fluid.executor import global_scope | ||
import numpy as np | ||
import six | ||
import pickle | ||
import os | ||
import errno | ||
from test_static_save_load import * | ||
|
||
paddle.enable_static() | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPUSaveLoadBase(TestSaveLoadBase): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPUSaveLoadPartial(TestSaveLoadPartial): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPUSaveLoadSetStateDict(TestSaveLoadSetStateDict): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPUProgramStatePartial(TestProgramStatePartial): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPULoadFromOldInterface(TestLoadFromOldInterface): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPULoadFromOldInterfaceSingleFile(TestLoadFromOldInterfaceSingleFile): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPUProgramStateOldSave(TestProgramStateOldSave): | ||
def setUp(self): | ||
self.test_dygraph = False | ||
|
||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
@unittest.skipIf(not paddle.is_compiled_with_npu(), | ||
"core is not compiled with NPU") | ||
class TestNPUProgramStateOldSaveSingleModel(TestProgramStateOldSaveSingleModel): | ||
def set_place(self): | ||
return fluid.CPUPlace() if not core.is_compiled_with_npu( | ||
) else paddle.NPUPlace(0) | ||
|
||
|
||
if __name__ == '__main__': | ||
paddle.enable_static() | ||
unittest.main() |
Oops, something went wrong.