Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'MHA' is not defined #10

Open
byrneml opened this issue Feb 27, 2024 · 18 comments
Open

NameError: name 'MHA' is not defined #10

byrneml opened this issue Feb 27, 2024 · 18 comments

Comments

@byrneml
Copy link

byrneml commented Feb 27, 2024

Trying to load the model from HuggingFace across many environments (Jupyter Notebook, local on MacOS, all python 3.10 and latest version of transformers) yields the error:

self.inner_mha_cls = MHA(
NameError: name 'MHA' is not defined

The code I'm using is the sample code from your HuggingFace example!

@Zymrael
Copy link
Collaborator

Zymrael commented Feb 28, 2024

Did you install flash attention?

@byrneml
Copy link
Author

byrneml commented Feb 28, 2024 via email

@Zymrael
Copy link
Collaborator

Zymrael commented Mar 6, 2024

Was this resolved?

@OdedKBio
Copy link

OdedKBio commented Mar 7, 2024

I'm getting the same error on Apple M3, any solutions?

@amoskalev
Copy link

I have the following issue with A100 NameError: name 'swap_mha_rope' is not defined. Have anyone faced the same issue?

@xmz111
Copy link

xmz111 commented Mar 9, 2024

Was this resolved?

I encounter this issue as well, it seems that flash_attn has some problems.
When I use pip install flash_attn, I get the version 2.5.6, but this version has some importing issues.
When I choose to install low version of flash_attn, it fails since cuda and pytorch version issues.
(3090)

@xmz111
Copy link

xmz111 commented Mar 10, 2024

Was this resolved?

I can't solve this problem, using RTX3090.

@exnx
Copy link
Collaborator

exnx commented Mar 11, 2024

It sounds like these are all flash attention compatibility issues with specific gpus

@xmz111
Copy link

xmz111 commented Mar 11, 2024

It sounds like these are all flash attention compatibility issues with specific gpus

Hi! After experiment, a conclusion can be get that there is nothing to do with GPU, at least, RTX3090 doesn't cause this problem.
It is some compiling error in flash_attn library, and I guess it is caused by version conflict.
Class MHA can not be imported because this lib isn't be compiled correctly. By run the code in model.py in huggingface repo:
from flash_attn.modules.mha import MHA print(MHA), there goes a problem: File "/miniconda3/envs/for_evo/lib/python3.8/site-packages/flash_attn/flash_attn_interface.py", line 10, in <module> import flash_attn_2_cuda as flash_attn_cuda ImportError: libtorch_cuda_cpp.so: cannot open shared object file: No such file or directory
This problem occurs when I try to install flash_attn by using ./install.py from their repo. However, I try pip install flash_attn and install the version 2.5.6, no error is raised. Nevertheless, the problem still exists but there is no alert. When I import class in flash_attn, the compiling problem hinder importing, so this problem occurs.

@xmz111
Copy link

xmz111 commented Mar 11, 2024

Dear all, this problem finally solved by changing flash_attn version.
First, this issue isn't caused by GPU. In flash_attn repo, it indicates A100 and RTX3090 is supported (See their repo), and I run the code successfully using 3090.
Second, according to README.md, pytorch should be installed first, however, version should be compatible between torch, cuda and related libs. For me, my version is below: torch 2.0.0+cu118 torchaudio 2.0.1+cu118 torchvision 0.15.1+cu118. Using nvcc -V, my version is Cuda compilation tools, release 11.8, V11.8.89. You may need install cudatoolkit and related libs using pip. For instance, conda install cudatoolkit==11.6 -c nvidia, conda install cuda-nvcc.
Third, this problem is caused by flash_attn lib and importing issue should be a global event, in other word, if you can import flash_attn correctly in your code, MHA can be imported correctly in model.py from Huggingface repo. So you should test if this lib can be used correctly first. For example, from flash_attn.modules.mha import MHA print(MHA), and a class will be returned.
The most important thing is that flash_attn has a lot of versions, so following to README.md, using pip install flash_attn , you may not get the version you need. What's worse, this lib won't report errors, even though compiling isn't complete, that's why I recommend you test whether this lib can be used. Given versions of cuda, torch, python, you can select a lib fits you in https://github.com/Dao-AILab/flash-attention/releases. Take myself as an example, pip install https://github.com/Dao-AILab/flash-attention/releases/download/v2.5.6/flash_attn-2.5.6+cu118torch2.0cxx11abiFALSE-cp38-cp38-linux_x86_64.whl.
I waste 3 days to figure out what happened to EVO. Hope that people can be reminded in README and everyone can enjoy EVO successfully.

@salehsereshkiucr
Copy link

Same issue for me using cuda_11.7.r11.7

@salehsereshkiucr
Copy link

The problem for me was the triton package was not installed. This solved the problem for me.

pip install triton

Also, I checked here https://github.com/Dao-AILab/flash-attention/releases and downloaded the right .whl file compatible with the cuda and torch version running on my system. and ran it by

pip install flash_attn-2.3.0+cu117torch1.13cxx11abiTRUE-cp38-cp38-linux_x86_64.whl

@hforoughmand
Copy link

I have similar problem on a V100. I installed several versions of pytorch and flash_attn and triton packages. But I receive the following error:

RuntimeError: Internal Triton PTX codegen error: 
ptxas /tmp/compile-ptx-src-b231af, line 147; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 147; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher              ptxas /tmp/compile-ptx-src-b231af, line 149; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 149; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 160; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 160; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 162; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 162; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 181; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 181; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 183; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 183; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 197; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 197; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 199; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 199; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 233; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 233; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 235; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 235; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 243; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 243; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 245; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/compile-ptx-src-b231af, line 245; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas fatal   : Ptx assembly aborted due to errors

Any suggestion how to fix this problem?

@salehsereshkiucr
Copy link

salehsereshkiucr commented May 3, 2024 via email

@cclough
Copy link

cclough commented May 9, 2024

I have the following issue with A100 NameError: name 'swap_mha_rope' is not defined. Have anyone faced the same issue?

I'm getting this too. did you find a solution?

@hforoughmand
Copy link

One suggestion from flash attention team was to use nightly build of everything. That solves some problems with the flash attention. But I still cannot use evo as I receive similar errors:

RuntimeError: Internal Triton PTX codegen error: 
ptxas /tmp/tmp8b6rqkxa.ptx, line 157; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 157; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 161; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 161; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 178; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 178; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 182; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 182; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 207; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 207; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 211; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 211; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 231; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 231; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 235; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 235; error   : Feature 'cvt with .f32.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 271; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 271; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 275; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 275; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 289; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 289; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 293; error   : Feature '.bf16' requires .target sm_80 or higher
ptxas /tmp/tmp8b6rqkxa.ptx, line 293; error   : Feature 'cvt.bf16.f32' requires .target sm_80 or higher
ptxas fatal   : Ptx assembly aborted due to errors

Any idea how can I fix it?

@JinwnK
Copy link

JinwnK commented Jul 10, 2024

I have the following issue with A100 NameError: name 'swap_mha_rope' is not defined. Have anyone faced the same issue?

I'm getting this too. did you find a solution?

I have the same problem, any solutions?

@cx0
Copy link

cx0 commented Jul 13, 2024

I am running inference on A100 without any issue. Here are the specific versions for the (most) relevant libraries. Hope this helps.
Screenshot 2024-07-13 at 12 32 44 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests