Skip to content
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

[Fix] Disbale gpu fuser on pt19 #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions mmgen/core/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import pickle
from abc import ABC, abstractmethod
from contextlib import contextmanager
from copy import deepcopy
from functools import partial

Expand Down Expand Up @@ -132,6 +133,21 @@ def _load_inception_torch(inception_args, metric):
return inception_model


@contextmanager
def disable_gpu_fuser_on_pt19():
# On PyTorch 1.9 a CUDA fuser bug prevents the Inception JIT model to run.
# Refers to:
# https://github.com/GaParmar/clean-fid/blob/5e1e84cdea9654b9ac7189306dfa4057ea2213d8/cleanfid/inception_torchscript.py#L9 # noqa
# https://github.com/GaParmar/clean-fid/issues/5
# https://github.com/pytorch/pytorch/issues/64062
if torch.__version__.startswith('1.9.'):
old_val = torch._C._jit_can_fuse_on_gpu()
torch._C._jit_override_can_fuse_on_gpu(False)
yield
if torch.__version__.startswith('1.9.'):
torch._C._jit_override_can_fuse_on_gpu(old_val)


def _ssim_for_multi_scale(img1,
img2,
max_val=255,
Expand Down Expand Up @@ -530,7 +546,8 @@ def feed_op(self, batch, mode):

if self.inception_style == 'StyleGAN':
batch = (batch * 127.5 + 128).clamp(0, 255).to(torch.uint8)
feat = self.inception_net(batch, return_features=True)
with disable_gpu_fuser_on_pt19():
feat = self.inception_net(batch, return_features=True)
else:
feat = self.inception_net(batch)[0].view(batch.shape[0], -1)

Expand Down Expand Up @@ -1086,7 +1103,8 @@ def get_pred(self, x):
np.array: Inception score.
"""
if self.use_tero_script:
x = self.inception_model(x, no_output_bias=True)
with disable_gpu_fuser_on_pt19():
x = self.inception_model(x, no_output_bias=True)
else:
# specify the dimension to avoid warning
x = F.softmax(self.inception_model(x), dim=1)
Expand Down