Skip to content

Commit

Permalink
Feat (graph/equalize): clean up scale invariant ops (#669)
Browse files Browse the repository at this point in the history
* Feat (graph/equalize): clean up scale invariant ops

* fix syntax
  • Loading branch information
volcacius authored Jul 17, 2023
1 parent ae7da18 commit 5cc521b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/brevitas/graph/equalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
nn.AdaptiveAvgPool1d,
nn.AdaptiveAvgPool2d,
nn.AdaptiveAvgPool3d,
nn.Identity)
nn.Identity,
nn.ReLU,
nn.LeakyReLU)

_scale_invariant_op = (torch.mul, operator.mul, operator.imul, operator.__mul__, operator.__imul__)

_select_op = (operator.getitem, operator.__getitem__)

_scale_invariant_activations = (torch.nn.ReLU,)

_scale_varying_activations = (
torch.nn.Sigmoid, torch.nn.Tanh, torch.nn.ReLU6, torch.nn.GELU, torch.nn.SiLU)

Expand Down Expand Up @@ -534,8 +534,7 @@ def _is_supported_module(graph_model: GraphModule, node: Node) -> bool:

def _is_scale_invariant_module(graph_model: GraphModule, node: Node) -> bool:
return node.op == 'call_module' and isinstance(
get_module(graph_model, node.target),
_scale_invariant_layers + _scale_invariant_activations)
get_module(graph_model, node.target), _scale_invariant_layers)


def _is_scale_varying_activation(graph_model, node):
Expand Down

0 comments on commit 5cc521b

Please sign in to comment.