Hey, I'm trying to implement conditional branching...
# ask-metaflow
d
Hey, I'm trying to implement conditional branching to give the option on the infrastructure used for computation (see code snippet below). I've seen conditional branching is not supported by metaflow, but do you have alternatives for this usecase ? Thank you !
Copy code
@step
    def evaluate_regression(self) -> None:
        if self.infra:
            self.next(self.evaluate_on_kubernetes)
        else:
            self.next(self.evaluate_locally)

    @kubernetes(
        gpu=1,
        cpu=4,
        memory=16_000,  # 16Gb
        namespace="X",
    )
    @step
    def evaluate_on_kubernetes(self) -> None:
        ...    
        self.next(self.join_target_results)

    @step
    def evaluate_locally(self) -> None:
        ...
        self.next(self.join_target_results)
1
f
You can set a var inside
evaluate_regression
and call both steps and have step specific logic based on this infra.
Copy code
@step
    def evaluate_regression(self) -> None:
        self.infra = True
        self.next(self.evaluate_on_kubernetes, self.evaluate_locally)

    @kubernetes(
        gpu=1,
        cpu=4,
        memory=16_000,  # 16Gb
        namespace="X",
    )
    @step
    def evaluate_on_kubernetes(self) -> None:
        ...
        if self.infra:
            # Infra logic
        self.next(self.join_target_results)


    @step
    def evaluate_locally(self) -> None:
        ...
        if not self.infra:
            # Local logic
        self.next(self.join_target_results)
I see the problem though i.e. you need access to k8s always even though you are running it locally
👍 1
d
I agree this is a working solution, but this will still launch a new GKE pod for nothing...
f
AFAIK sadly metaflow doesn't have a workaround for this
d
configs may help there too if you know when deploying which one you want to use (ie: if infra is a deploy time value and not a runtime one)