-
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.
- Loading branch information
Showing
51 changed files
with
111 additions
and
154 deletions.
There are no files selected for viewing
File renamed without changes.
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
63 changes: 0 additions & 63 deletions
63
elasticai/creator/base_modules/arithmetics/fixed_point_arithmetics.py
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from abc import abstractmethod | ||
from typing import Protocol | ||
|
||
from torch import Tensor | ||
|
||
|
||
class Quantize(Protocol): | ||
@abstractmethod | ||
def quantize(self, x: Tensor) -> Tensor: | ||
... | ||
|
||
|
||
class MatMul(Protocol): | ||
@abstractmethod | ||
def matmul(self, a: Tensor, b: Tensor) -> Tensor: | ||
... | ||
|
||
|
||
class Add(Protocol): | ||
@abstractmethod | ||
def add(self, a: Tensor, b: Tensor) -> Tensor: | ||
... |
6 changes: 3 additions & 3 deletions
6
elasticai/creator/base_modules/silu.py → ...ase_modules/siluwithtrainablescalebeta.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
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 +0,0 @@ | ||
from .conv1d import FPBatchNormedConv1d, FPConv1d | ||
from .hard_sigmoid import FPHardSigmoid | ||
from .hard_tanh import FPHardTanh | ||
from .identity import BufferedIdentity, BufferlessIdentity | ||
from .linear import FPBatchNormedLinear, FPLinear | ||
from .precomputed import FPSigmoid, FPTanh | ||
from .relu import FPReLU | ||
from .sequential import Sequential | ||
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import cast | ||
|
||
import torch | ||
from fixed_point._round_to_fixed_point import RoundToFixedPoint | ||
from fixed_point._two_complement_fixed_point_config import FixedPointConfig | ||
|
||
from elasticai.creator.base_modules.conv1d import MathOperations as Conv1dOps | ||
from elasticai.creator.base_modules.linear import MathOperations as LinearOps | ||
from elasticai.creator.base_modules.lstm_cell import MathOperations as LSTMOps | ||
|
||
|
||
class MathOperations(LinearOps, LSTMOps, Conv1dOps): | ||
def __init__(self, config: FixedPointConfig) -> None: | ||
self.config = config | ||
|
||
def quantize(self, a: torch.Tensor) -> torch.Tensor: | ||
return self._round(self._clamp(a)) | ||
|
||
def _clamp(self, a: torch.Tensor) -> torch.Tensor: | ||
return torch.clamp( | ||
a, min=self.config.minimum_as_rational, max=self.config.maximum_as_rational | ||
) | ||
|
||
def _round(self, a: torch.Tensor) -> torch.Tensor: | ||
return cast(torch.Tensor, RoundToFixedPoint.apply(a, self.config)) | ||
|
||
def add(self, a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: | ||
return self._clamp(a + b) | ||
|
||
def matmul(self, a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: | ||
return self.quantize(torch.matmul(a, b)) |
5 changes: 1 addition & 4 deletions
5
...utograd_functions/round_to_fixed_point.py → ...r/nn/fixed_point/_round_to_fixed_point.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
elasticai/creator/nn/hard_sigmoid/layer.py → ...ator/nn/fixed_point/hard_sigmoid/layer.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
elasticai/creator/nn/hard_tanh/layer.py → ...creator/nn/fixed_point/hard_tanh/layer.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
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
Oops, something went wrong.