我目前使用Kubeflow作为我的编排器。该编排器实际上是托管在GCP上的AI平台管道的实例。我如何使用Tensorflow Extended SDK创建运行时参数?我怀疑应该使用这个类,但文档意义不明,也没有提供任何示例。 https://www.tensorflow.org/tfx/api_docs/python/tfx/orchestration/data_types/RuntimeParameter
回答:
例如,假设你想将模块文件位置作为运行时参数传递给你的TFX管道中的转换组件。
首先,设置你的setup_pipeline.py文件并定义模块文件参数:
# setup_pipeline.pyfrom typing import Textfrom tfx.orchestration import data_types, pipelinefrom tfx.orchestration.kubeflow import kubeflow_dag_runnerfrom tfx.components import Transform_module_file_param = data_types.RuntimeParameter( name='module-file', default= '/tfx-src/tfx/examples/iris/iris_utils_native_keras.py', ptype=Text,)
接下来,定义一个函数来指定管道中使用的组件,并传递参数。
def create_pipeline(..., module_file): # 设置组件: ... transform = Transform( ... module_file=module_file ) ... components = [..., transform, ...] return pipeline.Pipeline( ..., components=components )
最后,设置Kubeflow DAG运行器,以便它将参数传递给create_pipeline
函数。有关更完整的示例,请参见这里。
if __name__ == "__main__": # 实例化kfp_runner ... kfp_runner = kubeflow_dag_runner.KubeflowDagRunner( ... ) kfp_runner.run( create_pipeline(..., module_file=_module_file_param ))
然后你可以运行python -m setup_pipeline
,这将生成指定管道配置的yaml文件,然后你可以将该文件上传到Kubeflow的GCP界面。