You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by ye zhouhai via Apache TVM Discuss <no...@discuss.tvm.ai> on 2021/08/06 10:43:41 UTC

[Apache TVM Discuss] [Questions] Add dynamic shape for pytorch expand converter op


I met following error when I try to feed input tensor with dynamic batch size: (bert model)

  File "/yezhouhai/xtcl-master/baidu/xpu/xmir/python/tvm/relay/frontend/common.py", line 529, in infer_value
    ), "All inputs to infer must be available in params."

This is because in function (pytorch.py) expand:
sizes[i] = int(_infer_value(sizes[i], {}).asnumpy())
This sizes[i] will be feeded to input of op.repeat (2nd parameter) which only accept int parameter. 

But in static case, the sizes is constructed by following:
sizes: [Constant(1), Constant(8)]
In dynamic case, the sizes is constructed by following:
sizes: [CallNode(Op(take), [CallNode(Op(shape_of), [Var(input_ids, ty=TensorType([?, 8], float32))], relay.attrs.ShapeOfAttrs(0x7f169cefa318), []), Constant(0)], relay.attrs.TakeAttrs(0x7f169cefabc8), []), Constant(8)]

So in dynamic case, the sizes[0] is a relay.Expr.Call and it can't be inferred as int. 


Two possible solution I can think of:
1) I try to reuse onnx's expand version. But find it's input shape is relay.Expr, but in our case the shape is a list type. I don't know how to convert a list to shape.
2)  Write a dyn.repeat op? So that it can accpet relay.Expr as its parameter? 

Any suggestions? Thanks!





---
[Visit Topic](https://discuss.tvm.apache.org/t/add-dynamic-shape-for-pytorch-expand-converter-op/10723/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/9f78571ceabd25a33733e59cef9bedb34b813a43088e161e08300229860a172b).

[Apache TVM Discuss] [Questions] Add dynamic shape for pytorch expand converter op

Posted by masahi via Apache TVM Discuss <no...@discuss.tvm.ai>.

I think you can use `op.concatenate(...)` to turn a list of Expr into a single Expr representing a dynamic shape. The second solution also sounds reasonable.





---
[Visit Topic](https://discuss.tvm.apache.org/t/add-dynamic-shape-for-pytorch-expand-converter-op/10723/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/e09838a7e847b21111281ff7766e7d3a2f9f11a553b2ad4b4044be486255fba1).