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

pytorch / opacus / 17051015565
80%

Build:
DEFAULT BRANCH: main
Ran 18 Aug 2025 08:08PM UTC
Jobs 0
Files 0
Run time –
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

pending completion
17051015565

push

github

facebook-github-bot
Fix AdaClipOptimizer (#779)

Summary:
## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] 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

AdaClipOptimizer fails on the attempt to [generate noise for `self.unclipped_num`](https://github.com/pytorch/opacus/blob/<a class=hub.com/pytorch/opacus/commit/<a class="double-link" href="https://git"><a class=hub.com/pytorch/opacus/commit/e1a695c1b82e6749e2ab80b491da9e3d2cfe823b">e1a695c1b/opacus/optimizers/adaclipoptimizer.py#L127C1-L131C10).
PyTorch fails after the first step complaining that torch.normal is not defined for LongTensors. Converting it to `.float` just before the noise addition seems the shortest change possible to fix the issue. Otherwise, AdaClip doesn't work with the current version of PyTorch:

```python
unclipped_num_noise = _generate_noise(
    std=self.unclipped_num_std,
    reference=self.unclipped_num.float(), <--
    generator=self.generator,
)
```

___
Btw, there is a general issue with how `unclipped_num_std` is handled. Initially it [starts as a ~int~float](https://github.com/pytorch/opacus/blob/e1a695c1b82e6749e2ab80b491da9e3d2cfe823b/opacus/optimizers/adaclipoptimizer.py#L85C9-L85C31):

```python
self.unclipped_num = 0
```

then gets [converted to a tensor almost unintentionally](https://github.com/pytorch/opacus/blob/e1a695c1b82e6749e2ab80b491da9e3d2cfe823b/opacus/optimizers/adaclipoptimizer.py#L108-L110):

```python
self.unclipped_num += (
    len(per_sample_clip_factor) - (per_sample_clip_factor < 1).sum()
)
```

then the place with the fix where it can [only be a tensor to work as a reference for the `_generate_noise`](https://github.com/pytorch/opacus/blob/42b0e7275/opacus/optimizers/optimizer.py#L106) function:

```python
unclipped_num_noise = _generate_noise(
    std=self.unclipped_num_std,
    reference=self.unclipped_num,
    generator=self.gener... (continued)
Source Files on build 17051015565
Detailed source file information is not available for this build.
  • Back to Repo
  • Github Actions Build #17051015565
  • 566c1e0c on github
  • Prev Build on main (#15989772801)
  • Next Build on main (#17054582968)
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