Skip to content

Commit

Permalink
fix: enable caching default behavior (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
julesbertrand authored Apr 12, 2024
1 parent 4c6436c commit 34663c1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
12 changes: 9 additions & 3 deletions deployer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,17 @@ def deploy( # noqa: C901
),
] = None,
enable_caching: Annotated[
bool,
Optional[bool],
typer.Option(
"--enable-caching", "-ec", help="Whether to enable caching when running the pipeline."
"--enable-caching / --no-cache",
"-ec / -nec",
help="Whether to turn on caching for the run."
"If this is not set, defaults to the compile time settings, which are True for all"
"tasks by default, while users may specify different caching options for individual"
"tasks. If this is set, the setting applies to all tasks in the pipeline."
"Overrides the compile time settings. Defaults to None.",
),
] = False,
] = None,
experiment_name: Annotated[
Optional[str],
typer.Option(
Expand Down
57 changes: 49 additions & 8 deletions deployer/pipeline_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,34 @@ def _check_experiment_name(self, experiment_name: Optional[str] = None) -> str:
def _create_pipeline_job(
self,
template_path: str,
enable_caching: bool = False,
enable_caching: Optional[bool] = None,
parameter_values: Optional[dict] = None,
input_artifacts: Optional[dict] = None,
) -> aiplatform.PipelineJob:
"""Create a pipeline job object
Args:
template_path (str): The path of PipelineJob or PipelineSpec JSON or YAML file. If the
Artifact Registry host is provided, this is the path to the pipeline template in
the Artifact Registry. Otherwise, this is the path to the pipeline template in
the local package.
enable_caching (Optional[bool], optional): Whether to turn on caching for the run.
If this is not set, defaults to the compile time settings, which are True for all
tasks by default, while users may specify different caching options for individual
tasks.
If this is set, the setting applies to all tasks in the pipeline.
Overrides the compile time settings. Defaults to None.
parameter_values (Optional[dict], optional): The mapping from runtime parameter names
to its values that control the pipeline run. Defaults to None.
input_artifacts (Optional[dict], optional): The mapping from the runtime parameter
name for this artifact to its resource id.
For example: "vertex_model":"456".
Note: full resource name ("projects/123/locations/us-central1/metadataStores/default/artifacts/456")
cannot be used. Defaults to None.
Returns:
aiplatform.PipelineJob: The pipeline job object
""" # noqa: E501
job = aiplatform.PipelineJob(
display_name=self.pipeline_name,
template_path=template_path,
Expand Down Expand Up @@ -156,7 +180,7 @@ def upload_to_registry(

def run(
self,
enable_caching: bool = False,
enable_caching: Optional[bool] = None,
parameter_values: Optional[dict] = None,
input_artifacts: Optional[dict] = None,
experiment_name: Optional[str] = None,
Expand All @@ -170,16 +194,33 @@ def run(
provided. Otherwise, use the pipeline file in the local package.
Args:
enable_caching (bool, optional): Whether to enable caching. Defaults to False.
parameter_values (dict, optional): Pipeline parameter values. Defaults to None.
input_artifacts (dict, optional): Pipeline input artifacts. Defaults to None.
enable_caching (Optional[bool], optional): Whether to turn on caching for the run.
If this is not set, defaults to the compile time settings, which are True for all
tasks by default, while users may specify different caching options for individual
tasks.
If this is set, the setting applies to all tasks in the pipeline.
Overrides the compile time settings. Defaults to None.
parameter_values (Optional[dict], optional): The mapping from runtime parameter names
to its values that control the pipeline run. Defaults to None.
input_artifacts (Optional[dict], optional): The mapping from the runtime parameter
name for this artifact to its resource id.
For example: "vertex_model":"456".
Note: full resource name ("projects/123/locations/us-central1/metadataStores/default/artifacts/456")
cannot be used. Defaults to None.
experiment_name (str, optional): Experiment name. Defaults to None.
tag (str, optional): Tag of the pipeline template. Defaults to None.
"""
""" # noqa: E501
experiment_name = self._check_experiment_name(experiment_name)

template_path = self._get_template_path(tag)

logger.debug(
f"Running pipeline '{self.pipeline_name}' with settings:"
f"\n {'template_path':<20} {template_path:<30}"
f"\n {'enable_caching':<20} {enable_caching!s:<30}"
f"\n {'experiment_name':<20} {experiment_name:<30}"
)

job = self._create_pipeline_job(
template_path=template_path,
enable_caching=enable_caching,
Expand Down Expand Up @@ -207,7 +248,7 @@ def run(

def compile_upload_run(
self,
enable_caching: bool = False,
enable_caching: Optional[bool] = None,
parameter_values: Optional[dict] = None,
experiment_name: Optional[str] = None,
tags: Optional[List[str]] = None,
Expand All @@ -229,7 +270,7 @@ def compile_upload_run(
def schedule(
self,
cron: str,
enable_caching: bool = False,
enable_caching: Optional[bool] = None,
parameter_values: Optional[dict] = None,
tag: Optional[str] = None,
delete_last_schedule: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion deployer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _DeployerDeploySettings(CustomBaseModel):
tags: Optional[List[str]] = constants.DEFAULT_TAGS
config_filepath: Optional[Path] = None
config_name: Optional[str] = None
enable_caching: bool = False
enable_caching: Optional[bool] = None
experiment_name: Optional[str] = None
local_package_path: Path = constants.DEFAULT_LOCAL_PACKAGE_PATH
skip_validation: bool = True
Expand Down
2 changes: 1 addition & 1 deletion docs/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ $ vertex-deployer deploy [OPTIONS] PIPELINE_NAMES...
* `--tags TEXT`: The tags to use when uploading the pipeline.
* `-cfp, --config-filepath FILE`: Path to the json/py file with parameter values and input artifacts to use when running the pipeline.
* `-cn, --config-name TEXT`: Name of the json/py file with parameter values and input artifacts to use when running the pipeline. It must be in the pipeline config dir. e.g. `config_dev.json` for `./vertex/configs/{pipeline-name}/config_dev.json`.
* `-ec, --enable-caching`: Whether to enable caching when running the pipeline.
* `-ec, --enable-caching / -nec, --no-cache`: Whether to turn on caching for the run.If this is not set, defaults to the compile time settings, which are True for alltasks by default, while users may specify different caching options for individualtasks. If this is set, the setting applies to all tasks in the pipeline.Overrides the compile time settings. Defaults to None.
* `-en, --experiment-name TEXT`: The name of the experiment to run the pipeline in.Defaults to '{pipeline_name}-experiment'.
* `-lpp, --local-package-path DIRECTORY`: Local dir path where pipelines will be compiled. [default: vertex/pipelines/compiled_pipelines]
* `-y, --skip-validation / -n, --no-skip`: Whether to continue without user validation of the settings. [default: skip-validation]
Expand Down

0 comments on commit 34663c1

Please sign in to comment.