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

add 128k yarn context for Qwen #10698

Merged
merged 3 commits into from
Dec 7, 2024
Merged

Conversation

robbiemu
Copy link
Contributor

@robbiemu robbiemu commented Dec 6, 2024

see: discussion

@bartowski1182 -- can I ask you to try this if you have a 7b+ Qwen2.5 handy ? I dont mind testing it but I thought it would be nice if a 3rd party did it.

quick instructions (correct me if Im wrong):

add rope scaling like:

  "rope_scaling": {
    "factor": 4.0,
    "original_max_position_embeddings": 32768,
    "type": "yarn"
  }

change max_position_embeddings to factor * orig_mpe:

  "max_position_embeddings": 131072,  

@github-actions github-actions bot added the python python script changes label Dec 6, 2024
@robbiemu
Copy link
Contributor Author

robbiemu commented Dec 7, 2024

Thanks to @ggerganov , I think I've verified my change working.

./convert_hf_to_gguf.py --outtype bf16 --outfile /Users/Shared/Public/huggingface/Qwen2.5-Coder-7B-Instruct/Qwen2.5_7b_bf16.gguf /Users/Shared/Public/huggingface/Qwen2.5-Coder-7B-Instruct
INFO:hf-to-gguf:Loading model: Qwen2.5-Coder-7B-Instruct
INFO:gguf.gguf_writer:gguf: This GGUF file is for Little Endian only
INFO:hf-to-gguf:Exporting model...
...
INFO:hf-to-gguf:Set model quantization version
INFO:gguf.gguf_writer:Writing the following files:
INFO:gguf.gguf_writer:/Users/Shared/Public/huggingface/Qwen2.5-Coder-7B-Instruct/Qwen2.5_7b_bf16.gguf: n_tensors = 339, total_size = 15.2G
huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:
	- Avoid using `tokenizers` before the fork if possible
	- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
Writing: 100%|██████████████████████████████████████| 15.2G/15.2G [00:44<00:00, 339Mbyte/s]
INFO:hf-to-gguf:Model successfully exported to /Users/Shared/Public/huggingface/Qwen2.5-Coder-7B-Instruct/Qwen2.5_7b_bf16.gguf

and then

llama-passkey -m ./Qwen2.5_7b_bf16_2.gguf --junk 5420
build: 4176 (9a4b79bc) with Apple clang version 16.0.0 (clang-1600.0.26.4) for arm64-apple-darwin24.1.0
llama_load_model_from_file: using device Metal (Apple M3 Max) - 40959 MiB free
llama_model_loader: loaded meta data with 38 key-value pairs and 339 tensors from ./Qwen2.5_7b_bf16_2.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.type str              = model
llama_model_loader: - kv   2:                               general.name str              = Qwen2.5 Coder 7B Instruct
llama_model_loader: - kv   3:                           general.finetune str              = Instruct
llama_model_loader: - kv   4:                           general.basename str              = Qwen2.5-Coder
llama_model_loader: - kv   5:                         general.size_label str              = 7B
llama_model_loader: - kv   6:                            general.license str              = apache-2.0
llama_model_loader: - kv   7:                       general.license.link str              = https://huggingface.co/Qwen/Qwen2.5-C...
llama_model_loader: - kv   8:                   general.base_model.count u32              = 1
llama_model_loader: - kv   9:                  general.base_model.0.name str              = Qwen2.5 Coder 7B
llama_model_loader: - kv  10:          general.base_model.0.organization str              = Qwen
llama_model_loader: - kv  11:              general.base_model.0.repo_url str              = https://huggingface.co/Qwen/Qwen2.5-C...
llama_model_loader: - kv  12:                               general.tags arr[str,6]       = ["code", "codeqwen", "chat", "qwen", ...
llama_model_loader: - kv  13:                          general.languages arr[str,1]       = ["en"]
llama_model_loader: - kv  14:                          qwen2.block_count u32              = 28
llama_model_loader: - kv  15:                       qwen2.context_length u32              = 131072
llama_model_loader: - kv  16:                     qwen2.embedding_length u32              = 3584
llama_model_loader: - kv  17:                  qwen2.feed_forward_length u32              = 18944
llama_model_loader: - kv  18:                 qwen2.attention.head_count u32              = 28
llama_model_loader: - kv  19:              qwen2.attention.head_count_kv u32              = 4
llama_model_loader: - kv  20:                       qwen2.rope.freq_base f32              = 1000000.000000
llama_model_loader: - kv  21:     qwen2.attention.layer_norm_rms_epsilon f32              = 0.000001
llama_model_loader: - kv  22:                          general.file_type u32              = 32
llama_model_loader: - kv  23:                    qwen2.rope.scaling.type str              = yarn
llama_model_loader: - kv  24:                  qwen2.rope.scaling.factor f32              = 4.000000
llama_model_loader: - kv  25: qwen2.rope.scaling.original_context_length u32              = 32768
llama_model_loader: - kv  26:     qwen2.rope.scaling.yarn_log_multiplier f32              = 0.100000
llama_model_loader: - kv  27:                       tokenizer.ggml.model str              = gpt2
llama_model_loader: - kv  28:                         tokenizer.ggml.pre str              = qwen2
llama_model_loader: - kv  29:                      tokenizer.ggml.tokens arr[str,152064]  = ["!", "\"", "#", "$", "%", "&", "'", ...
llama_model_loader: - kv  30:                  tokenizer.ggml.token_type arr[i32,152064]  = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
llama_model_loader: - kv  31:                      tokenizer.ggml.merges arr[str,151387]  = ["Ġ Ġ", "ĠĠ ĠĠ", "i n", "Ġ t",...
llama_model_loader: - kv  32:                tokenizer.ggml.eos_token_id u32              = 151645
llama_model_loader: - kv  33:            tokenizer.ggml.padding_token_id u32              = 151643
llama_model_loader: - kv  34:                tokenizer.ggml.bos_token_id u32              = 151643
llama_model_loader: - kv  35:               tokenizer.ggml.add_bos_token bool             = false
llama_model_loader: - kv  36:                    tokenizer.chat_template str              = {%- if tools %}\n    {{- '<|im_start|>...
llama_model_loader: - kv  37:               general.quantization_version u32              = 2
llama_model_loader: - type  f32:  141 tensors
llama_model_loader: - type bf16:  198 tensors
llm_load_vocab: special tokens cache size = 22
llm_load_vocab: token to piece cache size = 0.9310 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      = 131072
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     = yarn
llm_load_print_meta: freq_base_train  = 1000000.0
llm_load_print_meta: freq_scale_train = 0.25
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       = 7B
llm_load_print_meta: model ftype      = BF16
llm_load_print_meta: model params     = 7.62 B
llm_load_print_meta: model size       = 14.19 GiB (16.00 BPW) 
llm_load_print_meta: general.name     = Qwen2.5 Coder 7B Instruct
llm_load_print_meta: BOS token        = 151643 '<|endoftext|>'
llm_load_print_meta: EOS token        = 151645 '<|im_end|>'
llm_load_print_meta: EOT token        = 151645 '<|im_end|>'
llm_load_print_meta: PAD token        = 151643 '<|endoftext|>'
llm_load_print_meta: LF token         = 148848 'ÄĬ'
llm_load_print_meta: FIM PRE token    = 151659 '<|fim_prefix|>'
llm_load_print_meta: FIM SUF token    = 151661 '<|fim_suffix|>'
llm_load_print_meta: FIM MID token    = 151660 '<|fim_middle|>'
llm_load_print_meta: FIM PAD token    = 151662 '<|fim_pad|>'
llm_load_print_meta: FIM REP token    = 151663 '<|repo_name|>'
llm_load_print_meta: FIM SEP token    = 151664 '<|file_sep|>'
llm_load_print_meta: EOG token        = 151643 '<|endoftext|>'
llm_load_print_meta: EOG token        = 151645 '<|im_end|>'
llm_load_print_meta: EOG token        = 151662 '<|fim_pad|>'
llm_load_print_meta: EOG token        = 151663 '<|repo_name|>'
llm_load_print_meta: EOG token        = 151664 '<|file_sep|>'
llm_load_print_meta: max token length = 256
llm_load_tensors: offloading 28 repeating layers to GPU
llm_load_tensors: offloading output layer to GPU
llm_load_tensors: offloaded 29/29 layers to GPU
llm_load_tensors: Metal_Mapped model buffer size = 12447.28 MiB
llm_load_tensors:   CPU_Mapped model buffer size = 14526.27 MiB
........................................................................................
llama_new_context_with_model: n_seq_max     = 1
llama_new_context_with_model: n_ctx         = 131104
llama_new_context_with_model: n_ctx_per_seq = 131104
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    = 0.25
llama_new_context_with_model: n_ctx_pre_seq (131104) > n_ctx_train (131072) -- possible training context overflow
ggml_metal_init: allocating
ggml_metal_init: found device: Apple M3 Max
ggml_metal_init: picking default device: Apple M3 Max
ggml_metal_init: using embedded metal library
ggml_metal_init: GPU name:   Apple M3 Max
ggml_metal_init: GPU family: MTLGPUFamilyApple9  (1009)
ggml_metal_init: GPU family: MTLGPUFamilyCommon3 (3003)
ggml_metal_init: GPU family: MTLGPUFamilyMetal3  (5001)
ggml_metal_init: simdgroup reduction   = true
ggml_metal_init: simdgroup matrix mul. = true
ggml_metal_init: has bfloat            = true
ggml_metal_init: use bfloat            = false
ggml_metal_init: hasUnifiedMemory      = true
ggml_metal_init: recommendedMaxWorkingSetSize  = 42949.67 MB
ggml_metal_init: skipping kernel_get_rows_bf16                     (not supported)
ggml_metal_init: skipping kernel_mul_mv_bf16_f32                   (not supported)
ggml_metal_init: skipping kernel_mul_mv_bf16_f32_1row              (not supported)
ggml_metal_init: skipping kernel_mul_mv_bf16_f32_l4                (not supported)
ggml_metal_init: skipping kernel_mul_mv_bf16_bf16                  (not supported)
ggml_metal_init: skipping kernel_mul_mv_id_bf16_f32                (not supported)
ggml_metal_init: skipping kernel_mul_mm_bf16_f32                   (not supported)
ggml_metal_init: skipping kernel_mul_mm_id_bf16_f32                (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h64           (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h80           (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h96           (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h112          (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h128          (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h256          (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h128      (not supported)
ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h256      (not supported)
ggml_metal_init: skipping kernel_cpy_f32_bf16                      (not supported)
ggml_metal_init: skipping kernel_cpy_bf16_f32                      (not supported)
ggml_metal_init: skipping kernel_cpy_bf16_bf16                     (not supported)
llama_kv_cache_init:      Metal KV buffer size =  7169.75 MiB
llama_new_context_with_model: KV self size  = 7169.75 MiB, K (f16): 3584.88 MiB, V (f16): 3584.88 MiB
llama_new_context_with_model:        CPU  output buffer size =     0.58 MiB
llama_new_context_with_model:      Metal compute buffer size =  7453.81 MiB
llama_new_context_with_model:        CPU compute buffer size =   297.00 MiB
llama_new_context_with_model: graph nodes  = 986
llama_new_context_with_model: graph splits = 395 (with bs=512), 283 (with bs=1)

main: n_len = 130161, n_ctx = 131072, n_kv_req = 131104, n_grp = 1, n_batch = 2048, n_junk = 5420, i_pos = 547

prefix tokens: 30
prompt tokens: 130145
main: processed: [     0,   2048)
main: processed: [  2048,   4096)
main: processed: [  4096,   6144)
main: processed: [  6144,   8192)
main: processed: [  8192,  10240)
main: processed: [ 10240,  12288)
main: processed: [ 12288,  14336)
main: processed: [ 14336,  16384)
main: processed: [ 16384,  18432)
main: processed: [ 18432,  20480)
main: processed: [ 20480,  22528)
main: processed: [ 22528,  24576)
main: processed: [ 24576,  26624)
main: processed: [ 26624,  28672)
main: processed: [ 28672,  30720)
main: processed: [ 30720,  32768)
main: processed: [ 32768,  34816)
main: processed: [ 34816,  36864)
main: processed: [ 36864,  38912)
main: processed: [ 38912,  40960)
main: processed: [ 40960,  43008)
main: processed: [ 43008,  45056)
main: processed: [ 45056,  47104)
main: processed: [ 47104,  49152)
main: processed: [ 49152,  51200)
main: processed: [ 51200,  53248)
main: processed: [ 53248,  55296)
main: processed: [ 55296,  57344)
main: processed: [ 57344,  59392)
main: processed: [ 59392,  61440)
main: processed: [ 61440,  63488)
main: processed: [ 63488,  65536)
main: processed: [ 65536,  67584)
main: processed: [ 67584,  69632)
main: processed: [ 69632,  71680)
main: processed: [ 71680,  73728)
main: processed: [ 73728,  75776)
main: processed: [ 75776,  77824)
main: processed: [ 77824,  79872)
main: processed: [ 79872,  81920)
main: processed: [ 81920,  83968)
main: processed: [ 83968,  86016)
main: processed: [ 86016,  88064)
main: processed: [ 88064,  90112)
main: processed: [ 90112,  92160)
main: processed: [ 92160,  94208)
main: processed: [ 94208,  96256)
main: processed: [ 96256,  98304)
main: processed: [ 98304, 100352)
main: processed: [100352, 102400)
main: processed: [102400, 104448)
main: processed: [104448, 106496)
main: processed: [106496, 108544)
main: processed: [108544, 110592)
main: processed: [110592, 112640)
main: processed: [112640, 114688)
main: processed: [114688, 116736)
main: processed: [116736, 118784)
main: processed: [118784, 120832)
main: processed: [120832, 122880)
main: processed: [122880, 124928)
main: processed: [124928, 126976)
main: processed: [126976, 129024)
main: processed: [129024, 130145)

main: passkey = 25250, inserted at position 547 / 5420 (token pos: ~13134)

 What is the pass key? The pass key is 25250. Remember it. 25250

main: decoded 16 tokens in 13.52 s, speed: 1.18 t/s

llama_perf_context_print:        load time = 1721741.78 ms
llama_perf_context_print: prompt eval time = 1720734.48 ms / 130145 tokens (   13.22 ms per token,    75.63 tokens per second)
llama_perf_context_print:        eval time =   13509.73 ms /    16 runs   (  844.36 ms per token,     1.18 tokens per second)
llama_perf_context_print:       total time = 1735260.27 ms / 130161 tokens

ggml_metal_free: deallocating

note, it is a shame that it hid it so early .. on a previous run using only 1/2 the context it was clearly after the 32k original context window:

...
main: processed: [ 59392,  60065)
...
main: passkey = 25250, inserted at position 1807 / 2500 (token pos: ~43414)

 What is the pass key? The pass key is 25250. Remember it. 25250

main: decoded 16 tokens in 11.66 s, speed: 1.37 t/s

llama_perf_context_print:        load time =  571207.64 ms
llama_perf_context_print: prompt eval time =  570533.64 ms / 60065 tokens (    9.50 ms per token,   105.28 tokens per second)
llama_perf_context_print:        eval time =   11647.58 ms /    16 runs   (  727.97 ms per token,     1.37 tokens per second)
llama_perf_context_print:       total time =  582865.27 ms / 60081 tokens

I've converted this from draft for review :)

@robbiemu robbiemu marked this pull request as ready for review December 7, 2024 19:21
convert_hf_to_gguf.py Outdated Show resolved Hide resolved
@ggerganov ggerganov merged commit 62e84d9 into ggerganov:master Dec 7, 2024
5 checks passed
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Dec 20, 2024
* add 128k yarn context for Qwen

* added property for model tensors

* removing useless line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python python script changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants