docker tvm :AttributeError: module 'tvm' has no attribute 'testing'

最近在搞tvm [官网:https://tvm.ai/], 我采用的docker的方式来快速入手的, 总体来说很简单:

1. 获取docker镜像

sudo docker pull tvmai/demo-gpu

2. 运行docker镜像, 注意这里我们使用了GPU, 需要用到nvidia-docker来共享gpu设备, 由于要使用到jupyter notebook, 所以要端口, 默认的是8888, 可以自行配置, 最后就是共享了一个工作目录. 命令如下:

sudo nvidia-docker run -it -p 8888:8888 tvmai/demo-gpu -v /tvm_source:/source  --name tvmai_gpu /bin/bash

3. 运行jupyter notebook , 由于是root用户, 要加一个 --allow-root 参数

jupyter notebook --allow-root

道理就是这样, 但是好像有坑, 具体错误没有记录, 好像是socket.error bind端口出错了, 这个时候是因为没有notebook的配置.

4. 配置下jupyter notebook [参考的FQ_G的博客]

jupyter notebook --generate-config
vim ~/.jupyter/jupyter_notebook_config.py

找到下面参数, 做些修改:

c.NotebookApp.ip = '0.0.0.0' #所有的网络都可以
    # 如果你希望本机访问,可以配置为 127.0.0.1, 
    # 我试着配置了localhost, 发现不得行, 不晓得是hosts文件没有配置还是啥的, 供参考
c.NotebookApp.port = 8888   #这里可以配置运行的端口

配置了过后, 就jupyter notebook运行就没得毛病了

 

5. 另外一个坑, 跟着教程走, 遇到

AttributeError: module 'tvm' has no attribute 'testing'

这个错误网上没有找到,于是只有看源码了, 其实有个testing.py 很简单, 代码如下:

""" TVM testing utilities """
import numpy as np

def assert_allclose(actual, desired, rtol=1e-7, atol=1e-7):
    """ Version of np.testing.assert_allclose with `atol` and `rtol` fields set
    in reasonable defaults.

    Arguments `actual` and `desired` are not interchangable, since the function
    compares the `abs(actual-desired)` with `atol+rtol*abs(desired)`.  Since we
    often allow `desired` to be close to zero, we generally want non-zero `atol`.
    """
    np.testing.assert_allclose(actual, desired, rtol=rtol, atol=atol, verbose=True)

所以, 遇到这个错误, 你就可以直接把 tvm.testing 转换为 np.testing 即可, 如:

tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())

转换为:

np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy(), rtol=1e-7, atol=1e-7, verbose=True)

恩恩, 估计还会遇到不少问题, 继续慢慢看了, 有小伙伴在研究的, 可以组团 [w.w]

猜你喜欢

转载自blog.csdn.net/u012939880/article/details/84108312