Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
montanalow merged 2 commits intomasterfrommontana/deploys
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionpgml-cms/docs/SUMMARY.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspgml-cms/docs/introduction/apis/sql-extensions/pgml.deploy.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 waslastdeployedfor this projectisimmediately 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 deployedbefore to the current oneisdeployed. |

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 DownExpand 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 deletionpgml-extension/Cargo.lock
View file
Open in desktop

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

2 changes: 1 addition & 1 deletionpgml-extension/Cargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspgml-extension/sql/pgml--2.8.1--2.8.2.sql
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspgml-extension/src/api.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 deletionspgml-extension/src/orm/project.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspgml-extension/src/orm/strategy.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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(),
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp