提问者:小点点

如何参数化Kubeflow管道环境变量?


我正在探索用于运行机器学习训练作业的顶点AI管道。kubeflow管道文档清楚地说明了如何参数化容器的命令/参数。

是否也可以将输入传递给组件的环境变量或图像名称?组件的这种大摇大摆模式表明可以这样做,但此示例失败:

implementation:
  container:
    image: {concat: ["us.gcr.io/vcm-ml/emulator", {inputValue: tag}]
    # command is a list of strings (command-line arguments). 
    # The YAML language has two syntaxes for lists and you can use either of them. 
    # Here we use the "flow syntax" - comma-separated strings inside square brackets.
    command: [
      python3, 
      # Path of the program inside the container
      /pipelines/component/src/program.py,
      --input1-path,
      {inputPath: input_1},
      --param1, 
      --output1-path, 
    ]
    env:
      NAME: {inputValue: env}
inputs:
- {name: tag, type: String}
- {name: env, type: String}
- {name: input_1, type: String, description: 'Data for input_1'}

是否支持将{inputValue}传递给容器. env容器.tag。或者,是否可以使用V2 pythonDSL添加环境变量或更改图像名称。


共1个答案

匿名用户

抱歉造成混乱。

不幸的是,JsonSchema在这里是错误的(即它与实现不同)。与图像相同。

env实现使用静态映射。image也是静态的。

在Kubeflow管道(v1)中,您可能能够在创建组件实例后将环境变量设置为动态值。但这可能在顶点管道中不起作用。

my_task = my_op(...)
my_task.container.add_env_variable(V1EnvVar(name='MSG', value=task1.outputs["out1"]))

如果这不起作用,您可以在KFP存储库中创建有关env支持的GitHub问题。

对于图像,我们通常建议为不同的图像提供单独的组件文件。

解决方法是一个设置变量的小型包装脚本:

inputs:
- {name: tag, type: String}
- {name: env, type: String}
- {name: input_1, type: String, description: 'Data for input_1'}
implementation:
  container:
    image: "us.gcr.io/vcm-ml/emulator"
    command:
    - sh
    - -ec
    - 'NAME="$0" "$@"' # Set NAME to the first arg and execute the rest
    - {inputValue: env}
    - python3
      # Path of the program inside the container
    - /pipelines/component/src/program.py
    - --input1-path
    - {inputPath: input_1}
    - --param1 
    - --output1-path

相关问题