提交 a363d0aa 编写于 作者: 绝不原创的飞龙's avatar 绝不原创的飞龙

2024-02-05 13:58:25

上级 08918adb
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
- en: torch.random
id: totrans-0
prefs:
- PREF_H1
type: TYPE_NORMAL
zh: torch.random
- en: 原文:[https://pytorch.org/docs/stable/random.html](https://pytorch.org/docs/stable/random.html)
id: totrans-1
prefs:
- PREF_BQ
type: TYPE_NORMAL
zh: 原文:[https://pytorch.org/docs/stable/random.html](https://pytorch.org/docs/stable/random.html)
- en: '[PRE0]'
id: totrans-2
prefs: []
type: TYPE_PRE
zh: '[PRE0]'
- en: Forks the RNG, so that when you return, the RNG is reset to the state that it
was previously in.
id: totrans-3
prefs: []
type: TYPE_NORMAL
zh: 分叉RNG,以便在返回时,RNG被重置为先前的状态。
- en: Parameters
id: totrans-4
prefs: []
type: TYPE_NORMAL
zh: 参数
- en: '**devices** (*iterable* *of* *Device IDs*) devices for which to fork the
RNG. CPU RNG state is always forked. By default, [`fork_rng()`](#torch.random.fork_rng
"torch.random.fork_rng") operates on all devices, but will emit a warning if your
machine has a lot of devices, since this function will run very slowly in that
case. If you explicitly specify devices, this warning will be suppressed'
id: totrans-5
prefs:
- PREF_UL
type: TYPE_NORMAL
zh: '**devices** (*可迭代的* *设备ID*) 要分叉RNG的设备。CPU RNG状态始终被分叉。默认情况下,[`fork_rng()`](#torch.random.fork_rng
"torch.random.fork_rng")在所有设备上操作,但如果您的机器有很多设备,此函数将运行非常缓慢,将发出警告。如果您明确指定设备,则此警告将被抑制'
- en: '**enabled** ([*bool*](https://docs.python.org/3/library/functions.html#bool
"(in Python v3.12)")) if `False`, the RNG is not forked. This is a convenience
argument for easily disabling the context manager without having to delete it
and unindent your Python code under it.'
id: totrans-6
prefs:
- PREF_UL
type: TYPE_NORMAL
zh: '**enabled** ([*bool*](https://docs.python.org/3/library/functions.html#bool
"(在Python v3.12中)")) 如果为`False`,则不分叉RNG。这是一个方便的参数,可以轻松禁用上下文管理器,而无需删除它并将Python代码缩进在其下面。'
- en: '**deivce_type** ([*str*](https://docs.python.org/3/library/stdtypes.html#str
"(in Python v3.12)")) device type str, default is cuda. As for custom device,
see details in [Note: support the custom device with privateuse1]'
id: totrans-7
prefs:
- PREF_UL
type: TYPE_NORMAL
zh: '**deivce_type** ([*str*](https://docs.python.org/3/library/stdtypes.html#str
"(在Python v3.12中)")) 设备类型str,默认为cuda。至于自定义设备,请参阅[注:支持带有privateuse1的自定义设备]'
- en: Return type
id: totrans-8
prefs: []
type: TYPE_NORMAL
zh: 返回类型
- en: '[*Generator*](https://docs.python.org/3/library/typing.html#typing.Generator
"(in Python v3.12)")'
id: totrans-9
prefs: []
type: TYPE_NORMAL
zh: '[*生成器*](https://docs.python.org/3/library/typing.html#typing.Generator "(在Python
v3.12中)")'
- en: '[PRE1]'
id: totrans-10
prefs: []
type: TYPE_PRE
zh: '[PRE1]'
- en: Returns the random number generator state as a torch.ByteTensor.
id: totrans-11
prefs: []
type: TYPE_NORMAL
zh: 将随机数生成器状态返回为torch.ByteTensor。
- en: Return type
id: totrans-12
prefs: []
type: TYPE_NORMAL
zh: 返回类型
- en: '[*Tensor*](tensors.html#torch.Tensor "torch.Tensor")'
id: totrans-13
prefs: []
type: TYPE_NORMAL
zh: '[*张量*](tensors.html#torch.Tensor "torch.Tensor")'
- en: '[PRE2]'
id: totrans-14
prefs: []
type: TYPE_PRE
zh: '[PRE2]'
- en: Returns the initial seed for generating random numbers as a Python long.
id: totrans-15
prefs: []
type: TYPE_NORMAL
zh: 返回生成随机数的初始种子作为Python长整型。
- en: Return type
id: totrans-16
prefs: []
type: TYPE_NORMAL
zh: 返回类型
- en: '[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")'
id: totrans-17
prefs: []
type: TYPE_NORMAL
zh: '[int](https://docs.python.org/3/library/functions.html#int "(在Python v3.12中)")'
- en: '[PRE3]'
id: totrans-18
prefs: []
type: TYPE_PRE
zh: '[PRE3]'
- en: Sets the seed for generating random numbers. Returns a torch.Generator object.
id: totrans-19
prefs: []
type: TYPE_NORMAL
zh: 设置生成随机数的种子。返回一个torch.Generator对象。
- en: Parameters
id: totrans-20
prefs: []
type: TYPE_NORMAL
zh: 参数
- en: '**seed** ([*int*](https://docs.python.org/3/library/functions.html#int "(in
Python v3.12)")) The desired seed. Value must be within the inclusive range
[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]. Otherwise, a RuntimeError is
raised. Negative inputs are remapped to positive values with the formula 0xffff_ffff_ffff_ffff
+ seed.'
id: totrans-21
prefs: []
type: TYPE_NORMAL
zh: '**seed** ([*int*](https://docs.python.org/3/library/functions.html#int "(在Python
v3.12中)")) 所需种子。值必须在包含范围[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]内。否则,将引发RuntimeError。负输入将使用公式0xffff_ffff_ffff_ffff
+ seed重新映射为正值。'
- en: Return type
id: totrans-22
prefs: []
type: TYPE_NORMAL
zh: 返回类型
- en: '[*Generator*](generated/torch.Generator.html#torch.Generator "torch._C.Generator")'
id: totrans-23
prefs: []
type: TYPE_NORMAL
zh: '[*生成器*](generated/torch.Generator.html#torch.Generator "torch._C.Generator")'
- en: '[PRE4]'
id: totrans-24
prefs: []
type: TYPE_PRE
zh: '[PRE4]'
- en: Sets the seed for generating random numbers to a non-deterministic random number.
Returns a 64 bit number used to seed the RNG.
id: totrans-25
prefs: []
type: TYPE_NORMAL
zh: 将生成随机数的种子设置为非确定性随机数。返回用于种子RNG的64位数字。
- en: Return type
id: totrans-26
prefs: []
type: TYPE_NORMAL
zh: 返回类型
- en: '[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")'
id: totrans-27
prefs: []
type: TYPE_NORMAL
zh: '[int](https://docs.python.org/3/library/functions.html#int "(在Python v3.12中)")'
- en: '[PRE5]'
id: totrans-28
prefs: []
type: TYPE_PRE
zh: '[PRE5]'
- en: Sets the random number generator state.
id: totrans-29
prefs: []
type: TYPE_NORMAL
zh: 设置随机数生成器状态。
- en: Parameters
id: totrans-30
prefs: []
type: TYPE_NORMAL
zh: 参数
- en: '**new_state** (*torch.ByteTensor*) The desired state'
id: totrans-31
prefs: []
type: TYPE_NORMAL
zh: '**new_state** (*torch.ByteTensor*) 所需状态'
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册