Skip to main content

A package for applying differential privacy to model training using block-level gradient shuffling

Project description

🛡️ ForgetNet: Differentially Private Block-wise Gradient Shuffle for Deep Learning 🧠

PyPI version License: MIT

ForgetNet introduces a novel privacy-preserving technique for deep learning: Differentially Private Block-wise Gradient Shuffle (DP-BloGS). 🔒🔀

🌟 Features

  • 🚀 Fast training times, close to non-private training
  • 🎯 Competitive privacy guarantees compared to DP-SGD
  • 📊 Better privacy-utility trade-off in many scenarios
  • 🏋️ Scalable to large models (tested up to 1.1 billion parameters)
  • 🧮 Parameter-wise privacy budget allocation

📦 Installation

pip install forgetnet

🚀 Quick Start

from forgetnet import DPBloGSTrainer
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load your model and tokenizer
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")

# Initialize the DP-BloGS trainer
trainer = DPBloGSTrainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset,
    eval_dataset=eval_dataset,
    tokenizer=tokenizer,
    target_epsilon=1.0,
    delta=1e-5,
    clip_value=1.0
)

# Train your model with privacy guarantees
trainer.train()

📚 How It Works

DP-BloGS introduces a probabilistic approach to gradient noise through block-wise shuffling:

  1. 📊 Divide gradients into blocks
  2. 🔀 Shuffle blocks randomly
  3. 📏 Apply parameter-specific block sizes
  4. ✂️ Use batch layer clipping
  5. 🧮 Accumulate gradients

This combination allows for fast training while maintaining strong privacy guarantees!

📈 Performance

DP-BloGS has been tested on various model architectures, including:

  • GPT-2 (124M)
  • BERT (110M)
  • OPT (350M)
  • BLOOM (560M)
  • TinyLlama (1.1B)

Results show competitive or better performance compared to DP-SGD in terms of:

  • 🏃‍♂️ Training speed
  • 🎭 Privacy guarantees
  • 📊 Model utility

📄 Citation

If you use ForgetNet in your research, please cite my paper:

@article{zagardo2024dpblogs,
  title={Differentially Private Block-wise Gradient Shuffle for Deep Learning},
  author={Zagardo, David},
  journal={arXiv preprint arXiv:2024.XXXXX},
  year={2024}
}

🤝 Contributing

We welcome contributions! Please see my CONTRIBUTING.md for details on how to get started.

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgements

We thank the open-source community and the authors of the papers cited in our work for their valuable contributions to the field of privacy-preserving machine learning.


Built with 🧠 by David Zagardo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forgetnet-0.1.5.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forgetnet-0.1.5-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file forgetnet-0.1.5.tar.gz.

File metadata

  • Download URL: forgetnet-0.1.5.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for forgetnet-0.1.5.tar.gz
Algorithm Hash digest
SHA256 818e4bdbf40451bda1d87f4b70a38a2868aba9b3b88bd8dd40336c729af4f5d6
MD5 ee84636af41c087539d3bdc9fd09e5a0
BLAKE2b-256 89cc40137ce16fd1db94b21220cefac06632a17caf599d7abbb9963bff865940

See more details on using hashes here.

File details

Details for the file forgetnet-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: forgetnet-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for forgetnet-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5a7b48544c95c5cf3db150ae3efbbab02c4b047e0fdfea913181ef090b9cef3b
MD5 09490cfa1bf33ae1ff84887d35092c39
BLAKE2b-256 0bc95d5a0d2fff64a35dfa7a35fda68b8d99a30402d0faa31f6a0b0f18d2ca04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page