# Kubeflow Trainer

> Kubernetes-native distributed training and LLM fine-tuning across PyTorch, JAX, and more

- Category: Models & Inference / GPU & Compute Clouds
- Repository: https://github.com/kubeflow/trainer
- Website: https://www.kubeflow.org/docs/components/trainer
- Canonical page: https://ai-tldr.dev/tools/kubeflow-trainer/

## In short

Kubeflow Trainer is a Kubernetes-native platform for distributed AI training and large language model (LLM) fine-tuning. It runs multi-node, multi-GPU jobs across many frameworks, including PyTorch, MLX, HuggingFace, DeepSpeed, JAX, and XGBoost, and exposes them through two Kubernetes APIs: TrainJob and Runtimes. It sits in the GPU & Compute Clouds category of the Models & Inference tools.

## Overview

Kubeflow Trainer is a Kubernetes-native platform for distributed AI training and large language model (LLM) fine-tuning. It runs multi-node, multi-GPU jobs across many frameworks, including PyTorch, MLX, HuggingFace, DeepSpeed, JAX, and XGBoost, and exposes them through two Kubernetes APIs: TrainJob and Runtimes.

It is built for teams that already run on Kubernetes and need to scale training beyond a single machine. It brings MPI to Kubernetes to coordinate high-throughput communication between GPU nodes, and integrates with ecosystem projects like Kueue for topology-aware scheduling and JobSet and LeaderWorkerSet for workload orchestration.

As a compute-orchestration tool, it sits between your training code and the cluster. AI practitioners define jobs in Python with the Kubeflow SDK, while the operator handles pod creation, scheduling, and a distributed data cache that streams large datasets toward GPU nodes.

## What it does

- Distributed training and LLM fine-tuning across PyTorch, MLX, HuggingFace, DeepSpeed, JAX, and XGBoost
- Two Kubernetes APIs, TrainJob and Runtimes, for defining and reusing training setups
- MPI on Kubernetes for multi-node, multi-GPU jobs on HPC clusters
- Integrates with Kueue for topology-aware scheduling and with JobSet and LeaderWorkerSet for orchestration
- Distributed data cache that streams large datasets to GPU nodes with zero-copy transfer
- Python SDK (TrainerClient, CustomTrainer) to launch and manage jobs without writing Kubernetes manifests

## Getting started

Kubeflow Trainer has two parts: a control plane you install on a Kubernetes cluster, and a Python SDK you use to submit jobs. You need Kubernetes and kubectl 1.31 or newer.

1. Install the control plane

   Apply the Trainer manifests to your cluster with kubectl. Set VERSION to a released tag.

```bash
export VERSION=v2.2.0
kubectl apply --server-side -k "https://github.com/kubeflow/trainer.git/manifests/overlays/manager?ref=${VERSION}"
```

2. Verify the pods are running

   Check that the JobSet and Trainer controller managers are up in the kubeflow-system namespace.

```bash
kubectl get pods -n kubeflow-system
```

3. Install the Python SDK

   Install the Kubeflow SDK to talk to the Trainer APIs from Python.

```bash
pip install -U kubeflow
```

4. Submit a TrainJob

   List the available runtimes, then launch a CustomTrainer job with TrainerClient. Replace train_pytorch with your own training function.

```python
from kubeflow.trainer import TrainerClient, CustomTrainer

for r in TrainerClient().list_runtimes():
    print(f"Runtime: {r.name}")

job_id = TrainerClient().train(
    trainer=CustomTrainer(
        func=train_pytorch,
        num_nodes=4,
        resources_per_node={
            "cpu": 3,
            "memory": "16Gi",
            "gpu": 1,
        },
    )
)
```

## When to use it

- Fine-tune an LLM across several GPU nodes on a shared Kubernetes cluster
- Run distributed PyTorch or JAX training jobs without writing raw Kubernetes manifests
- Schedule multi-node MPI training on HPC hardware with queueing through Kueue
- Migrate existing Kubeflow Training Operator V1 workloads to the newer TrainJob API
