flash-attention icon indicating copy to clipboard operation
flash-attention copied to clipboard

Flash Attention 2.0 doesn't work: undefined symbol: _ZNK3c1010TensorImpl27throw_data_ptr_access_errorEv

Open FrancescoSaverioZuppichini opened this issue 2 years ago • 25 comments
trafficstars

Hi there,

cloing the repo and running pytest tests/test_flash_attn.py gives

ImportError while importing test module '/root/flash-attention/tests/test_flash_attn.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_flash_attn.py:10: in <module>
    from flash_attn import flash_attn_func, flash_attn_kvpacked_func, flash_attn_qkvpacked_func
/usr/local/lib/python3.10/dist-packages/flash_attn/__init__.py:3: in <module>
    from flash_attn.flash_attn_interface import flash_attn_func
/usr/local/lib/python3.10/dist-packages/flash_attn/flash_attn_interface.py:4: in <module>
    import flash_attn_2_cuda as flash_attn_cuda
E   ImportError: /usr/local/lib/python3.10/dist-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZNK3c1010TensorImpl27throw_data_ptr_access_errorEv

maybe somebody else have encountered this

Thanks a lot,

Fra

Error persist also on a small stupid tests

import torch 
from torch import nn
from flash_attn import flash_attn_qkvpacked_func

qvk = nn.Linear(1, 3, 196, 512).cuda()

res = flash_attn_qkvpacked_func(qvk=qvk)
print(res.shape)
print(res)
Traceback (most recent call last):
  File "/root/main.py", line 3, in <module>
    from flash_attn import flash_attn_qkvpacked_func
  File "/usr/local/lib/python3.10/dist-packages/flash_attn/__init__.py", line 3, in <module>
    from flash_attn.flash_attn_interface import flash_attn_func
  File "/usr/local/lib/python3.10/dist-packages/flash_attn/flash_attn_interface.py", line 4, in <module>
    import flash_attn_2_cuda as flash_attn_cuda
ImportError: /usr/local/lib/python3.10/dist-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZNK3c1010TensorImpl27throw_data_ptr_access_errorEv

I think you compiled with 2.0.7 and I am using torch 2.1.0

using

FROM nvcr.io/nvidia/pytorch:23.06-py3

so python 3.10, cuda 12.1 and torch 2.1 (see nvidia doc) and the correct wheel (https://github.com/Dao-AILab/flash-attention/releases/download/v2.0.7/flash_attn-2.0.7+cu121torch2.1cxx11abiTRUE-cp310-cp310-linux_x86_64.whl) still result in the same error

import flash_attn_2_cuda as flash_attn_cuda

ImportError: /usr/local/lib/python3.10/dist-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZNK3c1010TensorImpl27throw_data_ptr_access_errorEv

Thanks for the report. I saw just this error on nvcr 23.06 as well. nvcr 23.07 should work, can you try? The error is due to pytorch interface changing between the version used in 23.06 and 23.07.

tridao avatar Aug 15 '23 15:08 tridao

to

Thanks a lot, will try as soon as I go back to my pc, out of curiosity could to give me more details about due to pytorch interface changing between the version used in 23.06 and 23.07?

Oh it's a low-level change in error handling. Pytorch added this "throw_data_ptr_access_error" function in May 11. nvcr 23.06 uses pytorch version on May 2 and nvcr 23.07 uses pytorch version on June 7.

tridao avatar Aug 15 '23 16:08 tridao

Try a cxx11abiFALSE version

janelu9 avatar Aug 17 '23 02:08 janelu9

Hi @tridao! I have some troubles with python3.10, so I need to use nvcr 23.04. Is their any suggestion to handle this import error with lower version of images?

junjun3518 avatar Aug 25 '23 04:08 junjun3518

You can compile from source with FLASH_ATTENTION_FORCE_BUILD=TRUE: FLASH_ATTENTION_FORCE_BUILD=TRUE pip install flash-attn.

tridao avatar Aug 25 '23 04:08 tridao

Thank you for fast response! I will try it

junjun3518 avatar Aug 25 '23 04:08 junjun3518

Thank you It seems that it is working now

junjun3518 avatar Aug 25 '23 05:08 junjun3518

Thanks for the report. I saw just this error on nvcr 23.06 as well. nvcr 23.07 should work, can you try? The error is due to pytorch interface changing between the version used in 23.06 and 23.07.

Hi @tridao what is nvcr and how to change its version?

dtnghla avatar Jan 18 '24 06:01 dtnghla

import flash_attn_2_cuda as flash_attn_cuda ImportError: /home/nallu002/anaconda3/envs/myenv/lib/python3.9/site-packages/flash_attn_2_cuda.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNK3c106SymIntltEl

I am still facing this error. Chnaged the torch version from 2.1.2 to 2.1.0. And it is still not working.

Niyathi3011 avatar Jan 23 '24 05:01 Niyathi3011

Also facing this error, in Databricks. Torch Version: 2.1.0+cu121 torch.cuda.get_device_capability(): (7,0) Compiled from source but that did not work for me.

ImportError: /databricks/python/lib/python3.10/site-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZNK3c106SymIntltEl

achangtv avatar Feb 01 '24 19:02 achangtv

Try a cxx11abiFALSE version 试用版本 cxx11abiFALSE You can use this to solve the problem. Use pip to install the version package that matches yours directly. I use python 10, cuda11.8 torch 2.0, cxx11abiFALSE

https://github.com/Dao-AILab/flash-attention/releases/download/v2.5.2/flash_attn-2.5.2+cu118torch2.0cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

sleeper1023 avatar Feb 04 '24 03:02 sleeper1023

Also facing this.

jaanli avatar Feb 15 '24 16:02 jaanli

Also facing this issue with nvcr 24.01-py3

LeonEricsson avatar Feb 27 '24 12:02 LeonEricsson

For nvcr 23.12 and 24.01 please use flash-attn 2.5.1.post1

tridao avatar Feb 27 '24 16:02 tridao

For nvcr 23.12 and 24.01 please use flash-attn 2.5.1.post1

'preciate the immediate response 🙌🏼

LeonEricsson avatar Feb 27 '24 18:02 LeonEricsson

Try a cxx11abiFALSE version

Really helpful!

caoyang-sufe avatar Mar 07 '24 07:03 caoyang-sufe

Try a cxx11abiFALSE version 试用版本 cxx11abiFALSE You can use this to solve the problem. Use pip to install the version package that matches yours directly. I use python 10, cuda11.8 torch 2.0, cxx11abiFALSE

https://github.com/Dao-AILab/flash-attention/releases/download/v2.5.2/flash_attn-2.5.2+cu118torch2.0cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

thank you. That's work for me.

kanseaveg avatar Mar 16 '24 02:03 kanseaveg

Thanks for the report. I saw just this error on nvcr 23.06 as well. nvcr 23.07 should work, can you try? The error is due to pytorch interface changing between the version used in 23.06 and 23.07.

Hello, how can i use the version in nvcr 23.07, any details?

ponyzym avatar Mar 23 '24 10:03 ponyzym

You can compile from source with FLASH_ATTENTION_FORCE_BUILD=TRUE: FLASH_ATTENTION_FORCE_BUILD=TRUE pip install flash-attn.

is this genral useful for different nvcr versions? I a using "pytorch/pytorch:2.2.2-cuda12.1-cudnn8-devel" "# FROM nvcr.io/nvidia/pytorch:22.07-py3" "# FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-devel "

yiyepiaoling0715 avatar Apr 22 '24 06:04 yiyepiaoling0715

I got similar error. I think this error is caused by cuda version. I added: export CUDA_HOME=/usr/local/cuda export PATH="/usr/local/cuda/bin${PATH:+:${PATH}}" export LD_LIBRARY_PATH="/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"

to the end of ~/.bashrc and source ~/.bashrc then reinstall pytorch and flash attention. It works.

modelsplaid avatar Apr 28 '24 01:04 modelsplaid

Doing this:

Try a cxx11abiFALSE version 试用版本 cxx11abiFALSE You can use this to solve the problem. Use pip to install the version package that matches yours directly. I use python 10, cuda11.8 torch 2.0, cxx11abiFALSE

https://github.com/Dao-AILab/flash-attention/releases/download/v2.5.2/flash_attn-2.5.2+cu118torch2.0cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

and also forcing:

pip install xformers==v0.0.22

Fixed the issue for me.

UPDATE: it didnt, more problems down the line with missing torch operations

Laz4rz avatar Jul 01 '24 10:07 Laz4rz