运行 XGBoostJob

使用 Kueue 调度 XGBoostJob

此页面展示了在运行 Trainer XGBoostJob 时,如何利用 Kueue 的调度和资源管理能力。

本指南适用于对 Kueue 有基本了解的批处理用户。 欲了解更多信息,请参阅 Kueue 概述

开始之前

请查看管理集群配额, 以了解初始集群设置的详细信息。

查阅 Trainer 安装指南

请注意,Trainer 的最低要求版本是 v1.7.0。

你可以修改已安装版本的 Kueue 配置,以包含 XGBoostJobs 作为允许的工作负载。

XGBoostJob 定义

a. 队列选择

目标本地队列应在 XGBoostJob 配置的 metadata.labels 部分中指定。

metadata:
  labels:
    kueue.x-k8s.io/queue-name: user-queue

b. 可选择在 XGBoostJob 中设置 Suspend 字段

spec:
  runPolicy:
    suspend: true

默认情况下,Kueue 将通过 Webhook 将 suspend 设置为 true, 并在 XGBoostJob 被接受时取消挂起。

示例 XGBoostJob

此示例基于 https://github.com/kubeflow/trainer/blob/afba76bc5a168cbcbc8685c7661f36e9b787afd1/examples/xgboost/xgboostjob.yaml

apiVersion: kubeflow.org/v1
kind: XGBoostJob
metadata:
  name: xgboost-dist-iris-test-train
  namespace: default
  labels:
    kueue.x-k8s.io/queue-name: user-queue
spec:
  xgbReplicaSpecs:
    Master:
      replicas: 1
      restartPolicy: Never
      template:
        spec:
          containers:
            - name: xgboost
              image: docker.io/kubeflow/xgboost-dist-iris:latest
              resources:
                requests:
                  cpu: 0.5
                  memory: 256Mi
              ports:
                - containerPort: 9991
                  name: xgboostjob-port
              imagePullPolicy: Always
              args:
                - --job_type=Train
                - --xgboost_parameter=objective:multi:softprob,num_class:3
                - --n_estimators=10
                - --learning_rate=0.1
                - --model_path=/tmp/xgboost-model
                - --model_storage_type=local
    Worker:
      replicas: 2
      restartPolicy: ExitCode
      template:
        spec:
          containers:
            - name: xgboost
              image: docker.io/kubeflow/xgboost-dist-iris:latest
              resources:
                requests:
                  cpu: 0.5
                  memory: 256Mi
              ports:
                - containerPort: 9991
                  name: xgboostjob-port
              imagePullPolicy: Always
              args:
                - --job_type=Train
                - --xgboost_parameter="objective:multi:softprob,num_class:3"
                - --n_estimators=10
                - --learning_rate=0.1

最后修改 July 28, 2025: Localize xgboostjobs.md (#6206) (4645e911)