-
Notifications
You must be signed in to change notification settings - Fork 425
[Fix] Deprecate torch.cuda.amp API
#1675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,7 @@ | ||||||||||||||||||||||||||||
| # Copyright (c) OpenMMLab. All rights reserved. | ||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||
| from functools import partial | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||
| from unittest import TestCase | ||||||||||||||||||||||||||||
| from unittest.mock import MagicMock | ||||||||||||||||||||||||||||
|
Comment on lines
+3
to
7
|
||||||||||||||||||||||||||||
| from functools import partial | |
| import unittest | |
| from unittest import TestCase | |
| from unittest.mock import MagicMock | |
| import unittest | |
| from unittest import TestCase | |
| from unittest.mock import MagicMock | |
| from functools import partial |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Creating a module-level variable GradScaler through partial assignment makes the code less maintainable and harder to understand. Consider either: (1) using amp_GradScaler('cuda', ...) directly at call sites, or (2) creating a proper wrapper function with a docstring explaining the device binding.
| GradScaler = partial(amp_GradScaler, device='cuda') | |
| def get_cuda_grad_scaler(*args, **kwargs): | |
| """Return a torch.amp.GradScaler instance bound to the 'cuda' device. | |
| Args: | |
| *args: Positional arguments for torch.amp.GradScaler. | |
| **kwargs: Keyword arguments for torch.amp.GradScaler. | |
| Returns: | |
| amp_GradScaler: An instance of GradScaler with device='cuda'. | |
| """ | |
| return amp_GradScaler(*args, device='cuda', **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Creating a module-level variable
GradScalerthroughpartialassignment makes the code less maintainable and harder to understand. Consider either: (1) usingamp_GradScaler('cuda', ...)directly at call sites, or (2) creating a proper wrapper function with a docstring explaining the device binding.