Skip to content

Commit

Permalink
Make sparse jacobian/hessian threashold configurable
Browse files Browse the repository at this point in the history
Summary:
The threshold was previously hardcoded to 200, but can now be configured while maintaining the default value (no behavioral changes for downstream users unless explicitly modified).

Additionally, enforcing dense Jacobian/Hessian for retargeter benchmark improved performance from 3.22 ms to 2.93 ms by increasing the threshold configuration to 300 (where the parameter size is 204, so enforcing to dense jacobian/hessian).

Reviewed By: yutingye

Differential Revision: D69091231

fbshipit-source-id: 2fe8bb29f17e8ef224a5001e3dd19140d73fbb68
  • Loading branch information
jeongseok-meta authored and facebook-github-bot committed Feb 4, 2025
1 parent 2e9bc0c commit e1d536a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion momentum/solver/gauss_newton_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void GaussNewtonSolverT<T>::setOptions(const SolverOptions& options) {
doLineSearch_ = derivedOptions->doLineSearch;
useBlockJtJ_ = derivedOptions->useBlockJtJ;
directSparseJtJ_ = derivedOptions->directSparseJtJ;
sparseMatrixThreshold_ = derivedOptions->sparseMatrixThreshold;
}
}

Expand All @@ -49,7 +50,7 @@ void GaussNewtonSolverT<T>::initializeSolver() {
this->newParameterPattern_ = true;
this->lastError_ = std::numeric_limits<double>::max();

denseIteration_ = this->numParameters_ < 200;
denseIteration_ = this->numParameters_ < sparseMatrixThreshold_;
}

template <typename T>
Expand Down
5 changes: 5 additions & 0 deletions momentum/solver/gauss_newton_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct GaussNewtonSolverOptions : SolverOptions {
/// to true.
bool directSparseJtJ = false;

/// The minimum number of parameters required to switch from dense to sparse matrix
/// representations for Jacobian and Hessian computations.
size_t sparseMatrixThreshold = 200;

GaussNewtonSolverOptions() = default;

/* implicit */ GaussNewtonSolverOptions(const SolverOptions& baseOptions)
Expand Down Expand Up @@ -55,6 +59,7 @@ class GaussNewtonSolverT : public SolverT<T> {

bool useBlockJtJ_{};
bool directSparseJtJ_{};
size_t sparseMatrixThreshold_{200};
bool initialized_;
bool doLineSearch_;

Expand Down

0 comments on commit e1d536a

Please sign in to comment.