• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

meta-pytorch / opacus / 25035264545 / 2
80%
main: 80%

Build:
DEFAULT BRANCH: main
Ran 28 Apr 2026 05:32AM UTC
Files 137
Run time 3s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

10 Apr 2026 05:53PM UTC coverage: 79.595% (+0.3%) from 79.257%
25035264545.2

push

github

meta-codesync[bot]
Non-wrapping mode for better Transformers compatibility (#794)

Summary:
## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Docs change / refactoring / dependency upgrade

## Motivation and Context / Related issue

The primary goal of this PR is to introduce a **Non-wrapping mode** (controller-based) to Opacus. This feature allows for the computation of per-sample gradients without wrapping the original `nn.Module` in a `GradSampleModule` subclass.

This change addresses critical compatibility issues with third-party libraries—most notably HuggingFace `Transformers` and `Accelerate`—which often rely on strict module hierarchies or perform type checks that are disrupted by standard Opacus wrappers.

**Key Technical Changes:**
- **`GradSampleHooks` Controller**: Introduced a new architecture where gradient sampling hooks are managed by a standalone `GradSampleHooks` object instead of being embedded in a `GradSampleModule` wrapper.
- **`PrivacyEngine` Updates**: Modified `make_private` and `make_private_with_epsilon` to support a `wrap_model` parameter (defaults to `True` for backward compatibility). When `wrap_model=False`, Opacus attaches hooks to the original model and returns it along with a `GradSampleHooks` controller.
- **Enhanced Loss Compatibility**: Updated `DPLossFastGradientClipping` to handle custom loss implementations that lack a `reduction` attribute (a common occurrence in the `transformers` library). The implementation now explicitly sets the expected reduction if missing and restores the previous state after the backward pass.
- **HuggingFace Trainer Integration**: Verified the new mode via successful small-scale training runs using the HuggingFace `Trainer` with Fast Gradient Clipping. A new example (`examples/huggingface_trainer.py`) is included to d... (continued)

6374 of 8008 relevant lines covered (79.6%)

0.8 hits per line

Source Files on job run-2 - 25035264545.2
  • Tree
  • List 137
  • Changed 19
  • Source Changed 19
  • Coverage Changed 19
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 25035264545
  • 0eb4b151 on github
  • Prev Job for on main (#24173143467.1)
  • Next Job for on main (#25092101528.3)
  • Delete
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc