Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dpmodel/pt: Random methods without explicit seeds should be forbidden #3467

Closed
njzjz opened this issue Mar 15, 2024 · 1 comment · Fixed by #3773
Closed

dpmodel/pt: Random methods without explicit seeds should be forbidden #3467

njzjz opened this issue Mar 15, 2024 · 1 comment · Fixed by #3773
Assignees
Labels
Milestone

Comments

@njzjz
Copy link
Member

njzjz commented Mar 15, 2024

For new backends, random methods without explicit seeds should be forbidden, as they create unreproduced behavior.

dpmodel

rng = np.random.default_rng()
self.w = rng.normal(size=(num_in, num_out)).astype(prec)

pt

random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.device)
random_tensor.floor_() # binarize

rng = np.random.default_rng()

The following normal methods need to be provided with a torch Generator:

nn.init.normal_(self.matrix.data, std=stddev / np.sqrt(num_out + num_in))

nn.init.normal_(self.bias.data, mean=bavg, std=stddev)

nn.init.normal_(self.idt.data, mean=0.1, std=0.001)

nn.init.normal_(self.matrix.data, std=stddev / np.sqrt(num_out + num_in))

nn.init.normal_(self.bias.data, mean=bavg, std=stddev)

nn.init.normal_(self.idt.data, mean=1.0, std=0.001)

nn.init.normal_(self.matrix.data, std=stddev / np.sqrt(num_out + num_in))

nn.init.normal_(self.bias.data, mean=bavg, std=stddev)

nn.init.normal_(self.idt.data, mean=0.1, std=0.001)

nn.init.trunc_normal_(self.weight, mean=0.0, std=std)

nn.init.kaiming_normal_(self.weight, nonlinearity="linear")

nn.init.normal_(self.weight, mean=0.0, std=std)

nn.init.normal_(self.energe_agg_factor.weight, 0, 0.01)

I also noticed in some modules, torch.manual_seed is called to change the global seed after the network initlization. I don't see the meaning of them.

@wanghan-iapcm
Copy link
Collaborator

i do no think it is a issue at least in the UTs, as they do not rely on the reproducibility of the random numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants