-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Orchestrator] Add experiment orchestrator (#1847)
# Description - Node parallel execution is supported - support cancel running experiment Please add an informative description that covers that changes made by the pull request and link all relevant issues. # All Promptflow Contribution checklist: - [ ] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).** - [ ] **Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: [suggested workflow](../CONTRIBUTING.md#suggested-workflow).** ## General Guidelines and Best Practices - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes.
- Loading branch information
1 parent
5d64e41
commit fde9f4d
Showing
15 changed files
with
998 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,7 @@ | |
"otel", | ||
"OTLP", | ||
"spawnv", | ||
"spawnve", | ||
"addrs" | ||
], | ||
"flagWords": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/promptflow/promptflow/_sdk/_orm/experiment_node_run.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# --------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# --------------------------------------------------------- | ||
from sqlalchemy import TEXT, Column | ||
from sqlalchemy.exc import IntegrityError | ||
from sqlalchemy.orm import declarative_base | ||
|
||
from promptflow._sdk._constants import EXP_NODE_RUN_TABLE_NAME, ExperimentNodeRunStatus | ||
from promptflow._sdk._errors import ExperimentNodeRunNotFoundError | ||
|
||
from .retry import sqlite_retry | ||
from .session import mgmt_db_session | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class ExperimentNodeRun(Base): | ||
__tablename__ = EXP_NODE_RUN_TABLE_NAME | ||
|
||
run_id = Column(TEXT, primary_key=True) | ||
snapshot_id = Column(TEXT) | ||
node_name = Column(TEXT, nullable=False) | ||
experiment_name = Column(TEXT, nullable=False) | ||
status = Column(TEXT, nullable=False) | ||
|
||
# schema version, increase the version number when you change the schema | ||
__pf_schema_version__ = "1" | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def create_or_update(node_run: "ExperimentNodeRun") -> None: | ||
session = mgmt_db_session() | ||
run_id = node_run.run_id | ||
try: | ||
session.add(node_run) | ||
session.commit() | ||
except IntegrityError: | ||
session = mgmt_db_session() | ||
# Remove the _sa_instance_state | ||
update_dict = {k: v for k, v in node_run.__dict__.items() if not k.startswith("_")} | ||
session.query(ExperimentNodeRun).filter(ExperimentNodeRun.run_id == run_id).update(update_dict) | ||
session.commit() | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def delete(snapshot_id: str) -> None: | ||
with mgmt_db_session() as session: | ||
session.query(ExperimentNodeRun).filter(ExperimentNodeRun.snapshot_id == snapshot_id).delete() | ||
session.commit() | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def get(run_id: str, raise_error=True) -> "ExperimentNodeRun": | ||
with mgmt_db_session() as session: | ||
orchestrator = session.query(ExperimentNodeRun).filter(ExperimentNodeRun.run_id == run_id).first() | ||
if orchestrator is None and raise_error: | ||
raise ExperimentNodeRunNotFoundError(f"Not found the node run {run_id!r}.") | ||
return orchestrator | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def get_completed_node_by_snapshot_id( | ||
snapshot_id: str, experiment_name: str, raise_error=True | ||
) -> "ExperimentNodeRun": | ||
with mgmt_db_session() as session: | ||
node_run = ( | ||
session.query(ExperimentNodeRun) | ||
.filter( | ||
ExperimentNodeRun.snapshot_id == snapshot_id, | ||
ExperimentNodeRun.experiment_name == experiment_name, | ||
ExperimentNodeRun.status == ExperimentNodeRunStatus.COMPLETED, | ||
) | ||
.first() | ||
) | ||
if node_run is None and raise_error: | ||
raise ExperimentNodeRunNotFoundError( | ||
f"Not found the completed node run with snapshot id {snapshot_id!r}." | ||
) | ||
return node_run | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def get_node_runs_by_experiment(experiment_name: str) -> "ExperimentNodeRun": | ||
with mgmt_db_session() as session: | ||
node_runs = ( | ||
session.query(ExperimentNodeRun).filter(ExperimentNodeRun.experiment_name == experiment_name).all() | ||
) | ||
return node_runs | ||
|
||
@sqlite_retry | ||
def update_status(self, status: str) -> None: | ||
update_dict = {"status": status} | ||
with mgmt_db_session() as session: | ||
session.query(ExperimentNodeRun).filter(ExperimentNodeRun.run_id == self.run_id).update(update_dict) | ||
session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# --------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# --------------------------------------------------------- | ||
from sqlalchemy import INTEGER, TEXT, Column | ||
from sqlalchemy.exc import IntegrityError | ||
from sqlalchemy.orm import declarative_base | ||
|
||
from promptflow._sdk._constants import ORCHESTRATOR_TABLE_NAME | ||
from promptflow._sdk._errors import ExperimentNotFoundError | ||
|
||
from .retry import sqlite_retry | ||
from .session import mgmt_db_session | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class Orchestrator(Base): | ||
__tablename__ = ORCHESTRATOR_TABLE_NAME | ||
|
||
experiment_name = Column(TEXT, primary_key=True) | ||
pid = Column(INTEGER, nullable=True) | ||
status = Column(TEXT, nullable=False) | ||
# schema version, increase the version number when you change the schema | ||
__pf_schema_version__ = "1" | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def create_or_update(orchestrator: "Orchestrator") -> None: | ||
session = mgmt_db_session() | ||
experiment_name = orchestrator.experiment_name | ||
try: | ||
session.add(orchestrator) | ||
session.commit() | ||
except IntegrityError: | ||
session = mgmt_db_session() | ||
# Remove the _sa_instance_state | ||
update_dict = {k: v for k, v in orchestrator.__dict__.items() if not k.startswith("_")} | ||
session.query(Orchestrator).filter(Orchestrator.experiment_name == experiment_name).update(update_dict) | ||
session.commit() | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def get(experiment_name: str, raise_error=True) -> "Orchestrator": | ||
with mgmt_db_session() as session: | ||
orchestrator = session.query(Orchestrator).filter(Orchestrator.experiment_name == experiment_name).first() | ||
if orchestrator is None and raise_error: | ||
raise ExperimentNotFoundError(f"The experiment {experiment_name!r} hasn't been started yet.") | ||
return orchestrator | ||
|
||
@staticmethod | ||
@sqlite_retry | ||
def delete(name: str) -> None: | ||
with mgmt_db_session() as session: | ||
session.query(Orchestrator).filter(Orchestrator.experiment_name == name).delete() | ||
session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.