前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >torch、(二) Generators

torch、(二) Generators

作者头像
狼啸风云
修改2022-09-03 21:42:39
1K0
修改2022-09-03 21:42:39
举报

目录

class torch._C.Generator(device='cpu') → Generator

device

get_state() → Tensor

initial_seed() → int

manual_seed(seed) → Generator

seed() → int

set_state(new_state) → void


class torch._C.Generator(device='cpu') → Generator

Creates and returns a generator object which manages the state of the algorithm that produces pseudo random numbers. Used as a keyword argument in many In-place random sampling functions.

Parameters

device (torch.device, optional) – the desired device for the generator.

Returns

An torch.Generator object.

Return type

Generator

Example:

>>> g_cpu = torch.Generator()
>>> g_cuda = torch.Generator(device='cuda')

device

Generator.device -> device

Gets the current device of the generator.

Example:

>>> g_cpu = torch.Generator()
>>> g_cpu.device
device(type='cpu')

get_state() → Tensor

Returns the Generator state as a torch.ByteTensor.

Returns

A torch.ByteTensor which contains all the necessary bits to restore a Generator to a specific point in time.

Return type

Tensor

Example:

>>> g_cpu = torch.Generator()
>>> g_cpu.get_state()

initial_seed() → int

Returns the initial seed for generating random numbers.

Example:

>>> g_cpu = torch.Generator()
>>> g_cpu.initial_seed()
2147483647

manual_seed(seed) → Generator

Sets the seed for generating random numbers. Returns a torch.Generator object. It is recommended to set a large seed, i.e. a number that has a good balance of 0 and 1 bits. Avoid having many 0 bits in the seed.

Parameters

seed (int) – The desired seed.

Returns

An torch.Generator object.

Return type

Generator

Example:

>>> g_cpu = torch.Generator()
>>> g_cpu.manual_seed(2147483647)

seed() → int

Gets a non-deterministic random number from std::random_device or the current time and uses it to seed a Generator.

Example:

>>> g_cpu = torch.Generator()
>>> g_cpu.seed()
1516516984916

set_state(new_state) → void

Sets the Generator state.

Parameters

new_state (torch.ByteTensor) – The desired state.

Example:

>>> g_cpu = torch.Generator()
>>> g_cpu_other = torch.Generator()
>>> g_cpu.set_state(g_cpu_other.get_state())
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年09月23日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • class torch._C.Generator(device='cpu') → Generator
  • device
  • get_state() → Tensor
  • initial_seed() → int
  • manual_seed(seed) → Generator
  • seed() → int
  • set_state(new_state) → void
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档