skip to content

When migrating a Kubeflow Training Operator v1 PyTorchJob manifest to a Kubeflow Trainer v2.3.0 TrainJob, what changes, and where do its per-pod settings go?

level: seniorimportance: should knowfreq 6%

answer

  1. one kind instead of one per framework
  2. Master plus Worker becomes one count
  3. container fields move under trainer
  4. pod-level settings: runtime or patch
  5. watchers expect Complete, not Succeeded

basics

~20 s

The kubeflow.org/v1 PyTorchJob with Master and Worker pod templates becomes a trainer.kubeflow.org/v1alpha1 TrainJob that names a runtime, with Master plus Worker replicas folded into trainer.numNodes. Pod-level settings move into the runtime's template or a runtimePatches entry.

solid answer

~40 s

A v1 `PyTorchJob` (`kubeflow.org/v1`) described the whole topology itself: `pytorchReplicaSpecs` with a `Master` and a `Worker` entry, each with `replicas`, `restartPolicy` and a full pod template. In Trainer v2.3.0 the `TrainJob` (`trainer.kubeflow.org/v1alpha1`) names a runtime such as `torch-distributed` in `runtimeRef` and keeps only run values under `trainer`: the container's image and command, `numNodes` equal to Master plus Worker replicas, `resourcesPerNode` and `env`. There is no Master/Worker split any more; every node pod is equal and the Torch policy hands each its rank. Pod-level settings such as `nodeSelector`, `volumes` or `serviceAccountName` go into a runtime the platform team owns or a `runtimePatches` entry keyed by `manager`. Anything that watched the job must follow: the TrainJob succeeds with a `Complete` condition, not `Succeeded`.

code

yaml · 27 lines
yaml
apiVersion: trainer.kubeflow.org/v1alpha1
kind: TrainJob
metadata:
  name: layout-detect-ft
spec:
  runtimeRef:
    name: torch-distributed
  trainer:
    numNodes: 4            # was Master 1 + Worker 3
    image: registry.internal.example/doc-ai/layout-train:1.4
    command: ["torchrun", "/workspace/train.py"]
    resourcesPerNode:
      limits:
        nvidia.com/gpu: 8
  runtimePatches:
    - manager: doc-ai.internal.example/migration
      trainingRuntimeSpec:
        template:
          spec:
            replicatedJobs:
              - name: node
                template:
                  spec:
                    template:
                      spec:
                        nodeSelector:
                          gpu-pool: training-80g

go deeper

for a junior

Recall that Trainer v2 replaced PyTorchJob, TFJob and MPIJob with one TrainJob kind that references a runtime.

for a middle

Map the fields: replicas to numNodes, container fields to trainer, and pod-level settings to the runtime or runtimePatches.

for a senior

Plan the migration end to end, including watchers and Katib trial templates that expected Succeeded, the Master-plus-Worker count, and per-team settings kept out of shared runtimes.

for a principal

Sequence a fleet migration: which runtimes the platform must publish first, how long the v1 operator stays installed, and how teams verify parity before their PyTorchJobs are retired.

## What the legacy manifest carried The **Kubeflow Training Operator** (v1) had one kind per framework under `kubeflow.org/v1`. A `PyTorchJob` spelled out its topology in `pytorchReplicaSpecs`: a `Master` entry and a `Worker` entry, each with `replicas`, a `restartPolicy` such as `OnFailure`, and a complete Kubernetes pod template. `TFJob` did the same in `tfReplicaSpecs` with roles like `PS`, `Worker` and `Chief`, and `MPIJob` used `mpiReplicaSpecs` with a `Launcher` and `Worker`s plus `slotsPerWorker`. Every manifest therefore mixed what the run needed (image, command, replica count) with what the cluster needed (node pools, volumes, security context). **Kubeflow Trainer v2** replaces all three kinds with one `TrainJob` and the `TrainingRuntime` / `ClusterTrainingRuntime` blueprints, under `trainer.kubeflow.org/v1alpha1` in v2.3.0. The Trainer migration guide states it directly: v2 does not use separate CRDs for each framework. ## Field-by-field mapping | v1 `PyTorchJob` | Trainer v2.3.0 `TrainJob` | |---|---| | `apiVersion: kubeflow.org/v1`, `kind: PyTorchJob` | `apiVersion: trainer.kubeflow.org/v1alpha1`, `kind: TrainJob` | | Framework chosen by the kind | Framework chosen by the runtime's `mlPolicy` (`torch` for `torch-distributed`) | | `Master.replicas` + `Worker.replicas` | `trainer.numNodes` (1 + 3 becomes 4) | | Container `image`, `command`, `args`, `env` | `trainer.image`, `trainer.command`, `trainer.args`, `trainer.env` | | Container `resources` | `trainer.resourcesPerNode` | | Pod `nodeSelector`, `tolerations`, `volumes`, `serviceAccountName` | The runtime's template, or a `runtimePatches` entry | | Per-replica `restartPolicy` | The runtime's Job template | | Success condition `Succeeded` | Success condition `Complete` | ## Migrating a manifest, step by step 1. **Pick the runtime.** For plain PyTorch on the cluster's shared blueprint, `runtimeRef.name: torch-distributed`; for a team blueprint, `kind: TrainingRuntime` in the same namespace. 2. **Collapse the replicas.** Add `Master` and `Worker` replicas into `trainer.numNodes`. A PyTorchJob with one Master and three Workers becomes `numNodes: 4`, not 3. 3. **Move the container fields** into `trainer`. Drop the per-container ports and rendezvous wiring: the Torch policy injects `PET_NNODES`, `PET_NODE_RANK`, `PET_MASTER_ADDR` and the rest into each node container for `torchrun`. 4. **Relocate pod-level settings.** If every run on the cluster needs them, they belong in a runtime the platform team owns. If only this run needs them, add a `runtimePatches` entry with a `manager` name, which patches the runtime's JobSet template for this TrainJob alone. `runtimePatches` replaced an earlier Trainer field, `podTemplateOverrides`, so manifests written against that field need the same move. 5. **Update what watches the job.** Dashboards, scripts and Katib trial templates that waited for `Succeeded` must wait for `Complete`. Katib 0.19 defaults this for a TrainJob trial: its success condition looks for type `Complete`, and its primary pod labels select the `node` replicated job's completion index 0 instead of the v1 label `training.kubeflow.org/job-role: master`. 6. **Check the immutability.** `runtimeRef`, `trainer` and `initializer` cannot be edited after creation, so habits like patching replica counts on a live PyTorchJob no longer apply. ## What stays the same - **The training image and script.** The container that ran under the PyTorchJob can run unchanged, provided it starts through `torchrun` and takes its topology from the environment rather than from hard-coded Master addresses. - **The GPU request.** The same resource limits move from each replica's container into `trainer.resourcesPerNode`, applied to every node pod alike. - **The tuning objects.** Katib's `Experiment`, `Suggestion` and `Trial` keep their `kubeflow.org/v1beta1` API; only the `trialSpec` inside the template changes kind. - **The submission path for notebooks.** Practitioners who wrote Python rather than YAML move to the Kubeflow SDK's `TrainerClient`, which the Trainer migration guide names as the way to turn training code into a TrainJob. ## TFJob and MPIJob - **MPIJob** maps onto the `mpi` source of `mlPolicy`. The shipped `deepspeed-distributed` runtime shows the shape: a `launcher` replicated job plus `node` jobs, with `numProcPerNode` as slots per node (default 1), `mpiImplementation: OpenMPI`, `sshAuthMountPath` and `runLauncherAsNode`. - **TFJob** has no drop-in target among the runtimes shipped with v2.3.0 (`torch-distributed`, `deepspeed-distributed`, `jax-distributed`, `mlx-distributed`, `xgboost-distributed` and the TorchTune ones). Moving a TFJob means the platform team designing a runtime for it first. ## Pitfalls - **Counting only Workers** for `numNodes`, which silently loses a node. - **Leaving `kubeflow.org/v1`** as the apiVersion with TrainJob fields, which no controller serves. - **Editing the shared `torch-distributed` runtime** to add one team's node pool, which changes every other team's jobs. - **Expecting a master pod.** All node pods are peers; ranks come from the injected variables. - **Assuming an elastic range survives.** `trainer.numNodes` is a single integer in v1alpha1; restart and resume behaviour is a separate concern from the manifest.

  • Why does a runtimePatches entry carry a manager field?
    Several parties may patch the same TrainJob: the person submitting it, the Kubeflow SDK (which writes `trainer.kubeflow.org/kubeflow-sdk`) and controllers such as a queueing system. Each owns exactly one entry keyed by its `manager` name, so updating one entry replaces only that owner's content. The `manager` value is immutable, and the Trainer admission webhook stamps a `time` on each write for observability.
  • A Katib trial template still uses a PyTorchJob. What changes when you switch its trialSpec to a TrainJob?
    The `trialSpec` becomes a `trainer.kubeflow.org/v1alpha1` TrainJob, with the hyperparameter placeholders inside `trainer.command` or `args`. If you relied on defaults, Katib 0.19 now waits for a `Complete` condition and injects its metrics sidecar into the pod matching `jobset.sigs.k8s.io/replicatedjob-name: node` and completion index 0. Set `primaryContainerName` to the training container, `node` in the shipped runtimes.

  • trainer.numNodes should equal the Worker replicas, since the master is separate
  • A TrainJob keeps the kubeflow.org/v1 apiVersion of the PyTorchJob
  • Pod nodeSelector and volumes go into trainer.resourcesPerNode
  • TFJob manifests move to a TensorFlow runtime that ships with Trainer v2.3.0
  • Scripts can keep waiting for the Succeeded condition after migrating

Assumes Kubeflow Trainer v2.3.0 (trainer.kubeflow.org/v1alpha1) replacing the Training Operator v1 kinds under kubeflow.org/v1, and Katib 0.19 for trial defaults.