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

DLM gradients #161

Merged
merged 23 commits into from
Jun 7, 2022
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion theseus/optimizer/nonlinear/tests/test_backwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def quad_error_fn(optim_vars, aux_vars):
optimizer = th.GaussNewton(
objective,
max_iterations=15,
step_size=0.5,
step_size=1.0,
)

theseus_inputs = {
Expand Down Expand Up @@ -119,3 +119,19 @@ def fit_x(data_x_np):
updated_inputs["a"], data_x, retain_graph=True
)[0].squeeze()
assert torch.allclose(da_dx_numeric, da_dx_truncated, atol=1e-4)

updated_inputs, _ = theseus_optim.forward(
theseus_inputs,
optimizer_kwargs={
"track_best_solution": True,
"verbose": False,
"backward_mode": th.BackwardMode.DLM,
"dlm_epsilon": 0.001,
},
)
da_dx_truncated = torch.autograd.grad(
updated_inputs["a"], data_x, retain_graph=True
)[0].squeeze()
print(da_dx_numeric)
print(da_dx_truncated)
rtqichen marked this conversation as resolved.
Show resolved Hide resolved
assert torch.allclose(da_dx_numeric, da_dx_truncated, atol=1e-3)