Skip to content

Commit

Permalink
Add autograd create graph and strategy options for AutoDiffCostFuncti…
Browse files Browse the repository at this point in the history
  • Loading branch information
luisenp authored Jun 21, 2023
1 parent 5450659 commit b4dbbdd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion theseus/core/cost_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ def __init__(
cost_weight: Optional[CostWeight] = None,
aux_vars: Optional[Sequence[Variable]] = None,
name: Optional[str] = None,
autograd_create_graph: bool = True,
autograd_strict: bool = False,
autograd_vectorize: bool = False,
autograd_strategy: str = "reverse-mode",
autograd_mode: Union[str, AutogradMode] = AutogradMode.VMAP,
):
if cost_weight is None:
Expand All @@ -228,8 +230,10 @@ def __init__(

self._err_fn = err_fn
self._dim = dim
self._autograd_create_graph = autograd_create_graph
self._autograd_strict = autograd_strict
self._autograd_vectorize = autograd_vectorize
self._autograd_strategy = autograd_strategy

# The following are auxiliary Variable objects to hold tensor data
# during jacobian computation without modifying the original Variable objects
Expand Down Expand Up @@ -285,9 +289,10 @@ def _compute_autograd_jacobian(
return autogradF.jacobian(
jac_fn,
optim_tensors,
create_graph=True,
create_graph=self._autograd_create_graph,
strict=self._autograd_strict,
vectorize=self._autograd_vectorize,
strategy=self._autograd_strategy,
)

def _make_jac_fn_vmap(
Expand Down

0 comments on commit b4dbbdd

Please sign in to comment.