Skip to content

Bug: llama-server api first query very slow #9492

Open
@bosmart

Description

@bosmart

What happened?

I'm using the openai library to interact with llama-server docker image on an A6000:

docker run -p 8080:8080 --name llama-server -v ~/gguf_models:/models --gpus all ghcr.io/ggerganov/llama.cpp:server-cuda -m models/Meta-Llama-3.1-70B-Instruct-Q4_K_L.gguf -c 65536 -fa --host 0.0.0.0 --port 8080 --n-gpu-layers 99 -ctk q4_0 -ctv q4_0 -t 4

The first request I send takes about 80 seconds, during which at first a single CPU core gets 100% load for maybe ~55s (with GPU usage at 0%) and only then the GPU kicks in. The second time I execute the exact same call, it takes ~26s to respond and starts with both CPU (one core 100%) and GPU (~87%) working a the same time.

The API call itself is:

import openai  # openai-1.45.0

api_url = 'http://x.x.x.x:8080'

client = openai.OpenAI(
    base_url=f"{api_url}/v1",
    api_key = "unused"
)

messages = [
    {"role": "system", "content": "You are a helpful assistant. Your top priority is answering user questions truthfully, based solely on the information provided."},
    {"role": "user", "content": prompt} # prompt is around 450 words
]

completion = client.chat.completions.create(
    model=None,
    temperature=0.0,
    messages=messages
).choices[0].message

Name and Version

$./llama-server --version
version: 0 (unknown)
built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu

^^^ not very helpful but I have just pulled a fresh docker image today i.e. 15/09/2024:
docker pull ghcr.io/ggerganov/llama.cpp:server-cuda

What operating system are you seeing the problem on?

Linux

Relevant log output

warn: LLAMA_ARG_HOST environment variable is set, but will be overwritten by command line argument --host
INFO [                    main] build info | tid="126087453233152" timestamp=1726381552 build=0 commit="unknown"
INFO [                    main] system info | tid="126087453233152" timestamp=1726381552 n_threads=4 n_threads_batch=4 total_threads=36 system_info="AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | AVX512_BF16 = 0 | FMA = 1 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | RISCV_VECT = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | "
INFO [                    main] HTTP server is listening | tid="126087453233152" timestamp=1726381552 n_threads_http="35" port="8080" hostname="0.0.0.0"
INFO [                    main] loading model | tid="126087453233152" timestamp=1726381552 n_threads_http="35" port="8080" hostname="0.0.0.0"
llama_model_loader: loaded meta data with 33 key-value pairs and 724 tensors from models/Meta-Llama-3.1-70B-Instruct-Q4_K_L.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.type str              = model
llama_model_loader: - kv   2:                               general.name str              = Meta Llama 3.1 70B Instruct
llama_model_loader: - kv   3:                           general.finetune str              = Instruct
llama_model_loader: - kv   4:                           general.basename str              = Meta-Llama-3.1
llama_model_loader: - kv   5:                         general.size_label str              = 70B
llama_model_loader: - kv   6:                            general.license str              = llama3.1
llama_model_loader: - kv   7:                               general.tags arr[str,6]       = ["facebook", "meta", "pytorch", "llam...
llama_model_loader: - kv   8:                          general.languages arr[str,8]       = ["en", "de", "fr", "it", "pt", "hi", ...
llama_model_loader: - kv   9:                          llama.block_count u32              = 80
llama_model_loader: - kv  10:                       llama.context_length u32              = 131072
llama_model_loader: - kv  11:                     llama.embedding_length u32              = 8192
llama_model_loader: - kv  12:                  llama.feed_forward_length u32              = 28672
llama_model_loader: - kv  13:                 llama.attention.head_count u32              = 64
llama_model_loader: - kv  14:              llama.attention.head_count_kv u32              = 8
llama_model_loader: - kv  15:                       llama.rope.freq_base f32              = 500000.000000
llama_model_loader: - kv  16:     llama.attention.layer_norm_rms_epsilon f32              = 0.000010
llama_model_loader: - kv  17:                          general.file_type u32              = 15
llama_model_loader: - kv  18:                           llama.vocab_size u32              = 128256
llama_model_loader: - kv  19:                 llama.rope.dimension_count u32              = 128
llama_model_loader: - kv  20:                       tokenizer.ggml.model str              = gpt2
llama_model_loader: - kv  21:                         tokenizer.ggml.pre str              = llama-bpe
llama_model_loader: - kv  22:                      tokenizer.ggml.tokens arr[str,128256]  = ["!", "\"", "#", "$", "%", "&", "'", ...
llama_model_loader: - kv  23:                  tokenizer.ggml.token_type arr[i32,128256]  = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
llama_model_loader: - kv  24:                      tokenizer.ggml.merges arr[str,280147]  = ["Ġ Ġ", "Ġ ĠĠĠ", "ĠĠ ĠĠ", "...
llama_model_loader: - kv  25:                tokenizer.ggml.bos_token_id u32              = 128000
llama_model_loader: - kv  26:                tokenizer.ggml.eos_token_id u32              = 128009
llama_model_loader: - kv  27:                    tokenizer.chat_template str              = {{- bos_token }}\n{%- if custom_tools ...
llama_model_loader: - kv  28:               general.quantization_version u32              = 2
llama_model_loader: - kv  29:                      quantize.imatrix.file str              = /models_out/Meta-Llama-3.1-70B-Instru...
llama_model_loader: - kv  30:                   quantize.imatrix.dataset str              = /training_dir/calibration_datav3.txt
llama_model_loader: - kv  31:             quantize.imatrix.entries_count i32              = 560
llama_model_loader: - kv  32:              quantize.imatrix.chunks_count i32              = 125
llama_model_loader: - type  f32:  162 tensors
llama_model_loader: - type q8_0:    2 tensors
llama_model_loader: - type q4_K:  440 tensors
llama_model_loader: - type q5_K:   40 tensors
llama_model_loader: - type q6_K:   80 tensors
llm_load_vocab: special tokens cache size = 256
llm_load_vocab: token to piece cache size = 0.7999 MB
llm_load_print_meta: format           = GGUF V3 (latest)
llm_load_print_meta: arch             = llama
llm_load_print_meta: vocab type       = BPE
llm_load_print_meta: n_vocab          = 128256
llm_load_print_meta: n_merges         = 280147
llm_load_print_meta: vocab_only       = 0
llm_load_print_meta: n_ctx_train      = 131072
llm_load_print_meta: n_embd           = 8192
llm_load_print_meta: n_layer          = 80
llm_load_print_meta: n_head           = 64
llm_load_print_meta: n_head_kv        = 8
llm_load_print_meta: n_rot            = 128
llm_load_print_meta: n_swa            = 0
llm_load_print_meta: n_embd_head_k    = 128
llm_load_print_meta: n_embd_head_v    = 128
llm_load_print_meta: n_gqa            = 8
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             = 28672
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  = 500000.0
llm_load_print_meta: freq_scale_train = 1
llm_load_print_meta: n_ctx_orig_yarn  = 131072
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: ssm_dt_b_c_rms   = 0
llm_load_print_meta: model type       = 70B
llm_load_print_meta: model ftype      = Q4_K - Medium
llm_load_print_meta: model params     = 70.55 B
llm_load_print_meta: model size       = 40.32 GiB (4.91 BPW)
llm_load_print_meta: general.name     = Meta Llama 3.1 70B Instruct
llm_load_print_meta: BOS token        = 128000 '<|begin_of_text|>'
llm_load_print_meta: EOS token        = 128009 '<|eot_id|>'
llm_load_print_meta: LF token         = 128 'Ä'
llm_load_print_meta: EOT token        = 128009 '<|eot_id|>'
llm_load_print_meta: max token length = 256
ggml_cuda_init: GGML_CUDA_FORCE_MMQ:    no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 1 CUDA devices:
  Device 0: NVIDIA RTX A6000, compute capability 8.6, VMM: yes
llm_load_tensors: ggml ctx size =    0.68 MiB
llm_load_tensors: offloading 80 repeating layers to GPU
llm_load_tensors: offloading non-repeating layers to GPU
llm_load_tensors: offloaded 81/81 layers to GPU
llm_load_tensors:        CPU buffer size =  1064.62 MiB
llm_load_tensors:      CUDA0 buffer size = 40222.18 MiB
.................................................................................................
llama_new_context_with_model: n_ctx      = 65536
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  = 500000.0
llama_new_context_with_model: freq_scale = 1
llama_kv_cache_init:      CUDA0 KV buffer size =  5760.00 MiB
llama_new_context_with_model: KV self size  = 5760.00 MiB, K (q4_0): 2880.00 MiB, V (q4_0): 2880.00 MiB
llama_new_context_with_model:  CUDA_Host  output buffer size =     0.98 MiB
llama_new_context_with_model:      CUDA0 compute buffer size =   266.50 MiB
llama_new_context_with_model:  CUDA_Host compute buffer size =   144.01 MiB
llama_new_context_with_model: graph nodes  = 2247
llama_new_context_with_model: graph splits = 2
INFO [                    init] initializing slots | tid="126087453233152" timestamp=1726381574 n_slots=1
INFO [                    init] new slot | tid="126087453233152" timestamp=1726381574 id_slot=0 n_ctx_slot=65536
INFO [                    main] model loaded | tid="126087453233152" timestamp=1726381574
INFO [                    main] chat template | tid="126087453233152" timestamp=1726381574 chat_example="<|start_header_id|>system<|end_header_id|>\n\nYou are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHello<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHi there<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHow are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n" built_in=true
INFO [            update_slots] all slots are idle | tid="126087453233152" timestamp=1726381574
INFO [      log_server_request] request | tid="126086914506752" timestamp=1726381582 remote_addr="127.0.0.1" remote_port=35744 status=200 method="GET" path="/health" params={}
INFO [   launch_slot_with_task] slot is processing task | tid="126087453233152" timestamp=1726381587 id_slot=0 id_task=0
INFO [            update_slots] kv cache rm [p0, end) | tid="126087453233152" timestamp=1726381587 id_slot=0 id_task=0 p0=0
INFO [      log_server_request] request | tid="126086815940608" timestamp=1726381613 remote_addr="127.0.0.1" remote_port=59038 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086805454848" timestamp=1726381643 remote_addr="127.0.0.1" remote_port=35914 status=200 method="GET" path="/health" params={}
INFO [                 release] slot released | tid="126087453233152" timestamp=1726381666 id_slot=0 id_task=0 n_past=1011 truncated=false
INFO [           print_timings] prompt eval time     =   39264.22 ms /   685 tokens (   57.32 ms per token,    17.45 tokens per second) | tid="126087453233152" timestamp=1726381666 id_slot=0 id_task=0 t_prompt_processing=39264.217 n_prompt_tokens_processed=685 t_token=57.320024817518245 n_tokens_second=17.44591010181102
INFO [           print_timings] generation eval time =   40157.40 ms /   327 runs   (  122.81 ms per token,     8.14 tokens per second) | tid="126087453233152" timestamp=1726381666 id_slot=0 id_task=0 t_token_generation=40157.401 n_decoded=327 t_token=122.80550764525994 n_tokens_second=8.142957259609506
INFO [           print_timings]           total time =   79421.62 ms | tid="126087453233152" timestamp=1726381666 id_slot=0 id_task=0 t_prompt_processing=39264.217 t_token_generation=40157.401 t_total=79421.61799999999
INFO [            update_slots] all slots are idle | tid="126087453233152" timestamp=1726381666
INFO [      log_server_request] request | tid="126086904020992" timestamp=1726381666 remote_addr="10.147.20.194" remote_port=47472 status=200 method="POST" path="/v1/chat/completions" params={}
INFO [   launch_slot_with_task] slot is processing task | tid="126087453233152" timestamp=1726381670 id_slot=0 id_task=328
INFO [            update_slots] kv cache rm [p0, end) | tid="126087453233152" timestamp=1726381670 id_slot=0 id_task=328 p0=0
INFO [      log_server_request] request | tid="126086794969088" timestamp=1726381673 remote_addr="127.0.0.1" remote_port=44812 status=200 method="GET" path="/health" params={}
INFO [                 release] slot released | tid="126087453233152" timestamp=1726381696 id_slot=0 id_task=328 n_past=1011 truncated=false
INFO [           print_timings] prompt eval time     =    1319.62 ms /   685 tokens (    1.93 ms per token,   519.09 tokens per second) | tid="126087453233152" timestamp=1726381696 id_slot=0 id_task=328 t_prompt_processing=1319.625 n_prompt_tokens_processed=685 t_token=1.9264598540145985 n_tokens_second=519.0868617978592
INFO [           print_timings] generation eval time =   24725.42 ms /   327 runs   (   75.61 ms per token,    13.23 tokens per second) | tid="126087453233152" timestamp=1726381696 id_slot=0 id_task=328 t_token_generation=24725.416 n_decoded=327 t_token=75.61289296636086 n_tokens_second=13.225257767149397
INFO [           print_timings]           total time =   26045.04 ms | tid="126087453233152" timestamp=1726381696 id_slot=0 id_task=328 t_prompt_processing=1319.625 t_token_generation=24725.416 t_total=26045.041
INFO [            update_slots] all slots are idle | tid="126087453233152" timestamp=1726381696
INFO [      log_server_request] request | tid="126086904020992" timestamp=1726381696 remote_addr="10.147.20.194" remote_port=47472 status=200 method="POST" path="/v1/chat/completions" params={}
INFO [      log_server_request] request | tid="126086763511808" timestamp=1726381703 remote_addr="127.0.0.1" remote_port=57226 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086773997568" timestamp=1726381733 remote_addr="127.0.0.1" remote_port=58518 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086784483328" timestamp=1726381763 remote_addr="127.0.0.1" remote_port=36938 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086753026048" timestamp=1726381793 remote_addr="127.0.0.1" remote_port=34366 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086742540288" timestamp=1726381823 remote_addr="127.0.0.1" remote_port=36110 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086721568768" timestamp=1726381853 remote_addr="127.0.0.1" remote_port=41308 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086732054528" timestamp=1726381883 remote_addr="127.0.0.1" remote_port=44500 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086711083008" timestamp=1726381913 remote_addr="127.0.0.1" remote_port=51098 status=200 method="GET" path="/health" params={}
INFO [      log_server_request] request | tid="126086700597248" timestamp=1726381943 remote_addr="127.0.0.1" remote_port=39654 status=200 method="GET" path="/health" params={}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmedium severityUsed to report medium severity bugs in llama.cpp (e.g. Malfunctioning Features but still useable)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions