[C++ API] Add backward() to Tensor and Variable (#7750)

* Add backward() to Tensor and Variable

* Added a couple tests
This commit is contained in:
Peter Goldsborough
2018-05-22 10:43:04 -07:00
committed by GitHub
parent e5b830eb0e
commit 1e2762796f
19 changed files with 127 additions and 72 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ TEST_CASE("module/zero-grad") {
auto model = Linear(3, 4).build();
auto weight = Var(at::ones(at::CPU(at::kFloat), {8, 3}));
auto loss = model->forward({weight}).front().sum();
backward(loss);
loss.backward();
for (auto& parameter : model->parameters()) {
Variable grad = parameter.second.grad();
REQUIRE(grad.defined());