-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from AlejandroBaron/develop
v0.1.2
- Loading branch information
Showing
28 changed files
with
469 additions
and
204 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
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 |
---|---|---|
|
@@ -23,5 +23,5 @@ jobs: | |
- uses: pdm-project/setup-pdm@v4.1 | ||
|
||
- name: Publish package distributions to PyPI | ||
run: | ||
run: | ||
pdm publish |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def ez_azml_pipeline(test_input): | ||
"""Example pipeline function.""" | ||
# pytorch_script is the name of the registered component | ||
test_result = pytorch_script(data_path=test_input) # type: ignore # noqa F821 | ||
print_output(prev_output=test_result.outputs.output_path) # type: ignore # noqa F821 | ||
return {"test_output": test_result.outputs.output_path} |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
import argparse | ||
from pathlib import Path | ||
|
||
# Argument parsing | ||
parser = argparse.ArgumentParser(description="Print input") | ||
parser.add_argument("--path", type=Path, default="outputs", help="output to read") | ||
args = parser.parse_args() | ||
path: Path = args.path | ||
for file in path.glob("*.txt"): | ||
content = (path / file).read_text() | ||
print(content) |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .commands import Command, DockerCommand | ||
from .pipelines import Pipeline | ||
from .commands import CommandRun, DockerCommandRun | ||
from .pipelines import PipelineRun | ||
|
||
__all__ = ["Command", "DockerCommand", "Pipeline"] | ||
__all__ = ["CommandRun", "DockerCommandRun", "PipelineRun"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .command import Command | ||
from .docker_command import DockerCommand | ||
from .command import CommandRun | ||
from .docker_command import DockerCommandRun | ||
|
||
__all__ = ["DockerCommand", "Command"] | ||
__all__ = ["DockerCommandRun", "CommandRun"] |
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 |
---|---|---|
@@ -1,54 +1,117 @@ | ||
from typing import Optional | ||
import io | ||
from pathlib import Path | ||
from typing import Any, Optional, Union | ||
|
||
from azure.ai.ml import command | ||
from azure.ai.ml.entities import ( | ||
UserIdentityConfiguration, | ||
WorkspaceConnection, | ||
) | ||
import yaml | ||
from azure.ai.ml import Input, MLClient, Output, command, load_component | ||
from azure.ai.ml.entities import Command, UserIdentityConfiguration, WorkspaceConnection | ||
from typing_extensions import override | ||
|
||
from ez_azml.cloud_runs.cloud_run import CloudRun, RunOutput | ||
|
||
|
||
class Command(CloudRun): | ||
class CommandRun(CloudRun): | ||
"""Cloud run that is based on AzureML Commands. | ||
Args: | ||
code: location of the scripts to use | ||
code: location of the python scripts to use | ||
commands: commands to run on the cloud (e.g. `python my_script.py`) | ||
flags: flags to use with the last command. | ||
identity: credentials to use. | ||
name: command's name. | ||
register_kwargs: kwargs to use when registering component. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
code: str, | ||
commands: list[str], | ||
code: Union[str, Path], | ||
commands: Union[str, list[str]], | ||
ws_connection: Optional[WorkspaceConnection] = None, | ||
flags: Optional[list[str]] = None, | ||
identity: Optional[UserIdentityConfiguration] = None, | ||
name: Optional[str] = None, | ||
register_kwargs: Optional[dict[str, Any]] = None, | ||
**kwargs, | ||
) -> None: | ||
super().__init__(**kwargs) | ||
self.ws_connection = ws_connection | ||
identity = identity or UserIdentityConfiguration() | ||
self.identity = identity or UserIdentityConfiguration() | ||
if isinstance(commands, str): | ||
commands = [commands] | ||
if flags: | ||
commands[-1] += " " + " ".join(flags) | ||
self.job = command( | ||
command=";".join(commands), | ||
code=code, | ||
self.commands = commands | ||
self.code = Path(code) | ||
self.name = name or self.code.stem | ||
self.register_kwargs = register_kwargs or {} | ||
|
||
@property | ||
def cli_command(self) -> str: | ||
"""Actual cli command run on AzureML.""" | ||
return ";".join(self.commands) | ||
|
||
@property | ||
def command(self) -> Command: | ||
"""Runnable command.""" | ||
return command( | ||
command=self.cli_command, | ||
code=self.code, | ||
environment=self.environment, | ||
compute=self.compute.name, | ||
inputs=self.inputs, | ||
outputs=self.outputs, | ||
identity=identity, | ||
identity=self.identity, | ||
) | ||
|
||
def _get_io_dict( | ||
self, ios: dict[str, Union[Input, Output]], keys: Optional[list[str]] = None | ||
): | ||
ios_as_dict = {} | ||
keys = keys or ["type"] | ||
for key, io_obj in ios.items(): | ||
io_d = dict(io_obj) | ||
ios_as_dict[key] = {k: io_d[k] for k in keys if io_d[k] is not None} | ||
return ios_as_dict | ||
|
||
def _get_component_yaml_stream( | ||
self, name: Optional[str] = None, environment: Optional[str] = None, **kwargs | ||
) -> io.StringIO: | ||
inputs_dict = self._get_io_dict(self.inputs) | ||
outputs_dict = self._get_io_dict(self.outputs) | ||
if not environment: | ||
self.ml_client.environments.create_or_update(self.environment) | ||
version = self.environment.version or 1 | ||
environment = f"azureml:{self.environment.name}:{version}" | ||
yaml_dict = { | ||
"name": name or self.name, | ||
"inputs": inputs_dict, | ||
"outputs": outputs_dict, | ||
"code": str(self.code), | ||
"command": self.cli_command, | ||
"environment": environment, | ||
**kwargs, | ||
} | ||
yaml_stream = io.StringIO() | ||
yaml.dump(yaml_dict, yaml_stream) | ||
yaml_stream.seek(0) # Move the file pointer to the beginning | ||
return yaml_stream | ||
|
||
def get_component(self, **kwargs): | ||
"""Returns the mldesigner component.""" | ||
yaml_file = self._get_component_yaml_stream(**self.register_kwargs, **kwargs) | ||
return load_component(yaml_file) | ||
|
||
@override | ||
def register(self, ml_client: Optional[MLClient] = None, **kwargs): | ||
ml_client = ml_client or self.ml_client | ||
component = self.get_component(**kwargs) | ||
ml_client.components.create_or_update(component) | ||
return component | ||
|
||
@override | ||
def run(self) -> str: | ||
if self.ws_connection: | ||
self.ml_client.connections.create_or_update(self.ws_connection) | ||
self.ml_client.environments.create_or_update(self.environment) | ||
self.ml_client.begin_create_or_update(self.compute).result() | ||
cloud_job = self.ml_client.create_or_update(self.job) | ||
cloud_job = self.ml_client.create_or_update(self.command) | ||
return RunOutput(url=cloud_job.studio_url) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .pipeline import Pipeline, PipelineCommand | ||
from .pipeline import PipelineRun | ||
|
||
__all__ = ["Pipeline", "PipelineCommand"] | ||
__all__ = ["PipelineRun"] |
Oops, something went wrong.