Repository navigation
metal: skip empty asynchronous tensor uploads - #406
Conversation
Empty recurrent-state views can reach async uploads after #393. Metal cannot allocate a zero-length staging buffer. Assisted-by: Codex
|
Additional Apple M1 validation for this fix. Posting here to avoid a duplicate issue. SummaryBonsai-2 CRACK ( Related existing fix: #406 . This report provides additional M1 reproduction and validation evidence; it does not claim a new fix. The local patch below was tested, not the PR branch itself. Environment
ReproductionBuild the unmodified tag in a separate checkout: git clone --depth 1 --branch prism-b10826-c9c34bc https://github.com/PrismML-Eng/llama.cpp.git prism-llama
cmake -S prism-llama -B prism-llama/build-local \
-DCMAKE_BUILD_TYPE=Release -DGGML_METAL=ON \
-DGGML_METAL_EMBED_LIBRARY=ON -DLLAMA_BUILD_TESTS=OFF
cmake --build prism-llama/build-local --target llama-server -j 4Start the server, replacing the example model path: ./prism-llama/build-local/bin/llama-server \
-m /path/to/Bonsai-2-27B-PQ2_0-CRACK.gguf \
-ngl 10 -c 4096 -np 1 -b 128 -ub 128 \
--host 127.0.0.1 --port 18085 --no-warmup -lv 4Expected: server initializes and serves requests. The original reproduction also failed with Diagnostic evidenceSelected lines from the unmodified local build (local path omitted): A temporary diagnostic build logged uploads before the allocation: The diagnostic logging shifts the assertion from line 315 to 316. Both crash backtraces include At the pinned commit, Minimal local workaroundThis is the exact tested patch. It adds only three lines in diff --git a/ggml/src/ggml-metal/ggml-metal-context.m b/ggml/src/ggml-metal/ggml-metal-context.m
index 32d97cd..dd9b7b4 100644
--- a/ggml/src/ggml-metal/ggml-metal-context.m
+++ b/ggml/src/ggml-metal/ggml-metal-context.m
@@ -306,6 +306,9 @@ static struct ggml_metal_buffer_id ggml_metal_get_buffer_id(const struct ggml_te
void ggml_metal_set_tensor_async(ggml_metal_t ctx, struct ggml_tensor * tensor, const void * data, size_t offset, size_t size) {
@autoreleasepool {
+ if (size == 0) {
+ return;
+ }
// wrap the source data into a Metal buffer
id<MTLDevice> device = ggml_metal_device_get_obj(ctx->dev);
id<MTLBuffer> buf_src = [device newBufferWithBytes:dataPatch SHA-256: PR #406 uses the same function, condition and early return, but places the guard before Validation of the local patchWith the same model and server options:
After applying the patch and rebuilding, the completion probe was: curl http://127.0.0.1:18085/health
curl http://127.0.0.1:18085/completion \
-H 'Content-Type: application/json' \
-d '{"prompt":"The capital of Japan is","n_predict":16,"temperature":0,"seed":42}'Both saved responses contain Saved server logs also confirm 16-token evaluation in both configurations. This is a short startup/completion check, not a general correctness or stability test. Long contexts, image inputs, concurrency, extended runs, perplexity and backend regression tests were not validated locally. The local source build reproduces the release-commit failure, but does not reproduce every release-build setting. AI assistance disclosureAI assistance was used for diagnosis, preparing the local workaround and validation workflow, and drafting this report. The actual hardware runs are documented in saved logs and response JSON. For this report, the patch file, pinned source, current source diff, diagnostic logs and successful response records were inspected for consistency. This is a limited local workaround offered for maintainer review, not a claim of comprehensive validation. |
Since the scheduler upload batching in #393, zero-byte recurrent-state views can reach
ggml_metal_set_tensor_async. Metal cannot allocate a zero-length staging buffer, so the assert fires and decode aborts for Qwen3.5-architecture models on Metal, with either the gathered or the rows state path.This returns early for empty uploads. No behavior change for non-empty tensors.
Validation: Release Metal build on an M5 Pro; the previously crashing Qwen3.5-architecture decode runs complete, and Metal GATED_DELTA_NET and SET_ROWS test-backend-ops pass (259/259).