mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
Set random seed at the start of C++ tests (#8903)
Summary:
Sets the random seed at the start of C++ tests so that everything is super deterministic.
I made sure we only generate random values from torch instead of `std::`, so that this seed always applies. I.e. I do:
```
torch::randint(2, {2}, at::kInt64)
```
instead of
```
std::rand() % 2
```
Also got rid of the tests that test the random seeding, since it would interfere here. And the test is not useful since we just use ATen's seeding mechanism, which should work.
Fixes #7288 #7286 #7289
ebetica ezyang
Closes https://github.com/pytorch/pytorch/pull/8903
Differential Revision: D8667269
Pulled By: goldsborough
fbshipit-source-id: a833e86e156d5e68dae8c53a4b1c433cb0608b6c
This commit is contained in:
committed by
Facebook Github Bot
parent
a41d433d9d
commit
03d0a70a4d
@@ -8,6 +8,7 @@
|
||||
#include <torch/nn/modules/functional.h>
|
||||
#include <torch/nn/modules/linear.h>
|
||||
#include <torch/tensor.h>
|
||||
#include <torch/utils.h>
|
||||
|
||||
#include <test/cpp/api/util.h>
|
||||
|
||||
@@ -38,6 +39,7 @@ class NestedModel : public torch::nn::Module {
|
||||
};
|
||||
|
||||
TEST_CASE("modules") {
|
||||
torch::manual_seed(0);
|
||||
SECTION("conv") {
|
||||
SECTION("1d") {
|
||||
Conv1d model(Conv1dOptions(3, 2, 3).stride(2));
|
||||
@@ -180,10 +182,8 @@ TEST_CASE("modules") {
|
||||
y.backward();
|
||||
REQUIRE(y.ndimension() == 1);
|
||||
REQUIRE(y.size(0) == 100);
|
||||
// TODO: These two tests are flaky
|
||||
// https://github.com/pytorch/pytorch/issues/7286
|
||||
// REQUIRE(y.sum().toCFloat() < 130); // Probably
|
||||
// REQUIRE(y.sum().toCFloat() > 70); // Probably
|
||||
REQUIRE(y.sum().toCFloat() < 130); // Probably
|
||||
REQUIRE(y.sum().toCFloat() > 70); // Probably
|
||||
|
||||
dropout->eval();
|
||||
y = dropout->forward(x);
|
||||
@@ -240,6 +240,7 @@ TEST_CASE("modules") {
|
||||
}
|
||||
|
||||
TEST_CASE("modules_cuda", "[cuda]") {
|
||||
torch::manual_seed(0);
|
||||
SECTION("1") {
|
||||
Linear model(5, 2);
|
||||
model->cuda();
|
||||
|
||||
Reference in New Issue
Block a user