Skip to content

Bug: server crash when changing LoRA scale while using CUDA #9451

Closed
@mgonzs13

Description

@mgonzs13

What happened?

The server chases when changing the LoRA scale and using CUDA. To reproduce it:

  • Start the server with a model and a LoRA and load layers to CUDA.
  • Then, prompt the model as usual.
  • After that, modify the scale of the LoRA to 0.0.
  • Finally, prompt the model again and you will get the error.

This also happens if you start the LoRA with a scale of 0.0 and modify the scale to a value greater than 0.0. When layers are not loaded in GPU, it works well. In the provided example only happens when 32 and 33 layers are loaded in GPU.

Name and Version

~/llama.cpp$ ./llama-cli --version
version: 3735 (df4b7945)
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?

Linux

Relevant log output

~/llama.cpp$ ./llama-server -m ../.cache/huggingface/hub/models--bartowski--Phi-3.5-mini-instruct-GGUF/snapshots/5c8d5381f90b6ca4348f090238be34eada23d192/Phi-3.5-mini-instruct-Q4_K_M.gguf -c 4096 --n-gpu-layers 33 --lora-scaled ../.cache/huggingface/hub/models--zhhan--adapter-Phi-3-mini-4k-instruct_code_writing/snapshots/fdabd0c9eaaa3bf6ce180f15f76adf62e1d57166/Phi-3-mini-4k-instruct-adaptor-f16-code_writer.gguf 0.5
INFO [                    main] build info | tid="127234101325824" timestamp=1726136860 build=3735 commit="df4b7945"
INFO [                    main] system info | tid="127234101325824" timestamp=1726136860 n_threads=8 n_threads_batch=8 total_threads=32 system_info="AVX = 1 | AVX_VNNI = 1 | 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="127234101325824" timestamp=1726136860 n_threads_http="31" port="8080" hostname="127.0.0.1"
INFO [                    main] loading model | tid="127234101325824" timestamp=1726136860 n_threads_http="31" port="8080" hostname="127.0.0.1"
llama_model_loader: loaded meta data with 40 key-value pairs and 197 tensors from ../.cache/huggingface/hub/models--bartowski--Phi-3.5-mini-instruct-GGUF/snapshots/5c8d5381f90b6ca4348f090238be34eada23d192/Phi-3.5-mini-instruct-Q4_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              = phi3
llama_model_loader: - kv   1:                               general.type str              = model
llama_model_loader: - kv   2:                               general.name str              = Phi 3.5 Mini Instruct
llama_model_loader: - kv   3:                           general.finetune str              = instruct
llama_model_loader: - kv   4:                           general.basename str              = Phi-3.5
llama_model_loader: - kv   5:                         general.size_label str              = mini
llama_model_loader: - kv   6:                            general.license str              = mit
llama_model_loader: - kv   7:                       general.license.link str              = https://huggingface.co/microsoft/Phi-...
llama_model_loader: - kv   8:                               general.tags arr[str,3]       = ["nlp", "code", "text-generation"]
llama_model_loader: - kv   9:                          general.languages arr[str,1]       = ["multilingual"]
llama_model_loader: - kv  10:                        phi3.context_length u32              = 131072
llama_model_loader: - kv  11:  phi3.rope.scaling.original_context_length u32              = 4096
llama_model_loader: - kv  12:                      phi3.embedding_length u32              = 3072
llama_model_loader: - kv  13:                   phi3.feed_forward_length u32              = 8192
llama_model_loader: - kv  14:                           phi3.block_count u32              = 32
llama_model_loader: - kv  15:                  phi3.attention.head_count u32              = 32
llama_model_loader: - kv  16:               phi3.attention.head_count_kv u32              = 32
llama_model_loader: - kv  17:      phi3.attention.layer_norm_rms_epsilon f32              = 0.000010
llama_model_loader: - kv  18:                  phi3.rope.dimension_count u32              = 96
llama_model_loader: - kv  19:                        phi3.rope.freq_base f32              = 10000.000000
llama_model_loader: - kv  20:                          general.file_type u32              = 15
llama_model_loader: - kv  21:              phi3.attention.sliding_window u32              = 262144
llama_model_loader: - kv  22:              phi3.rope.scaling.attn_factor f32              = 1.190238
llama_model_loader: - kv  23:                       tokenizer.ggml.model str              = llama
llama_model_loader: - kv  24:                         tokenizer.ggml.pre str              = default
llama_model_loader: - kv  25:                      tokenizer.ggml.tokens arr[str,32064]   = ["<unk>", "<s>", "</s>", "<0x00>", "<...
llama_model_loader: - kv  26:                      tokenizer.ggml.scores arr[f32,32064]   = [-1000.000000, -1000.000000, -1000.00...
llama_model_loader: - kv  27:                  tokenizer.ggml.token_type arr[i32,32064]   = [3, 3, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...
llama_model_loader: - kv  28:                tokenizer.ggml.bos_token_id u32              = 1
llama_model_loader: - kv  29:                tokenizer.ggml.eos_token_id u32              = 32000
llama_model_loader: - kv  30:            tokenizer.ggml.unknown_token_id u32              = 0
llama_model_loader: - kv  31:            tokenizer.ggml.padding_token_id u32              = 32000
llama_model_loader: - kv  32:               tokenizer.ggml.add_bos_token bool             = false
llama_model_loader: - kv  33:               tokenizer.ggml.add_eos_token bool             = false
llama_model_loader: - kv  34:                    tokenizer.chat_template str              = {% for message in messages %}{% if me...
llama_model_loader: - kv  35:               general.quantization_version u32              = 2
llama_model_loader: - kv  36:                      quantize.imatrix.file str              = /models_out/Phi-3.5-mini-instruct-GGU...
llama_model_loader: - kv  37:                   quantize.imatrix.dataset str              = /training_dir/calibration_datav3.txt
llama_model_loader: - kv  38:             quantize.imatrix.entries_count i32              = 128
llama_model_loader: - kv  39:              quantize.imatrix.chunks_count i32              = 151
llama_model_loader: - type  f32:   67 tensors
llama_model_loader: - type q4_K:   81 tensors
llama_model_loader: - type q5_K:   32 tensors
llama_model_loader: - type q6_K:   17 tensors
llm_load_vocab: special tokens cache size = 14
llm_load_vocab: token to piece cache size = 0.1685 MB
llm_load_print_meta: format           = GGUF V3 (latest)
llm_load_print_meta: arch             = phi3
llm_load_print_meta: vocab type       = SPM
llm_load_print_meta: n_vocab          = 32064
llm_load_print_meta: n_merges         = 0
llm_load_print_meta: vocab_only       = 0
llm_load_print_meta: n_ctx_train      = 131072
llm_load_print_meta: n_embd           = 3072
llm_load_print_meta: n_layer          = 32
llm_load_print_meta: n_head           = 32
llm_load_print_meta: n_head_kv        = 32
llm_load_print_meta: n_rot            = 96
llm_load_print_meta: n_swa            = 262144
llm_load_print_meta: n_embd_head_k    = 96
llm_load_print_meta: n_embd_head_v    = 96
llm_load_print_meta: n_gqa            = 1
llm_load_print_meta: n_embd_k_gqa     = 3072
llm_load_print_meta: n_embd_v_gqa     = 3072
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             = 8192
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  = 10000.0
llm_load_print_meta: freq_scale_train = 1
llm_load_print_meta: n_ctx_orig_yarn  = 4096
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       = 3B
llm_load_print_meta: model ftype      = Q4_K - Medium
llm_load_print_meta: model params     = 3.82 B
llm_load_print_meta: model size       = 2.23 GiB (5.01 BPW) 
llm_load_print_meta: general.name     = Phi 3.5 Mini Instruct
llm_load_print_meta: BOS token        = 1 '<s>'
llm_load_print_meta: EOS token        = 32000 '<|endoftext|>'
llm_load_print_meta: UNK token        = 0 '<unk>'
llm_load_print_meta: PAD token        = 32000 '<|endoftext|>'
llm_load_print_meta: LF token         = 13 '<0x0A>'
llm_load_print_meta: EOT token        = 32007 '<|end|>'
llm_load_print_meta: max token length = 48
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 4070 Laptop GPU, compute capability 8.9, VMM: yes
llm_load_tensors: ggml ctx size =    0.21 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 =    52.84 MiB
llm_load_tensors:      CUDA0 buffer size =  2228.84 MiB
............................................................................................
llama_new_context_with_model: n_ctx      = 4096
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  = 10000.0
llama_new_context_with_model: freq_scale = 1
llama_kv_cache_init:      CUDA0 KV buffer size =  1536.00 MiB
llama_new_context_with_model: KV self size  = 1536.00 MiB, K (f16):  768.00 MiB, V (f16):  768.00 MiB
llama_new_context_with_model:  CUDA_Host  output buffer size =     0.24 MiB
llama_new_context_with_model:      CUDA0 compute buffer size =   300.00 MiB
llama_new_context_with_model:  CUDA_Host compute buffer size =    14.01 MiB
llama_new_context_with_model: graph nodes  = 1286
llama_new_context_with_model: graph splits = 2
llama_lora_adapter_init_internal: loading lora adapter from '../.cache/huggingface/hub/models--zhhan--adapter-Phi-3-mini-4k-instruct_code_writing/snapshots/fdabd0c9eaaa3bf6ce180f15f76adf62e1d57166/Phi-3-mini-4k-instruct-adaptor-f16-code_writer.gguf' ...
llama_lora_adapter_init_internal:      CUDA0 LoRA buffer size =    48.00 MiB
llama_lora_adapter_init_internal: loaded 256 tensors from lora file
INFO [                    init] initializing slots | tid="127234101325824" timestamp=1726136860 n_slots=1
INFO [                    init] new slot | tid="127234101325824" timestamp=1726136860 id_slot=0 n_ctx_slot=4096
INFO [                    main] model loaded | tid="127234101325824" timestamp=1726136860
INFO [                    main] chat template | tid="127234101325824" timestamp=1726136860 chat_example="<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nHow are you?<|end|>\n<|assistant|>\n" built_in=true
INFO [            update_slots] all slots are idle | tid="127234101325824" timestamp=1726136860
INFO [   launch_slot_with_task] slot is processing task | tid="127234101325824" timestamp=1726136906 id_slot=0 id_task=0
INFO [            update_slots] kv cache rm [p0, end) | tid="127234101325824" timestamp=1726136906 id_slot=0 id_task=0 p0=0
INFO [                 release] slot released | tid="127234101325824" timestamp=1726136908 id_slot=0 id_task=0 n_past=139 truncated=false
INFO [           print_timings] prompt eval time     =      44.79 ms /    12 tokens (    3.73 ms per token,   267.90 tokens per second) | tid="127234101325824" timestamp=1726136908 id_slot=0 id_task=0 t_prompt_processing=44.793 n_prompt_tokens_processed=12 t_token=3.73275 n_tokens_second=267.89900207621724
INFO [           print_timings] generation eval time =    2263.79 ms /   128 runs   (   17.69 ms per token,    56.54 tokens per second) | tid="127234101325824" timestamp=1726136908 id_slot=0 id_task=0 t_token_generation=2263.787 n_decoded=128 t_token=17.6858359375 n_tokens_second=56.54242205649207
INFO [           print_timings]           total time =    2308.58 ms | tid="127234101325824" timestamp=1726136908 id_slot=0 id_task=0 t_prompt_processing=44.793 t_token_generation=2263.787 t_total=2308.58
INFO [            update_slots] all slots are idle | tid="127234101325824" timestamp=1726136908
INFO [      log_server_request] request | tid="127233226178560" timestamp=1726136908 remote_addr="127.0.0.1" remote_port=51384 status=200 method="POST" path="/completion" params={}
INFO [            update_slots] all slots are idle | tid="127234101325824" timestamp=1726137083
INFO [      log_server_request] request | tid="127233236664320" timestamp=1726137083 remote_addr="127.0.0.1" remote_port=56872 status=200 method="POST" path="/lora-adapters" params={}




INFO [      log_server_request] request | tid="127233215692800" timestamp=1726137135 remote_addr="127.0.0.1" remote_port=47630 status=200 method="GET" path="/lora-adapters" params={}
INFO [   launch_slot_with_task] slot is processing task | tid="127234101325824" timestamp=1726137142 id_slot=0 id_task=130
INFO [            update_slots] kv cache rm [p0, end) | tid="127234101325824" timestamp=1726137142 id_slot=0 id_task=130 p0=0
CUDA error: invalid argument
  current device: 0, in function ggml_backend_cuda_graph_compute at ggml/src/ggml-cuda.cu:2727
  cudaGraphKernelNodeSetParams(cuda_ctx->cuda_graph->nodes[i], &cuda_ctx->cuda_graph->params[i])
ggml/src/ggml-cuda.cu:103: CUDA error
Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No stack.
The program is not being run.
Aborted (core dumped)
# here you have the curl requests
~/llama.cpp$ curl --request POST \
    --url http://localhost:8080/completion \
    --header "Content-Type: application/json" \
    --data '{"prompt": "Write the python code to show an image using cv2:","n_predict": 128}'
{"content":"\n\nimport cv2\n\n# Load an image from file\nimage = cv2.imread('path/to/image.jpg')\n\n# Display the image in a window\ncv2.imshow('Image', image)\n\n# Wait for a key press and then close the window\ncv2.waitKey(0)\ncv2.destroyAllWindows()\n\nIn this code, we first import the OpenCV library as cv2. Then, we load an image from a file using the imread() function and store it in the 'image' variable. \n\nNext, we","id_slot":0,"stop":true,"model":"../.cache/huggingface/hub/models--bartowski--Phi-3.5-mini-instruct-GGUF/snapshots/5c8d5381f90b6ca4348f090238be34eada23d192/Phi-3.5-mini-instruct-Q4_K_M.gguf","tokens_predicted":128,"tokens_evaluated":12,"generation_settings":{"n_ctx":4096,"n_predict":-1,"model":"../.cache/huggingface/hub/models--bartowski--Phi-3.5-mini-instruct-GGUF/snapshots/5c8d5381f90b6ca4348f090238be34eada23d192/Phi-3.5-mini-instruct-Q4_K_M.gguf","seed":4294967295,"seed_cur":2038132409,"temperature":0.800000011920929,"dynatemp_range":0.0,"dynatemp_exponent":1.0,"top_k":40,"top_p":0.949999988079071,"min_p":0.05000000074505806,"tfs_z":1.0,"typical_p":1.0,"repeat_last_n":64,"repeat_penalty":1.0,"presence_penalty":0.0,"frequency_penalty":0.0,"mirostat":0,"mirostat_tau":5.0,"mirostat_eta":0.10000000149011612,"penalize_nl":false,"stop":[],"max_tokens":128,"n_keep":0,"n_discard":0,"ignore_eos":false,"stream":false,"n_probs":0,"min_keep":0,"grammar":"","samplers":["top_k","tfs_z","typ_p","top_p","min_p","temperature"]},"prompt":"Write the python code to show an image using cv2:","truncated":false,"stopped_eos":false,"stopped_word":false,"stopped_limit":true,"stopping_word":"","tokens_cached":139,"timings":{"prompt_n":12,"prompt_ms":44.793,"prompt_per_token_ms":3.73275,"prompt_per_second":267.89900207621724,"predicted_n":128,"predicted_ms":2263.787,"predicted_per_token_ms":17.6858359375,"premiguel:

~/llama.cpp$ curl --request POST \
    --url http://localhost:8080/lora-adapters \
    --header "Content-Type: application/json" \
    --data '[{"id": 0, "scale": 0.0}]'

~/llama.cpp$ curl --request GET \ --request GET \
    --url http://localhost:8080/lora-adapters \
    --header "Content-Type: application/json"
[{"id":0,"path":"../.cache/huggingface/hub/models--zhhan--adapter-Phi-3-mini-4k-instruct_code_writing/snapshots/fdabd0c9eaaa3bf6ce180f15f76adf62e1d57166/Phi-3-mini-4k-instruct-adaptor-f16-code_writer.gguf

~/llama.cpp$ curl --request POST \
    --url http://localhost:8080/completion \
    --header "Content-Type: application/json" \
    --data '{"prompt": "Write the python code to show an image using cv2:","n_predict": 128}'
curl: (52) Empty reply from server

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-unconfirmedcritical severityUsed to report critical severity bugs in llama.cpp (e.g. Crashing, Corrupted, Dataloss)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions