Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implicit/truncated backward modes #29

Merged
merged 14 commits into from
Jan 19, 2022
Prev Previous commit
Next Next commit
update backward tests
  • Loading branch information
bamos committed Jan 19, 2022
commit 41e7b46afc5ab20fe320736517eb4197e0789aa6
23 changes: 11 additions & 12 deletions theseus/optimizer/nonlinear/tests/test_backwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,16 @@ def fit_x(data_x_np):
].squeeze()
assert torch.allclose(da_dx_numeric, da_dx_full, atol=1e-3)

# TODO: Debug a little more
# updated_inputs, info = theseus_optim.forward(
# theseus_inputs,
# track_best_solution=True, verbose=False,
# backward_mode=th.BackwardMode.IMPLICIT,
# )
# da_dx_implicit = torch.autograd.grad(
# updated_inputs['a'], data_x,
# retain_graph=True)[0].squeeze()
# EPS=1e-3
# assert torch.allclose(da_dx_numeric, da_dx_implicit, atol=EPS)
updated_inputs, info = theseus_optim.forward(
theseus_inputs,
track_best_solution=True,
verbose=False,
backward_mode=th.BackwardMode.IMPLICIT,
)
da_dx_implicit = torch.autograd.grad(
updated_inputs["a"], data_x, retain_graph=True
)[0].squeeze()
assert torch.allclose(da_dx_numeric, da_dx_implicit, atol=1e-4)

updated_inputs, info = theseus_optim.forward(
theseus_inputs,
Expand All @@ -112,7 +111,7 @@ def fit_x(data_x_np):
da_dx_truncated = torch.autograd.grad(
updated_inputs["a"], data_x, retain_graph=True
)[0].squeeze()
assert torch.allclose(da_dx_numeric, da_dx_truncated, atol=1e-1)
assert torch.allclose(da_dx_numeric, da_dx_truncated, atol=1e-4)


test_backwards()