Skip to content

rand类函数增加seed参数 #54058

@DrownFish19

Description

@DrownFish19

需求描述 Feature Description

任务目标(请描述你正在做的项目是什么,如模型、论文、项目是什么?);

模型复现和论文代码实现

需求场景(请描述你的项目中为什么需要用此功能);

通过指定的随机数,产生相同的随机结果。在模型正向运行过程中,仅保存随机数种子即可。

功能描述(请简单描述或设计这个功能)

为rand类函数增加seed参数。

  1. randn函数:randn函数调用standard_normal函数,进而调用gaussian函数。在gaussian函数中,原作者指定seed始终为0,此处可以增加一个seed接口。
  2. rand函数:rand函数调用uniform函数,在uniform函数,原作者使用默认seed=0。

以上举例说明,增加seed参数可行,但需要修改rand类函数内部参数传递。

替代实现 Alternatives

实现方式:
1.参考pytorch, 使用generatot类进行处理,参考代码如下:

def _randn(size, dtype, device, seed):
    generator = torch.Generator(device).manual_seed(int(seed))
    return torch.randn(size, dtype=dtype, device=device, generator=generator)

2.在当前版本,仅在函数内部增加seed参数传递即可实现。

Metadata

Metadata

Assignees

Labels

PFCCPaddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfccstatus/following-up跟进中type/feature-request新需求申请

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions