-
Notifications
You must be signed in to change notification settings - Fork 820
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 the possibility of defining default decorators for steps #1837
Conversation
8acf3ab
to
3d94bbe
Compare
0dadd14
to
0921711
Compare
metaflow/decorators.py
Outdated
attrstr = ",".join(attr_list) | ||
return "%s:%s" % (self.name, attrstr) | ||
else: | ||
return self.name | ||
|
||
def __str__(self): | ||
mode = "decorated" if self.statically_defined else "cli" | ||
mode = "decorated" if self.statically_defined else "cli or configuration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe undecorated
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find "undecorated" to be less specific. It doesn't really give much information. What do you think of "injected". We could also have "static" and "dynamic" simply. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep - static and dynamic works well.
metaflow/cli.py
Outdated
@@ -837,6 +859,7 @@ def version(obj): | |||
multiple=True, | |||
help="Add a decorator to all steps. You can specify this option " | |||
"multiple times to attach multiple decorators in steps.", | |||
callback=use_conf_and_merge_cb, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit - decospecs_callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't have a huge preference but my intent was to make this function useful for anything that comes from conf too. Maybe use_conf_for_multiple_cb
. It also doesn't apply to all decospecs for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just config_callback
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure on the cause, as no changes touch this codepath directly:
when running a flow remotely with f.ex. --with kubernetes
, I'm getting to following in stdout
'nbrun' requires an interactive python environment (such as Jupyter)
same is not happening with master
This is in preparation of having default decorators injected by the user and/or various metaflow extensions.
Mechanism is now as follows: - users can set METAFLOW_DECOSPECS in their configuration or in the environment - extensions can set DECOSPECS in their config or set a list of TOGGLE_DECOSPECS METAFLOW_DECOSPECS/DECOSPECS is a string (space separated to form an array) Precedence order (from first priority to last): - DECOSPECS from extension if it sets DECOSPECS = ... - METAFLOW_DECOSPECS in the environment - METAFLOW_DECOSPECS in the configuration - DECOSPECS (default from extension if it uses from_conf...) - If still not set after all these checks, form by adding all the TOGGLE_DECOSPECS together
metaflow/cli.py
Outdated
splits = DECOSPECS.split() | ||
if len(splits) == len(value) and all([a == b for (a, b) in zip(splits, value)]): | ||
return value | ||
return tuple(DECOSPECS.split() + list(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this was decided already before, but noting some oddities regarding the hierarchy in the config.
test setup:
# metaflow config.json
"METAFLOW_DECOSPECS": "kubernetes:memory=3072"
# cmd
python HelloFlow.py run --with "kubernetes:memory=1024,cpu=2"
results in the higher memory value being used, and cpu omitted.
same setup with additional env var set
METAFLOW_DECOSPECS="kubernetes:memory=2048"
results in env var overriding value from config.json (as expected)
directly supplying values in a deco seems to override everything else as expected
@kubernetes(memory=512, cpu=3)
so the succession right now seems to be
explicit decorator in flow file
> METAFLOW_DECOSPEC env
> METAFLOW_DECOSPEC in config.json
> CLI --with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing I found odd with the succession is treating an explicit CLI --with
secondary when the config/envvar values are advertised as setting defaults only. My expectation would be that an option passed through CLI would perhaps override defaults
Disregard if this is intended behaviour :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed the behavior that is coded. There is no notion of "decorator merge" although there should be. For now though, I think this is good enough but going forward we should see how we can merge decorators. This is the same problem as the @Environment decorator where one overrides all others (and they don't merge). There is also no warning of duplicate decorators because they are all non static. In short, we have not changed the behavior at all but it can be a bit weird. You can try for example --with kubernetes:memory=2048 --with kubernetes:memory=1024,cpu=2
, the second one will be ignored just like it is right now. You can view the default decospecs as stuff that is prepended basically. Am happy to make it post pended though if ppl prefer, as in:
explicit deco in flow file
CLI --with
METAFLOW_DECOSPEC env
METAFLOW_DECOSPEC in config.json.
Given we have no promises on any ordering right now, I don't view that as a huge issue and I think we need to more cleanly address it but that would be for another set of changes.
ccde7ed
to
b6bddb5
Compare
@saikonen -- could you try again. I rebased on master and addressed @savingoyal 's comments. I suspect the error you are getting had to do with the previous changes for the runner and I didn't take all the "fixes" and master was, at some point, in a bad state. |
seems to be fixed now 👍 |
The order is now: - statically defined using a decorator - passed using --with - passed using METAFLOW_DECOSPECS in the environment variable - passed using METAFLOW_DECOSPECS in a configuration - passed using TOGGLE_DECOSPECS in the configuration Note that an error will occur if: - a decorator is defined statically and dynamically and it doesn't allow multiple An error will NOT be raised if: - a decorator is passed multiple times dynamically (newer ones are *ignored*)
./myflow.py run --with foo both work properly
elif n == "TOGGLE_DECOSPECS": | ||
if any([x.startswith("-") for x in o]): | ||
raise ValueError("Removing decospecs is not currently supported") | ||
if any(" " in x for x in o): | ||
raise ValueError("Decospecs cannot contain spaces") | ||
_TOGGLE_DECOSPECS.extend(o) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the latest on this? it seems we can only add decospecs for now through extensions, not remove them.
The usage is a bit different from the PR description as well, not requiring prepending a +
for adding a decospec. This makes sense for now as -
is not supported, but should we agree on the final form already, or is there a use case for this yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for adding decospecs the mechanism is working as expected 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@savingoyal had me remove the - option since he thought it would be confusing. It can easily be added back if we feel the need for it later (I don't need it right now, I had initially done the - to keep in line with the TOGGLE_STEP_DECORATOR for example (but that one I really needed the -)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was more so wondering about the prefixes in general, as currently +
is not supported either, so do we even need a check against -
?
not working at the moment. Is this intended?
TOGGLE_DECOSPECS = ["+kubernetes:memory=1024"]
this works fine
TOGGLE_DECOSPECS = ["kubernetes:memory=1024"]
as its currently append-only, naming the var toggle
is a bit confusing. We can keep it as is though if the end goal is to support toggling the decospecs.
Default decorators can be defined in one of two ways:
METAFLOW_DEFAULT_STEP_DECORATORS
configuration (env var or configuration value). If this is set, it will be applied regardless of anything else. This is a comma separated string.I will add tests and try it out but putting it here for initial review to see if the method is OK.