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
@@ -233,6 +233,7 @@ bool test_mnist(
|
||||
}
|
||||
|
||||
TEST_CASE("integration/cartpole") {
|
||||
torch::manual_seed(0);
|
||||
std::cerr << "Training episodic policy gradient with a critic for up to 3000"
|
||||
" episodes, rest your eyes for a bit!\n";
|
||||
auto model = std::make_shared<torch::SimpleContainer>();
|
||||
@@ -331,6 +332,7 @@ TEST_CASE("integration/cartpole") {
|
||||
}
|
||||
|
||||
TEST_CASE("integration/mnist", "[cuda]") {
|
||||
torch::manual_seed(0);
|
||||
auto model = std::make_shared<torch::SimpleContainer>();
|
||||
auto conv1 = model->add(Conv2d(1, 10, 5), "conv1");
|
||||
auto conv2 = model->add(Conv2d(10, 20, 5), "conv2");
|
||||
@@ -366,6 +368,7 @@ TEST_CASE("integration/mnist", "[cuda]") {
|
||||
}
|
||||
|
||||
TEST_CASE("integration/mnist/batchnorm", "[cuda]") {
|
||||
torch::manual_seed(0);
|
||||
auto model = std::make_shared<torch::SimpleContainer>();
|
||||
auto conv1 = model->add(Conv2d(1, 10, 5), "conv1");
|
||||
auto batchnorm2d =
|
||||
|
||||
Reference in New Issue
Block a user