Skip to content

Commit

Permalink
fix: add dummy batch dimension to meet the requirements of the batch …
Browse files Browse the repository at this point in the history
…norm
  • Loading branch information
julianhoever committed Aug 12, 2023
1 parent 7642f80 commit 0f499f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions elasticai/creator/nn/batch_normed_conv1d/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ def forward(self, inputs: torch.Tensor) -> torch.Tensor:
input_shape = (
(inputs.shape[0], self._conv1d.in_channels, -1)
if has_batches
else (self._conv1d.in_channels, -1)
else (1, self._conv1d.in_channels, -1)
)
output_shape = (inputs.shape[0], -1) if has_batches else (-1,)

x = inputs.view(*input_shape)
x = self._conv1d(x)
x = self._batch_norm(x)
x = self._arithmetics.quantize(x)
outputs = x.view(*output_shape)
return outputs

return x.view(*output_shape)

def translate(self, name: str) -> FPConv1dDesign:
def float_to_signed_int(value: float | list) -> int | list:
Expand Down
11 changes: 9 additions & 2 deletions elasticai/creator/nn/batch_normed_linear/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ def __init__(
)

def forward(self, inputs: torch.Tensor) -> torch.Tensor:
x = self._linear(inputs)
has_batches = inputs.dim() == 2
input_shape = inputs.shape if has_batches else (1, -1)
output_shape = (inputs.shape[0], -1) if has_batches else (-1,)

x = inputs.view(*input_shape)
x = self._linear(x)
x = self._batch_norm(x)
return self._arithmetics.quantize(x)
x = self._arithmetics.quantize(x)

return x.view(*output_shape)

def translate(self, name: str) -> FPLinearDesign:
def float_to_signed_int(value: float | list) -> int | list:
Expand Down

0 comments on commit 0f499f0

Please sign in to comment.