Skip to content

Commit

Permalink
[quantizer] reduce the number of pad operators (#381)
Browse files Browse the repository at this point in the history
* [quantizer] reduce the number of pad operators

* rename add_padop to add_pad_op
  • Loading branch information
mjq2020 authored Dec 12, 2024
1 parent ccf5d73 commit f897615
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tinynn/converter/operators/torch/aten.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,11 +1386,17 @@ def parse(self, node, attrs, args, graph_converter):

assert dilation_h == dilation_w == 1, "Only dilation == 1 is supported"

padding = tfl_schema.Padding.VALID
add_pad_op = not (
stride_h == stride_w == 1 and pad_h == kernel_h // 2 and pad_w == kernel_w // 2 and not ceil_mode
)
padding = tfl_schema.Padding.SAME
if add_pad_op:
padding = tfl_schema.Padding.VALID

maxpool_op = tfl.MaxPool2dOperator(inputs, outputs, padding, stride_w, stride_h, kernel_w, kernel_h)
ops = self.wrap_ops_with_nhwc_nchw_transposes([maxpool_op])
self.handle_padding(pad_h, pad_w, 1, ops, ceil_mode)
if add_pad_op:
self.handle_padding(pad_h, pad_w, 1, ops, ceil_mode)

for op in ops:
graph_converter.add_operator(op)
Expand Down

0 comments on commit f897615

Please sign in to comment.