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 Puddingfjz via TVM Discuss <no...@discuss.tvm.ai> on 2020/04/06 07:37:44 UTC
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Hi, I tried the following code:
```
# logging config (for printing tuning log to screen)
logging.getLogger('autotvm').setLevel(logging.DEBUG)
logging.getLogger('autotvm').addHandler(logging.StreamHandler(sys.stdout))
# the last layer in resnet
N, H, W, CO, CI, KH, KW, strides, padding = 1, 7, 7, 512, 512, 3, 3, (1, 1), (1, 1)
data = te.placeholder((N, CI, H, W), name='data')
kernel = te.placeholder((CO, CI, KH, KW), name='kernel')
conv = topi.nn.conv2d_nchw(data, kernel, strides, padding, dilation=1, out_dtype='float32')
cfg = autotvm.get_config()
task = autotvm.task.create("conv2d_nchw.cuda",
args=(cfg, [conv]),
target='cuda')
print(task.config_space)
```
But output is as follows:
```
Cannot find config for target=None, workload=None. A fallback configuration is used, which may bring great performance regression.
Traceback (most recent call last):
File "tune_conv2d_cuda_builtin_tmp.py", line 194, in <module>
target='cuda')
File "/usr/tvm/python/tvm/autotvm/task/task.py", line 406, in create
args = serialize_args(args)
File "/usr/tvm/python/tvm/autotvm/task/task.py", line 64, in serialize_args
ret.append(_encode(t))
File "/usr/tvm/python/tvm/autotvm/task/task.py", line 61, in _encode
'primitive types or tvm.tir.Var only' % type(x))
RuntimeError: Do not support type "<class 'tvm.autotvm.task.space.FallbackConfigEntity'>" in argument. Consider to useprimitive types or tvm.tir.Var only
```
Could you give me some advice on this situation?
Thanks in advance.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/4) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/f53743910c6acb3addca713ac631212a4b671bc31c0e016e2c83bc4fdb5a70cd).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by Puddingfjz via TVM Discuss <no...@discuss.tvm.ai>.
I change my code as follows:
```
import logging
import sys
import numpy as np
import tvm
from tvm import te
import topi
from topi.testing import conv2d_nchw_python
from tvm import autotvm
logging.getLogger('autotvm').setLevel(logging.DEBUG)
logging.getLogger('autotvm').addHandler(logging.StreamHandler(sys.stdout))
# the last layer in resnet
N, H, W, CO, CI, KH, KW, strides, padding = 1, 7, 7, 512, 512, 3, 3, (1, 1), (1, 1)
data = te.placeholder((N, CI, H, W), name='data')
kernel = te.placeholder((CO, CI, KH, KW), name='kernel')
#conv = topi.nn.conv2d_nchw(data, kernel, strides, padding, dilation=1, out_dtype='float32')
#cfg = autotvm.get_config()
task = autotvm.task.create("conv2d_nchw.cuda",
args=(data, kernel, strides, padding, 1, 'float32'),
target='cuda')
print(task.config_space)
```
Now it runs well.
I have another question: in the Tuning High Performance Convolution on NVIDIA GPUs tutorial, the tuned operator is built by:
```
# apply history best from log file
with autotvm.apply_history_best('conv2d.log'):
with tvm.target.create("cuda"):
s, arg_bufs = conv2d_no_batching(N, H, W, CO, CI, KH, KW, strides, padding)
func = tvm.build(s, arg_bufs)
```
How can I build the operator when I tune it with AutoTVM?
Thanks a lot.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/12) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/67420e5e0fd55531274ab8fbbd9b4952d41b9b35033e35cf59914acdb73344b5).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by Puddingfjz via TVM Discuss <no...@discuss.tvm.ai>.
Also, could you please help me on [this question](https://discuss.tvm.ai/t/how-to-build-a-module-with-one-op-using-tvm/6237)? I am also trying to build a module with only one operator using tvm and use AutoTVM to tune it. Your help will be greatly appreciated.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/13) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/75efa109591933b70271f4a47874eacae8ceee1fb0958d3bb6752c128d2e3958).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by "Cody H. Yu via TVM Discuss" <no...@discuss.tvm.ai>.
Not exactly. The task name corresponds to a pair of compute and schedule functions. When creating a task (or even a TVM program), we always create a compute first, and create a schedule accordingly, so does AutoTVM.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/11) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/2b4344dcc376bd0d4b33b988d79a5510ffdb86a8ad244599256cacd2c1a5ffd6).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by Puddingfjz via TVM Discuss <no...@discuss.tvm.ai>.
You mean for this line
[quote="puddingfjz, post:6, topic:4895"]
task = autotvm.task.create("conv2d_nchw.cuda", args=([conv],), target='cuda')
[/quote]
in my code, the task_name ```"conv2d_nchw.cuda"``` here is actually the name for the ```compute``` rather than ```schedule```?
[quote="puddingfjz, post:8, topic:4895"]
@autotvm.register_topi_compute("conv2d_nchw.cuda")
[/quote]
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/10) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/3783109fd7b12033c9efa4ef34f4c99d23b6c38c2a485457448e32aa4ee1797e).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by "Cody H. Yu via TVM Discuss" <no...@discuss.tvm.ai>.
You are filling the compute, so the compute function at line 30 is what you should look at.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/9) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/839ca752c769e8be488f403335d75e4e186d0c29067e9289ab3f871244b613da).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by Puddingfjz via TVM Discuss <no...@discuss.tvm.ai>.
But according to the schedule definition:
https://github.com/apache/incubator-tvm/blob/9816efc2df63cf6a14a6de46dc2adfafde58acc1/topi/python/topi/cuda/conv2d.py#L36
we only need one parameter ```outs``` here.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/8) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/56492445f225860eda611933de0cba227fd3c9589c6c0df035ba7f9d34793aea).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by "Cody H. Yu via TVM Discuss" <no...@discuss.tvm.ai>.
As the error message suggested, you need to specify all required arguments. You still miss 4 of them.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/7) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/7384762be1385f7fef3027693621649dd35f3d1e00c6d72e974eee782b1a958f).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by Puddingfjz via TVM Discuss <no...@discuss.tvm.ai>.
Thank you for your reply.
I remove the ```cfg```, and I get the following error.
```
Traceback (most recent call last):
File "tune_conv2d_cuda_builtin_tmp_2.py", line 23, in <module>
target='cuda')
File "/usr/tvm/python/tvm/autotvm/task/task.py", line 418, in create
sch, _ = ret.func(*args)
File "/usr/tvm/python/tvm/autotvm/task/task.py", line 209, in __call__
return self._default_func(*args, **kwargs)
File "/usr/tvm/python/tvm/autotvm/task/task.py", line 215, in _default_func
out = self.fcompute(*args, **kwargs)
File "/usr/tvm/python/tvm/autotvm/task/topi_integration.py", line 155, in wrapper
node = topi_compute(cfg, *args)
TypeError: conv2d_nchw() missing 4 required positional arguments: 'kernel', 'strides', 'padding', and 'dilation'
```
The code now is:
```
import logging
import sys
import numpy as np
import tvm
from tvm import te
import topi
from topi.testing import conv2d_nchw_python
from tvm import autotvm
logging.getLogger('autotvm').setLevel(logging.DEBUG)
logging.getLogger('autotvm').addHandler(logging.StreamHandler(sys.stdout))
# the last layer in resnet
N, H, W, CO, CI, KH, KW, strides, padding = 1, 7, 7, 512, 512, 3, 3, (1, 1), (1, 1)
data = te.placeholder((N, CI, H, W), name='data')
kernel = te.placeholder((CO, CI, KH, KW), name='kernel')
conv = topi.nn.conv2d_nchw(data, kernel, strides, padding, dilation=1, out_dtype='float32')
#cfg = autotvm.get_config()
task = autotvm.task.create("conv2d_nchw.cuda",
args=([conv],),
target='cuda')
print(task.config_space)
```
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/6) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/8716537dc60e70b82a556f743621cc0ce87a4c0261d301b3b93cc31e540396e8).
[TVM Discuss] [Questions] How to use AutoTVM with manually created
TOPI computations?
Posted by "Cody H. Yu via TVM Discuss" <no...@discuss.tvm.ai>.
You don't need to provide `cfg` in arguments. The first `cfg` argument in the template is handled by the template registration decorator and will be provided by the current context.
---
[Visit Topic](https://discuss.tvm.ai/t/how-to-use-autotvm-with-manually-created-topi-computations/4895/5) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/add986e0957e0857b140ebd31c1bcfd3909a4066ebbfa944254553aa21a9c53a).