Repository navigation
ggml : add ggml_backend_op_alloc_size_may_expand, use it in RPC - #27960
Merged
Merged
Conversation
some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their get_alloc_size implementations. add ggml_backend_op_alloc_size_may_expand() to the backend utils, listing these ops, and assert in ggml_backend_buft_get_alloc_size that a backend expanding the alloc size of a compute op only does so for ops listed in the helper. use the helper in the RPC backend to decide whether to query the remote server for the actual alloc size, instead of a hardcoded list. Assisted-by: pi:llama.cpp/Qwen3.8-27B
ggerganov
marked this pull request as ready for review
August 29, 2026 11:58
Member
Author
|
This fixes Qwen4 garbage generation when running over RPC with Metal. |
danielhanchen
added a commit
to unslothai/llama.cpp
that referenced
this pull request
Aug 31, 2026
The pin was 50 commits behind the PR head and sat before "Add MTP support", so the nightly shipped GLM-5-Next without the NextN draft head, without the master merge, and without the pooled-key shift fix. Verified against b10705 by replaying the resolve step: the new commit fetches from ggml-org, is a commit of ggml-org#27754, and merges onto the base plus the pins listed before it with no conflict. Unrelated, and not fixed here: ggml-org#25731 stops merging at b10705. Upstream ggml-org#27960 touched ggml/src/ggml-rpc/ggml-rpc.cpp, which the Inkling branch also edits, and additive_merge.py correctly refuses it. It merges on b10698, the base of the last shipped nightly, so the next run on a newer base will fail there until that branch is merged forward.
ggerganov
added a commit
to ggml-org/ggml
that referenced
this pull request
Sep 4, 2026
This was referenced Sep 4, 2026
Merged
ggerganov
added a commit
that referenced
this pull request
Sep 4, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont #27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
1 task done
alin-o
pushed a commit
to alin-o/llama.cpp-qwen38
that referenced
this pull request
Sep 6, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org/llama.cpp#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
alin-o
pushed a commit
to alin-o/llama.cpp-qwen38
that referenced
this pull request
Sep 6, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org/llama.cpp#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
alin-o
pushed a commit
to alin-o/llama.cpp-qwen38
that referenced
this pull request
Sep 6, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org/llama.cpp#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
thecodacus
pushed a commit
to thecodacus/llama.cpp
that referenced
this pull request
Sep 7, 2026
…-org#27960) some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their get_alloc_size implementations. add ggml_backend_op_alloc_size_may_expand() to the backend utils, listing these ops, and assert in ggml_backend_buft_get_alloc_size that a backend expanding the alloc size of a compute op only does so for ops listed in the helper. use the helper in the RPC backend to decide whether to query the remote server for the actual alloc size, instead of a hardcoded list. Assisted-by: pi:llama.cpp/Qwen3.8-27B
x1250
pushed a commit
to x1250/llama.cpp
that referenced
this pull request
Sep 9, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
milpster
pushed a commit
to milpster/gfx906-llama-cpp
that referenced
this pull request
Sep 10, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org/llama.cpp#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
zbrad
pushed a commit
to zbrad/llama.cpp
that referenced
this pull request
Sep 10, 2026
…-org#27960) some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their get_alloc_size implementations. add ggml_backend_op_alloc_size_may_expand() to the backend utils, listing these ops, and assert in ggml_backend_buft_get_alloc_size that a backend expanding the alloc size of a compute op only does so for ops listed in the helper. use the helper in the RPC backend to decide whether to query the remote server for the actual alloc size, instead of a hardcoded list. Assisted-by: pi:llama.cpp/Qwen3.8-27B
zbrad
pushed a commit
to zbrad/llama.cpp
that referenced
this pull request
Sep 10, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
pl752
pushed a commit
to pl752/llama.cpp
that referenced
this pull request
Sep 15, 2026
…-org#27960) some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their get_alloc_size implementations. add ggml_backend_op_alloc_size_may_expand() to the backend utils, listing these ops, and assert in ggml_backend_buft_get_alloc_size that a backend expanding the alloc size of a compute op only does so for ops listed in the helper. use the helper in the RPC backend to decide whether to query the remote server for the actual alloc size, instead of a hardcoded list. Assisted-by: pi:llama.cpp/Qwen3.8-27B
pl752
pushed a commit
to pl752/llama.cpp
that referenced
this pull request
Sep 15, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
zsogitbe
pushed a commit
to zsogitbe/llama.cpp
that referenced
this pull request
Sep 17, 2026
…-org#27960) some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their get_alloc_size implementations. add ggml_backend_op_alloc_size_may_expand() to the backend utils, listing these ops, and assert in ggml_backend_buft_get_alloc_size that a backend expanding the alloc size of a compute op only does so for ops listed in the helper. use the helper in the RPC backend to decide whether to query the remote server for the actual alloc size, instead of a hardcoded list. Assisted-by: pi:llama.cpp/Qwen3.8-27B
zsogitbe
pushed a commit
to zsogitbe/llama.cpp
that referenced
this pull request
Sep 17, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
Te-eMster
pushed a commit
to Te-eMster/mx-llama.cpp
that referenced
this pull request
Sep 18, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
Te-eMster
pushed a commit
to Te-eMster/mx-llama.cpp
that referenced
this pull request
Sep 18, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
Jesssullivan
added a commit
to Jesssullivan/llama.cpp
that referenced
this pull request
Sep 20, 2026
PLACEHOLDER MESSAGE — rewrite before opening a pull request. llama.cpp CONTRIBUTING prohibits AI-written commit messages and PR descriptions; this text was prepared by tooling so the branch could be pushed, and the author is expected to replace it with their own words (git commit --amend). ggml_backend_buft_get_alloc_size guards the documented lower bound of the buffer-type contract with a plain assert(), which is compiled out under NDEBUG, while the upper bound two lines below is a GGML_ASSERT. A buffer type that under-reports therefore passes silently in release builds and only fails later, in the in-place-reuse path, at ggml-alloc.c GGML_ASSERT(parent_size >= node_size). Promote the lower bound to GGML_ASSERT so the failure lands on the buffer type that produced the wrong size. The neighbouring assert already evaluates ggml_nbytes in release builds, so there is no added cost. ref: ggml-org#27960 ref: ggml-org#28038 ref: ggml-org#17884 Assisted-by: Claude Opus 5
Jesssullivan
added a commit
to Jesssullivan/llama.cpp
that referenced
this pull request
Sep 20, 2026
… at ggml_nbytes PLACEHOLDER MESSAGE — rewrite before opening a pull request. llama.cpp CONTRIBUTING prohibits AI-written commit messages and PR descriptions; this text was prepared by tooling so the branch could be pushed, and the author is expected to replace it with their own words (git commit --amend). The process-global memo added in ggml-org#18626 keys RPC_CMD_GET_ALLOC_SIZE results on {device, type, op, op_params, ne} and omits nb. Two tensors with identical ne but different strides therefore share one entry, and the second caller receives the first tensor's size. When that size is smaller than ggml_nbytes, the buffer-type contract documented in ggml-org#27960 and ggml-org#28038 is violated and allocation fails downstream. Add nb to the cache key and never return less than ggml_nbytes. The memo is preserved: contiguous tensors, which are the common case, keep the same hit rate. rpc_tensor already carries nb over the wire, so there is no protocol or API change and RPC_PROTO_* is untouched. Reproduced against a local ggml-rpc-server -d CPU: a packed tensor reports 16384/16384 and a strided view with the same ne reports nbytes 32512, alloc_size 16384, then aborts; with this change the second call reports 32512 and the run completes. The regression is folded into tests/test-rpc-multi-server. ref: ggml-org#28360 ref: ggml-org#18626 ref: ggml-org#27960 Assisted-by: Claude Opus 5
Jesssullivan
added a commit
to Jesssullivan/llama.cpp
that referenced
this pull request
Sep 22, 2026
PLACEHOLDER MESSAGE — rewrite before opening a pull request. llama.cpp CONTRIBUTING prohibits AI-written commit messages and PR descriptions; this text was prepared by tooling so the branch could be pushed, and the author is expected to replace it with their own words (git commit --amend). ggml_backend_buft_get_alloc_size guards the documented lower bound of the buffer-type contract with a plain assert(), which is compiled out under NDEBUG, while the upper bound two lines below is a GGML_ASSERT. A buffer type that under-reports therefore passes silently in release builds and only fails later, in the in-place-reuse path, at ggml-alloc.c GGML_ASSERT(parent_size >= node_size). Promote the lower bound to GGML_ASSERT so the failure lands on the buffer type that produced the wrong size. The neighbouring assert already evaluates ggml_nbytes in release builds, so there is no added cost. ref: ggml-org#27960 ref: ggml-org#28038 ref: ggml-org#17884 Assisted-by: Claude Opus 5
Jesssullivan
added a commit
to Jesssullivan/llama.cpp
that referenced
this pull request
Sep 22, 2026
… at ggml_nbytes PLACEHOLDER MESSAGE — rewrite before opening a pull request. llama.cpp CONTRIBUTING prohibits AI-written commit messages and PR descriptions; this text was prepared by tooling so the branch could be pushed, and the author is expected to replace it with their own words (git commit --amend). The process-global memo added in ggml-org#18626 keys RPC_CMD_GET_ALLOC_SIZE results on {device, type, op, op_params, ne} and omits nb. Two tensors with identical ne but different strides therefore share one entry, and the second caller receives the first tensor's size. When that size is smaller than ggml_nbytes, the buffer-type contract documented in ggml-org#27960 and ggml-org#28038 is violated and allocation fails downstream. Add nb to the cache key and never return less than ggml_nbytes. The memo is preserved: contiguous tensors, which are the common case, keep the same hit rate. rpc_tensor already carries nb over the wire, so there is no protocol or API change and RPC_PROTO_* is untouched. Reproduced against a local ggml-rpc-server -d CPU: a packed tensor reports 16384/16384 and a strided view with the same ne reports nbytes 32512, alloc_size 16384, then aborts; with this change the second call reports 32512 and the run completes. The regression is folded into tests/test-rpc-multi-server. ref: ggml-org#28360 ref: ggml-org#18626 ref: ggml-org#27960 Assisted-by: Claude Opus 5
frostyautumnleaf
pushed a commit
to frostyautumnleaf/llama.cpp
that referenced
this pull request
Oct 5, 2026
…-org#27960) some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their get_alloc_size implementations. add ggml_backend_op_alloc_size_may_expand() to the backend utils, listing these ops, and assert in ggml_backend_buft_get_alloc_size that a backend expanding the alloc size of a compute op only does so for ops listed in the helper. use the helper in the RPC backend to decide whether to query the remote server for the actual alloc size, instead of a hardcoded list. Assisted-by: pi:llama.cpp/Qwen3.8-27B
frostyautumnleaf
pushed a commit
to frostyautumnleaf/llama.cpp
that referenced
this pull request
Oct 5, 2026
* ggml : rename and make private ggml_op_alloc_size_may_expand() (ggml/0) cont ggml-org#27960 * ggml : bump version to 0.23.0 (ggml/1618) * sync : ggml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Some backends (Metal, SYCL, WebGPU) require additional memory for fleeting data for certain ops, which is reflected in their
get_alloc_sizeimplementations. The RPC backend had a hardcoded list of such ops (FLASH_ATTN_EXT,MUL_MAT_ID): if a backend started expanding the alloc size of another op and the list was not updated, the RPC client would under-allocate.ggml_backend_op_alloc_size_may_expand()to the backend utils, returningtruefor the ops that expand the alloc size in any backend (FLASH_ATTN_EXT,MUL_MAT_ID,CUMSUM,ARGSORT,TOP_K)GGML_ASSERTinggml_backend_buft_get_alloc_size()catching a backend that expands the alloc size of a compute op that is not listed in the helperCUMSUM/ARGSORT/TOP_Kfor e.g. a Metal serverAdditional information
The op list was derived by auditing all
get_alloc_sizeimplementations in the tree. All relevant sites are marked with a[TAG_ALLOC_SIZE_EXPAND]comment so that they can be found easily when adding a new op.The assert exempts non-compute tensors (
ggml_op_is_empty), since type-dependent expansions (e.g. quantized weight padding) apply to weights regardless of op.ref: #15966
Requirements