提问者:小点点

如何使用YAML规范从组件记录指标?


我们在Google Clouds VertexAI中使用kpf v2,并希望从yaml规范构建的组件中记录指标。

我们只能通过基于Python函数的组件来完成这项工作,我们可以直接使用log_metrics(…)调用mlpieling-metrics(类型为Output[Metrics])。

https://www.kubeflow.org/docs/components/pipelines/sdk/pipelines-metrics/的文档说你可以用json将你的指标从容器内部写入名为MLPipeline Metrics的OutputPath。但是这在顶点AI不起作用,因为metr8cs不会显示在控制台中。

我们的组件设置如下:

name: a component

outputs:
- {name: MLPipeline Metrics, type: Metrics}

implementation:
  container:
    image: eu.gcr.io/project/knark/base:latest
    command: [python3, -m, module.foo,
              --metrics, {outputPath: MLPipeline Metrics}

指标文件是这样写的:

parser = ArgumentParser()
parser.add_argument('-m', '--metrics', default='/mlpipeline-metrics.json')
opts = parser.parse_args()

metrics = {'cluster-entropy': .5, 'inertia': 100.}

with open(metrics_path, 'w') as f:
    json.dump({'metrics': [{'name': m, 'value': v, 'format': 'RAW'} for m, v in metrics.items()]}, f)

我们也试过设置

    fileOutputs:
      mlpipeline-metrics: /mlpipeline-metrics.json

在组件中,这似乎是早期的方法,但这似乎也不起作用。

在写出指标时是否缺少任何细节,或者这根本不起作用,或者在顶点AI中不受支持?


共1个答案

匿名用户

一种在Docs中解释过的方法,neh。但是在Kubeflow管道Repo的一个问题中,他得到了一个解决方案,他修改了. yaml一点,并通过调用Execator类在组件代码中进行了小的修改。

https://github.com/kubeflow/pipelines/issues/6116#issuecomment-1059174206

我给它添加了一些东西,并将其放在一个repo中,用于仅使用容器的部署,并添加了带有输入工件和输入参数的示例

https://github.com/juansebashr/VertexPipelinesCICD