lixiaoquan commented on a change in pull request #6008:
URL: https://github.com/apache/incubator-tvm/pull/6008#discussion_r451980232
##########
File path: python/tvm/relay/op/algorithm.py
##########
@@ -82,9 +84,12 @@ def topk(data, k=1, axis=-1, ret_type="both",
out : relay.Expr or List[relay.Expr]
The computed result.
"""
- if isinstance(k, int):
- k = const(k, "int64")
- out = _make.topk(data, k, axis, ret_type, is_ascend, dtype)
+ if isinstance(k, Constant):
+ k = np.asscalar(k.data.asnumpy())
+ if isinstance(k, Expr):
Review comment:
What I meant is `data`, not `k`. `data` can only be Relay Expr. Should
we always use _dyn.topk and let DynmaicToStatic determine whether can convert
it to static op?
Because TopK's out_shape depends on shape of data, if shape of data is
dynamic, out_shape becomes dynamic, we need to use shape function in that case
https://github.com/apache/incubator-tvm/blob/eafb2aa13d6cd223629f17d5f6aab5a8d4fce7f5/src/relay/op/algorithm/topk.cc#L50
```
shape = infer_shape(data)
if Any_in_shape():
# go dynamic
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]