Skip to content

Commit fa70526

Browse files
committed
deploy specific models
1 parent e811499 commit fa70526

File tree

8 files changed

+73
-11
lines changed

8 files changed

+73
-11
lines changed

.github/workflows/ubuntu-packages-and-docker-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
packageVersion:
7-
default: "2.8.1"
7+
default: "2.8.2"
88
jobs:
99
#
1010
# PostgresML extension.

.github/workflows/ubuntu-postgresml-python-package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
packageVersion:
7-
default: "2.8.1"
7+
default: "2.8.2"
88

99
jobs:
1010
postgresml-python:

pgml-extension/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pgml-extension/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pgml"
3-
version = "2.8.1"
3+
version = "2.8.2"
44
edition = "2021"
55

66
[lib]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- src/api.rs:317
2+
-- pgml::api::deploy
3+
DROP FUNCTION IF EXISTS pgml."deploy"(BIGINT);
4+
CREATE FUNCTION pgml."deploy"(
5+
"model_id" BIGINT /* i64 */
6+
) RETURNS TABLE (
7+
"project" TEXT, /* alloc::string::String */
8+
"strategy" TEXT, /* alloc::string::String */
9+
"algorithm" TEXT /* alloc::string::String */
10+
)
11+
LANGUAGE c /* Rust */
12+
AS 'MODULE_PATHNAME', 'deploy_model_wrapper';
13+
14+
DROP FUNCTION IF EXISTS pgml."deploy"(text, pgml.Strategy, pgml.Algorithm);
15+
CREATE FUNCTION pgml."deploy"(
16+
"project_name" TEXT, /* &str */
17+
"strategy" pgml.Strategy, /* pgml::orm::strategy::Strategy */
18+
"algorithm" pgml.Algorithm DEFAULT NULL /* core::option::Option<pgml::orm::algorithm::Algorithm> */
19+
) RETURNS TABLE (
20+
"project" TEXT, /* alloc::string::String */
21+
"strategy" TEXT, /* alloc::string::String */
22+
"algorithm" TEXT /* alloc::string::String */
23+
)
24+
LANGUAGE c /* Rust */
25+
AS 'MODULE_PATHNAME', 'deploy_strategy_wrapper';
26+
27+
ALTER TYPE pgml.strategy ADD VALUE 'specific';

pgml-extension/src/api.rs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn train_joint(
287287
};
288288

289289
if deploy {
290-
project.deploy(model.id);
290+
project.deploy(model.id, Strategy::new_score);
291291
} else {
292292
warning!("Not deploying newly trained model.");
293293
}
@@ -300,8 +300,40 @@ fn train_joint(
300300
)])
301301
}
302302

303-
#[pg_extern]
304-
fn deploy(
303+
#[pg_extern(name = "deploy")]
304+
fn deploy_model(
305+
model_id: i64
306+
) -> TableIterator<
307+
'static,
308+
(
309+
name!(project, String),
310+
name!(strategy, String),
311+
name!(algorithm, String),
312+
),
313+
> {
314+
let model = unwrap_or_error!(Model::find_cached(model_id));
315+
316+
let project_id = Spi::get_one_with_args::<i64>(
317+
"SELECT projects.id from pgml.projects JOIN pgml.models ON models.project_id = projects.id WHERE models.id = $1",
318+
vec![(PgBuiltInOids::INT8OID.oid(), model_id.into_datum())],
319+
)
320+
.unwrap();
321+
322+
let project_id =
323+
project_id.unwrap_or_else(|| error!("Project does not exist."));
324+
325+
let project = Project::find(project_id).unwrap();
326+
project.deploy(model_id, Strategy::specific);
327+
328+
TableIterator::new(vec![(
329+
project.name,
330+
Strategy::specific.to_string(),
331+
model.algorithm.to_string(),
332+
)])
333+
}
334+
335+
#[pg_extern(name = "deploy")]
336+
fn deploy_strategy(
305337
project_name: &str,
306338
strategy: Strategy,
307339
algorithm: default!(Option<Algorithm>, "NULL"),
@@ -378,7 +410,7 @@ fn deploy(
378410
let algorithm = algorithm.expect("No qualified models exist for this deployment.");
379411

380412
let project = Project::find(project_id).unwrap();
381-
project.deploy(model_id);
413+
project.deploy(model_id, strategy);
382414

383415
TableIterator::new(vec![(
384416
project_name.to_string(),
@@ -922,7 +954,7 @@ fn tune(
922954
};
923955

924956
if deploy {
925-
project.deploy(model.id);
957+
project.deploy(model.id, Strategy::new_score);
926958
}
927959

928960
TableIterator::new(vec![(

pgml-extension/src/orm/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ impl Project {
8989
.unwrap()
9090
}
9191

92-
pub fn deploy(&self, model_id: i64) {
92+
pub fn deploy(&self, model_id: i64, strategy: Strategy) {
9393
info!("Deploying model id: {:?}", model_id);
9494
Spi::get_one_with_args::<i64>(
9595
"INSERT INTO pgml.deployments (project_id, model_id, strategy) VALUES ($1, $2, $3::pgml.strategy) RETURNING id",
9696
vec![
9797
(PgBuiltInOids::INT8OID.oid(), self.id.into_datum()),
9898
(PgBuiltInOids::INT8OID.oid(), model_id.into_datum()),
99-
(PgBuiltInOids::TEXTOID.oid(), Strategy::most_recent.to_string().into_datum()),
99+
(PgBuiltInOids::TEXTOID.oid(), strategy.to_string().into_datum()),
100100
],
101101
).unwrap();
102102
let mut projects = PROJECT_ID_TO_DEPLOYED_MODEL_ID.exclusive();

pgml-extension/src/orm/strategy.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub enum Strategy {
88
best_score,
99
most_recent,
1010
rollback,
11+
specific,
1112
}
1213

1314
impl std::str::FromStr for Strategy {
@@ -19,6 +20,7 @@ impl std::str::FromStr for Strategy {
1920
"best_score" => Ok(Strategy::best_score),
2021
"most_recent" => Ok(Strategy::most_recent),
2122
"rollback" => Ok(Strategy::rollback),
23+
"specific" => Ok(Strategy::rollback),
2224
_ => Err(()),
2325
}
2426
}
@@ -31,6 +33,7 @@ impl std::string::ToString for Strategy {
3133
Strategy::best_score => "best_score".to_string(),
3234
Strategy::most_recent => "most_recent".to_string(),
3335
Strategy::rollback => "rollback".to_string(),
36+
Strategy::specific => "specific".to_string(),
3437
}
3538
}
3639
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy