Skip to content
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

ggml backends interface v1 #547

Merged
merged 23 commits into from
Oct 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
18 changes: 13 additions & 5 deletions examples/gpt-2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,21 @@ bool gpt2_model_load(const std::string & fname, gpt2_model & model, gpt_vocab &

printf("%s: memory size = %8.2f MB, n_mem = %d\n", __func__, memory_size/1024.0/1024.0, n_mem);

// allocate buffer and tensors
// create a backend buffer (can be in host or device memory)
model.buffer_kv = ggml_backend_alloc_buffer(model.backend, memory_size + 256);

ggml_allocr * alloc = ggml_allocr_new_from_buffer(model.buffer_kv);
ggml_allocr_alloc(alloc, model.memory_k);
ggml_allocr_alloc(alloc, model.memory_v);
ggml_allocr_free(alloc);
// allocate the tensors into the backend buffer
// TODO: better API for this
ggerganov marked this conversation as resolved.
Show resolved Hide resolved
{
ggml_allocr * alloc = ggml_allocr_new_from_buffer(model.buffer_kv);

// this updates the pointers in the tensors to point to the correct location in the buffer
// this is necessary since the ggml_context is .no_alloc == true
ggerganov marked this conversation as resolved.
Show resolved Hide resolved
ggml_allocr_alloc(alloc, model.memory_k);
ggml_allocr_alloc(alloc, model.memory_v);

ggml_allocr_free(alloc);
}
}

// load weights
Expand Down