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

Log project backend for local runs with no environment #2207

Merged
merged 5 commits into from Dec 17, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions mlflow/projects/__init__.py
Expand Up @@ -137,15 +137,14 @@ def _run(uri, experiment_id, entry_point="main", version=None, parameters=None,
experiment_id=experiment_id, cluster_spec=backend_config)

elif backend == "local" or backend is None:
tracking.MlflowClient().set_tag(active_run.info.run_id, MLFLOW_PROJECT_BACKEND, "local")
command_args = []
command_separator = " "
# If a docker_env attribute is defined in MLproject then it takes precedence over conda yaml
# environments, so the project will be executed inside a docker container.
if project.docker_env:
tracking.MlflowClient().set_tag(active_run.info.run_id, MLFLOW_PROJECT_ENV,
"docker")
tracking.MlflowClient().set_tag(active_run.info.run_id, MLFLOW_PROJECT_BACKEND,
"local")
_validate_docker_env(project)
_validate_docker_installation()
image = _build_docker_image(work_dir=work_dir,
Expand All @@ -159,7 +158,6 @@ def _run(uri, experiment_id, entry_point="main", version=None, parameters=None,
# to avoid failures due to multiple concurrent attempts to create the same conda env.
elif use_conda:
tracking.MlflowClient().set_tag(active_run.info.run_id, MLFLOW_PROJECT_ENV, "conda")
tracking.MlflowClient().set_tag(active_run.info.run_id, MLFLOW_PROJECT_BACKEND, "local")
command_separator = " && "
conda_env_name = _get_or_create_conda_env(project.conda_env_path)
command_args += _get_conda_command(conda_env_name)
Expand Down
11 changes: 7 additions & 4 deletions tests/projects/test_docker_projects.py
Expand Up @@ -10,9 +10,9 @@
from mlflow.entities import ViewType
from mlflow.projects import ExecutionException, _get_docker_image_uri
from mlflow.store.tracking import file_store
from mlflow.utils.mlflow_tags import MLFLOW_PROJECT_ENV, MLFLOW_DOCKER_IMAGE_URI, \
MLFLOW_DOCKER_IMAGE_ID

from mlflow.utils.mlflow_tags import (
MLFLOW_PROJECT_ENV, MLFLOW_PROJECT_BACKEND, MLFLOW_DOCKER_IMAGE_URI, MLFLOW_DOCKER_IMAGE_ID,
)
from tests.projects.utils import TEST_DOCKER_PROJECT_DIR
from tests.projects.utils import docker_example_base_image # pylint: disable=unused-import
from tests.projects.utils import tracking_uri_mock # pylint: disable=unused-import
Expand Down Expand Up @@ -46,7 +46,10 @@ def test_docker_project_execution(
run = mlflow_service.get_run(run_id)
assert run.data.params == expected_params
assert run.data.metrics == {"some_key": 3}
exact_expected_tags = {MLFLOW_PROJECT_ENV: "docker"}
exact_expected_tags = {
MLFLOW_PROJECT_ENV: "docker",
MLFLOW_PROJECT_BACKEND: "local",
}
approx_expected_tags = {
MLFLOW_DOCKER_IMAGE_URI: "docker-example",
MLFLOW_DOCKER_IMAGE_ID: "sha256:",
Expand Down
19 changes: 18 additions & 1 deletion tests/projects/test_projects.py
Expand Up @@ -18,7 +18,8 @@
from mlflow.utils import env
from mlflow.utils.mlflow_tags import MLFLOW_PARENT_RUN_ID, MLFLOW_USER, MLFLOW_SOURCE_NAME, \
MLFLOW_SOURCE_TYPE, MLFLOW_GIT_BRANCH, MLFLOW_GIT_REPO_URL, LEGACY_MLFLOW_GIT_BRANCH_NAME, \
LEGACY_MLFLOW_GIT_REPO_URL, MLFLOW_PROJECT_ENTRY_POINT
LEGACY_MLFLOW_GIT_REPO_URL, MLFLOW_PROJECT_ENTRY_POINT, MLFLOW_PROJECT_BACKEND, \
MLFLOW_PROJECT_ENV

from tests.projects.utils import TEST_PROJECT_DIR, TEST_PROJECT_NAME, GIT_PROJECT_URI, \
validate_exit_status, assert_dirs_equal
Expand Down Expand Up @@ -208,6 +209,21 @@ def test_use_conda(tracking_uri_mock): # pylint: disable=unused-argument
os.environ["CONDA_EXE"] = conda_exe_path


def test_expected_tags_logged_when_using_conda(
tracking_uri_mock): # pylint: disable=unused-argument
with mock.patch.object(mlflow.tracking.MlflowClient, "set_tag") as tag_mock:
try:
mlflow.projects.run(TEST_PROJECT_DIR, use_conda=True)
finally:
tag_mock.assert_has_calls(
[
mock.call(mock.ANY, MLFLOW_PROJECT_BACKEND, "local"),
mock.call(mock.ANY, MLFLOW_PROJECT_ENV, "conda"),
],
any_order=True,
)


def test_is_valid_branch_name(local_git_repo):
assert mlflow.projects._is_valid_branch_name(local_git_repo, "master")
assert not mlflow.projects._is_valid_branch_name(local_git_repo, "dev")
Expand Down Expand Up @@ -257,6 +273,7 @@ def test_run_local_git_repo(patch_user, # pylint: disable=unused-argument
assert "file:" in tags[MLFLOW_SOURCE_NAME]
assert tags[MLFLOW_SOURCE_TYPE] == SourceType.to_string(SourceType.PROJECT)
assert tags[MLFLOW_PROJECT_ENTRY_POINT] == "test_tracking"
assert tags[MLFLOW_PROJECT_BACKEND] == "local"

if version == "master":
assert tags[MLFLOW_GIT_BRANCH] == "master"
Expand Down