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' flash_attn_with_kvcache 'is not defined #11200

Open
1074224619 opened this issue Nov 7, 2024 · 1 comment
Open

NameError: name' flash_attn_with_kvcache 'is not defined #11200

1074224619 opened this issue Nov 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@1074224619
Copy link

Describe the bug

When I use flash attn=2.0.4, running Nemo will result in an error NameError: name' flash_attn_with_kvcache 'is not defined

After checking the code, I found that when

try:
  # Flash Attention 1.X
  from flash_attn.bert_padding import pad_input, unpad_input
  from flash_attn.flash_attn_interface import flash_attn_unpadded_func

  HAVE_FLASH_ATTENTION = True
  flash_attn_func = None

After success, below

except (ImportError, ModuleNotFoundError):
  try:
    from flash_attn import flash_attn_with_kvcache
  except
    flash_attn_with_kvcache = None

I won't execute it
So below

if (
  flash_attn_with_kvcache is not None
  and self.use_flash_attention
  and rotary_pos_emb is not None
  and inference_max_sequence_len
  and not set_inference_key_value_memory

The above error will be reported, I think this is a bug, right?

@1074224619 1074224619 added the bug Something isn't working label Nov 7, 2024
@csn1011
Copy link

csn1011 commented Nov 13, 2024

what is the output of pip freeze?

I'm running flash-attn==2.0.4 and nemo_toolkit==1.23.0 and

>>> from nemo.collections.nlp.modules.common.megatron.attention import CoreAttention

runs without issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants