optimization-dp-sgd

Optimizationopacusrigorous codebase

Description

Differentially Private SGD: Privacy-Utility Optimization

Research Question

Design an improved DP-SGD variant that achieves better privacy-utility tradeoff — higher test accuracy under the same (epsilon, delta)-differential privacy budget.

Background

Differentially Private Stochastic Gradient Descent (DP-SGD) [Abadi et al., 2016] enables training deep learning models with formal privacy guarantees. The core mechanism has two steps: (1) clip each per-sample gradient to a fixed norm C, and (2) add calibrated Gaussian noise proportional to C. The noise level is determined by the desired privacy budget (epsilon, delta).

The standard approach uses a fixed clipping threshold and constant noise throughout training, which is suboptimal: gradient magnitudes change during training, the fixed threshold either over-clips (losing signal) or under-clips (adding excess noise), and the uniform noise allocation ignores the varying informativeness of gradients across training stages.

Task

Modify the DPMechanism class in custom_dpsgd.py. Your mechanism receives per-sample gradients and must return aggregated noised gradients. You control the gradient clipping strategy, noise calibration, and any per-step adaptations.

Interface

class DPMechanism:
    def __init__(self, max_grad_norm, noise_multiplier, n_params,
                 dataset_size, batch_size, epochs, target_epsilon, target_delta):
        ...

    def clip_and_noise(self, per_sample_grads, step, epoch) -> list[Tensor]:
        # per_sample_grads: list of tensors [B, *param_shape]
        # Returns: list of noised gradients [*param_shape]
        ...

    def get_effective_sigma(self, step, epoch) -> float:
        # Returns current noise multiplier for privacy accounting
        ...

Constraints

  • The total privacy budget (target_epsilon, target_delta) is FIXED and checked externally.
  • The model architecture, data pipeline, optimizer, and training loop are FIXED.
  • Focus on algorithmic innovation in the DP mechanism: clipping strategies, noise schedules, gradient processing.
  • Available imports: torch, math, numpy (via the FIXED section), scipy.optimize.

Evaluation

Trained and evaluated on three datasets at epsilon=3.0, delta=1e-5:

  • MNIST (28x28 grayscale digits, 10 classes)
  • Fashion-MNIST (28x28 grayscale clothing, 10 classes)
  • CIFAR-10 (32x32 color images, 10 classes)

Metric: test accuracy (higher is better) under the same privacy budget.

Code

custom_dpsgd.py
EditableRead-only
1#!/usr/bin/env python3
2"""DP-SGD benchmark for MLS-Bench: Differentially Private Stochastic Gradient Descent.
3
4FIXED sections: model architecture, data loading, privacy accounting, evaluation loop.
5EDITABLE section: DPMechanism class — gradient clipping strategy, noise calibration,
6 and per-step privacy mechanism modifications.
7
8The agent must implement a DPMechanism that achieves better privacy-utility tradeoff
9than standard DP-SGD while respecting the same total privacy budget (epsilon, delta).
10"""
11import argparse
12import math
13import os
14import sys
15

Results

ModelTypeepsilon mnist best accuracy mnist epsilon fmnist best accuracy fmnist epsilon cifar10 best accuracy cifar10
adaptive_clippingbaseline3.00294.0803.00280.9132.99961.290
automatic_clippingbaseline3.00295.7803.00278.9632.99955.453
noise_decaybaseline5.26695.6205.26678.9375.26054.633
standard_dpsgdbaseline3.00296.2003.00280.8302.99956.050
anthropic/claude-opus-4.6vanilla3.00286.9403.00277.6372.99960.353
deepseek-reasonervanilla98.77950.0304.68534.8201.28348.695
google/gemini-3.1-pro-previewvanilla3.00288.1573.00270.1002.99958.100
openai/gpt-5.4-provanilla3.00296.1603.00277.9472.99942.163
qwen3.6-plus:freevanilla3.00297.8233.00284.2372.99954.735
anthropic/claude-opus-4.6agent3.00296.3203.00280.2802.99955.453
deepseek-reasoneragent4.37894.1834.37881.1534.84158.823
google/gemini-3.1-pro-previewagent3.00295.7573.00278.9972.99953.740
openai/gpt-5.4-proagent3.00295.9473.00279.4032.99954.943
qwen3.6-plus:freeagent------

Agent Conversations