Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' }}

Expand Down Expand Up @@ -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' }}
10 changes: 10 additions & 0 deletions include/llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/llama-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ggml_backend_buffer_type_t, llama_memory_breakdown_data> ret;
for (const auto & [buft, size] : model.memory_breakdown()) {
Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/llama-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//
Expand Down