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

feat: add LLAMA_CPP_N_THREADS env #742

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Changes from 2 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: 6 additions & 1 deletion crates/llama-cpp-bindings/src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,13 @@ std::unique_ptr<TextInferenceEngine> create_engine(bool use_gpu, rust::Str model
llama_context_params ctx_params = llama_context_default_params();
ctx_params.n_ctx = N_CTX * parallelism;
ctx_params.n_batch = N_BATCH;
if (const char* n_threads = std::getenv("LLAMA_CPP_N_THREADS")) {
ctx_params.n_threads = std::stoi(n_threads);
erfanium marked this conversation as resolved.
Show resolved Hide resolved
}
if (const char* n_threads_batch = std::getenv("LLAMA_CPP_N_THREADS_BATCH")) {
ctx_params.n_threads_batch = std::stoi(n_threads_batch);
}
llama_context* ctx = llama_new_context_with_model(model, ctx_params);

return std::make_unique<TextInferenceEngineImpl>(
owned<llama_model>(model, llama_free_model),
owned<llama_context>(ctx, llama_free),
Expand Down