Content-Length: 581720 | pFad | http://github.com/postgresml/postgresml/commit/5fdbd5dc15230beb68d7bb04f9c448c6915afb3d

00 Activate venv at server start and remove the check from functions (#1… · postgresml/postgresml@5fdbd5d · GitHub
Skip to content

Commit 5fdbd5d

Browse files
authored
Activate venv at server start and remove the check from functions (#1276)
1 parent 24ff2d2 commit 5fdbd5d

File tree

6 files changed

+2
-26
lines changed

6 files changed

+2
-26
lines changed

pgml-extension/src/bindings/langchain/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use crate::create_pymodule;
88
create_pymodule!("/src/bindings/langchain/langchain.py");
99

1010
pub fn chunk(splitter: &str, text: &str, kwargs: &serde_json::Value) -> Result<Vec<String>> {
11-
crate::bindings::python::activate()?;
12-
1311
let kwargs = serde_json::to_string(kwargs).unwrap();
1412

1513
Python::with_gil(|py| -> Result<Vec<String>> {

pgml-extension/src/bindings/python/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub fn activate() -> Result<bool> {
3030
}
3131

3232
pub fn pip_freeze() -> Result<TableIterator<'static, (name!(package, String),)>> {
33-
activate()?;
3433
let packages = Python::with_gil(|py| -> Result<Vec<String>> {
3534
let freeze = get_module!(PY_MODULE).getattr(py, "freeze")?;
3635
let result = freeze.call0(py)?;
@@ -42,7 +41,6 @@ pub fn pip_freeze() -> Result<TableIterator<'static, (name!(package, String),)>>
4241
}
4342

4443
pub fn validate_dependencies() -> Result<bool> {
45-
activate()?;
4644
Python::with_gil(|py| {
4745
let sys = PyModule::import(py, "sys").unwrap();
4846
let version: String = sys.getattr("version").unwrap().extract().unwrap();
@@ -68,7 +66,6 @@ pub fn validate_dependencies() -> Result<bool> {
6866
}
6967

7068
pub fn version() -> Result<String> {
71-
activate()?;
7269
Python::with_gil(|py| {
7370
let sys = PyModule::import(py, "sys").unwrap();
7471
let version: String = sys.getattr("version").unwrap().extract().unwrap();
@@ -77,7 +74,6 @@ pub fn version() -> Result<String> {
7774
}
7875

7976
pub fn package_version(name: &str) -> Result<String> {
80-
activate()?;
8177
Python::with_gil(|py| {
8278
let package = py.import(name)?;
8379
Ok(package.getattr("__version__")?.extract()?)

pgml-extension/src/bindings/transformers/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ pub fn get_model_from(task: &Value) -> Result<String> {
3434
}
3535

3636
pub fn embed(transformer: &str, inputs: Vec<&str>, kwargs: &serde_json::Value) -> Result<Vec<Vec<f32>>> {
37-
crate::bindings::python::activate()?;
38-
3937
let kwargs = serde_json::to_string(kwargs)?;
4038
Python::with_gil(|py| -> Result<Vec<Vec<f32>>> {
4139
let embed: Py<PyAny> = get_module!(PY_MODULE).getattr(py, "embed").format_traceback(py)?;
@@ -58,8 +56,6 @@ pub fn embed(transformer: &str, inputs: Vec<&str>, kwargs: &serde_json::Value) -
5856
}
5957

6058
pub fn tune(task: &Task, dataset: TextDataset, hyperparams: &JsonB, path: &Path) -> Result<HashMap<String, f64>> {
61-
crate::bindings::python::activate()?;
62-
6359
let task = task.to_string();
6460
let hyperparams = serde_json::to_string(&hyperparams.0)?;
6561

@@ -86,8 +82,6 @@ pub fn tune(task: &Task, dataset: TextDataset, hyperparams: &JsonB, path: &Path)
8682
}
8783

8884
pub fn generate(model_id: i64, inputs: Vec<&str>, config: JsonB) -> Result<Vec<String>> {
89-
crate::bindings::python::activate()?;
90-
9185
Python::with_gil(|py| -> Result<Vec<String>> {
9286
let generate = get_module!(PY_MODULE).getattr(py, "generate").format_traceback(py)?;
9387
let config = serde_json::to_string(&config.0)?;
@@ -162,8 +156,6 @@ pub fn load_dataset(
162156
limit: Option<usize>,
163157
kwargs: &serde_json::Value,
164158
) -> Result<usize> {
165-
crate::bindings::python::activate()?;
166-
167159
let kwargs = serde_json::to_string(kwargs)?;
168160

169161
let dataset = Python::with_gil(|py| -> Result<String> {
@@ -313,8 +305,6 @@ pub fn load_dataset(
313305
}
314306

315307
pub fn clear_gpu_cache(memory_usage: Option<f32>) -> Result<bool> {
316-
crate::bindings::python::activate().unwrap();
317-
318308
Python::with_gil(|py| -> Result<bool> {
319309
let clear_gpu_cache: Py<PyAny> = get_module!(PY_MODULE)
320310
.getattr(py, "clear_gpu_cache")

pgml-extension/src/bindings/transformers/transform.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub fn transform<T: serde::Serialize>(
4646
args: &serde_json::Value,
4747
inputs: T,
4848
) -> Result<serde_json::Value> {
49-
crate::bindings::python::activate()?;
5049
whitelist::verify_task(task)?;
5150

5251
let task = serde_json::to_string(task)?;
@@ -74,7 +73,6 @@ pub fn transform_stream<T: serde::Serialize>(
7473
args: &serde_json::Value,
7574
input: T,
7675
) -> Result<Py<PyAny>> {
77-
crate::bindings::python::activate()?;
7876
whitelist::verify_task(task)?;
7977

8078
let task = serde_json::to_string(task)?;

pgml-extension/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extension_sql_file!("../sql/schema.sql", name = "schema");
2424
#[cfg(not(feature = "use_as_lib"))]
2525
#[pg_guard]
2626
pub extern "C" fn _PG_init() {
27+
bindings::python::activate().expect("Error setting python venv");
2728
orm::project::init();
2829
}
2930

pgml-extension/src/orm/model.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ impl Model {
8888
},
8989
};
9090

91-
if runtime == Runtime::python {
92-
let _ = crate::bindings::python::activate();
93-
}
94-
9591
let dataset = snapshot.tabular_dataset();
9692
let status = Status::in_progress;
9793
// Create the model record.
@@ -334,10 +330,7 @@ impl Model {
334330
}
335331

336332
#[cfg(feature = "python")]
337-
Runtime::python => {
338-
let _ = crate::bindings::python::activate();
339-
crate::bindings::sklearn::Estimator::from_bytes(&data)?
340-
}
333+
Runtime::python => crate::bindings::sklearn::Estimator::from_bytes(&data)?,
341334

342335
#[cfg(not(feature = "python"))]
343336
Runtime::python => {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgresml/postgresml/commit/5fdbd5dc15230beb68d7bb04f9c448c6915afb3d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy