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

[Ready for Review] Make TOGGLE_DECOSPECS only add default decorator once. #2097

Merged
merged 9 commits into from
Feb 21, 2025

Conversation

darinyu
Copy link
Collaborator

@darinyu darinyu commented Oct 13, 2024

This is needed when we add value to DECOSPECS (or TOGGLE_DECOPSECS).

Changes:

  1. update the METAFLOW_DECOSPECS (from config) to METAFLOW_DEFAULT_DECOSPECS. This will no longer collide with user override METAFLOW_DECOSPECS which translate to --with
  2. remove config_merge_cb from start but move it to run. This is because "start" is called both in beginning of runtime and start of each task subprocess. Moving it to run will also attach decorator to each step.

Before the change:
when we use TOGGLE_DECOSPECS and run a flow, it first inject X as decorator at flow level (by this config_merge_cb. It then get passed to the subprocess when we run step. When step starts, it injects this X again, resulting in double decorators

After the change
when we use TOGGLE_DECOSPECS and run a flow, it no longer inject X (because this config_merge_cb is no longer in start in cli.py), When subprocess starts to run step, we inject this X to decorator (within step command line execution).

To test:

The following should include default card (once) in each step.

METAFLOW_DEFAULT_DECOSPECS=card python ./helloworld.py run

@darinyu darinyu changed the title do not let default decospec overwrite existing "--with" [WIP] do not let default decospec overwrite existing "--with" Oct 13, 2024
@darinyu darinyu force-pushed the default_decospecs branch 2 times, most recently from bf90146 to c0c0299 Compare December 12, 2024 18:14
@darinyu darinyu changed the title [WIP] do not let default decospec overwrite existing "--with" [Ready for review] Make TOGGLE_DECOSPECS only add default decorator once. Dec 12, 2024
@darinyu darinyu changed the title [Ready for review] Make TOGGLE_DECOSPECS only add default decorator once. [WIP] Make TOGGLE_DECOSPECS only add default decorator once. Feb 5, 2025
@@ -285,7 +285,7 @@
###
# Format is a space separated string of decospecs (what is passed
# using --with)
DECOSPECS = from_conf("DECOSPECS", "")
DECOSPECS = from_conf("DEFAULT_DECOSPECS", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent, I would rename this: DEFAULT_DECOSPECS = from_conf("DEFAULT_DECOSPECS", "")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@@ -739,7 +739,9 @@ class BlankCard(MetaflowCard):

type = "blank"

def __init__(self, options=dict(title=""), components=[], graph=None, **kwargs):
def __init__(
self, options=dict(title=""), components=[], graph=None, flow=None, **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated change? I think it's valid though but jsut checking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

its old, removed

@@ -7,6 +7,7 @@
from ..task import MetaflowTask
from ..unbounded_foreach import UBF_CONTROL, UBF_TASK
from ..util import decompress_list
from ..metaflow_config import DECOSPECS
Copy link
Contributor

Choose a reason for hiding this comment

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

this would therefore be DEFAULT_DECOSPECS

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@@ -127,6 +128,20 @@ def step(
raise CommandException("Function *%s* is not a step." % step_name)
echo("Executing a step, *%s*" % step_name, fg="magenta", bold=False)

decospecs = tuple(DECOSPECS.split())
if decospecs:
decorators._attach_decorators_to_step(func, decospecs)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be done earlier when we do _attach_decorators because here you may be missing out on some of the lifecycle hooks. The issue though is we still need to prevent them from loading the second time around. What I would suggest (and not 100% sure this would work) is that when we launch the subprocess (or any of the commands), we explicitly set METAFLOW_DEFAULT_DECOSPECS to an empty value since all decospecs will now be passed using METAFLOW_DECOSPECS or on the CL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just realized that we can rely on run_cmd because it also add decorator to downstream. can you help review updated PR?

# then check if we see any duplicate attributes. If we do,
# we ignore the new decorator and continue.
for deco in func.decorators:
if deco.name == decotype.name and deco.attributes == kwargs:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is where we can merge with defaults so that we can properly compare.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

weird enough, we dont reach this function now (maybe some changes to the flow or maybe I hallucinated, I need to take a deeper look on what's going on with the check

@darinyu darinyu changed the title [WIP] Make TOGGLE_DECOSPECS only add default decorator once. [Ready for Review] Make TOGGLE_DECOSPECS only add default decorator once. Feb 13, 2025
@npow
Copy link
Contributor

npow commented Feb 13, 2025

how did you test this PR?

@darinyu
Copy link
Collaborator Author

darinyu commented Feb 13, 2025

how did you test this PR?

added the test command in the description

@npow
Copy link
Contributor

npow commented Feb 14, 2025

Can we add an actual test for this?

Edit: just realized this is in the OSS repo. Maybe add a UX test on our end?

@darinyu darinyu requested review from romain-intel and npow February 19, 2025 18:27
@darinyu
Copy link
Collaborator Author

darinyu commented Feb 19, 2025

Can we add an actual test for this?

Edit: just realized this is in the OSS repo. Maybe add a UX test on our end?

yes, I made this change so that we can add default metrics card for runs with GPU, will update UX test for that

romain-intel
romain-intel previously approved these changes Feb 20, 2025
Copy link
Contributor

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

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

I think this is fine. I think we can further simplify though.

# from_conf)

# Special case where DEFAULT_DECOSPECS and value are the same. This happens
# when there is no --with option at the TL and DEFAULT_DECOSPECS is read from
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it's not the TL but more at the run/resume level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

# when there is no --with option at the TL and DEFAULT_DECOSPECS is read from
# the env var. In this case, click also passes it as value
splits = DEFAULT_DECOSPECS.split()
if len(splits) == len(value) and all([a == b for (a, b) in zip(splits, value)]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this: https://click.palletsprojects.com/en/stable/advanced/#callback-evaluation-order, the callback is called even if there is no value passed in but I don't think it will have the value DEFAULT_DECOSPECS since now that is not the same name as before. I think we can get rid this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated, and also comments.

@darinyu darinyu merged commit f5b1502 into master Feb 21, 2025
29 checks passed
@darinyu darinyu deleted the default_decospecs branch February 21, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants