2020-12-20 13:15:07 +08:00
|
|
|
# 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.
|
2021-08-17 15:29:30 +08:00
|
|
|
from functools import wraps
|
2020-12-20 13:15:07 +08:00
|
|
|
|
2020-12-01 18:13:30 +08:00
|
|
|
from paddle import distributed as dist
|
|
|
|
|
2020-12-09 15:58:39 +08:00
|
|
|
__all__ = ["rank_zero_only"]
|
|
|
|
|
|
|
|
|
2020-12-01 18:13:30 +08:00
|
|
|
def rank_zero_only(func):
|
|
|
|
@wraps(func)
|
|
|
|
def wrapper(*args, **kwargs):
|
2021-02-18 19:09:54 +08:00
|
|
|
if dist.get_rank() != 0:
|
2020-12-20 13:15:07 +08:00
|
|
|
return
|
2020-12-01 18:13:30 +08:00
|
|
|
result = func(*args, **kwargs)
|
|
|
|
return result
|
|
|
|
|
2020-12-20 13:15:07 +08:00
|
|
|
return wrapper
|