diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 3b952797d141..2bd22c83ddc9 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -165,7 +165,7 @@ jobs: dry-run: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }} windows: - runs-on: windows-2025 + runs-on: windows-2022 steps: - name: Clone @@ -178,7 +178,7 @@ jobs: - name: ccache uses: ggml-org/ccache-action@v1.2.21 with: - key: server-windows-2025-x64 + key: server-windows-2022-x64 evict-old-files: 1d save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} @@ -227,7 +227,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} with: - key: server-windows-2025-x64 + key: server-windows-2022-x64 older: 5m min: 1 dry-run: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }} diff --git a/include/llama.h b/include/llama.h index 2cdf34626029..b5bbbdd5b844 100644 --- a/include/llama.h +++ b/include/llama.h @@ -569,6 +569,16 @@ extern "C" { // NOTE: After creating a llama_context, it is recommended to query the actual values using these functions // In some cases the requested values via llama_context_params may differ from the actual values used by the context // ref: https://github.com/ggml-org/llama.cpp/pull/17046#discussion_r2503085732 + // Native buffer footprint of this context, excluding shared model weights. + // On a no_alloc model, compute and KV are the backend's planned sizes. + // Includes the context's output buffer in the pool where it resides. + struct llama_context_buffer_bytes { + uint64_t host; + uint64_t device; + }; + LLAMA_API bool llama_context_get_buffer_bytes( + const struct llama_context * ctx, struct llama_context_buffer_bytes * out); + LLAMA_API uint32_t llama_n_ctx (const struct llama_context * ctx); LLAMA_API uint32_t llama_n_ctx_seq (const struct llama_context * ctx); LLAMA_API uint32_t llama_n_batch (const struct llama_context * ctx); diff --git a/src/llama-context.cpp b/src/llama-context.cpp index 49cd7fc868a0..0435d90fcf22 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -3493,6 +3493,21 @@ void llama_context::perf_reset() { n_reused = 0; } +llama_context_buffer_bytes llama_context::buffer_bytes() const { + llama_context_buffer_bytes result = {}; + const auto add = [&](ggml_backend_buffer_type_t buft, uint64_t bytes) { + auto & pool = ggml_backend_buft_is_host(buft) ? result.host : result.device; + pool += bytes; + }; + for (const auto & [buft, bytes] : memory_breakdown()) { + add(buft, bytes.context + bytes.compute); + } + if (buf_output) { + add(ggml_backend_buffer_get_type(buf_output.get()), ggml_backend_buffer_get_size(buf_output.get())); + } + return result; +} + llama_memory_breakdown llama_context::memory_breakdown() const { std::map ret; for (const auto & [buft, size] : model.memory_breakdown()) { @@ -4255,6 +4270,19 @@ void llama_perf_context_reset(llama_context * ctx) { // ext // +bool llama_context_get_buffer_bytes(const llama_context * ctx, llama_context_buffer_bytes * out) { + if (!ctx || !out) { + return false; + } + try { + *out = ctx->buffer_bytes(); + return true; + } catch (const std::exception & e) { + LLAMA_LOG_ERROR("%s: %s\n", __func__, e.what()); + return false; + } +} + llama_memory_breakdown llama_get_memory_breakdown(const struct llama_context * ctx) { return ctx->memory_breakdown(); } diff --git a/src/llama-context.h b/src/llama-context.h index 2f591d621106..6cb6806150f1 100644 --- a/src/llama-context.h +++ b/src/llama-context.h @@ -211,6 +211,7 @@ struct llama_context { llama_perf_context_data perf_get_data() const; void perf_reset(); + llama_context_buffer_bytes buffer_bytes() const; llama_memory_breakdown memory_breakdown() const; //