Skip to content

deploy specific models #1265

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

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-packages-and-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
packageVersion:
default: "2.8.1"
default: "2.8.2"
jobs:
#
# PostgresML extension.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-postgresml-python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
packageVersion:
default: "2.8.1"
default: "2.8.2"

jobs:
postgresml-python:
Expand Down
2 changes: 1 addition & 1 deletion pgml-cms/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* [pgml.tune()](introduction/apis/sql-extensions/pgml.tune.md)
* [Client SDKs](introduction/apis/client-sdks/README.md)
* [Overview](introduction/apis/client-sdks/getting-started.md)
* [Collections](../../pgml-docs/docs/guides/sdks/collections.md)
* [Collections](introduction/apis/client-sdks/collections.md)
* [Pipelines](introduction/apis/client-sdks/pipelines.md)
* [Search](introduction/apis/client-sdks/search.md)
* [Tutorials](introduction/apis/client-sdks/tutorials/README.md)
Expand Down
36 changes: 28 additions & 8 deletions pgml-cms/docs/introduction/apis/sql-extensions/pgml.deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pgml.deploy(

There are 3 different deployment strategies available:

| Strategy | Description |
| ------------- | --------------------------------------------------------------------------------------------------------------------- |
| `most_recent` | The most recently trained model for this project is immediately deployed, regardless of metrics. |
| `best_score` | The model that achieved the best key metric score is immediately deployed. |
| `rollback` | The model that was last deployed for this project is immediately redeployed, overriding the currently deployed model. |
| Strategy | Description |
| ------------- |--------------------------------------------------------------------------------------------------|
| `most_recent` | The most recently trained model for this project is immediately deployed, regardless of metrics. |
| `best_score` | The model that achieved the best key metric score is immediately deployed. |
| `rollback` | The model that was deployed before to the current one is deployed. |

The default deployment behavior allows any algorithm to qualify. It's automatically used during training, but can be manually executed as well:

Expand All @@ -40,11 +40,12 @@ The default deployment behavior allows any algorithm to qualify. It's automatica

#### SQL

<pre class="language-sql"><code class="lang-sql"><strong>SELECT * FROM pgml.deploy(
</strong> 'Handwritten Digit Image Classifier',
```sql
SELECT * FROM pgml.deploy(
'Handwritten Digit Image Classifier',
strategy => 'best_score'
);
</code></pre>
```

#### Output

Expand Down Expand Up @@ -121,3 +122,22 @@ SELECT * FROM pgml.deploy(
Handwritten Digit Image Classifier | rollback | xgboost
(1 row)
```

### Specific Model IDs

In the case you need to deploy an exact model that is not the `most_recent` or `best_score`, you may deploy a model by id. Model id's can be found in the `pgml.models` table.

#### SQL

```sql
SELECT * FROM pgml.deploy(12);
```

#### Output

```sql
project | strategy | algorithm
------------------------------------+----------+-----------
Handwritten Digit Image Classifier | specific | xgboost
(1 row)
```
2 changes: 1 addition & 1 deletion pgml-extension/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pgml-extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgml"
version = "2.8.1"
version = "2.8.2"
edition = "2021"

[lib]
Expand Down
27 changes: 27 additions & 0 deletions pgml-extension/sql/pgml--2.8.1--2.8.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- src/api.rs:317
-- pgml::api::deploy
DROP FUNCTION IF EXISTS pgml."deploy"(BIGINT);
CREATE FUNCTION pgml."deploy"(
"model_id" BIGINT /* i64 */
) RETURNS TABLE (
"project" TEXT, /* alloc::string::String */
"strategy" TEXT, /* alloc::string::String */
"algorithm" TEXT /* alloc::string::String */
)
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'deploy_model_wrapper';

DROP FUNCTION IF EXISTS pgml."deploy"(text, pgml.Strategy, pgml.Algorithm);
CREATE FUNCTION pgml."deploy"(
"project_name" TEXT, /* &str */
"strategy" pgml.Strategy, /* pgml::orm::strategy::Strategy */
"algorithm" pgml.Algorithm DEFAULT NULL /* core::option::Option<pgml::orm::algorithm::Algorithm> */
) RETURNS TABLE (
"project" TEXT, /* alloc::string::String */
"strategy" TEXT, /* alloc::string::String */
"algorithm" TEXT /* alloc::string::String */
)
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'deploy_strategy_wrapper';

ALTER TYPE pgml.strategy ADD VALUE 'specific';
42 changes: 37 additions & 5 deletions pgml-extension/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn train_joint(
};

if deploy {
project.deploy(model.id);
project.deploy(model.id, Strategy::new_score);
} else {
warning!("Not deploying newly trained model.");
}
Expand All @@ -300,8 +300,40 @@ fn train_joint(
)])
}

#[pg_extern]
fn deploy(
#[pg_extern(name = "deploy")]
fn deploy_model(
model_id: i64
) -> TableIterator<
'static,
(
name!(project, String),
name!(strategy, String),
name!(algorithm, String),
),
> {
let model = unwrap_or_error!(Model::find_cached(model_id));

let project_id = Spi::get_one_with_args::<i64>(
"SELECT projects.id from pgml.projects JOIN pgml.models ON models.project_id = projects.id WHERE models.id = $1",
vec![(PgBuiltInOids::INT8OID.oid(), model_id.into_datum())],
)
.unwrap();

let project_id =
project_id.unwrap_or_else(|| error!("Project does not exist."));

let project = Project::find(project_id).unwrap();
project.deploy(model_id, Strategy::specific);

TableIterator::new(vec![(
project.name,
Strategy::specific.to_string(),
model.algorithm.to_string(),
)])
}

#[pg_extern(name = "deploy")]
fn deploy_strategy(
project_name: &str,
strategy: Strategy,
algorithm: default!(Option<Algorithm>, "NULL"),
Expand Down Expand Up @@ -378,7 +410,7 @@ fn deploy(
let algorithm = algorithm.expect("No qualified models exist for this deployment.");

let project = Project::find(project_id).unwrap();
project.deploy(model_id);
project.deploy(model_id, strategy);

TableIterator::new(vec![(
project_name.to_string(),
Expand Down Expand Up @@ -922,7 +954,7 @@ fn tune(
};

if deploy {
project.deploy(model.id);
project.deploy(model.id, Strategy::new_score);
}

TableIterator::new(vec![(
Expand Down
4 changes: 2 additions & 2 deletions pgml-extension/src/orm/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ impl Project {
.unwrap()
}

pub fn deploy(&self, model_id: i64) {
pub fn deploy(&self, model_id: i64, strategy: Strategy) {
info!("Deploying model id: {:?}", model_id);
Spi::get_one_with_args::<i64>(
"INSERT INTO pgml.deployments (project_id, model_id, strategy) VALUES ($1, $2, $3::pgml.strategy) RETURNING id",
vec![
(PgBuiltInOids::INT8OID.oid(), self.id.into_datum()),
(PgBuiltInOids::INT8OID.oid(), model_id.into_datum()),
(PgBuiltInOids::TEXTOID.oid(), Strategy::most_recent.to_string().into_datum()),
(PgBuiltInOids::TEXTOID.oid(), strategy.to_string().into_datum()),
],
).unwrap();
let mut projects = PROJECT_ID_TO_DEPLOYED_MODEL_ID.exclusive();
Expand Down
3 changes: 3 additions & 0 deletions pgml-extension/src/orm/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum Strategy {
best_score,
most_recent,
rollback,
specific,
}

impl std::str::FromStr for Strategy {
Expand All @@ -19,6 +20,7 @@ impl std::str::FromStr for Strategy {
"best_score" => Ok(Strategy::best_score),
"most_recent" => Ok(Strategy::most_recent),
"rollback" => Ok(Strategy::rollback),
"specific" => Ok(Strategy::rollback),
_ => Err(()),
}
}
Expand All @@ -31,6 +33,7 @@ impl std::string::ToString for Strategy {
Strategy::best_score => "best_score".to_string(),
Strategy::most_recent => "most_recent".to_string(),
Strategy::rollback => "rollback".to_string(),
Strategy::specific => "specific".to_string(),
}
}
}
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