Skip to content

Commit

Permalink
add paddle version check help function (PaddlePaddle#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoxiaWang authored Aug 22, 2022
1 parent a813f64 commit afce826
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 5 additions & 3 deletions fleetx/core/engine/eager_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from fleetx.core.engine.basic_engine import BasicEngine
from fleetx.core.module.basic_module import BasicModule
from fleetx.utils.tensor_fusion_helper import all_reduce_parameters
from fleetx.utils.version import version_check


class EagerEngine(BasicEngine):
Expand Down Expand Up @@ -81,6 +82,7 @@ def configure_optimizers(self):
"""
super().__init__()
version_check()

self.mode = mode

Expand Down Expand Up @@ -492,8 +494,8 @@ def load(self):
opt_dict = paddle.load(opt_path)
self._module.optimizer.set_state_dict(opt_dict)
else:
raise ValueError("No optimizer checkpoint file found in %s." %
opt_path)
raise ValueError(
"No optimizer checkpoint file found in %s." % opt_path)

if os.path.exists(meta_path):
meta_dict = paddle.load(meta_path)
Expand All @@ -507,7 +509,7 @@ def load(self):
self._module.global_step = resume_step
else:
raise ValueError("No meta checkpoint file found in %s." %
meta_path)
meta_path)

logger.info("successfully load checkpoints")
else:
Expand Down
3 changes: 2 additions & 1 deletion fleetx/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def _download(url, fullname):
def download(url, path):
local_rank = 0
world_size = 1
if paddle.fluid.core.is_compiled_with_dist():
if paddle.fluid.core.is_compiled_with_dist(
) and paddle.distributed.get_world_size() > 1:
local_rank = paddle.distributed.ParallelEnv().dev_id
world_size = paddle.distributed.get_world_size()
if world_size > 1 and local_rank != 0:
Expand Down
21 changes: 21 additions & 0 deletions fleetx/utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2022 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 paddle


def version_check():
version = paddle.version.full_version
if version != '0.0.0':
paddle.utils.require_version(min_version='2.3.0')

0 comments on commit afce826

Please sign in to comment.