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

Add --env-manager option for mlflow models commands and deprecate --no-conda flag #5567

Merged
merged 16 commits into from
Apr 1, 2022

Conversation

harupy
Copy link
Member

@harupy harupy commented Mar 31, 2022

Signed-off-by: harupy 17039389+harupy@users.noreply.github.com

What changes are proposed in this pull request?

As a stepping stone for pyenv + virtualenv support in MLflow Models & Projects, introduce --env-manager option and deprecate --no-conda.

How is this patch tested?

Unit tests

Does this PR change the documentation?

  • No. You can skip the rest of this section.
  • Yes. Make sure the changed pages / sections render correctly by following the steps below.
  1. Check the status of the ci/circleci: build_doc check. If it's successful, proceed to the
    next step, otherwise fix it.
  2. Click Details on the right to open the job page of CircleCI.
  3. Click the Artifacts tab.
  4. Click docs/build/html/index.html.
  5. Find the changed pages / sections and make sure they render correctly.

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

(Details in 1-2 sentences. You can just refer to another PR with a description if this PR is part of a larger change.)

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

How should the PR be classified in the release notes? Choose one:

  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@github-actions github-actions bot added the rn/none List under Small Changes in Changelogs. label Mar 31, 2022
@harupy harupy changed the title Introduce --env-manager option and deprecate --no-conda flag Introduce --env-manager option and deprecate --no-conda flag Mar 31, 2022
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy marked this pull request as draft March 31, 2022 07:21
Comment on lines +25 to +26
CONDA = "conda"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CONDA = "conda"
CONDA = "conda"
VIRTUALENV = "virtualenv"

VIRTUALENV will be added in #5380

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy requested review from WeichenXu123 and dbczumar and removed request for WeichenXu123 March 31, 2022 08:00
mlflow/pyfunc/backend.py Outdated Show resolved Hide resolved
@harupy harupy changed the title Introduce --env-manager option and deprecate --no-conda flag Add --env-manager option for mlflow models commands and deprecate --no-conda flag Mar 31, 2022
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Copy link
Collaborator

@WeichenXu123 WeichenXu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy marked this pull request as ready for review March 31, 2022 10:07
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@@ -45,12 +49,49 @@
NO_CONDA = click.option(
"--no-conda",
is_flag=True,
help="If specified, will assume that MLmodel/MLproject is running within "
help="[Deprecated] If specified, will assume that MLmodel/MLproject is running within "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the help message to tell the user to use --env-manager=local instead?

Copy link
Member Author

@harupy harupy Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Comment on lines 66 to 67
"environment manager. Valid values are ['local', 'conda']. If unspecified, default to "
"'conda'.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we explain what each of this values means? I.e. local -> use the local environment. conda -> use conda.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!


ENV_MANAGER = click.option(
"--env-manager",
default=None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we default to conda instead of defaulting to None and resolving later?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, suppose old version users he might use command with argument --no-conda, then when upgrading to new version mlflow command will fail.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently --no-conda argument is deprecated not removed, so we should keep --no-conda works.

Copy link
Member Author

@harupy harupy Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbczumar I chose None to detect whether or not --env-manager is specified and distinguish the following cases:

mlflow models ... --no-conda
mlflow models ... --no-conda --env-manager=conda  # should fail

Copy link
Member Author

@harupy harupy Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could use sys.argv:

import sys


def _resolve_env_manager(ctx, param, value):
    no_conda = ctx.params["no_conda"]
    env_manager = EnvManager.from_string(value)
    if not no_conda:
        return env_manager

    is_env_manager_specified = param.opts[0] in sys.argv[1:]
    # only --no-conda is specified
    if not is_env_manager_specified:
        return EnvManager.LOCAL

    # Both --no-conda and --env-manager are specified. An exception should be thrown.
    raise Exception("...")


ENV_MANAGER = click.option(
    "--env-manager",
    default="conda",
    required=False,
    type=click.UNPROCESSED,
    callback=_resolve_env_manager,
    ...
)

Copy link
Member Author

@harupy harupy Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or can we ignore --env-manager (and raise a warning) if --no-conda is supplied?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's throw if both are supplied.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave this as None by default; that's fine :). I didn't see the issue before. Makes sense now!

)


def _validate_env_manager(no_conda, env_manager):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: resolve_env_manager seems clearer. We're not just performing validation, we're figuring out which internal env manager to use based on the value of no_conda and env_manager. Can we add a docstring here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually looking for a better name for this function. resolve_env_manager sounds much better, thanks!

Copy link
Collaborator

@dbczumar dbczumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once remaining comments are addressed. Thanks @harupy !

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Copy link
Collaborator

@WeichenXu123 WeichenXu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy merged commit 14d2000 into mlflow:master Apr 1, 2022
@harupy harupy deleted the introduce-env-mangager-option branch April 1, 2022 08:27
erensahin pushed a commit to erensahin/mlflow that referenced this pull request Apr 11, 2022
… `--no-conda` flag (mlflow#5567)

* Introduce --env-manager option and deprecate --no-conda flag

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* add env_manager

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* remove no_conda in PyFuncBackend

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* add from_string

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* add __str__

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* replace no_conda

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* address comments

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* fix tests

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* set default value for env_manager

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* use --env-manager

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* fix condition

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* use extend

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* address comments

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* use click.BadParameter

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* fix help text

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn/none List under Small Changes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants