Skip to content

Fixed Eval Bug: 12163 : Fallback to CPU when loading model: vk::PhysicalDevice::createDevice: ErrorExtensionNotPresent. #12329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions ggml/src/ggml-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,11 @@ static bool alloc_tensor_range(struct ggml_context * ctx,
}

ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft) {

if (buft == NULL) {
// Fall back to CPU buffer type
return ggml_backend_alloc_ctx_tensors_from_buft(ctx, ggml_backend_cpu_buffer_type());
}
GGML_ASSERT(ggml_get_no_alloc(ctx) == true);

size_t alignment = ggml_backend_buft_get_alignment(buft);
Expand Down
26 changes: 26 additions & 0 deletions ggml/src/ggml-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const char * ggml_backend_buft_name(ggml_backend_buffer_type_t buft) {
}

ggml_backend_buffer_t ggml_backend_buft_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
if (buft == NULL) {
// Fall back to CPU buffer type
return ggml_backend_buft_alloc_buffer(ggml_backend_cpu_buffer_type(), size);
}

if (size == 0) {
// return a dummy buffer for zero-sized allocations
return ggml_backend_buffer_init(buft, {}, NULL, 0);
Expand All @@ -45,11 +50,20 @@ ggml_backend_buffer_t ggml_backend_buft_alloc_buffer(ggml_backend_buffer_type_t
}

size_t ggml_backend_buft_get_alignment(ggml_backend_buffer_type_t buft) {
if (buft == NULL) {
// Return a safe default alignment or use CPU buffer type's alignment
return ggml_backend_buft_get_alignment(ggml_backend_cpu_buffer_type());
}
return buft->iface.get_alignment(buft);
}

size_t ggml_backend_buft_get_max_size(ggml_backend_buffer_type_t buft) {
// get_max_size is optional, defaults to SIZE_MAX
if (buft == NULL) {
// Return a safe default (CPU buffer type's max size)
return ggml_backend_buft_get_max_size(ggml_backend_cpu_buffer_type());
}

if (buft->iface.get_max_size) {
return buft->iface.get_max_size(buft);
}
Expand All @@ -58,6 +72,11 @@ size_t ggml_backend_buft_get_max_size(ggml_backend_buffer_type_t buft) {

size_t ggml_backend_buft_get_alloc_size(ggml_backend_buffer_type_t buft, struct ggml_tensor * tensor) {
// get_alloc_size is optional, defaults to ggml_nbytes
if (buft == NULL) {
// Return ggml_nbytes as fallback
return ggml_nbytes(tensor);
}

if (buft->iface.get_alloc_size) {
size_t size = buft->iface.get_alloc_size(buft, tensor);
assert(size >= ggml_nbytes(tensor));
Expand All @@ -67,13 +86,20 @@ size_t ggml_backend_buft_get_alloc_size(ggml_backend_buffer_type_t buft, struct
}

bool ggml_backend_buft_is_host(ggml_backend_buffer_type_t buft) {
if (buft == NULL) {
return true; // CPU is host, so assume true for NULL
}

if (buft->iface.is_host) {
return buft->iface.is_host(buft);
}
return false;
}

ggml_backend_dev_t ggml_backend_buft_get_device(ggml_backend_buffer_type_t buft) {
if (buft == NULL) {
return NULL;
}
return buft->device;
}

Expand Down
Loading