yocto-gl icon indicating copy to clipboard operation
yocto-gl copied to clipboard

[FR] Allow passing in bool parameters in MLproject entrypoint

Open tanmaymathur89 opened this issue 5 years ago • 16 comments

Proposal


conda_env: my_env.yaml

entry_points:
  main:
    parameters:
      data_file: path
      regularization: {type: float, default: 0.1}
    command: "python script.py -r {regularization} {data_file}"
  validate:
    parameters:
      data_file: path
    command: "python validate.py {data_file}"

Only allows you to pass a string, float, path or uri. However, python allows you to pass bool command line arguments that we cannot fit into this format.

Motivation

Command I want to execute is python script.py --train -r {regularization} {data_file} where --train is an optional boolean argument.

Proposed Changes


conda_env: my_env.yaml

entry_points:
  main:
    parameters:
      data_file: path
      regularization: {type: float, default: 0.1}
      train : {type: bool, default: False}      
    command: "python script.py -r  {regularization} {train} {data_file} "
  validate:
    parameters:
      data_file: path
    command: "python validate.py {data_file}"

MLflow run execution: mlflow run . -P data_file=data.csv train=True translates to python script.py --train -r 0.1 data.csv

tanmaymathur89 avatar Oct 16 '19 20:10 tanmaymathur89

I proposed this in #1572 and it was rejected for reasons I still don't understand.

lorenzwalthert avatar Jan 06 '20 20:01 lorenzwalthert

Also looking for boolean parameter support.

andrewbrooks-o avatar Jan 14 '20 03:01 andrewbrooks-o

Hi @tanmaymathur89, @lorenzwalthert, and @andrewbrooks-o! Thanks for your feedback - this seems like something that would be nice to support. Would any of you be willing to make a PR to add in this capability?

juntai-zheng avatar Jan 31 '20 22:01 juntai-zheng

@juntai-zheng I can create a PR for it. Thanks

tanmaymathur89 avatar Feb 01 '20 15:02 tanmaymathur89

@tanmaymathur89 @lorenzwalthert @andrewbrooks-o I think that adding boolean parameter support sounds great. #2453 currently introduces support for an action parameter, which appears to be relatively Python or bash-specific; @tanmaymathur89 can we refactor this to introduce support for True/False boolean parameters rather than actions?

dbczumar avatar Mar 20 '20 23:03 dbczumar

@dbczumar is this still open? If @tanmaymathur89 won't do it, I can prepare a PR for adding boolean parameter support.

sn1c avatar Jun 11 '20 13:06 sn1c

@dbczumar is this still open? If @tanmaymathur89 won't do it, I can prepare a PR for adding boolean parameter support.

Go ahead @sn1c. I thought I posted a comment earlier but can't see it anymore. I was wondering what the advantage is converting from action to boolean? We are essentially passing through the values to a downstream python code in this case.

tanmaymathur89 avatar Jun 11 '20 16:06 tanmaymathur89

@dbczumar is this still open? If @tanmaymathur89 won't do it, I can prepare a PR for adding boolean parameter support.

Go ahead @sn1c. I thought I posted a comment earlier but can't see it anymore. I was wondering what the advantage is converting from action to boolean? We are essentially passing through the values to a downstream python code in this case.

Oh found it, https://github.com/mlflow/mlflow/pull/2453#issuecomment-602315646

tanmaymathur89 avatar Jun 11 '20 16:06 tanmaymathur89

@tanmaymathur89 I feel like the reason for the stand for booleans and against actions is, that the developers seem to want MLflow to be as language-agnostic as possible. What is your take on that?

sn1c avatar Jun 21 '20 18:06 sn1c

@tanmaymathur89 I feel like the reason for the stand for booleans and against actions is, that the developers seem to want MLflow to be as language-agnostic as possible. What is your take on that?

IMO its just a pass through. Adding additional grammar is confusing but thats my opinion.

tanmaymathur89 avatar Jun 22 '20 20:06 tanmaymathur89

So, what's the workaround to work with that? I see no reference to boolean types in the MLFlow doc

EKami avatar Dec 31 '20 09:12 EKami

Well, a simple workaround is to use an integer parameter (and supply 0, 1 only) and convert to boolean in your script.

lorenzwalthert avatar Dec 31 '20 09:12 lorenzwalthert

Ok, so here is my workaround:

# MLProject
name: my_project

entry_points:
  main:
    parameters:
      my_bool: {type: string, default: "no_my_bool"}
    command: python my_module.py --{my_bool}

In the calling code:

# main.py
mlflow.run(".", entrypoint, parameters={"my_bool": "with_my_bool" if a_boolean else "no_my_bool"})

And finally in the module

@click.command(help="Demo")
@click.option('--with_my_bool/--no_my_bool')
def main(my_bool):
    # Do something with my_bool

if __name__ == "__main__":
    main()

Notice you are forced to use a default in MLProject, use the False value by default which is equivalent to not specifying the flag.

EKami avatar Dec 31 '20 09:12 EKami

I am not sure I’d do it that way. Of course you can pass flags, but mostly you want to use key value pairs and not just flags (not sure what your use case is). Like early_stopping=True. This also makes more sense in the context of filtering runs I believe and is consistent with string and numeric parameters. So I'd just do early_stoping=1 as any other numeric parameter and then convert to bool in your script (not sure, maybe click supports that out of the box when parsing the parameter).

lorenzwalthert avatar Dec 31 '20 09:12 lorenzwalthert

Both are valid I think, it's just a matter of taste. To me when the module is run separately as an independent script I find it cleaner to specify --early_stopping instead of --early_stoping=1

EKami avatar Dec 31 '20 09:12 EKami

Any update on the boolean parameter support? I'm in need of such a feature. If I can help somehow I'd be happy to.

florianblume avatar Sep 28 '21 10:09 florianblume

How is this still not supported? Big gap in MLFlow.

anton164 avatar May 17 '23 16:05 anton164

This issue has been put under a low priority, but I think we can do a quick fix for it. Keep it open and we will welcome OSS contributions.

chenmoneygithub avatar Oct 05 '23 21:10 chenmoneygithub