glenn-jocher commited on
Commit
71209a6
1 Parent(s): fd71fe8

exportable Hardswish() implementation

Browse files
Files changed (1) hide show
  1. utils/activations.py +7 -0
utils/activations.py CHANGED
@@ -10,6 +10,13 @@ class Swish(nn.Module): #
10
  return x * torch.sigmoid(x)
11
 
12
 
 
 
 
 
 
 
 
13
  class MemoryEfficientSwish(nn.Module):
14
  class F(torch.autograd.Function):
15
  @staticmethod
 
10
  return x * torch.sigmoid(x)
11
 
12
 
13
+ class Hardswish(nn.Module): # alternative to nn.Hardswish() for export
14
+ @staticmethod
15
+ def forward(x):
16
+ # return x * F.hardsigmoid(x)
17
+ return x * F.hardtanh(x + 3, 0., 6.) / 6.
18
+
19
+
20
  class MemoryEfficientSwish(nn.Module):
21
  class F(torch.autograd.Function):
22
  @staticmethod