tvm icon indicating copy to clipboard operation
tvm copied to clipboard

Persistent RNN Cells

Open siju-samuel opened this issue 8 years ago • 12 comments

Dear @tqchen , Im trying to implement RNN Cells for darknet front end, but i have an issue which need your support. In RNN, the complete "network" needs to be run multiple times to get the next output. I need to preserve the RNN cell state across multiple iterations of the network.
Is there any way to preserve the state and can be used for the next iteration? I saw cache_read and cache_write in schedule? Whether this can be used to preserve the state? If so, how to use that?

siju-samuel avatar Feb 22 '18 09:02 siju-samuel

I don't know what the 'best' way to do this is, but you could have the RNN cell's new updated hidden state as an output to your computation so you can feed that in on the next time step

alex-weaver avatar Feb 22 '18 11:02 alex-weaver

see https://github.com/dmlc/tvm/tree/master/topi/recipe/rnn for some recipe

tqchen avatar Feb 22 '18 16:02 tqchen

BTW, since this is a community project, you do not have to specifically at me to ask questions :)

tqchen avatar Feb 22 '18 16:02 tqchen

@alex-weaver I will have multiple RNN Cells with different output size.. so its little difficult to keep track of all the outputs, again feeding at input..

siju-samuel avatar Feb 23 '18 01:02 siju-samuel

what is global/shared/local cache? if i use global, the values will be preserved for the entire lifespan?

siju-samuel avatar Feb 23 '18 01:02 siju-samuel

the memory scope only has things to do with their location on thread scope. We do support multiple input and states in the scan operator, which gives the lstm example here

tqchen avatar Feb 25 '18 19:02 tqchen

Any idea why this error is happenning while executing matexp.py?
The same script was running before and now im getting this error.

File "matexp.py", line 152, in <module> rnn_matexp() File "matexp.py", line 149, in rnn_matexp check_device("cuda") File "matexp.py", line 117, in check_device f = tvm.build(s, [s_scan, Whh], target) File "/home/siju/.local/lib/python3.6/site-packages/tvm-0.2.0-py3.6-linux-x86_64.egg/tvm/build_module.py", line 449, in build mdev = codegen.build_module(fdevice, str(target_device)) File "/home/siju/.local/lib/python3.6/site-packages/tvm-0.2.0-py3.6-linux-x86_64.egg/tvm/codegen.py", line 20, in build_module return _Build(lowered_func, target) File "/home/siju/.local/lib/python3.6/site-packages/tvm-0.2.0-py3.6-linux-x86_64.egg/tvm/_ffi/function.py", line 255, in my_api_func return flocal(*args) File "tvm/_ffi/_cython/./function.pxi", line 264, in core.FunctionBase.__call__ File "tvm/_ffi/_cython/./function.pxi", line 213, in core.FuncCall File "tvm/_ffi/_cython/./function.pxi", line 205, in core.FuncCall3 File "tvm/_ffi/_cython/./base.pxi", line 131, in core.CALL tvm._ffi.base.TVMError: b'TVMCall CFunc Error:\nTraceback (most recent call last):\n File "tvm/_ffi/_cython/./function.pxi", line 39, in core.tvm_callback\n File "matexp.py", line 27, in tvm_callback_cuda_compile\n ptx = nvcc.compile_cuda(code, target="ptx")\n File "/home/siju/.local/lib/python3.6/site-packages/tvm-0.2.0-py3.6-linux-x86_64.egg/tvm/contrib/nvcc.py", line 69, in compile_cuda\n cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n File "/home/siju/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__\n restore_signals, start_new_session)\n File "/home/siju/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child\n raise child_exception_type(errno_num, err_msg, err_filename)\nFileNotFoundError: [Errno 2] No such file or directory: \'nvcc\': \'nvcc\'\n'

siju-samuel avatar Feb 26 '18 15:02 siju-samuel

look at the error message, it says nvcc not available, put cuda bin to your path

tqchen avatar Feb 26 '18 15:02 tqchen

cuda/bin path is already given as part of make/config.mk the other examples can run fine (the ones in tutorials folder).. except matexp.py


siju@siju-DAEMON:~/D/Community/nnvm/tvm/topi/recipe/rnn$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
siju@siju-DAEMON:~/D/Community/nnvm/tvm/topi/recipe/rnn$ cat ../../../make/config.mk | grep CUDA
# whether enable CUDA during compile
USE_CUDA = 1
# add the path to CUDA library to link and compile flag
CUDA_PATH = /usr/local/cuda-8.0
siju@siju-DAEMON:~/D/Community/nnvm/tvm/topi/recipe/rnn$ 

siju-samuel avatar Feb 26 '18 16:02 siju-samuel

This is the runtime(nvcc compiler) that requires the cuda path, you need to do that by

export PATH=${PATH}:/usr/local/cuda/bin

tqchen avatar Feb 26 '18 19:02 tqchen

:+1: Yeah. Thanks a lot. I forgot to set this path after rebooting.

siju-samuel avatar Feb 27 '18 01:02 siju-samuel

please close this for now as the original issue has been answered, we prefer to aggressively close issues and open new ones when necessary so there is minimum amount of issues, and the community won't forget about them

tqchen avatar Feb 27 '18 16:02 tqchen