Skip to content

Training, adaptation, compression, and systems techniques · Training, fine-tuning, adaptation, compression, and systems techniques · TRN035 · Training method

Differentially private SGD

Combines per-example gradient clipping, calibrated noise, and privacy accounting to limit information revealed about training records.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through learn.torch_mlp, synth.flow, synth.flow_matching, synth.gan, synth.tvae. The reference's example ran here in one language.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Combines per-example gradient clipping, calibrated noise, and privacy accounting to limit information revealed about training records.

Question / hypotheses

Does this intervention improve the intended quality, adaptation, resource, or reliability objective under a controlled comparison? It defines a method, not an intrinsic null-hypothesis test.

Architecture / computational structure

Per-example gradients are clipped before averaging; Gaussian noise is added to the aggregate; an accountant composes privacy loss over steps.

Assumptions

The privacy unit, neighboring-dataset definition, sampling mechanism, clipping sensitivity, and accountant must match the implementation. Ordinary minibatch gradient clipping is insufficient.

Formula / computational definition

gˉi=gi/max⁡(1,∥gi∥/C),g~=B−1[∑igˉi+N(0,σ2C2I)].\bar g_i=g_i/\max(1,\|g_i\|/C),\quad\tilde g=B^{-1}[\sum_i\bar g_i+\mathcal N(0,\sigma^2C^2I)].

Parameters and notation

Learned: model weights. Hyperparameters: clipping C, noise multiplier sigma, sampling rate, steps, target delta, accountant, privacy unit. Epsilon is derived under the complete accounting setup.

Fitting, fine-tuning, and adaptation

Fine-tune with a supported per-sample-gradient engine, ensure preprocessing and hyperparameter selection are included in the privacy analysis when required, and report privacy/utility tradeoffs.

How to use and calibrate

Evaluate task quality, subgroup behavior, and certified epsilon/delta under an explicit threat model. Example: adapt a model on permitted sensitive data with a defined privacy requirement.

Example application

adapt a model on permitted sensitive data with a defined privacy requirement.

Interpretation / pitfalls

Watch out

The toy computes one noisy clipped gradient but supplies no privacy guarantee without sampling and composition accounting. Record-level privacy does not automatically provide user-level privacy.

Python and R code examples

Scope: numerical mechanism demonstration. Validation: Python executed successfully on the supplied synthetic inputs; R reviewed but not executed (Rscript unavailable).

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — numerical mechanism demonstration. · needs numpy

import numpy as np
G=np.array([[3.,4.],[.3,.4]]); C=1.; sigma=.5; rng=np.random.default_rng(7)
clipped=G/np.maximum(1,np.linalg.norm(G,axis=1,keepdims=True)/C)
print((clipped.sum(0)+rng.normal(0,sigma*C,2))/len(G))
R

Component demo, not a trained model — numerical mechanism demonstration.

set.seed(7); G <- rbind(c(3,4),c(.3,.4)); C <- 1; sigma <- .5
clipped <- G/pmax(1,sqrt(rowSums(G^2))/C)
print((colSums(clipped)+rnorm(2,sd=sigma*C))/nrow(G))

Sources

From the CodeSplash reference, entry TRN035.