Skip to content

Patch stale clipping bound for FastGradientClipping - #847

Open
eddiestudies wants to merge 3 commits into
meta-pytorch:mainfrom
eddiestudies:eddiestudies/ghost_scheduler_patch
Open

eddiestudies wants to merge 3 commits into
meta-pytorch:mainfrom
eddiestudies:eddiestudies/ghost_scheduler_patch

Conversation

@eddiestudies

Copy link
Copy Markdown
Contributor

Types of changes

This test passes through max_grad_norm for scenarios where the optimizer changes it between steps. Previously, the original max_grad_norm was saved and used throughout and the scheduled max_grad_norm in the optimizer was ignored.

  • 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

When Opacus wraps the user's objects, some privacy affecting values are saved as scalars. These copies can become stale if any algorithm requires changing them or the user mutates them.

For FastGradientClipping, the scheduled max_grad_norm is ignored since the original scalar value is read directly instead of the optimizer's max_grad_norm.
This PR resolves this bug in GradSampleHooksFastGradientClipping and warns users if the module's and optimizer's max_grad_norm differ when the DP loss is built.

This PR also adds xfails for locations where stale values can lead to incorrect behavior.
An .isort.cfg is also added to reduce the nuances when running isort and black for linting.

How Has This Been Tested (if it applies)

Added tests for each of the clipping_bound_owner effects. Added tests for similar bugs.

Checklist

  • The documentation is up-to-date with the changes I made.
  • I have read the CONTRIBUTING document and completed the CLA (see CONTRIBUTING).
  • All tests passed, and additional code has been covered with new tests.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 6, 2026
@meta-codesync

meta-codesync Bot commented Oct 6, 2026

Copy link
Copy Markdown

This pull request has been imported. If you are a Meta employee, you can view this in D123688838. (Because this pull request was imported automatically, there will not be any future comments.)

@eddiestudies eddiestudies changed the title Patch stale ghost clipping bound and add xfail tests for similar bugs Patch stale clipping bound for FastGradientClipping and add xfail tests for similar bugs Oct 6, 2026
Comment thread .isort.cfg
@@ -0,0 +1,6 @@
[settings]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helps with the ordering issue with linting vs isort

@eddiestudies eddiestudies changed the title Patch stale clipping bound for FastGradientClipping and add xfail tests for similar bugs Patch stale clipping bound for FastGradientClipping Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant