Skip to content

ggml: migrate work_data to stack allocation - #18083

Closed
GermanAizek wants to merge 1 commit into
ggml-org:masterfrom
GermanAizek:heap-to-stack
Closed

GermanAizek wants to merge 1 commit into
ggml-org:masterfrom
GermanAizek:heap-to-stack

Conversation

@GermanAizek

@GermanAizek GermanAizek commented Dec 16, 2025 •

Copy link
Copy Markdown

Summary

As you can see from my tests, llama-bench finishes its work faster by as much as 5-7 seconds, and also shows the number of tokens better in the tg128 tests. Please check my changes, as I may have measurement errors due to NUMA architecture.

References about changes

My benchmark tests

heap-to-stack branch

devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ bash ./test.sh
| model                          |       size |     params | backend    | threads |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | ------: | --------------: | -------------------: |
Attaching to process 19315
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           pp512 |        424.85 ± 1.38 |
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           tg128 |         22.18 ± 0.09 |

build: d6742125 (7421)
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ bash ./test.sh
| model                          |       size |     params | backend    | threads |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | ------: | --------------: | -------------------: |
Attaching to process 23670
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           pp512 |        427.63 ± 8.25 |                                                                                      
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           tg128 |         29.12 ± 0.18 |                                                                                      
                                                                                                                                                                                                                  
build: 39b00eae (7422)                                                                             

quantize-perf log
quantize-perf-benchmark_heap_to_stack.txt

monitor graph
plot1b_heap_to_stack

master branch

devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ bash ./test.sh
| model                          |       size |     params | backend    | threads |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | ------: | --------------: | -------------------: |
Attaching to process 21292
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           pp512 |        425.27 ± 3.99 |
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           tg128 |         17.31 ± 0.22 |

build: d6742125 (7421)
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ bash ./test.sh
| model                          |       size |     params | backend    | threads |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | ------: | --------------: | -------------------: |
Attaching to process 21808
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           pp512 |        426.61 ± 5.37 |
| llama 1B Q2_K - Medium         | 546.50 MiB |     1.24 B | CPU        |      36 |           tg128 |         18.12 ± 0.64 |

build: d6742125 (7421)

quantize-perf log
quantize-perf-benchmark-master.txt

monitor graph
plot1b_master

@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning labels Dec 16, 2025
@am17an

am17an commented Dec 16, 2025

Copy link
Copy Markdown
Contributor

Considering your previous PRs, I am a bit hesitant to look at this code. Please mark AI usage if any, the idea seems reasonable to me.

@GermanAizek

Copy link
Copy Markdown
Author

Considering your previous PRs, I am a bit hesitant to look at this code. Please mark AI usage if any, the idea seems reasonable to me.

after bad experience with them as they generate commit changes and references poorly, I gave up for a long time.

@am17an

am17an commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

I see a drop in performance

Master

model size params backend threads test t/s
llama 7B Q5_K - Medium 4.45 GiB 6.74 B CPU 8 pp512 22.42 ± 0.07
llama 7B Q5_K - Medium 4.45 GiB 6.74 B CPU 8 tg128 6.05 ± 0.06

PR:

model size params backend threads test t/s
llama 7B Q5_K - Medium 4.45 GiB 6.74 B CPU 8 pp512 21.79 ± 0.46
llama 7B Q5_K - Medium 4.45 GiB 6.74 B CPU 8 tg128 5.86 ± 0.18

@GermanAizek

Copy link
Copy Markdown
Author

I see a drop in performance

I believe you, because NUMA makes my results jump not accurate, and I need to use hyperfine to average time all llama-bench tests after 10 runs.

@GermanAizek

Copy link
Copy Markdown
Author

@am17an,

devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ hyperfine --warmup 2 "./llama-bench -m Llama-3.2-1B-Instruct-Q2_K.gguf -p 512 -n 128"
Benchmark 1: ./llama-bench -m Llama-3.2-1B-Instruct-Q2_K.gguf -p 512 -n 128
  Time (mean ± σ):     29.344 s ±  0.406 s    [User: 1041.751 s, System: 1.148 s]
  Range (min … max):   28.619 s … 30.130 s    10 runs
 
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ cd ../..
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp$ git branch --show-current
master
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp$ cd cmake-build-release/bin/
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ hyperfine --warmup 2 "./llama-bench -m Llama-3.2-1B-Instruct-Q2_K.gguf -p 512 -n 128"
Benchmark 1: ./llama-bench -m Llama-3.2-1B-Instruct-Q2_K.gguf -p 512 -n 128
  Time (mean ± σ):     32.172 s ±  5.520 s    [User: 1143.268 s, System: 1.125 s]
  Range (min … max):   28.211 s … 42.510 s    10 runs
 
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp/cmake-build-release/bin$ cd ../..
devuan@devuan:/media/devuan/437889e5-f1cd-4f29-84a0-605eacc7cd49/GIT/llama.cpp$ git branch --show-current
heap-to-stack

I tested 2 startup warmups more correctly, and 10 averaged ones on each branch, and indeed I did worse. Now I'm not going to create PRS that I haven't tested well, now I've found a better way to benchmark on my server. I close this changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants