Skip to content
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

Misc bugfixes #3234

Merged
merged 9 commits into from
Dec 2, 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 examples/e2e/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 2024.11.20-2-g760142f
_commit: 2024.11.28
_src_path: gh:zenml-io/template-e2e-batch
data_quality_checks: true
email: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e_nlp/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 2024.10.30-2-g1ae14e3
_commit: 2024.11.28
_src_path: gh:zenml-io/template-nlp
accelerator: cpu
cloud_of_choice: aws
Expand Down
2 changes: 1 addition & 1 deletion examples/llm_finetuning/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 2024.11.08-2-gece1d46
_commit: 2024.11.28
_src_path: gh:zenml-io/template-llm-finetuning
bf16: true
cuda_version: cuda11.8
Expand Down
2 changes: 1 addition & 1 deletion examples/mlops_starter/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 2024.10.30-7-gb60e441
_commit: 2024.11.28
_src_path: gh:zenml-io/template-starter
email: [email protected]
full_name: ZenML GmbH
Expand Down
127 changes: 48 additions & 79 deletions src/zenml/cli/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@
logger = get_logger(__name__)


def _import_pipeline(source: str) -> Pipeline:
"""Import a pipeline.

Args:
source: The pipeline source.

Returns:
The pipeline.
"""
try:
pipeline_instance = source_utils.load(source)
except ModuleNotFoundError as e:
source_root = source_utils.get_source_root()
cli_utils.error(
f"Unable to import module `{e.name}`. Make sure the source path is "
f"relative to your source root `{source_root}`."
)
except AttributeError as e:
cli_utils.error("Unable to load attribute from module: " + str(e))

if not isinstance(pipeline_instance, Pipeline):
cli_utils.error(
f"The given source path `{source}` does not resolve to a pipeline "
"object."
)

return pipeline_instance


@cli.group(cls=TagGroup, tag=CliCategories.MANAGEMENT_TOOLS)
def pipeline() -> None:
"""Interact with pipelines, runs and schedules."""
Expand Down Expand Up @@ -85,22 +114,7 @@ def register_pipeline(
"source code root."
)

try:
pipeline_instance = source_utils.load(source)
except ModuleNotFoundError as e:
source_root = source_utils.get_source_root()
cli_utils.error(
f"Unable to import module `{e.name}`. Make sure the source path is "
f"relative to your source root `{source_root}`."
)
except AttributeError as e:
cli_utils.error("Unable to load attribute from module: " + str(e))

if not isinstance(pipeline_instance, Pipeline):
cli_utils.error(
f"The given source path `{source}` does not resolve to a pipeline "
"object."
)
pipeline_instance = _import_pipeline(source=source)

parameters: Dict[str, Any] = {}
if parameters_path:
Expand Down Expand Up @@ -176,24 +190,9 @@ def build_pipeline(
"your source code root."
)

try:
pipeline_instance = source_utils.load(source)
except ModuleNotFoundError as e:
source_root = source_utils.get_source_root()
cli_utils.error(
f"Unable to import module `{e.name}`. Make sure the source path is "
f"relative to your source root `{source_root}`."
)
except AttributeError as e:
cli_utils.error("Unable to load attribute from module: " + str(e))

if not isinstance(pipeline_instance, Pipeline):
cli_utils.error(
f"The given source path `{source}` does not resolve to a pipeline "
"object."
)

with cli_utils.temporary_active_stack(stack_name_or_id=stack_name_or_id):
pipeline_instance = _import_pipeline(source=source)

pipeline_instance = pipeline_instance.with_options(
config_path=config_path
)
Expand Down Expand Up @@ -277,36 +276,21 @@ def run_pipeline(
"your source code root."
)

try:
pipeline_instance = source_utils.load(source)
except ModuleNotFoundError as e:
source_root = source_utils.get_source_root()
cli_utils.error(
f"Unable to import module `{e.name}`. Make sure the source path is "
f"relative to your source root `{source_root}`."
)
except AttributeError as e:
cli_utils.error("Unable to load attribute from module: " + str(e))

if not isinstance(pipeline_instance, Pipeline):
cli_utils.error(
f"The given source path `{source}` does not resolve to a pipeline "
"object."
)

build: Union[str, PipelineBuildBase, None] = None
if build_path_or_id:
if uuid_utils.is_valid_uuid(build_path_or_id):
build = build_path_or_id
elif os.path.exists(build_path_or_id):
build = PipelineBuildBase.from_yaml(build_path_or_id)
else:
cli_utils.error(
f"The specified build {build_path_or_id} is not a valid UUID "
"or file path."
)

with cli_utils.temporary_active_stack(stack_name_or_id=stack_name_or_id):
pipeline_instance = _import_pipeline(source=source)

build: Union[str, PipelineBuildBase, None] = None
if build_path_or_id:
if uuid_utils.is_valid_uuid(build_path_or_id):
build = build_path_or_id
elif os.path.exists(build_path_or_id):
build = PipelineBuildBase.from_yaml(build_path_or_id)
else:
cli_utils.error(
f"The specified build {build_path_or_id} is not a valid UUID "
"or file path."
)

pipeline_instance = pipeline_instance.with_options(
config_path=config_path,
build=build,
Expand Down Expand Up @@ -369,24 +353,9 @@ def create_run_template(
"init` at your source code root."
)

try:
pipeline_instance = source_utils.load(source)
except ModuleNotFoundError as e:
source_root = source_utils.get_source_root()
cli_utils.error(
f"Unable to import module `{e.name}`. Make sure the source path is "
f"relative to your source root `{source_root}`."
)
except AttributeError as e:
cli_utils.error("Unable to load attribute from module: " + str(e))

if not isinstance(pipeline_instance, Pipeline):
cli_utils.error(
f"The given source path `{source}` does not resolve to a pipeline "
"object."
)

with cli_utils.temporary_active_stack(stack_name_or_id=stack_name_or_id):
pipeline_instance = _import_pipeline(source=source)

pipeline_instance = pipeline_instance.with_options(
config_path=config_path
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ def prepare_step_run(self, info: "StepRunInfo") -> None:
NeptuneExperimentTrackerSettings, self.get_settings(info)
)

self.run_state.token = self.config.api_token
self.run_state.project = self.config.project
self.run_state.run_name = info.run_name
self.run_state.tags = list(settings.tags)
self.run_state.initialize(
project=self.config.project,
token=self.config.api_token,
run_name=info.run_name,
tags=list(settings.tags),
)

def get_step_run_metadata(
self, info: "StepRunInfo"
Expand All @@ -107,4 +109,4 @@ def cleanup_step_run(self, info: "StepRunInfo", step_failed: bool) -> None:
"""
self.run_state.active_run.sync()
self.run_state.active_run.stop()
self.run_state.reset_active_run()
self.run_state.reset()
Loading