-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix custom fwd and bwd for older PyTorch versions (#596)
* fix custom fwd and bwd for older torch versions * forgot to push the new utils file.. * use partial to fix kwargs passing with dec
- Loading branch information
Showing
5 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import torch | ||
from functools import partial | ||
|
||
|
||
def custom_amp_decorator(dec, cuda_amp_deprecated): | ||
def decorator(func): | ||
return dec(func) if not cuda_amp_deprecated else partial(dec, func, device_type="cuda") | ||
return decorator | ||
|
||
|
||
if hasattr(torch.amp, "custom_fwd"): | ||
deprecated = True | ||
from torch.amp import custom_fwd, custom_bwd | ||
else: | ||
deprecated = False | ||
from torch.cuda.amp import custom_fwd, custom_bwd | ||
|
||
custom_fwd = custom_amp_decorator(custom_fwd, deprecated) | ||
custom_bwd = custom_amp_decorator(custom_bwd, deprecated) |