- Notifications
You must be signed in to change notification settings - Fork328
Allow user to limit the number of threads that OpenMP spawns.#1362
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
15 commits Select commitHold shift + click to select a range
4612b4f
Refactor the initialization of GUC parameters.
higuoxing58e2aec
Allow user to limit the number of threads that OpenMP spawns.
higuoxing99bebe2
Merge branch 'master' into set-omp-num-threads
higuoxing58f8a9a
Merge branch 'master' into set-omp-num-threads
higuoxing2dc1964
Merge branch 'master' into set-omp-num-threads
higuoxing1361bce
Merge branch 'master' into set-omp-num-threads
higuoxing4e84e08
Address review comments.
higuoxing2a1853c
Address review comments
higuoxing3768179
Simplify global variables.
higuoxing6e3fe80
Fixup!!
higuoxing2e1891c
Merge branch 'master' into set-omp-num-threads
higuoxingd05644a
Update pgml-extension/src/bindings/transformers/whitelist.rs
higuoxing663ed25
Update pgml-extension/src/bindings/transformers/whitelist.rs
higuoxingc81c42e
Address review comments.
higuoxingede3d92
Merge branch 'master' into set-omp-num-threads
kczimmFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 3 additions & 5 deletionspgml-extension/src/bindings/python/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
45 changes: 21 additions & 24 deletionspgml-extension/src/bindings/transformers/whitelist.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
88 changes: 72 additions & 16 deletionspgml-extension/src/config.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,72 @@ | ||
use pgrx::{GucContext, GucFlags, GucRegistry, GucSetting}; | ||
use std::ffi::CStr; | ||
#[cfg(any(test, feature = "pg_test"))] | ||
use pgrx::{pg_schema, pg_test}; | ||
pub static PGML_VENV: GucSetting<Option<&'static CStr>> = GucSetting::<Option<&'static CStr>>::new(None); | ||
pub static PGML_HF_WHITELIST: GucSetting<Option<&'static CStr>> = GucSetting::<Option<&'static CStr>>::new(None); | ||
pub static PGML_HF_TRUST_REMOTE_CODE: GucSetting<bool> = GucSetting::<bool>::new(false); | ||
pub static PGML_HF_TRUST_REMOTE_CODE_WHITELIST: GucSetting<Option<&'static CStr>> = | ||
GucSetting::<Option<&'static CStr>>::new(None); | ||
pub static PGML_OMP_NUM_THREADS: GucSetting<i32> = GucSetting::<i32>::new(1); | ||
extern "C" { | ||
fn omp_set_num_threads(num_threads: i32); | ||
} | ||
pub fn initialize_server_params() { | ||
GucRegistry::define_string_guc( | ||
"pgml.venv", | ||
"Python's virtual environment path", | ||
"", | ||
&PGML_VENV, | ||
GucContext::Userset, | ||
GucFlags::default(), | ||
); | ||
GucRegistry::define_string_guc( | ||
"pgml.huggingface_whitelist", | ||
"Models allowed to be downloaded from huggingface", | ||
"", | ||
&PGML_HF_WHITELIST, | ||
GucContext::Userset, | ||
GucFlags::default(), | ||
); | ||
GucRegistry::define_bool_guc( | ||
"pgml.huggingface_trust_remote_code", | ||
"Whether model can execute remote codes", | ||
"", | ||
&PGML_HF_TRUST_REMOTE_CODE, | ||
GucContext::Userset, | ||
GucFlags::default(), | ||
); | ||
GucRegistry::define_string_guc( | ||
"pgml.huggingface_trust_remote_code_whitelist", | ||
"Models allowed to execute remote codes when pgml.hugging_face_trust_remote_code = 'on'", | ||
"", | ||
&PGML_HF_TRUST_REMOTE_CODE_WHITELIST, | ||
GucContext::Userset, | ||
GucFlags::default(), | ||
); | ||
GucRegistry::define_int_guc( | ||
higuoxing marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
"pgml.omp_num_threads", | ||
"Specifies the number of threads used by default of underlying OpenMP library. Only positive integers are valid", | ||
"", | ||
&PGML_OMP_NUM_THREADS, | ||
1, | ||
i32::max_value(), | ||
GucContext::Backend, | ||
GucFlags::default(), | ||
); | ||
let omp_num_threads = PGML_OMP_NUM_THREADS.get(); | ||
unsafe { | ||
omp_set_num_threads(omp_num_threads); | ||
} | ||
} | ||
#[cfg(any(test, feature = "pg_test"))] | ||
@@ -26,17 +82,17 @@ pub fn set_config(name: &str, value: &str) -> Result<(), pgrx::spi::Error> { | ||
mod tests { | ||
use super::*; | ||
#[pg_test] | ||
fn read_pgml_huggingface_whitelist() { | ||
let name = "pgml.huggingface_whitelist"; | ||
let value = "meta-llama/Llama-2-7b"; | ||
set_config(name, value).unwrap(); | ||
assert_eq!(PGML_HF_WHITELIST.get().unwrap().to_str().unwrap(), value); | ||
} | ||
#[pg_test] | ||
fn omp_num_threads_cannot_be_set_after_startup() { | ||
let result = std::panic::catch_unwind(|| set_config("pgml.omp_num_threads", "1")); | ||
assert!(result.is_err()); | ||
} | ||
} |
3 changes: 2 additions & 1 deletionpgml-extension/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.