ggerganov / llama.cpp

LLM inference in C/C++
MIT License
67.1k stars 9.63k forks source link

Bug: RPC backend crash #9214

Closed xvim closed 2 months ago

xvim commented 2 months ago

What happened?

crash

Name and Version

./build_rpc_cuda/bin/llama-cli --version

version: 3639 (20f1789d) built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu

What operating system are you seeing the problem on?

No response

Relevant log output

# CUDA_VISIBLE_DEVICES=0  ./build_rpc_cuda/bin/rpc-server -p 50052 -H 0.0.0.0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING: Host ('0.0.0.0') is != '127.0.0.1'
         Never expose the RPC server to an open network!
         This is an experimental feature and is not secure!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

create_backend: using CUDA backend
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 GeForce RTX 4060 Ti, compute capability 8.9, VMM: yes
Starting RPC server on 0.0.0.0:50052, backend memory: 7686 MB
Accepted client connection, free_mem=8059486208, total_mem=8222670848
Client connection closed
Accepted client connection, free_mem=8059486208, total_mem=8222670848
Client connection closed
Accepted client connection, free_mem=8059486208, total_mem=8222670848
CUDA error: CUBLAS_STATUS_NOT_INITIALIZED
  current device: 0, in function cublas_handle at /data/liucong/llama.cpp/ggml/src/ggml-cuda/common.cuh:644
  cublasCreate_v2(&cublas_handles[device])
/data/liucong/llama.cpp/ggml/src/ggml-cuda.cu:102: CUDA error
[New LWP 1787661]
[New LWP 1787662]
[New LWP 1787663]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007a9f1d8ea42f in __GI___wait4 (pid=1787815, stat_loc=0x7ffdc789f208, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
30  ../sysdeps/unix/sysv/linux/wait4.c: 没有那个文件或目录.
#0  0x00007a9f1d8ea42f in __GI___wait4 (pid=1787815, stat_loc=0x7ffdc789f208, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
30  in ../sysdeps/unix/sysv/linux/wait4.c
#1  0x00007a9f1e071053 in ggml_print_backtrace () at /data/liucong/llama.cpp/ggml/src/ggml.c:229
229         waitpid(pid, &wstatus, 0);
#2  0x00007a9f1e0711a6 in ggml_abort (file=0x7a9f1e506540 "/data/liucong/llama.cpp/ggml/src/ggml-cuda.cu", line=102, fmt=0x7a9f1e506535 "CUDA error") at /data/liucong/llama.cpp/ggml/src/ggml.c:256
256     ggml_print_backtrace();
#3  0x00007a9f1e1899bb in ggml_cuda_error (stmt=0x7a9f1e5063f8 "cublasCreate_v2(&cublas_handles[device])", func=0x7a9f1e5063ea "cublas_handle", file=0x7a9f1e5062e8 "/data/liucong/llama.cpp/ggml/src/ggml-cuda/common.cuh", line=644, msg=0x7a9f1e506196 "CUBLAS_STATUS_NOT_INITIALIZED") at /data/liucong/llama.cpp/ggml/src/ggml-cuda.cu:102
102     GGML_ABORT("CUDA error");
#4  0x00007a9f1e195b2c in ggml_backend_cuda_context::cublas_handle (this=0x61bafcf012f0, device=0) at /data/liucong/llama.cpp/ggml/src/ggml-cuda/common.cuh:644
644             CUBLAS_CHECK(cublasCreate(&cublas_handles[device]));
#5  0x00007a9f1e195bca in ggml_backend_cuda_context::cublas_handle (this=0x61bafcf012f0) at /data/liucong/llama.cpp/ggml/src/ggml-cuda/common.cuh:651
651         return cublas_handle(device);
#6  0x00007a9f1e18fdea in ggml_cuda_mul_mat_batched_cublas (ctx=..., src0=0x61bafd870000, src1=0x61bafd870170, dst=0x61bafd8702e0) at /data/liucong/llama.cpp/ggml/src/ggml-cuda.cu:1768
1768        CUBLAS_CHECK(cublasSetStream(ctx.cublas_handle(), main_stream));
#7  0x00007a9f1e190c66 in ggml_cuda_mul_mat (ctx=..., src0=0x61bafd870000, src1=0x61bafd870170, dst=0x61bafd8702e0) at /data/liucong/llama.cpp/ggml/src/ggml-cuda.cu:1956
1956            ggml_cuda_mul_mat_batched_cublas(ctx, src0, src1, dst);
#8  0x00007a9f1e192073 in ggml_cuda_compute_forward (ctx=..., dst=0x61bafd8702e0) at /data/liucong/llama.cpp/ggml/src/ggml-cuda.cu:2259
2259                    ggml_cuda_mul_mat(ctx, dst->src[0], dst->src[1], dst);
#9  0x00007a9f1e192eee in ggml_backend_cuda_graph_compute (backend=0x61bafce75720, cgraph=0x61bafd865660) at /data/liucong/llama.cpp/ggml/src/ggml-cuda.cu:2632
2632                    bool ok = ggml_cuda_compute_forward(*cuda_ctx, node);
#10 0x00007a9f1e0c2139 in ggml_backend_graph_compute_async (backend=0x61bafce75720, cgraph=0x61bafd865660) at /data/liucong/llama.cpp/ggml/src/ggml-backend.c:282
282     return backend->iface.graph_compute(backend, cgraph);
#11 0x00007a9f1e0c20f9 in ggml_backend_graph_compute (backend=0x61bafce75720, cgraph=0x61bafd865660) at /data/liucong/llama.cpp/ggml/src/ggml-backend.c:276
276     enum ggml_status err = ggml_backend_graph_compute_async(backend, cgraph);
#12 0x00007a9f1e3ef4cd in rpc_server::graph_compute (this=0x7ffdc789f970, input=std::vector of length 403072, capacity 403072 = {...}, output=std::vector of length 0, capacity 0) at /data/liucong/llama.cpp/ggml/src/ggml-rpc.cpp:1082
1082        ggml_status status = ggml_backend_graph_compute(backend, graph);
#13 0x00007a9f1e3ef946 in rpc_serve_client (backend=0x61bafce75720, sockfd=34, free_mem=8059486208, total_mem=8222670848) at /data/liucong/llama.cpp/ggml/src/ggml-rpc.cpp:1162
1162                    ok = server.graph_compute(input, output);
#14 0x00007a9f1e3efd45 in start_rpc_server (backend=0x61bafce75720, endpoint=0x7ffdc789fae0 "0.0.0.0:50052", free_mem=8059486208, total_mem=8222670848) at /data/liucong/llama.cpp/ggml/src/ggml-rpc.cpp:1219
1219            rpc_serve_client(backend, client_socket->fd, free_mem, total_mem);
#15 0x000061bafadf507b in main (argc=5, argv=0x7ffdc789fc98) at /data/liucong/llama.cpp/examples/rpc/rpc-server.cpp:142
142     start_rpc_server(backend, endpoint.c_str(), free_mem, total_mem);
[Inferior 1 (process 1787660) detached]
已中止
rgerganov commented 2 months ago

I am not able to reproduce this error. Does llama-cli work with the CUDA backend?

xvim commented 2 months ago

I am not able to reproduce this error. Does llama-cli work with the CUDA backend?

yes, use CUDA backend success.

root@kylin-Default-string:/data/liucong/llama.cpp# ./build_rpc_cuda/bin/llama-cli --version
version: 3639 (20f1789d)
built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu
root@kylin-Default-string:/data/liucong/llama.cpp# ./build_rpc_cuda/bin/llama-server -m /data/models/huggingface/Qwen/Qwen2-7B-Instruct-GGUF/qwen2-7b-instruct-q4_0.gguf -ngl 33 --host 0.0.0.0
INFO [                    main] build info | tid="139330554249216" timestamp=1724836378 build=3639 commit="20f1789d"
INFO [                    main] system info | tid="139330554249216" timestamp=1724836378 n_threads=14 n_threads_batch=-1 total_threads=28 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 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | "
INFO [                    main] HTTP server is listening | tid="139330554249216" timestamp=1724836378 n_threads_http="27" port="8080" hostname="0.0.0.0"
INFO [                    main] loading model | tid="139330554249216" timestamp=1724836378 n_threads_http="27" port="8080" hostname="0.0.0.0"
llama_model_loader: loaded meta data with 26 key-value pairs and 339 tensors from /data/models/huggingface/Qwen/Qwen2-7B-Instruct-GGUF/qwen2-7b-instruct-q4_0.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              = qwen2
llama_model_loader: - kv   1:                               general.name str              = qwen2-7b-instruct
llama_model_loader: - kv   2:                          qwen2.block_count u32              = 28
llama_model_loader: - kv   3:                       qwen2.context_length u32              = 32768
llama_model_loader: - kv   4:                     qwen2.embedding_length u32              = 3584
llama_model_loader: - kv   5:                  qwen2.feed_forward_length u32              = 18944
llama_model_loader: - kv   6:                 qwen2.attention.head_count u32              = 28
llama_model_loader: - kv   7:              qwen2.attention.head_count_kv u32              = 4
llama_model_loader: - kv   8:                       qwen2.rope.freq_base f32              = 1000000.000000
llama_model_loader: - kv   9:     qwen2.attention.layer_norm_rms_epsilon f32              = 0.000001
llama_model_loader: - kv  10:                          general.file_type u32              = 2
llama_model_loader: - kv  11:                       tokenizer.ggml.model str              = gpt2
llama_model_loader: - kv  12:                         tokenizer.ggml.pre str              = qwen2
llama_model_loader: - kv  13:                      tokenizer.ggml.tokens arr[str,152064]  = ["!", "\"", "#", "$", "%", "&", "'", ...
llama_model_loader: - kv  14:                  tokenizer.ggml.token_type arr[i32,152064]  = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
llama_model_loader: - kv  15:                      tokenizer.ggml.merges arr[str,151387]  = ["Ġ Ġ", "ĠĠ ĠĠ", "i n", "Ġ t",...
llama_model_loader: - kv  16:                tokenizer.ggml.eos_token_id u32              = 151645
llama_model_loader: - kv  17:            tokenizer.ggml.padding_token_id u32              = 151643
llama_model_loader: - kv  18:                tokenizer.ggml.bos_token_id u32              = 151643
llama_model_loader: - kv  19:                    tokenizer.chat_template str              = {% for message in messages %}{% if lo...
llama_model_loader: - kv  20:               tokenizer.ggml.add_bos_token bool             = false
llama_model_loader: - kv  21:               general.quantization_version u32              = 2
llama_model_loader: - kv  22:                      quantize.imatrix.file str              = ../Qwen2/gguf/qwen2-7b-imatrix/imatri...
llama_model_loader: - kv  23:                   quantize.imatrix.dataset str              = ../sft_2406.txt
llama_model_loader: - kv  24:             quantize.imatrix.entries_count i32              = 196
llama_model_loader: - kv  25:              quantize.imatrix.chunks_count i32              = 1937
llama_model_loader: - type  f32:  141 tensors
llama_model_loader: - type q4_0:  194 tensors
llama_model_loader: - type q4_1:    3 tensors
llama_model_loader: - type q6_K:    1 tensors
llm_load_vocab: special tokens cache size = 421
llm_load_vocab: token to piece cache size = 0.9352 MB
llm_load_print_meta: format           = GGUF V3 (latest)
llm_load_print_meta: arch             = qwen2
llm_load_print_meta: vocab type       = BPE
llm_load_print_meta: n_vocab          = 152064
llm_load_print_meta: n_merges         = 151387
llm_load_print_meta: vocab_only       = 0
llm_load_print_meta: n_ctx_train      = 32768
llm_load_print_meta: n_embd           = 3584
llm_load_print_meta: n_layer          = 28
llm_load_print_meta: n_head           = 28
llm_load_print_meta: n_head_kv        = 4
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            = 7
llm_load_print_meta: n_embd_k_gqa     = 512
llm_load_print_meta: n_embd_v_gqa     = 512
llm_load_print_meta: f_norm_eps       = 0.0e+00
llm_load_print_meta: f_norm_rms_eps   = 1.0e-06
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             = 18944
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        = 2
llm_load_print_meta: rope scaling     = linear
llm_load_print_meta: freq_base_train  = 1000000.0
llm_load_print_meta: freq_scale_train = 1
llm_load_print_meta: n_ctx_orig_yarn  = 32768
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       = ?B
llm_load_print_meta: model ftype      = Q4_0
llm_load_print_meta: model params     = 7.62 B
llm_load_print_meta: model size       = 4.13 GiB (4.66 BPW) 
llm_load_print_meta: general.name     = qwen2-7b-instruct
llm_load_print_meta: BOS token        = 151643 '<|endoftext|>'
llm_load_print_meta: EOS token        = 151645 '<|im_end|>'
llm_load_print_meta: PAD token        = 151643 '<|endoftext|>'
llm_load_print_meta: LF token         = 148848 'ÄĬ'
llm_load_print_meta: EOT token        = 151645 '<|im_end|>'
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 2 CUDA devices:
  Device 0: NVIDIA GeForce RTX 4060 Ti, compute capability 8.9, VMM: yes
  Device 1: NVIDIA GeForce RTX 2060, compute capability 7.5, VMM: yes
llm_load_tensors: ggml ctx size =    0.45 MiB
llm_load_tensors: offloading 28 repeating layers to GPU
llm_load_tensors: offloading non-repeating layers to GPU
llm_load_tensors: offloaded 29/29 layers to GPU
llm_load_tensors:        CPU buffer size =   292.36 MiB
llm_load_tensors:      CUDA0 buffer size =  2138.17 MiB
llm_load_tensors:      CUDA1 buffer size =  1802.04 MiB
......................................................................................
llama_new_context_with_model: n_ctx      = 32768
llama_new_context_with_model: n_batch    = 2048
llama_new_context_with_model: n_ubatch   = 512
llama_new_context_with_model: flash_attn = 0
llama_new_context_with_model: freq_base  = 1000000.0
llama_new_context_with_model: freq_scale = 1
llama_kv_cache_init:      CUDA0 KV buffer size =  1088.00 MiB
llama_kv_cache_init:      CUDA1 KV buffer size =   704.00 MiB
llama_new_context_with_model: KV self size  = 1792.00 MiB, K (f16):  896.00 MiB, V (f16):  896.00 MiB
llama_new_context_with_model:  CUDA_Host  output buffer size =     1.16 MiB
llama_new_context_with_model: pipeline parallelism enabled (n_copies=4)
ggml_gallocr_reserve_n: reallocating CUDA0 buffer from size 0.00 MiB to 2104.01 MiB
ggml_gallocr_reserve_n: reallocating CUDA1 buffer from size 0.00 MiB to 2104.02 MiB
ggml_gallocr_reserve_n: reallocating CUDA_Host buffer from size 0.00 MiB to 263.02 MiB
llama_new_context_with_model:      CUDA0 compute buffer size =  2104.01 MiB
llama_new_context_with_model:      CUDA1 compute buffer size =  2104.02 MiB
llama_new_context_with_model:  CUDA_Host compute buffer size =   263.02 MiB
llama_new_context_with_model: graph nodes  = 986
llama_new_context_with_model: graph splits = 3
rgerganov commented 2 months ago

It looks like you have 2 CUDA devices and you are using CUDA_VISIBLE_DEVICES=0 when starting the rpc-server. Maybe at some point the CUDA backend decides to also use device 1 which is not initialized.

xvim commented 2 months ago
# CUDA_VISIBLE_DEVICES=0  ./build_rpc_cuda/bin/rpc-server -p 50052 -H 0.0.0.0

remove CUDA_VISIBLE_DEVICES=0 then run rpc-server ,also crash

xvim commented 2 months ago

upgrade cuda version ,seems no crash