Official implementation of "GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators" (NeurIPS 2020)

Overview

GS-WGAN

LICENSE Python

This repository contains the implementation for GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators (NeurIPS 2020).

Contact: Dingfan Chen ([email protected])

Requirements

The environment can be set up using Anaconda with the following commands:

conda create --name gswgan-pytorch python=3.6
conda activate gswgan-pytorch
conda install pytorch=1.2.0 
conda install torchvision -c pytorch
pip install -r requirements.txt

Please note that modifications in registering the backward_hook (in source/main.py) may be required if you plan to use a different pytorch version. Please refer to the pytorch document (select pytorch version → torch.nnModule → search for register_backward_hook) for more information.

Training

Step 1. To warm-start the discriminators:

cd source
sh pretrain.sh
  • To run the training in parallel: adjust the 'meta_start' argument and run the script multiple times in parallel.
  • Alternatively, you can download the pre-trained models using the links below.

Step 2. To train the differentially private generator:

cd source
python main.py -data 'mnist' -name 'ResNet_default' -ldir '../results/mnist/pretrain/ResNet_default'
  • Please refer to source/config.py (or execute python main.py -h) for the complete list of arguments.

  • The default setting require ~22G GPU memory. Please allocate multiple GPUs by specifying the '-ngpus' argument if it does not fit in the memory of one GPU.

Evaluation

Privacy

  • To compute the privacy cost:
    cd evaluation
    python privacy_analysis.py -data 'mnist' -name 'ResNet_default'
    

Pre-trained Models

Pre-trained model checkpoints can be downloaded using the links below. The discriminators are obtained after the warm-starting step (step 1), while the generators are obtained after the DP training step (step 2). The pre-trained models are stored as .pth files and the corresponding training configurations are stored in params.pkl and params.txt.

Generator Discriminators
MNIST link link
Fashion-MNIST link link

Citation

@inproceedings{neurips20chen,
title = {GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators},
author = {Dingfan Chen and Tribhuvanesh Orekondy and Mario Fritz},
year = {2020},
date = {2020-12-06},
booktitle = {Neural Information Processing Systems (NeurIPS)},
pubstate = {published},
tppubtype = {inproceedings}
}

Acknowledgements

Our implementation uses the source code from the following repositories:

Comments
  • Poor Generator Performance

    Poor Generator Performance

    Hi. I've tried pre-training 1000 Discriminators for 2K iters each (as per the subsampling rate mentioned in the appendix). The metrics (G_cost, D_cost,Wasserstein) are in the [-0.5, 2.4 ish] interval, however the corresponding stats for the Generator that loads and uses these, are much higher (~13 or 11 for each). The metrics don't improve at all (when training for 20K iters in main.py) and the final images are all just blank. I am using the default noise-multiplier, and default architectures. Am I missing something here?

    opened by tazwar22 8
  • Question about how the hook affect the gradient pass to Generator

    Question about how the hook affect the gradient pass to Generator

    Hi Dingfan, Thank you for your work! I'm a postgraduate student in Beihang university.Recently I've read your paper and tried to find out how the Mechanism affect the gradient in the backward process. In your code ( source/main.py line294) , you defined the dynamic_hook_function = dp_conv_hook, which means you changed the dummy_hook to dp_conv_hook to let the DP Mechanism( clip-gradient and add noise) work. However, I noticed that in line301-302 p.requires_grad = False, you actually set the netD parameters fixed and it seems the dp_conv_hook will not modify the gradients in the backward process, so I wander how could the hook take effect?Or what should I do to let the dp_conv_hook work? Thank you !

    opened by lsl001006 2
  • Questions for the gradient clipping operation

    Questions for the gradient clipping operation

    Dear author,

    I have a question about the gradient clipping operation in your code.

    From my point of view, the operation of gradient-clipping is to scale the large gradients to CLIP_BOUND, and for the gradients smaller than CLIP_BOUND, it should not be scaled.

    But in your code, https://github.com/DingfanChen/GS-WGAN/blob/5f33f21249431e53f44167da3ae7587e0dc695d9/source/main.py#L72-L74

    it seems we change all the gradients (even for the gradients whose norm is smaller than the CLIP_BOUND), it seems we need to add the following code

    clip_coef = clip_coef.clamp(max=1.0)

    Is this the right implementation? Or am I missing something?

    opened by XiangQiu42 2
  • Have you tested the case of using multiple GPUs?

    Have you tested the case of using multiple GPUs?

    Hi, I have tried to train the generator using 4 GPUs. I used your pretrained D and using the defualt configuration only with different number of GPUs. The finally generated images are terrible. So, have you tested the case of using multiple GPUs? Should I change some configurations, e.g., noise scale and iterations?

    opened by TheSunWillRise 2
  • Suggestion on Hyper-parameter Tuning given low eps (eps <= 1)

    Suggestion on Hyper-parameter Tuning given low eps (eps <= 1)

    Hi,

    Thanks a lot for open-sourcing the code.

    I am wondering if you have any advice on how to select the proper hyper-parameter given low eps, especially when eps <= 1.

    Thanks :)

    opened by boxin-wbx 1
  • Question about the privacy cost calculation

    Question about the privacy cost calculation

    Hi Dingfan! Sorry to bother you again.

    When I'm evaluating the privacy cost of the GS-WGAN code from GS-WGAN/evaluation/privacy_analysis.py:

    def main(config):
        delta = 1e-5
        batch_size = config['batchsize']
        prob = 1. / config['num_discriminators']  # subsampling rate
        n_steps = config['iterations']  # training iterations
        sigma = config['noise_multiplier']  # noise scale
        func = lambda x: rdp_bank.RDP_gaussian({'sigma': sigma}, x)
    
        acct = rdp_acct.anaRDPacct()
        acct.compose_subsampled_mechanism(func, prob, coeff=n_steps * batch_size)
        epsilon = acct.get_eps(delta)
        print("Privacy cost is: epsilon={}, delta={}".format(epsilon, delta))
    

    It seems that the final privacy cost is about the calculation of parameter delta, batch_size, num_discriminators, iterations, and noise_multiplier, but in the dp_conv_hook module in main.py:

    def dp_conv_hook(module, grad_input, grad_output):
        '''
        gradient modification + noise hook
        :param module:
        :param grad_input:
        :param grad_output:
        :return:
        '''
        global noise_multiplier
        ### get grad wrt. input (image)
        grad_wrt_image = grad_input[0]
        grad_input_shape = grad_wrt_image.size()
        batchsize = grad_input_shape[0]
        clip_bound_ = CLIP_BOUND / batchsize
    
        grad_wrt_image = grad_wrt_image.view(batchsize, -1)
        grad_input_norm = torch.norm(grad_wrt_image, p=2, dim=1)
    
        ### clip
        clip_coef = clip_bound_ / (grad_input_norm + 1e-10)
        clip_coef = torch.min(clip_coef, torch.ones_like(clip_coef))
        clip_coef = clip_coef.unsqueeze(-1)
        grad_wrt_image = clip_coef * grad_wrt_image
    
        ### add noise
        noise = clip_bound_ * noise_multiplier * SENSITIVITY * torch.randn_like(grad_wrt_image)
        grad_wrt_image = grad_wrt_image + noise
        grad_input_new = [grad_wrt_image.view(grad_input_shape)]
        for i in range(len(grad_input) - 1):
            grad_input_new.append(grad_input[i + 1])
        return tuple(grad_input_new)
    

    It seems that there are also hyperparameters like CLIP_BOUND, and SENSITIVITY associated with the backward loss, so I'm confused about 2 questions as follows:

    1. when calculating privacy cost, why are the hyperparams like CLIP_BOUND,SENSITIVITY not included in the privacy_analysis function?
    2. why should we define the variable prob in privacy_analysis.py's main function as 1/config['num_discriminators'] ? Does this mean that privacy problems may occur when num_discriminators is small?

    Thank you very much for reading the above, and I'm looking forward to your reply if you got time to answer this.

    opened by lsl001006 1
  • How to reproduce federated results?

    How to reproduce federated results?

    Hi, I am currently doing my bachelor's thesis and I want to reproduce the results from your paper in the federated setting. Do you happen to have code available or steps to be able to reproduce the findings for the federated setting with EMNIST?

    opened by gregor160300 1
Owner
null
Official Pytorch implementation of 'GOCor: Bringing Globally Optimized Correspondence Volumes into Your Neural Network' (NeurIPS 2020)

Official implementation of GOCor This is the official implementation of our paper : GOCor: Bringing Globally Optimized Correspondence Volumes into You

Prune Truong 71 Nov 18, 2022
Official Implementation of Swapping Autoencoder for Deep Image Manipulation (NeurIPS 2020)

Swapping Autoencoder for Deep Image Manipulation Taesung Park, Jun-Yan Zhu, Oliver Wang, Jingwan Lu, Eli Shechtman, Alexei A. Efros, Richard Zhang UC

null 449 Dec 27, 2022
[NeurIPS 2020] Official repository for the project "Listening to Sound of Silence for Speech Denoising"

Listening to Sounds of Silence for Speech Denoising Introduction This is the repository of the "Listening to Sounds of Silence for Speech Denoising" p

Henry Xu 40 Dec 20, 2022
Implementation of "Fast and Flexible Temporal Point Processes with Triangular Maps" (Oral @ NeurIPS 2020)

Fast and Flexible Temporal Point Processes with Triangular Maps This repository includes a reference implementation of the algorithms described in "Fa

Oleksandr Shchur 20 Dec 2, 2022
UDP++ (ECCVW 2020 Oral), (Winner of COCO 2020 Keypoint Challenge).

UDP-Pose This is the pytorch implementation for UDP++, which won the Fisrt place in COCO Keypoint Challenge at ECCV 2020 Workshop. Top-Down Results on

null 20 Jul 29, 2022
git《Beta R-CNN: Looking into Pedestrian Detection from Another Perspective》(NeurIPS 2020) GitHub:[fig3]

Beta R-CNN: Looking into Pedestrian Detection from Another Perspective This is the pytorch implementation of our paper "[Beta R-CNN: Looking into Pede

null 35 Sep 8, 2021
Diverse Image Captioning with Context-Object Split Latent Spaces (NeurIPS 2020)

Diverse Image Captioning with Context-Object Split Latent Spaces This repository is the PyTorch implementation of the paper: Diverse Image Captioning

Visual Inference Lab @TU Darmstadt 34 Nov 21, 2022
《Dual-Resolution Correspondence Network》(NeurIPS 2020)

Dual-Resolution Correspondence Network Dual-Resolution Correspondence Network, NeurIPS 2020 Dependency All dependencies are included in asset/dualrcne

Active Vision Laboratory 45 Nov 21, 2022
(NeurIPS 2020) Wasserstein Distances for Stereo Disparity Estimation

Wasserstein Distances for Stereo Disparity Estimation Accepted in NeurIPS 2020 as Spotlight. [Project Page] Wasserstein Distances for Stereo Disparity

Divyansh Garg 92 Dec 12, 2022
[NeurIPS 2020] Blind Video Temporal Consistency via Deep Video Prior

pytorch-deep-video-prior (DVP) Official PyTorch implementation for NeurIPS 2020 paper: Blind Video Temporal Consistency via Deep Video Prior TensorFlo

Yazhou XING 90 Oct 19, 2022
Code for ICE-BeeM paper - NeurIPS 2020

ICE-BeeM: Identifiable Conditional Energy-Based Deep Models Based on Nonlinear ICA This repository contains code to run and reproduce the experiments

Ilyes Khemakhem 65 Dec 22, 2022
Code for Discriminative Sounding Objects Localization (NeurIPS 2020)

Discriminative Sounding Objects Localization Code for our NeurIPS 2020 paper Discriminative Sounding Objects Localization via Self-supervised Audiovis

null 51 Dec 11, 2022
Advances in Neural Information Processing Systems (NeurIPS), 2020.

What is being transferred in transfer learning? This repo contains the code for the following paper: Behnam Neyshabur*, Hanie Sedghi*, Chiyuan Zhang*.

Google Research 36 Aug 26, 2022
Neuron Merging: Compensating for Pruned Neurons (NeurIPS 2020)

Neuron Merging: Compensating for Pruned Neurons Pytorch implementation of Neuron Merging: Compensating for Pruned Neurons, accepted at 34th Conference

Woojeong Kim 33 Dec 30, 2022
Multi-Task Temporal Shift Attention Networks for On-Device Contactless Vitals Measurement (NeurIPS 2020)

MTTS-CAN: Multi-Task Temporal Shift Attention Networks for On-Device Contactless Vitals Measurement Paper Xin Liu, Josh Fromm, Shwetak Patel, Daniel M

Xin Liu 106 Dec 30, 2022
Defending graph neural networks against adversarial attacks (NeurIPS 2020)

GNNGuard: Defending Graph Neural Networks against Adversarial Attacks Authors: Xiang Zhang ([email protected]), Marinka Zitnik (marinka@hms.

Zitnik Lab @ Harvard 44 Dec 7, 2022
Code for the Population-Based Bandits Algorithm, presented at NeurIPS 2020.

Population-Based Bandits (PB2) Code for the Population-Based Bandits (PB2) Algorithm, from the paper Provably Efficient Online Hyperparameter Optimiza

Jack Parker-Holder 22 Nov 16, 2022
Code release for NeurIPS 2020 paper "Co-Tuning for Transfer Learning"

CoTuning Official implementation for NeurIPS 2020 paper Co-Tuning for Transfer Learning. [News] 2021/01/13 The COCO 70 dataset used in the paper is av

THUML @ Tsinghua University 35 Sep 23, 2022
Discovering Interpretable GAN Controls [NeurIPS 2020]

GANSpace: Discovering Interpretable GAN Controls Figure 1: Sequences of image edits performed using control discovered with our method, applied to thr

Erik Härkönen 1.7k Jan 3, 2023