-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove unnecessary output quantization of the SiLU base module
- Loading branch information
1 parent
a5aecb3
commit 350faa5
Showing
6 changed files
with
7 additions
and
36 deletions.
There are no files selected for viewing
15 changes: 2 additions & 13 deletions
15
elasticai/creator/base_modules/silu_with_trainable_scale_beta.py
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,22 +1,11 @@ | ||
from typing import Protocol | ||
|
||
import torch | ||
|
||
from elasticai.creator.base_modules.math_operations import Quantize | ||
|
||
|
||
class MathOperations(Quantize, Protocol): | ||
... | ||
|
||
|
||
class SiLUWithTrainableScaleBeta(torch.nn.SiLU): | ||
def __init__(self, operations: MathOperations) -> None: | ||
def __init__(self) -> None: | ||
super().__init__(inplace=False) | ||
self._operations = operations | ||
self.scale = torch.nn.Parameter(torch.ones(1, requires_grad=True)) | ||
self.beta = torch.nn.Parameter(torch.zeros(1, requires_grad=True)) | ||
|
||
def forward(self, input: torch.Tensor) -> torch.Tensor: | ||
a = self.scale * super().forward(input) + self.beta | ||
x = self._operations.quantize(a) | ||
return x | ||
return self.scale * super().forward(input) + self.beta |
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
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