0

我正在探索 Vertex AI Pipelines 以运行机器学习训练作业。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}container.envcontainer.tag支持。或者,是否可以使用 V2 python DSL 添加环境变量或更改图像名称。

4

1 回答 1

1

对困惑感到抱歉。

不幸的是,这里的 JsonSchema 是错误的(即它与实现不同)。与image.

env 实现使用静态地图。而且image也是静态的。

在 Kubeflow Pipelines (v1) 中,您可以在创建组件实例后将环境变量设置为动态值。但这可能不适用于 Vertex Pipelines。

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
于 2021-07-19T07:44:06.893 回答