ngxson / wllama

WebAssembly binding for llama.cpp - Enabling in-browser LLM inference
https://huggingface.co/spaces/ngxson/wllama
MIT License
430 stars 21 forks source link

null function or function signature mismatch at wllama.wasm #10

Closed flatsiedatsie closed 6 months ago

flatsiedatsie commented 6 months ago

I'm catching a lot of errors like this:

Screenshot 2024-04-29 at 20 26 02

While attempting to load: https://huggingface.co/bartowski/h2o-danube2-1.8b-chat-GGUF/resolve/main/h2o-danube2-1.8b-chat-Q5_0.gguf ..with a 8192 context.

I'm probably doing something wrong. From what I could find online, perhaps it has something to do with improper callbacks?

Full log:

Loading "wllama.wasm" from "https://localhostje.dd/wasm4/esm/multi-thread/wllama.wasm"
32worker.ts:250 Loading "wllama.worker.mjs" from "https://localhostje.dd/wasm4/esm/multi-thread/wllama.worker.mjs"
worker.ts:251 AVX = 0 | AVX_VNNI = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 0 | ARM_FMA = 0 | F16C = 0 | FP16_VA = 0 | WASM_SIMD = 1 | BLAS = 0 | SSE3 = 0 | SSSE3 = 0 | VSX = 0 | MATMUL_INT8 = 0 | 
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: loaded meta data with 27 key-value pairs and 219 tensors from /models/model.gguf (version GGUF V3 (latest))
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   0:                       general.architecture str              = llama
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   1:                               general.name str              = h2o-danube2-1.8b-chat
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   2:                          llama.block_count u32              = 24
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   3:                       llama.context_length u32              = 8192
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   4:                     llama.embedding_length u32              = 2560
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   5:                  llama.feed_forward_length u32              = 6912
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   6:                 llama.attention.head_count u32              = 32
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   7:              llama.attention.head_count_kv u32              = 8
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   8:                       llama.rope.freq_base f32              = 10000.000000
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv   9:     llama.attention.layer_norm_rms_epsilon f32              = 0.000010
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  10:                          general.file_type u32              = 8
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  11:                           llama.vocab_size u32              = 32000
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  12:                 llama.rope.dimension_count u32              = 80
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  13:                       tokenizer.ggml.model str              = llama
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  14:                      tokenizer.ggml.tokens arr[str,32000]   = ["<unk>", "<s>", "</s>", "<0x00>", "<...
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  15:                      tokenizer.ggml.scores arr[f32,32000]   = [0.000000, 0.000000, 0.000000, 0.0000...
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  16:                  tokenizer.ggml.token_type arr[i32,32000]   = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  17:                tokenizer.ggml.bos_token_id u32              = 1
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  18:                tokenizer.ggml.eos_token_id u32              = 2
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  19:            tokenizer.ggml.unknown_token_id u32              = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  20:          tokenizer.ggml.seperator_token_id u32              = 2
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  21:            tokenizer.ggml.padding_token_id u32              = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  22:                tokenizer.ggml.cls_token_id u32              = 2
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  23:               tokenizer.ggml.add_bos_token bool             = false
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  24:               tokenizer.ggml.add_eos_token bool             = false
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  25:                    tokenizer.chat_template str              = {% for message in messages %}{% if me...
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - kv  26:               general.quantization_version u32              = 2
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - type  f32:   49 tensors
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - type q5_0:  169 tensors
onRecvMsg @ worker.ts:251
worker.ts:251 llama_model_loader: - type q6_K:    1 tensors
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_vocab: special tokens definition check successful ( 259/32000 ).
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: format           = GGUF V3 (latest)
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: arch             = llama
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: vocab type       = SPM
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_vocab          = 32000
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_merges         = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_ctx_train      = 8192
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_embd           = 2560
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_head           = 32
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_head_kv        = 8
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_layer          = 24
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_rot            = 80
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_embd_head_k    = 80
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_embd_head_v    = 80
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_gqa            = 4
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_embd_k_gqa     = 640
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_embd_v_gqa     = 640
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: f_norm_eps       = 0.0e+00
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: f_norm_rms_eps   = 1.0e-05
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: f_clamp_kqv      = 0.0e+00
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: f_max_alibi_bias = 0.0e+00
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: f_logit_scale    = 0.0e+00
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_ff             = 6912
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_expert         = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_expert_used    = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: causal attn      = 1
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: pooling type     = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: rope type        = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: rope scaling     = linear
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: freq_base_train  = 10000.0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: freq_scale_train = 1
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: n_yarn_orig_ctx  = 8192
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: rope_finetuned   = unknown
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: ssm_d_conv       = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: ssm_d_inner      = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: ssm_d_state      = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: ssm_dt_rank      = 0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: model type       = ?B
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: model ftype      = Q5_0
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: model params     = 1.83 B
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: model size       = 1.18 GiB (5.55 BPW) 
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: general.name     = h2o-danube2-1.8b-chat
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: BOS token        = 1 '<s>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: EOS token        = 2 '</s>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: UNK token        = 0 '<unk>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: SEP token        = 2 '</s>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: PAD token        = 0 '<unk>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: CLS token        = 2 '</s>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_print_meta: LF token         = 13 '<0x0A>'
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_tensors: ggml ctx size =    0.09 MiB
onRecvMsg @ worker.ts:251
worker.ts:251 llm_load_tensors:        CPU buffer size =  1211.40 MiB
onRecvMsg @ worker.ts:251
worker.ts:251 ............................................................................................warning: munmap failed: Invalid argument
onRecvMsg @ worker.ts:251
worker.ts:251 .
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: n_ctx      = 8192
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: n_batch    = 2048
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: n_ubatch   = 512
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: freq_base  = 10000.0
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: freq_scale = 1
onRecvMsg @ worker.ts:251
worker.ts:251 llama_kv_cache_init:        CPU KV buffer size =   480.00 MiB
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: KV self size  =  480.00 MiB, K (f16):  240.00 MiB, V (f16):  240.00 MiB
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model:        CPU  output buffer size =     0.12 MiB
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model:        CPU compute buffer size =   548.01 MiB
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: graph nodes  = 774
onRecvMsg @ worker.ts:251
worker.ts:251 llama_new_context_with_model: graph splits = 1
onRecvMsg @ worker.ts:251
llama_cpp.js:774 on
ngxson commented 6 months ago

Seems like cpp code throws an exception, but it's unable to display the exception correctly. I'll have a look in the next days when I have more time.

ngxson commented 6 months ago

Also have you tried with other parameters? For example lower context length or try with multi / single thread build

flatsiedatsie commented 6 months ago

Also have you tried with other parameters? For example lower context length or try with multi / single thread build

I have literally tried both those thing :-)

Singular, spaced out inference works fine. It believe it has something to do with running tasks one after the other, in quick succession (summarizing a document in mutiple chunks). Shortening context also helped, but for summarization defeats the point a bit.

There are more things I can try on this end. I'm trying to space tasks out more.

oh it just crashed again, darn.

// The Brave tab had grown to 16Gb, on a 1Gb model.

// I think my code is restarting a bit too eagerly on a crash with that one.

flatsiedatsie commented 6 months ago

I think the issue is in my code.

flatsiedatsie commented 6 months ago

I've done some more testing and found the issue. As predicted, it was in my code.

I was setting the model's context (n_ctx) size only, as that was the only variable of that nature that needed to be set in llama_cpp_wasm. But with Wllama, which offers much more low level control, the n_seq_max and n_batch values also needed to be set explicitly. Setting all three to the same value (8192 in this case) solved the issue.