Skip to content

ggml-meta: propagate buffer usage and call init on the new tensors - #27586

Merged
ggerganov merged 1 commit into
masterfrom
maxk/meta-backend-fixes
Aug 26, 2026
Merged

ggml-meta: propagate buffer usage and call init on the new tensors#27586
ggerganov merged 1 commit into
masterfrom
maxk/meta-backend-fixes

Conversation

@max-krasnyansky

Copy link
Copy Markdown
Member

Overview

Another try at fixing ggml-meta to propagate buffer usage and properly initialize new tensors.
Original PR was #26502

Tested with ggml-metal and ggml-hexagon backends.

GGML_METAL_DEVICES=2 ./build-macos/bin/llama-completion  -m ../gguf/gemma-4-E4B_q4_0-it.gguf  -p "just a test"  -n 32  -ngl 99 --split-mode tensor  --device MTL0,MTL1 -no-cnv

tensor_init moved after tensor->data is setup which should resolve issues with CUDA.

@max-krasnyansky
max-krasnyansky requested review from ggerganov and removed request for JohannesGaessler August 23, 2026 05:40
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Aug 23, 2026
@cdanis

cdanis commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

As requested, tested with -sm tensor on a few different model archs on dual RTX A5000. Seems to work great, thanks @max-krasnyansky !

@max-krasnyansky

Copy link
Copy Markdown
Member Author

@youyoulyz
Can you please check on your CUDA setup as well.

Looking good with ggml-metal on my M4 Pro

GGML_METAL_DEVICES=2 ./build-macos/bin/test-llama-archs
...

@max-krasnyansky

Copy link
Copy Markdown
Member Author

double-checked on my CUDA setup.

./build-cuda/bin/llama-completion --device CUDA0,CUDA1 --split-mode tensor -m Qwen3.8-27B-Q4_0.gguf -f sample_prompt_4096.txt --ctx-size 8192 --jinja -st -v 
...
0.03.052.429 I llama_prepare_model_devices: creating a Meta device with 2 devices
0.03.052.432 I llama_prepare_model_devices: - device 0: CUDA0
0.03.052.432 I llama_prepare_model_devices: - device 1: CUDA1
...
0.14.309.941 I common_perf_print: prompt eval time =    3350.21 ms /  4018 tokens (    0.83 ms per token,  1199.33 tokens per second)
0.14.309.942 I common_perf_print:        eval time =    2984.28 ms /   186 runs   (   16.04 ms per token,    62.33 tokens per second)
0.14.309.943 I common_perf_print:       total time =    6434.54 ms /  4204 tokens
0.14.309.946 I common_perf_print: unaccounted time =      44.12 ms /   0.7 %      (total - sampling - prompt eval - eval) / (total)
0.14.309.947 I common_perf_print:    graphs reused =        184
0.14.310.083 I common_memory_breakdown_print: | memory breakdown [MiB] |  total     free    self   model   context   compute    unaccounted |
0.14.310.085 I common_memory_breakdown_print: |   - Meta() (Meta())    | 162305 = 145039 + (8028 =  7184 +     330 +     513) +        9237 |
0.14.310.086 I common_memory_breakdown_print: |   - Host               |                     710 =   682 +       0 +      28                |
0.14.310.190 D ~llama_context:     Meta() compute buffer size is 513.0177 MiB, matches expectation of 513.0177 MiB
0.14.310.194 D ~llama_context:  CUDA_Host compute buffer size is  28.0196 MiB, matches expectation of  28.0196 MiB

@ggerganov should be good to merge

@max-krasnyansky

Copy link
Copy Markdown
Member Author

@ggerganov sorry for bugging you. It's blocking for #26501
I could probably workaround in there but seems like this is clean and simple, besides breaking CUDA on the first try :), but that's all tested now.

@max-krasnyansky
max-krasnyansky force-pushed the maxk/meta-backend-fixes branch from f3aa3ae to 3218261 Compare August 26, 2026 00:44
@ggerganov

Copy link
Copy Markdown
Member

@ggerganov sorry for bugging you. It's blocking for #26501 I could probably workaround in there but seems like this is clean and simple, besides breaking CUDA on the first try :), but that's all tested now.

No problem at all. I was just planning to add more tests with -sm tensor to the CI, but can't get around to do that still.

@ggerganov
ggerganov merged commit 5d5cb4c into master Aug 26, 2026
26 of 33 checks passed
@ggerganov
ggerganov deleted the maxk/meta-backend-fixes branch August 26, 2026 05:27
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
Githab-capibara added a commit to Githab-capibara/llama.cpp that referenced this pull request Sep 10, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants