mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
Update C++ API tests to use Catch2 (#7108)
* Update C++ API tests to use Catch2 * Update download_mnist.py to be less verbose
This commit is contained in:
committed by
Edward Z. Yang
parent
25e7d5c612
commit
afe3c2688f
@@ -0,0 +1,42 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <torch/autograd.h>
|
||||
|
||||
using namespace autograd;
|
||||
|
||||
TEST_CASE("misc") {
|
||||
SECTION("no_grad") {
|
||||
no_grad_guard guard;
|
||||
auto model = Linear(5, 2).make();
|
||||
auto x = Var(at::CPU(at::kFloat).randn({10, 5}), true);
|
||||
auto y = model->forward({x})[0];
|
||||
Variable s = y.sum();
|
||||
|
||||
backward(s);
|
||||
REQUIRE(!model->parameters()["weight"].grad().defined());
|
||||
}
|
||||
|
||||
SECTION("CPU random seed") {
|
||||
int size = 100;
|
||||
setSeed(7);
|
||||
auto x1 = Var(at::CPU(at::kFloat).randn({size}));
|
||||
setSeed(7);
|
||||
auto x2 = Var(at::CPU(at::kFloat).randn({size}));
|
||||
|
||||
auto l_inf = (x1.data() - x2.data()).abs().max().toCFloat();
|
||||
REQUIRE(l_inf < 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("misc_cuda", "[cuda]") {
|
||||
SECTION("CUDA random seed") {
|
||||
int size = 100;
|
||||
setSeed(7);
|
||||
auto x1 = Var(at::CUDA(at::kFloat).randn({size}));
|
||||
setSeed(7);
|
||||
auto x2 = Var(at::CUDA(at::kFloat).randn({size}));
|
||||
|
||||
auto l_inf = (x1.data() - x2.data()).abs().max().toCFloat();
|
||||
REQUIRE(l_inf < 1e-10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user