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

Flash Attention not working with NVIDIA Quadro P3200 Pascal Architecture GPU #7055

Closed
countzero opened this issue May 3, 2024 · 11 comments · Fixed by #7188
Closed

Flash Attention not working with NVIDIA Quadro P3200 Pascal Architecture GPU #7055

countzero opened this issue May 3, 2024 · 11 comments · Fixed by #7188

Comments

@countzero
Copy link

I am using the server of llama.cpp b2781 on a Windows machine with enabled --flash-attn option.

The Compute Capability of the Quadro P3200 GPU in the machine is 6.1. The installed NVIDIA Driver is at 552.22 and CUDA 12.3.

I am getting the following error message:

ERROR: CUDA kernel flash_attn_ext_f16 has no device code compatible with CUDA arch 610. ggml-cuda.cu was compiled for: 520,610,700

Log

system_info":"AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 0 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | "}
llama_model_loader: loaded meta data with 24 key-value pairs and 291 tensors from .\vendor\llama.cpp\models\openchat-3.5-0106.Q5_K_M.gguf (version GGUF V3 (latest))
llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
llama_model_loader: - kv   0:                       general.architecture str              = llama
llama_model_loader: - kv   1:                               general.name str              = D:\Arbeit\windows_manage_large_langua...
llama_model_loader: - kv   2:                           llama.vocab_size u32              = 32002
llama_model_loader: - kv   3:                       llama.context_length u32              = 8192
llama_model_loader: - kv   4:                     llama.embedding_length u32              = 4096
llama_model_loader: - kv   5:                          llama.block_count u32              = 32
llama_model_loader: - kv   6:                  llama.feed_forward_length u32              = 14336
llama_model_loader: - kv   7:                 llama.rope.dimension_count u32              = 128
llama_model_loader: - kv   8:                 llama.attention.head_count u32              = 32
llama_model_loader: - kv   9:              llama.attention.head_count_kv u32              = 8
llama_model_loader: - kv  10:     llama.attention.layer_norm_rms_epsilon f32              = 0.000010
llama_model_loader: - kv  11:                       llama.rope.freq_base f32              = 10000.000000
llama_model_loader: - kv  12:                          general.file_type u32              = 17
llama_model_loader: - kv  13:                       tokenizer.ggml.model str              = llama
llama_model_loader: - kv  14:                      tokenizer.ggml.tokens arr[str,32002]   = ["<unk>", "<s>", "</s>", "<0x00>", "<...
llama_model_loader: - kv  15:                      tokenizer.ggml.scores arr[f32,32002]   = [0.000000, 0.000000, 0.000000, 0.0000...
llama_model_loader: - kv  16:                  tokenizer.ggml.token_type arr[i32,32002]   = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...
llama_model_loader: - kv  17:                tokenizer.ggml.bos_token_id u32              = 1
llama_model_loader: - kv  18:                tokenizer.ggml.eos_token_id u32              = 32000
llama_model_loader: - kv  19:            tokenizer.ggml.unknown_token_id u32              = 0
llama_model_loader: - kv  20:               tokenizer.ggml.add_bos_token bool             = true
llama_model_loader: - kv  21:               tokenizer.ggml.add_eos_token bool             = false
llama_model_loader: - kv  22:                    tokenizer.chat_template str              = {{ bos_token }}{% for message in mess...
llama_model_loader: - kv  23:               general.quantization_version u32              = 2
llama_model_loader: - type  f32:   65 tensors
llama_model_loader: - type q5_K:  193 tensors
llama_model_loader: - type q6_K:   33 tensors
llm_load_vocab: special tokens definition check successful ( 261/32002 ).
llm_load_print_meta: format           = GGUF V3 (latest)
llm_load_print_meta: arch             = llama
llm_load_print_meta: vocab type       = SPM
llm_load_print_meta: n_vocab          = 32002
llm_load_print_meta: n_merges         = 0
llm_load_print_meta: n_ctx_train      = 8192
llm_load_print_meta: n_embd           = 4096
llm_load_print_meta: n_head           = 32
llm_load_print_meta: n_head_kv        = 8
llm_load_print_meta: n_layer          = 32
llm_load_print_meta: n_rot            = 128
llm_load_print_meta: n_embd_head_k    = 128
llm_load_print_meta: n_embd_head_v    = 128
llm_load_print_meta: n_gqa            = 4
llm_load_print_meta: n_embd_k_gqa     = 1024
llm_load_print_meta: n_embd_v_gqa     = 1024
llm_load_print_meta: f_norm_eps       = 0.0e+00
llm_load_print_meta: f_norm_rms_eps   = 1.0e-05
llm_load_print_meta: f_clamp_kqv      = 0.0e+00
llm_load_print_meta: f_max_alibi_bias = 0.0e+00
llm_load_print_meta: f_logit_scale    = 0.0e+00
llm_load_print_meta: n_ff             = 14336
llm_load_print_meta: n_expert         = 0
llm_load_print_meta: n_expert_used    = 0
llm_load_print_meta: causal attn      = 1
llm_load_print_meta: pooling type     = 0
llm_load_print_meta: rope type        = 0
llm_load_print_meta: rope scaling     = linear
llm_load_print_meta: freq_base_train  = 10000.0
llm_load_print_meta: freq_scale_train = 1
llm_load_print_meta: n_yarn_orig_ctx  = 8192
llm_load_print_meta: rope_finetuned   = unknown
llm_load_print_meta: ssm_d_conv       = 0
llm_load_print_meta: ssm_d_inner      = 0
llm_load_print_meta: ssm_d_state      = 0
llm_load_print_meta: ssm_dt_rank      = 0
llm_load_print_meta: model type       = 8B
llm_load_print_meta: model ftype      = Q5_K - Medium
llm_load_print_meta: model params     = 7.24 B
llm_load_print_meta: model size       = 4.78 GiB (5.67 BPW)
llm_load_print_meta: general.name     = D:\Arbeit\windows_manage_large_language_models\source
llm_load_print_meta: BOS token        = 1 '<s>'
llm_load_print_meta: EOS token        = 32000 '<|end_of_turn|>'
llm_load_print_meta: UNK token        = 0 '<unk>'
llm_load_print_meta: LF token         = 13 '<0x0A>'
ggml_cuda_init: GGML_CUDA_FORCE_MMQ:   no
ggml_cuda_init: CUDA_USE_TENSOR_CORES: yes
ggml_cuda_init: found 1 CUDA devices:
  Device 0: Quadro P3200 with Max-Q Design, compute capability 6.1, VMM: yes
llm_load_tensors: ggml ctx size =    0.30 MiB
llm_load_tensors: offloading 32 repeating layers to GPU
llm_load_tensors: offloading non-repeating layers to GPU
llm_load_tensors: offloaded 33/33 layers to GPU
llm_load_tensors:        CPU buffer size =    85.94 MiB
llm_load_tensors:      CUDA0 buffer size =  4807.06 MiB
...................................................................................................
llama_new_context_with_model: n_ctx      = 8192
llama_new_context_with_model: n_batch    = 2048
llama_new_context_with_model: n_ubatch   = 512
llama_new_context_with_model: flash_attn = 1
llama_new_context_with_model: freq_base  = 10000.0
llama_new_context_with_model: freq_scale = 1
llama_kv_cache_init:      CUDA0 KV buffer size =  1024.00 MiB
llama_new_context_with_model: KV self size  = 1024.00 MiB, K (f16):  512.00 MiB, V (f16):  512.00 MiB
llama_new_context_with_model:  CUDA_Host  output buffer size =     0.24 MiB
llama_new_context_with_model:      CUDA0 compute buffer size =    88.00 MiB
llama_new_context_with_model:  CUDA_Host compute buffer size =    24.01 MiB
llama_new_context_with_model: graph nodes  = 903
llama_new_context_with_model: graph splits = 2
[1714720299] warming up the model with an empty run
D:\Arbeit\windows_llama.cpp\vendor\llama.cpp\ggml-cuda\fattn.cu:571: ERROR: CUDA kernel flash_attn_ext_f16 has no device code compatible with CUDA arch 610. ggml-cuda.cu was compiled for: 520,610,700
[...]
D:\Arbeit\windows_llama.cpp\vendor\llama.cpp\ggml-cuda\fattn.cu:571: ERROR: CUDA kernel flash_attn_ext_f16 has no device code compatible with CUDA arch 610. ggml-cuda.cu was compiled for: 520,610,700
ggml_cuda_compute_forward: SILU failed
CUDA error: unspecified launch failure
  current device: 0, in function ggml_cuda_compute_forward at D:\Arbeit\windows_llama.cpp\vendor\llama.cpp\ggml-cuda.cu:2305
  err
GGML_ASSERT: D:\Arbeit\windows_llama.cpp\vendor\llama.cpp\ggml-cuda.cu:61: !"CUDA error"

Flash Attention is working for me on a Turing GPU.

Question: Should llama.cpp support Pascal GPUs?

If not it would be nice to have a feature detection and a speaking error message that indicates this.

@JohannesGaessler
Copy link
Collaborator

As of right now there are only CUDA FlashAttention kernels that use tensor cores which in turn means you need Turing/Volta or newer.

@countzero
Copy link
Author

@JohannesGaessler Okay, that explains things 😉

So basically the Flash Attention implementation of llama.cpp relies on the NVIDIA GPU to have Tensor Cores.

Suggestion

If I read https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#features-and-technical-specifications correctly we can programmatically determine if a GPU has Tensor Cores.

Could the llama.cpp implementation check the Compute Capability of the GPU and ignore the --flash-attn option with a warning message if it is < 7.0 ?

I am getting a Compute Capability of 6.1 on the NVIDIA Quadro P3200 using the following command:

nvidia-smi --query-gpu=compute_cap --format=csv

@JohannesGaessler
Copy link
Collaborator

I'm writing FlashAttention kernels that don't need tensor cores as we speak.

@crashr
Copy link

crashr commented May 3, 2024

@JohannesGaessler I already read on LocalLLaMA. I am smiling in 5xP40.

@scottmudge
Copy link

scottmudge commented May 8, 2024

@JohannesGaessler Is this the PR for that change? #7061

EDIT: Nevermind, I assume so since the branch name is cuda-fa-no-tc-5. I'll test it on my Pascal cards.

@JohannesGaessler
Copy link
Collaborator

You're going to get correct results but unless you have a P100 the performance is going to be terrible.

@scottmudge
Copy link

Ah, good to know. 2x1080 Ti's, which are roughly equivalent, perhaps marginally faster(?) than P100s in some metrics. It will be an interesting experiment anyway.

@JohannesGaessler
Copy link
Collaborator

No, it will literally only perform well on P100s because all other Pascal cards have gimped FP16 performance.

@scottmudge
Copy link

Ah that's a shame, well that's good to know.

@scottmudge
Copy link

scottmudge commented May 8, 2024

Yeah, went from:

(9.1ms/T = 109.51T/s), Generate:17.10s (18.4ms/T = 54.43T/s), Total:17.45s (53.35T/s)

To:

(11.4ms/T = 87.46T/s), Generate:12.72s (13.7ms/T = 73.20T/s), Total:35.45s (26.26T/s)

With FP16 flash-attention on my non-P100 Pascal cards. So not great. I have a 12GB Maxwell card that I don't think has the same NVIDIA FP16 kneecapping, but for now I'll just leave FA off.

@JohannesGaessler
Copy link
Collaborator

General Pascal support: #7188 .
Performance for large batch sizes is still suboptimal due to a lack of a specialized kernel.

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

Successfully merging a pull request may close this issue.

4 participants