ekalda commented on a change in pull request #9209:
URL: https://github.com/apache/tvm/pull/9209#discussion_r724833711
##########
File path: python/tvm/relay/backend/contrib/ethosu/legalize.py
##########
@@ -208,6 +208,96 @@ def __call__(self, *args, **kwargs):
pass
+class EthosuDepthwise2DRewriter(DFPatternCallback):
+ """Convert ethosu.qnn_depthwise2d composite functions to
ethosu_depthwise2d operators"""
+
+ def __init__(self):
+ super().__init__(require_type=True)
+ self.pattern = (
+ wildcard().has_attr({"Composite":
ethosu_patterns.QnnDepthwise2DParams.composite_name})
+ )(wildcard())
+
+ def callback(
+ self, pre: tvm.relay.Expr, post: tvm.relay.Expr, node_map:
tvm.ir.container.Map
+ ) -> tvm.relay.Expr:
+ params = ethosu_patterns.QnnDepthwise2DParams(post.op.body)
+ params.ifm.tensor = post.args[0]
+ channels_map = {
+ "NHWC": 3,
+ }
+ if str(params.ofm.layout) not in channels_map.keys():
+ raise UnsupportedLayout(str(params.ofm.layout))
+ kernel_shape_map = {
+ "HWOI": params.weights.shape[0:2],
Review comment:
IIRC, in the Relay that corresponds to depthwise conv2d operator from
TFLite, the weights are always in HWOI, that's why other formats are not
handled here.
##########
File path: python/tvm/relay/op/contrib/ethosu.py
##########
@@ -223,12 +223,13 @@ def __init__(self, func_body: tvm.relay.Function):
self.strides = qnn_conv2d.attrs.strides
self.dilation = qnn_conv2d.attrs.dilation
self.activation = activation
+ self.channels = qnn_conv2d.attrs.channels
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]