-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Félix <[email protected]>
- Loading branch information
1 parent
1c63525
commit c92705e
Showing
3 changed files
with
34 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
import torch | ||
from typing import Callable | ||
|
||
import math | ||
|
||
import torch | ||
|
||
from e3nn.util.jit import compile_mode | ||
|
||
|
||
@torch.jit.script | ||
def ShiftedSoftPlus(x): | ||
def shifted_soft_plus(x: torch.Tensor) -> torch.Tensor: | ||
return torch.nn.functional.softplus(x) - math.log(2.0) | ||
|
||
|
||
@compile_mode("script") | ||
class ShiftedSoftPlus(torch.nn.Module): | ||
def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
return shifted_soft_plus(x) | ||
|
||
|
||
def get_nonlinearity(name: str) -> Callable: | ||
if name == "abs": | ||
return torch.abs | ||
elif name == "tanh": | ||
return torch.nn.Tanh() | ||
elif name == "ssp": | ||
return ShiftedSoftPlus() | ||
elif name == "silu": | ||
return torch.nn.SiLU() | ||
else: | ||
raise KeyError(f"No such nonlinearity `{name}`") |