jax_privacy.training#
End-to-end training loop for differentially private training.
This module provides DPTrainer, a class that
encapsulates the static configuration for a DP training loop (execution plan,
loss function, optimizer) and exposes a reusable train_step that can be
independently JIT-compiled or ahead-of-time compiled.
Design notes: This module aims to provide a framework-agnostic and model agnostic DP training loop that can be easily configured to use a variety of mechanism variants and performance knobs. Since it is defined in terms of an ExecutionPlanConfig object, it automatically works with any mechanism plan supported by our Tier 2 API.
Because it is designed to be framework and model-agnostic, there are a few things that are explicitly out of scope, like checkpointing and metrics logging. Callers are expected to implement these things themselves via dependency injection through the callback_fn option.
Example Usage:
>>> def loss_fn(params, batch, prng):
... return jax.numpy.mean((params - batch) ** 2), {}
>>> cfg = BandMFConfig.default(1, 5, 5, noise_multiplier=0.0)
>>> trainer = DPTrainer(config=cfg, loss_fn=loss_fn, optimizer=optax.sgd(0.5))
>>> data, in_c, out_c = np.zeros((8, 2)), np.ones((4, 2)), -np.ones((4, 2))
>>> params0 = np.zeros(2)
>>> state0 = trainer.init(params0)
>>> state = trainer.fit(np.vstack([data, in_c]), state0, rng_or_seed=0)
>>> auditor = audit(loss_fn, state.params, in_c, out_c, params0)
>>> auditor.attack_auroc()
1.0
Functions
|
Scores held-in and held-out canaries and returns an auditor. |
Classes
|
Stateless trainer encapsulating the static configuration of a DP loop. |
|
Expected contract for loss functions used in DP training. |
|
Container for the state of the training loop. |