idiap / fast-transformers

Pytorch library for fast transformer implementations
1.65k stars 179 forks source link

Can't import causal_product_cuda #96

Closed 15805383399 closed 3 years ago

15805383399 commented 3 years ago

I got a TypeError : 'NoneType' object is not callable I found that it is because causal_product_cuda can't be imported. And the corresponding function is set to None image image

I found that there is no casual_product_gpu in the directory ,and it can't be imported I have tried --no-cache-dir to recompile (referenced in this issue https://github.com/idiap/fast-transformers/issues/45#issue-738516769) but it didn't work I have tried to run the model on ubuntu 20.04 LTS and windows 10, but I got the same error. I have also tried building the lib from source. But also, it didn't work. And if I only use cpu to run the model, it works properly.

image

Originally posted by @15805383399 in https://github.com/idiap/fast-transformers/issues/45#issuecomment-886186347

15805383399 commented 3 years ago

I have deat with this problem by call nvcc using the absolute path in setup.py

@lru_cache(None)
def cuda_toolkit_available():
    try:
        call(["/usr/local/cuda-11.1/bin/nvcc"], stdout=DEVNULL, stderr=DEVNULL)
        return True
    except FileNotFoundError:
        return False

instead of the original code

@lru_cache(None)
def cuda_toolkit_available():
    try:
        call(["nvcc"], stdout=DEVNULL, stderr=DEVNULL)
        return True
    except FileNotFoundError:
        return False

nvcc is callable in terminal image But in Python Console, I can't call it just using call("nvcc"), but the absolute path works

from subprocess import DEVNULL, call
call("nvcc")

Traceback (most recent call last):
  File "/home/lyk/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-f29d24e71b69>", line 1, in <module>
    call("nvcc")
  File "/home/lyk/anaconda3/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/home/lyk/anaconda3/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/lyk/anaconda3/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'nvcc'

call("/usr/local/cuda-11.1/bin/nvcc")
nvcc fatal   : No input files specified; use option --help for more information