jax_privacy.optimizers.scale_then_privatize#
- jax_privacy.optimizers.scale_then_privatize(base_optimizer, eps=1e-08, eps_root=0.0, extract_preconditioner_from_state_fn=None)[source]#
Constructs an AugmentedGradientTransformation for scale-then-privatize.
This implements Algorithm 8 from Ganesh, McMahan, Thakurta (2507.01129). The key idea is to use the optimizer’s second-moment estimate \(v_{t-1}\) from the previous step to define a non-isotropic geometry for clipping and noising per-example gradients. Specifically:
\[s_t = 1 / (\sqrt{v_{t-1} + \text{eps\_root}} + \text{eps})\]Before clipping, each per-example gradient \(g\) is transformed to \(s_t \odot g\). After clipping + aggregation + noise addition, the
updatefunction applies the inverse (divides by \(s_t\)) before passing to the base optimizer’s update.A large
epsoreps_rootpassed here (but not in the adaptive optimizer’s scaling) will cause all coordinates to be scaled nearly-identically, effectively retrieving no pre-clipping transform.epsoreps_rootmatching the adaptive optimizer may add large noise in coordinates where the gradient is small. Ideally, this parameter should be tuned to tradeoff between these two regimes.- Parameters:
base_optimizer (
GradientTransformation) – A standardoptax.GradientTransformation, typically an adaptive optimizer likeoptax.adamw(...),optax.adam(...), or any chained transformation containing ascale_by_adam(or similar) component.eps (
float) – A small constant added to the denominator outside the square root when computing the scaling vector \(s_t\). Analogous to theepsparameter in Adam. This also acts as a stability constant to prevent excessively large scaling in coordinates where \(v\) is very small. Corresponds to \(\varepsilon_{s_1}\) in Algorithm 8 of the paper. See the note above on tuning this parameter.eps_root (
float) – A small constant added to \(v\) inside the square root, analogous toeps_rootinoptax.scale_by_adam(). See the note above on tuning this parameter.extract_preconditioner_from_state_fn (
Optional[Callable[[Union[Array,ndarray,bool,number,bool,int,float,complex,Iterable[optax.ArrayTree],Mapping[Any, optax.ArrayTree]]],Union[Array,ndarray,bool,number,bool,int,float,complex,Iterable[optax.ArrayTree],Mapping[Any, optax.ArrayTree]]]]) – A function that takes the optimizer state and returns the second-moment estimate (\(v\)) pytree. IfNone, uses a default implementation that handles common optax adaptive optimizers (Adam, AMSGrad, RMSProp, AdaGrad).
- Return type:
- Returns:
An
AugmentedGradientTransformationfor the scale-then-privatize technique.