Skip to content

Commit

Permalink
Update: Adopt PR NVlabs/stylegan2-ada-pytorch#197 to fix `Update: Ado…
Browse files Browse the repository at this point in the history
…pt PR NVlabs/stylegan2-ada-pytorch#197 to fix ` on PyTorch 1.10 and above.
  • Loading branch information
BrandoZhang committed Jun 10, 2022
1 parent 388ed20 commit 3eeeb81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion third_party/stylegan2_official_ops/conv2d_gradfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import warnings
import contextlib
import torch
from distutils.version import LooseVersion

enabled = True # Enable the custom op by setting this to true.
weight_gradients_disabled = False # Forcefully disable computation of gradients with respect to the weights.
Expand Down Expand Up @@ -61,7 +62,7 @@ def _should_use_custom_op(input):
return False
if input.device.type != 'cuda':
return False
if any(torch.__version__.startswith(x) for x in ['1.7.', '1.8.', '1.9']):
if LooseVersion(torch.__version__) >= LooseVersion('1.7.0'):
return True
warnings.warn(f'conv2d_gradfix not supported on PyTorch {torch.__version__}. Falling back to torch.nn.functional.conv2d().')
return False
Expand Down
3 changes: 2 additions & 1 deletion third_party/stylegan2_official_ops/grid_sample_gradfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import warnings
import torch
from distutils.version import LooseVersion

#----------------------------------------------------------------------------

Expand All @@ -43,7 +44,7 @@ def grid_sample(input, grid, impl='cuda'):
def _should_use_custom_op():
if not enabled:
return False
if any(torch.__version__.startswith(x) for x in ['1.7.', '1.8.', '1.9']):
if LooseVersion(torch.__version__) >= LooseVersion('1.7.0'):
return True
warnings.warn(f'grid_sample_gradfix not supported on PyTorch {torch.__version__}. Falling back to torch.nn.functional.grid_sample().')
return False
Expand Down

0 comments on commit 3eeeb81

Please sign in to comment.