Skip to content

Commit

Permalink
[Fix] Support SiLU for Pytorch <= 1.5.0 (#158)
Browse files Browse the repository at this point in the history
* support denoising unet for ddpm-based models

* revise known issues

* cvt mean/var_cfg to mean/var_mode

* add unit test

* support SiLU for pt<=1.5.0

* fix bug in pt version check

* fix another bug in pt version checking
  • Loading branch information
LeoXing1996 authored Nov 9, 2021
1 parent a6162b6 commit 9a70b87
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mmgen/models/architectures/ddpm/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from copy import deepcopy
from functools import partial

import mmcv
import numpy as np
import torch
import torch.nn as nn
Expand Down Expand Up @@ -41,6 +42,9 @@ class SiLU(nn.Module):

def __init__(self, inplace=False):
super().__init__()
if torch.__version__ < '1.6.0' and inplace:
mmcv.print_log('Inplace version of \'SiLU\' is not supported for '
f'torch < 1.6.0, found \'{torch.version}\'.')
self.inplace = inplace

def forward(self, x):
Expand All @@ -52,6 +56,9 @@ def forward(self, x):
torch.Tensor: Tensor after activation.
"""

if torch.__version__ < '1.6.0':
return x * torch.sigmoid(x)

return F.silu(x, inplace=self.inplace)


Expand Down

0 comments on commit 9a70b87

Please sign in to comment.