Content-Length: 6416 | pFad | http://github.com/postgresml/postgresml/pull/1276.diff
thub.com
diff --git a/pgml-extension/src/bindings/langchain/mod.rs b/pgml-extension/src/bindings/langchain/mod.rs
index d17993df7..75d94914e 100644
--- a/pgml-extension/src/bindings/langchain/mod.rs
+++ b/pgml-extension/src/bindings/langchain/mod.rs
@@ -8,8 +8,6 @@ use crate::create_pymodule;
create_pymodule!("/src/bindings/langchain/langchain.py");
pub fn chunk(splitter: &str, text: &str, kwargs: &serde_json::Value) -> Result> {
- crate::bindings::python::activate()?;
-
let kwargs = serde_json::to_string(kwargs).unwrap();
Python::with_gil(|py| -> Result> {
diff --git a/pgml-extension/src/bindings/python/mod.rs b/pgml-extension/src/bindings/python/mod.rs
index 84e7505b7..ba59bef8e 100644
--- a/pgml-extension/src/bindings/python/mod.rs
+++ b/pgml-extension/src/bindings/python/mod.rs
@@ -30,7 +30,6 @@ pub fn activate() -> Result {
}
pub fn pip_freeze() -> Result> {
- activate()?;
let packages = Python::with_gil(|py| -> Result> {
let freeze = get_module!(PY_MODULE).getattr(py, "freeze")?;
let result = freeze.call0(py)?;
@@ -42,7 +41,6 @@ pub fn pip_freeze() -> Result>
}
pub fn validate_dependencies() -> Result {
- activate()?;
Python::with_gil(|py| {
let sys = PyModule::import(py, "sys").unwrap();
let version: String = sys.getattr("version").unwrap().extract().unwrap();
@@ -68,7 +66,6 @@ pub fn validate_dependencies() -> Result {
}
pub fn version() -> Result {
- activate()?;
Python::with_gil(|py| {
let sys = PyModule::import(py, "sys").unwrap();
let version: String = sys.getattr("version").unwrap().extract().unwrap();
@@ -77,7 +74,6 @@ pub fn version() -> Result {
}
pub fn package_version(name: &str) -> Result {
- activate()?;
Python::with_gil(|py| {
let package = py.import(name)?;
Ok(package.getattr("__version__")?.extract()?)
diff --git a/pgml-extension/src/bindings/transformers/mod.rs b/pgml-extension/src/bindings/transformers/mod.rs
index b300d84e3..6a4a2133e 100644
--- a/pgml-extension/src/bindings/transformers/mod.rs
+++ b/pgml-extension/src/bindings/transformers/mod.rs
@@ -34,8 +34,6 @@ pub fn get_model_from(task: &Value) -> Result {
}
pub fn embed(transformer: &str, inputs: Vec<&str>, kwargs: &serde_json::Value) -> Result>> {
- crate::bindings::python::activate()?;
-
let kwargs = serde_json::to_string(kwargs)?;
Python::with_gil(|py| -> Result>> {
let embed: Py = 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) -
}
pub fn tune(task: &Task, dataset: TextDataset, hyperparams: &JsonB, path: &Path) -> Result> {
- crate::bindings::python::activate()?;
-
let task = task.to_string();
let hyperparams = serde_json::to_string(&hyperparams.0)?;
@@ -86,8 +82,6 @@ pub fn tune(task: &Task, dataset: TextDataset, hyperparams: &JsonB, path: &Path)
}
pub fn generate(model_id: i64, inputs: Vec<&str>, config: JsonB) -> Result> {
- crate::bindings::python::activate()?;
-
Python::with_gil(|py| -> Result> {
let generate = get_module!(PY_MODULE).getattr(py, "generate").format_traceback(py)?;
let config = serde_json::to_string(&config.0)?;
@@ -162,8 +156,6 @@ pub fn load_dataset(
limit: Option,
kwargs: &serde_json::Value,
) -> Result {
- crate::bindings::python::activate()?;
-
let kwargs = serde_json::to_string(kwargs)?;
let dataset = Python::with_gil(|py| -> Result {
@@ -313,8 +305,6 @@ pub fn load_dataset(
}
pub fn clear_gpu_cache(memory_usage: Option) -> Result {
- crate::bindings::python::activate().unwrap();
-
Python::with_gil(|py| -> Result {
let clear_gpu_cache: Py = get_module!(PY_MODULE)
.getattr(py, "clear_gpu_cache")
diff --git a/pgml-extension/src/bindings/transformers/transform.rs b/pgml-extension/src/bindings/transformers/transform.rs
index 21503f186..41fd04512 100644
--- a/pgml-extension/src/bindings/transformers/transform.rs
+++ b/pgml-extension/src/bindings/transformers/transform.rs
@@ -46,7 +46,6 @@ pub fn transform(
args: &serde_json::Value,
inputs: T,
) -> Result {
- crate::bindings::python::activate()?;
whitelist::verify_task(task)?;
let task = serde_json::to_string(task)?;
@@ -74,7 +73,6 @@ pub fn transform_stream(
args: &serde_json::Value,
input: T,
) -> Result> {
- crate::bindings::python::activate()?;
whitelist::verify_task(task)?;
let task = serde_json::to_string(task)?;
diff --git a/pgml-extension/src/lib.rs b/pgml-extension/src/lib.rs
index 2bf5235d4..6c2884cee 100644
--- a/pgml-extension/src/lib.rs
+++ b/pgml-extension/src/lib.rs
@@ -24,6 +24,7 @@ extension_sql_file!("../sql/schema.sql", name = "schema");
#[cfg(not(feature = "use_as_lib"))]
#[pg_guard]
pub extern "C" fn _PG_init() {
+ bindings::python::activate().expect("Error setting python venv");
orm::project::init();
}
diff --git a/pgml-extension/src/orm/model.rs b/pgml-extension/src/orm/model.rs
index 8deebe042..5c2f75230 100644
--- a/pgml-extension/src/orm/model.rs
+++ b/pgml-extension/src/orm/model.rs
@@ -88,10 +88,6 @@ impl Model {
},
};
- if runtime == Runtime::python {
- let _ = crate::bindings::python::activate();
- }
-
let dataset = snapshot.tabular_dataset();
let status = Status::in_progress;
// Create the model record.
@@ -334,10 +330,7 @@ impl Model {
}
#[cfg(feature = "python")]
- Runtime::python => {
- let _ = crate::bindings::python::activate();
- crate::bindings::sklearn::Estimator::from_bytes(&data)?
- }
+ Runtime::python => crate::bindings::sklearn::Estimator::from_bytes(&data)?,
#[cfg(not(feature = "python"))]
Runtime::python => {
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/postgresml/postgresml/pull/1276.diff
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy