同步操作将从 PaddlePaddle/Paddle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# 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.# TODO: define random apiimport paddle.fluid as fluidfrom paddle.fluid import core__all__ = []def seed(seed):"""Sets the seed for global default generator, which manages the random number generation.Args:seed(int): The random seed to set. It is recommend to set a large int number.Returns:Generator: The global default generator object.Examples:.. code-block:: pythonimport paddlegen = paddle.seed(102)"""#TODO(zhiqiu): 1. remove program.random_seed when all random-related op upgrade# 2. support gpu generator by global deviceseed = int(seed)if core.is_compiled_with_cuda():for i in range(core.get_cuda_device_count()):core.default_cuda_generator(i)._is_init_py = Truecore.default_cuda_generator(i).manual_seed(seed)core.default_cpu_generator()._is_init_py = Truereturn core.default_cpu_generator().manual_seed(seed)def get_cuda_rng_state():"""Get random state of cuda generators.Args:NoneReturns:GeneratorState: object.Examples:.. code-block:: pythonimport paddlests = paddle.get_cuda_rng_state()"""state_list = []if core.is_compiled_with_cuda():for i in range(core.get_cuda_device_count()):state_list.append(core.default_cuda_generator(i).get_state())return state_listdef set_cuda_rng_state(state_list):"""Sets generator state for all cuda generatorsArgs:state_list(list|tuple): The cuda states to set back to cuda generators. state_list is obtained from get_cuda_rng_state().Returns:NoneExamples:.. code-block:: pythonimport paddlests = paddle.get_cuda_rng_state()paddle.set_cuda_rng_state(sts)"""if core.is_compiled_with_cuda():if not len(state_list) == core.get_cuda_device_count():raise ValueError("Length of cuda state list shoule be equal to the cuda device count")for i in range(core.get_cuda_device_count()):core.default_cuda_generator(i).set_state(state_list[i])def _manual_program_seed(seed):"""Sets global seed for generating random numbers.NOTE(zhiqiu): This is the original implemention of seed. Keeps it temporallysince CUDA generator is not developed, so we need it in the unittest.Args:seed(int): The random seed to set. It is recommend to set a large int number.Returns:None"""fluid.default_main_program().random_seed = seedfluid.default_startup_program().random_seed = seedprogram = fluid.Program()program.global_seed(seed)def set_random_seed_generator(name, seed):core.set_random_seed_generator(name, seed)def get_random_seed_generator(name):return core.get_random_seed_generator(name)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。