问题描述
我目前正在使用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.py
from typing import Text
from tfx.orchestration import data_types,pipeline
from tfx.orchestration.kubeflow import kubeflow_dag_runner
from 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):
# setup components:
...
transform = Transform(
...
module_file=module_file
)
...
components = [...,transform,...]
return pipeline.Pipeline(
...,components=components
)
最后,设置Kubeflow DAG运行器,以便它将参数传递到create_pipeline
函数。有关更完整的示例,请参见here。
if __name__ == "__main__":
# instantiate a 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界面。