mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
[C++ API] Add backward() to Tensor and Variable (#7750)
* Add backward() to Tensor and Variable * Added a couple tests
This commit is contained in:
committed by
GitHub
parent
e5b830eb0e
commit
1e2762796f
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user