Bug fix: allow std 0 in the meta definition of `normal_` (#70085)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70085
All other `normal` variants allow 0. Looks like a mistake made while
copying the check. Even the `normal_` implementation disagrees:
```
>>> t = torch.rand(2, 3, device='meta')
>>> t.normal_(mean=4, std=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: normal_ expects std > 0.0, but found std=0
>>>
>>>
>>> t = torch.rand(2, 3)
>>> t.normal_(mean=4, std=0)
tensor([[4., 4., 4.],
[4., 4., 4.]])
```
Fixes #69523.
Test Plan: Imported from OSS
Reviewed By: davidberard98
Differential Revision: D34089967
Pulled By: bdhirsh
fbshipit-source-id: c57963e55f06c9513c4f0839f8f7a21eca86b584
(cherry picked from commit d6ffe43ddddd24daa5d9eb8befc852dd2108fc89)
diff --git a/aten/src/ATen/native/Distributions.cpp b/aten/src/ATen/native/Distributions.cpp
index b4063af..9ba10eb 100644
--- a/aten/src/ATen/native/Distributions.cpp
+++ b/aten/src/ATen/native/Distributions.cpp
@@ -262,7 +262,7 @@
}
Tensor& normal_meta_(Tensor& self, double mean, double std, c10::optional<Generator> gen) {
- TORCH_CHECK(std > 0.0, "normal_ expects std > 0.0, but found std=", std); // TODO: dedupe
+ TORCH_CHECK(std >= 0.0, "normal_ expects std >= 0.0, but found std=", std); // TODO: dedupe
return self;
}