elegant-painter-46407
01/27/2025, 12:02 PMargo-workflows create
. When the flow was previously deployed in batch, one of our flows used an environment variable to switch between different compute environments by modifying the @batch
decorator accordingly. Now, that we are using @kubernetes
and due to the static nature of the json file which defines the env variables during deployment, I am having some trouble using this switch.
I noticed metaflow introduced Configs but I am not sure they can be used for this.
To give you a more visual representation of what I mean, we want the decorator_args
and kwargs
to change based on some user defined value. For instance, if the env is GPU, then the same code will execute on a GPU node in K8s
kubernetes(*decorator_args, **kwargs)
Thanksdry-beach-38304
01/27/2025, 5:33 PMgpu
value somewhere in it (so something like:
{
"gpu_count_to_use": 1
}
in your config (default is JSON, you can use other formats but we provide a JSON parser by default). You can then use something like this:
class MyFlow(FlowSpec):
config = Config("config")
@kubernetes(gpu=config.gpu_count_to_use)
@step
...
The above method implies that you modify your config (or have different configs for different things — you can pass your config using myflow.py --config <config_file> …
)
• You can also use an unpublished (as of now) method that allows you to run a function to set things in decorators, etc. This should be coming out officially soon but if you want some example, you can look here: https://github.com/Netflix/metaflow/blob/master/test_config/mutable_flow.py.
Feel free to let me know if this doesn’t help or you want more detail.elegant-painter-46407
01/28/2025, 11:40 AMA config is persisted when the flow is deployed. When using a production scheduler such as Argo Workflows, deployment happens when you call create. In the case of a local run, "deployment" happens just prior to the execution of the run. Think of "deployment" here as gathering all that is needed to run the flow.
and
Configs are evaluated and snapshot during the deployment, as this command executes. Changes in config files won't affect any existing deployment. Also all the decorator values become fixed at this point, allowing the deployment to execute as per defined in the configs.
This means I can't do
@kubernetes(nodeSelector=gpuNodes)
or
@kubernetes(nodeSelector=cpuNodes)
within a single flow based on config value for instance
device=cpu
or device=gpu
---
That being said, I shall take a look at the unpublished methoddry-beach-38304
01/28/2025, 7:30 PMdevice
, gpuNodes
and cpuNodes
exist in the config.