Kubeflow Trainer v2: run a distributed PyTorch training job with TrainJob and the torch-distributed runtime
domain: ml-ops · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Install the Kubeflow Trainer control plane on your cluster and the Kubeflow Python SDK with `pip install -U kubeflow`
Verify the available training runtimes with `for r in TrainerClient().list_runtimes(): print(r.name)` — you should see `torch-distributed` listed
Write a training function containing your full PyTorch DDP/FSDP code with all imports inside the function body (Kubeflow Trainer auto-configures `dist.init_process_group`, `WORLD_SIZE`, `RANK`, and `LOCAL_RANK` via torchrun on every node)
Create the job with `TrainerClient().train(runtime=TrainerClient().get_runtime("torch-distributed"), trainer=CustomTrainer(func=train_fn, num_nodes=N, resources_per_node={"cpu":3,"memory":"16Gi","gpu":1}, packages_to_install=[...]))`, which returns a `job_id`
Check step status with `TrainerClient().get_job(name=job_id).steps` and stream logs with `TrainerClient().get_job_logs(job_id, follow=True)` (or `step="node-0"` for a specific node)
If migrating an existing standalone `PyTorchJob` (kubeflow.org/v1, documented under the Training Operator v1 docs), follow the official Kubeflow Trainer v2 migration guide rather than reusing the old CRD directly
Known gotchas
All imports needed by the training function must be declared inside the function body itself, since Kubeflow Trainer ships the function to every node for execution
The `torch-distributed` runtime ships with a fixed, pre-installed package set (torch/torchvision/torchaudio); add extra deps per-job via `packages_to_install` on `CustomTrainer`, not by editing the runtime
Kubeflow's own docs describe the standalone PyTorchJob CRD (Training Operator v1) as the prior generation and Kubeflow Trainer v2 (TrainJob) as the current path for new clusters; the two APIs and SDKs are not drop-in compatible, so check the official migration guide before switching an existing setup
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?