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
7 changes: 7 additions & 0 deletions include/llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ extern "C" {
LLAMA_API const char * llama_model_weight_backend_name (const struct llama_model * model, size_t i);
LLAMA_API size_t llama_model_weight_backend_bytes(const struct llama_model * model, size_t i);

// Account for the allocator's actual memory pool, including pinned host buffers.
struct llama_weight_allocation {
size_t host;
size_t device;
};
LLAMA_API struct llama_weight_allocation llama_model_weight_allocation(const struct llama_model * model);

// Get the default chat template. Returns nullptr if not available
// If name is NULL, returns the default chat template
LLAMA_API const char * llama_model_chat_template(const struct llama_model * model, const char * name);
Expand Down
12 changes: 12 additions & 0 deletions src/llama-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,18 @@ size_t llama_model_n_weight_backends(const llama_model * model) {
return llama_model_weight_backends(model).size();
}

llama_weight_allocation llama_model_weight_allocation(const llama_model * model) {
llama_weight_allocation allocation = {};
for (const auto & [buft, bytes] : model->memory_breakdown()) {
if (ggml_backend_buft_is_host(buft)) {
allocation.host += bytes;
} else {
allocation.device += bytes;
}
}
return allocation;
}

const char * llama_model_weight_backend_name(const llama_model * model, size_t i) {
const auto v = llama_model_weight_backends(model);
return i < v.size() ? v[i].first : nullptr;
Expand Down