Add SPSA (Simultaneous Perturbation Stochastic Approximation) optimizer to contrib - #1753
Open
jaideeppyne wants to merge 4 commits into
Open
Add SPSA (Simultaneous Perturbation Stochastic Approximation) optimizer to contrib#1753jaideeppyne wants to merge 4 commits into
jaideeppyne wants to merge 4 commits into
Conversation
SPSA (Spall, 1992) is a gradient-free optimizer that estimates the whole gradient from only two objective evaluations per step, regardless of the number of parameters. This is useful when the objective is non-differentiable, a black box, or expensive to differentiate. Implements it following the obj_fn/ExtraArgs convention already used by `hutchinson_estimator_diag_hessian`: - `spsa_gradient(...)`: a `GradientTransformationExtraArgs` returning the SPSA gradient estimate (two `obj_fn` evaluations, +/-1 perturbation, decaying perturbation size `c_k = c / (k+1)**gamma`). - `spsa(learning_rate, ...)`: convenience optimizer chaining the estimator with a step size. Adds a dedicated test file covering convergence on a convex objective (scalar and pytree params), unbiasedness of the estimator (its mean recovers the true gradient), state handling, and error cases. Resolves google-deepmind#357.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@googlebot I signed it! |
The jax=0.5.3 test matrix does not install chex; use a plain dtype assertion instead so the module imports everywhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #357 (labeled
help wanted).What
Adds SPSA (Simultaneous Perturbation Stochastic Approximation; Spall, 1992) to
optax.contrib. SPSA is a gradient-free optimizer: it estimates the entire gradient from only two objective evaluations per step, independent of the number of parameters. That makes it useful when the objective is non-differentiable, only available as a black box, or expensive to differentiate — a capability optax doesn't currently offer.Design
It follows the
obj_fn/GradientTransformationExtraArgsconvention already established byhutchinson_estimator_diag_hessian(the objective is passed at update time via theobj_fnkeyword, and the incominggradsare ignored):spsa_gradient(c=0.1, gamma=0.101, seed=None)— returns the SPSA gradient estimate. At step k it draws a ±1 perturbationΔ_k, evaluatesf(θ ± c_k Δ_k)withc_k = c / (k+1)**gamma, and returns((f₊ − f₋) / (2 c_k)) · Δ_k(using1/Δᵢ = ΔᵢforΔᵢ ∈ {−1,+1}).spsa(learning_rate, ...)— convenience optimizer chaining the estimator with a step size (optax.scale_by_learning_rate). Spall's classic decayinga_kcan be supplied via a schedule.Tests
Dedicated
_spsa_test.py:atol=5e-2).ValueErroron missingobj_fn/params.All tests pass. It is gradient-free (ignores incoming grads and needs
obj_fn), so it lives in its own test file rather than the gradient-based_common_test.pyharness — happy to wire it into_common_test.pytoo if you'd prefer.