首页 > 解决方案 > 尝试使用 TFX 运行非常简单的 Kubeflow 管道时,为什么 GKE 集群上的 pod 会 OOMkilled?

问题描述

我正在按照Cloud AI Platform Pipelines 上的 TFX教程在 Google Cloud 上实现 Kubeflow 编排的管道。主要区别在于我正在尝试实现对象检测解决方案,而不是本教程提出的出租车应用程序。

出于这个原因,我(在本地)创建了一个通过 labelImg 标记的图像数据集,并使用我上传到 GS 存储桶上的这个脚本将其转换为 .tfrecord。然后我按照 TFX 教程创建 GKE 集群(默认集群,使用此配置)和运行代码所需的 Jupyter Notebook,导入相同的模板。

主要区别在于管道的第一个组件,我将CSVExampleGen组件更改为ImportExampleGen组件:

def create_pipeline(
    pipeline_name: Text,
    pipeline_root: Text,
    data_path: Text,
    # TODO(step 7): (Optional) Uncomment here to use BigQuery as a data source.
    # query: Text,
    preprocessing_fn: Text,
    run_fn: Text,
    train_args: tfx.proto.TrainArgs,
    eval_args: tfx.proto.EvalArgs,
    eval_accuracy_threshold: float,
    serving_model_dir: Text,
    metadata_connection_config: Optional[
        metadata_store_pb2.ConnectionConfig] = None,
    beam_pipeline_args: Optional[List[Text]] = None,
    ai_platform_training_args: Optional[Dict[Text, Text]] = None,
    ai_platform_serving_args: Optional[Dict[Text, Any]] = None,
) -> tfx.dsl.Pipeline:
  """Implements the chicago taxi pipeline with TFX."""

  components = []

  # Brings data into the pipeline or otherwise joins/converts training data.
  example_gen = tfx.components.ImportExampleGen(input_base=data_path)
  # TODO(step 7): (Optional) Uncomment here to use BigQuery as a data source.
  # example_gen = tfx.extensions.google_cloud_big_query.BigQueryExampleGen(
  #     query=query)
  components.append(example_gen)

管道中没有插入其他组件,数据路径指向包含 .tfrecord 的存储桶上的文件夹位置:

DATA_PATH = 'gs://(project bucket)/(dataset folder)'

这是运行器代码(与 TFX 教程中的基本相同):

def run():
  """Define a kubeflow pipeline."""

  # Metadata config. The defaults works work with the installation of
  # KF Pipelines using Kubeflow. If installing KF Pipelines using the
  # lightweight deployment option, you may need to override the defaults.
  # If you use Kubeflow, metadata will be written to MySQL database inside
  # Kubeflow cluster.
  metadata_config = tfx.orchestration.experimental.get_default_kubeflow_metadata_config(
  )

  runner_config = tfx.orchestration.experimental.KubeflowDagRunnerConfig(
      kubeflow_metadata_config=metadata_config,
      tfx_image=configs.PIPELINE_IMAGE)
  pod_labels = {
      'add-pod-env': 'true',
      tfx.orchestration.experimental.LABEL_KFP_SDK_ENV: 'tfx-template'
  }
  tfx.orchestration.experimental.KubeflowDagRunner(
      config=runner_config, pod_labels_to_attach=pod_labels
  ).run(
      pipeline.create_pipeline(
          pipeline_name=configs.PIPELINE_NAME,
          pipeline_root=PIPELINE_ROOT,
          data_path=DATA_PATH,
          # TODO(step 7): (Optional) Uncomment below to use BigQueryExampleGen.
          # query=configs.BIG_QUERY_QUERY,
          preprocessing_fn=configs.PREPROCESSING_FN,
          run_fn=configs.RUN_FN,
          train_args=tfx.proto.TrainArgs(num_steps=configs.TRAIN_NUM_STEPS),
          eval_args=tfx.proto.EvalArgs(num_steps=configs.EVAL_NUM_STEPS),
          eval_accuracy_threshold=configs.EVAL_ACCURACY_THRESHOLD,
          serving_model_dir=SERVING_MODEL_DIR,
          # TODO(step 7): (Optional) Uncomment below to use provide GCP related
          #               config for BigQuery with Beam DirectRunner.
          # beam_pipeline_args=configs
          # .BIG_QUERY_WITH_DIRECT_RUNNER_BEAM_PIPELINE_ARGS,
          # TODO(step 8): (Optional) Uncomment below to use Dataflow.
          # beam_pipeline_args=configs.DATAFLOW_BEAM_PIPELINE_ARGS,
          # TODO(step 9): (Optional) Uncomment below to use Cloud AI Platform.
          # ai_platform_training_args=configs.GCP_AI_PLATFORM_TRAINING_ARGS,
          # TODO(step 9): (Optional) Uncomment below to use Cloud AI Platform.
          # ai_platform_serving_args=configs.GCP_AI_PLATFORM_SERVING_ARGS,
      ))


if __name__ == '__main__':
  logging.set_verbosity(logging.INFO)
  run()

然后创建管道并使用 Notebook 中的以下代码调用运行:

!tfx pipeline create  --pipeline-path=kubeflow_runner.py --endpoint={ENDPOINT} --build-image
!tfx run create --pipeline-name={PIPELINE_NAME} --endpoint={ENDPOINT}

问题是,虽然示例中的管道运行没有问题,但该管道总是失败,GKE 集群上的 pod 以代码 137 ( OOMKilled ) 退出。

这是集群工作负载状态的快照,是崩溃运行的完整日志转储

我已经尝试过减小数据集大小(现在整个 .tfrecord 大约为 6MB)并将其在本地分成两组(验证和训练),因为当组件应该拆分数据集时似乎会发生崩溃,但两者都没有这些改变了局面。

您对它为什么会出现内存不足以及我可以采取哪些步骤来解决这个问题有任何想法吗?

非常感谢。

标签: google-cloud-platformgoogle-kubernetes-enginekubeflow-pipelinestfxgoogle-cloud-ai-platform-pipelines

解决方案


如果应用程序发生内存泄漏或尝试使用超过设定限制量的内存,Kubernetes 将通过“OOMKilled - 达到容器限制”事件和退出代码 137 来终止它。

当您看到这样的消息时,您有两个选择:增加 pod 的限制或开始调试。例如,如果您的网站负载增加,那么调整限制是有意义的。另一方面,如果内存使用是突然的或意外的,则可能表明内存泄漏,您应该立即开始调试。

请记住,Kubernetes 像这样杀死一个 pod 是一件好事——它阻止了所有其他 pod 在同一个节点上运行。

也参考类似的问题link1link2,希望它有帮助。谢谢


推荐阅读