OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Private Transformers

Private Transformers is a Python library that provides a privacy engine for differentially private training of Hugging Face transformer models. It builds on and rewrites Opacus to integrate with Transformers and supports ghost clipping to reduce memory use during private training.

Independent OpenViST project profile, based on linked sources.

Private Transformers — OpenViST project profile in AI Developer Tools & SDKs.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use it when building a Python training workflow that needs differential privacy for a supported Hugging Face transformer model, particularly when experimenting with ghost clipping.

Who it is for

  • Developers experimenting with differentially private fine-tuning of Hugging Face models.
  • Researchers comparing private training approaches, including ghost clipping.
  • Teams building privacy-preserving NLP training pipelines.

Documented uses

  • Attach a privacy engine to a transformer model's optimizer.
  • Train using per-example losses passed to the optimizer's step method.
  • Try ghost clipping when reducing peak GPU memory is important.
  • Use the included examples as starting points for table-to-text and classification experiments.
Before you choose

Requirements & limits

The project is a public GitHub repository listed under the Apache-2.0 license. Installation instructions require Python 3.8 or later; the documented test suite requires pytest and a GPU.

  • The optimizer step expects a one-dimensional per-example loss passed as a keyword argument; users should not call loss.backward() directly.
  • Inputs must be batch-first, and the model must be in training mode for the underlying hooks to run.
  • Ghost clipping is a one-setting change in the documented example, with a potential trade-off of slower training.
  • The README lists specific supported model classes rather than claiming universal Transformers model support.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Set up Private Transformers

Install the Python package from its GitHub repository and run the documented test suite.

Before you start

  • Python 3.8 or later
  • pytest
  • A GPU to run the test suite

Steps

  1. Install with the command below.

    Documented command
    pip install git+https://github.com/lxuechen/private-transformers.git
  2. Run pytest -s tests from the project checkout.

Expected outcome

The package is installed and the project's documented test suite has been invoked.

Guide limitations

  • The test suite requires a GPU.
  • This setup recipe does not cover training a model.
Source-based practical guide

Add the privacy engine to a Hugging Face training loop

Use the documented per-example-loss workflow for differentially private transformer training.

Before you start

  • An installed Private Transformers package
  • A Hugging Face transformer model and optimizer
  • Mini-batch inputs and a one-dimensional per-example loss

Steps

  1. Create the transformer model and optimizer, then attach the optimizer to a PrivacyEngine.

  2. Set the model to training mode and compute a one-dimensional loss with one value per example.

  3. Pass the loss as a keyword argument to optimizer.step or optimizer.virtual_step; do not call loss.backward() directly.

  4. Repeat the loss computation and optimizer step for subsequent mini-batches.

Expected outcome

The documented training loop routes per-example losses through the privacy-enabled optimizer.

Guide limitations

  • Inputs must use batch-first format.
  • The project lists support for particular Hugging Face model classes; BART conditional generation requires frozen positional embedding layers.
  • Ghost clipping can reduce memory use but may slow training.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
17 October 2026
Original website title
lxuechen/private-transformers · Official homepage title · retained in its source language