Skip to content

Commit 8fe2bd2

Browse files
authored
Training: Reorganized Training Operator Docs (#3719)
* Training: Reorganized Training Operator Docs Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Create reference page Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Update links for TensorFlow Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Fix more links Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Fix links in getting started Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Modify Getting Started Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Add stable status notice to overview page Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Add Why Training Operator Section Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Fix Lifecycle Diagram Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Change text font Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Add working example Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Add 2nd version for AI/ML lifecycle Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Update AI/ML Lifecycle Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Fix install command Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> * Remove old diagram Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com> --------- Signed-off-by: Andrey Velichkevich <andrey.velichkevich@gmail.com>
1 parent 32a95ba commit 8fe2bd2

20 files changed

Lines changed: 551 additions & 499 deletions

‎content/en/_redirects‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ docs/started/requirements/ /docs/started/getting-started/
8181
/docs/components/seldon /docs/external-add-ons/serving/seldon
8282
/docs/components/trtinferenceserver /docs/external-add-ons/serving/tritoninferenceserver
8383
/docs/components/tfbatchpredict /docs/external-add-ons/serving/tfbatchpredict
84-
/docs/components/tftraining /docs/components/training/tftraining
84+
/docs/components/tftraining /docs/components/training/user-guides/tensorflow
85+
/docs/components/training/pytorch /docs/components/training/user-guides/pytorch
86+
/docs/components/training/mpi /docs/components/training/user-guides/mpi
87+
/docs/components/training/mxnet /docs/components/training/user-guides/mxnet
88+
/docs/components/training/paddlepaddle /docs/components/training/user-guides/paddle
89+
/docs/components/training/xgboost /docs/components/training/user-guides/xgboost
90+
/docs/components/training/tftraining /docs/components/training/user-guides/tensorflow
8591
/docs/components/tfserving_new /docs/external-add-ons/serving/tfserving_new
8692

8793
# Deleted the PyTorch serving page

‎content/en/docs/components/katib/experiment.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ These are the fields in the experiment configuration spec:
142142

143143
- [Kubernetes `Job`](https://kubernetes.io/docs/concepts/workloads/controllers/job/)
144144

145-
- [Kubeflow `TFJob`](/docs/components/training/tftraining/)
145+
- [Kubeflow `TFJob`](/docs/components/training/user-guides/tensorflow/)
146146

147-
- [Kubeflow `PyTorchJob`](/docs/components/training/pytorch/)
147+
- [Kubeflow `PyTorchJob`](/docs/components/training/user-guides/pytorch/)
148148

149-
- [Kubeflow `MXJob`](/docs/components/training/mxnet)
149+
- [Kubeflow `MXJob`](/docs/components/training/user-guides/mxnet/)
150150

151-
- [Kubeflow `XGBoostJob`](/docs/components/training/xgboost)
151+
- [Kubeflow `XGBoostJob`](/docs/components/training/user-guides/xgboost/)
152152

153-
- [Kubeflow `MPIJob`](/docs/components/training/mpi)
153+
- [Kubeflow `MPIJob`](/docs/components/training/user-guides/mpi/)
154154

155155
- [Tekton `Pipelines`](https://github.com/kubeflow/katib/tree/master/examples/v1beta1/tekton)
156156

@@ -802,7 +802,6 @@ For more information, check:
802802
- The DARTS example —
803803
[`darts-gpu.yaml`](https://github.com/kubeflow/katib/blob/master/examples/v1beta1/nas/darts-gpu.yaml).
804804

805-
806805
<a id="pbt"></a>
807806

808807
#### Population Based Training (PBT)

‎content/en/docs/components/katib/hyperparameter.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ an experiment using the random search example:
271271
trial template, annotation should be under
272272
[`.trialSpec.spec.template.metadata.annotations`](https://github.com/kubeflow/katib/blob/master/examples/v1beta1/hp-tuning/random.yaml#L52).
273273
For the Kubeflow `TFJob` or other training operators check
274-
[here](/docs/components/training/tftraining/#what-is-tfjob)
274+
[here](/docs/components/training/user-guides/tensorflow/#what-is-tfjob)
275275
how to set the annotation.
276276
277277
1. Deploy the example:
@@ -483,7 +483,7 @@ View the results of the experiment in the Katib UI:
483483

484484
If you installed Katib as part of Kubeflow, you can’t run experiments in the
485485
Kubeflow namespace. Run the following commands to launch an experiment using
486-
the Kubeflow's [TensorFlow training job operator](/docs/components/training/tftraining), `TFJob`:
486+
the Kubeflow's [TensorFlow training job operator](/docs/components/training/user-guides/tensorflow/), `TFJob`:
487487
488488
1. Download `tfjob-mnist-with-summaries.yaml`:
489489
@@ -504,7 +504,7 @@ the Kubeflow's [TensorFlow training job operator](/docs/components/training/tftr
504504
Istio, you have to disable sidecar injection. To do that, specify this annotation:
505505
`sidecar.istio.io/inject: "false"` in your experiment's trial template.
506506
For the provided `TFJob` example check
507-
[here](/docs/components/training/tftraining/#what-is-tfjob)
507+
[here](/docs/components/training/user-guides/tensorflow/#what-is-tfjob)
508508
how to set the annotation.
509509

510510
1. Deploy the example:
@@ -526,7 +526,7 @@ Follow the steps as described for the _random search algorithm example_
526526

527527
If you installed Katib as part of Kubeflow, you can’t run experiments in the
528528
Kubeflow namespace. Run the following commands to launch an experiment
529-
using Kubeflow's [PyTorch training job operator](/docs/components/training/pytorch), `PyTorchJob`:
529+
using Kubeflow's [PyTorch training job operator](/docs/components/training/user-guides/pytorch), `PyTorchJob`:
530530
531531
1. Download `pytorchjob-mnist.yaml`:
532532
@@ -547,7 +547,7 @@ using Kubeflow's [PyTorch training job operator](/docs/components/training/pytor
547547
Istio, you have to disable sidecar injection. To do that, specify this annotation:
548548
`sidecar.istio.io/inject: "false"` in your experiment's trial template.
549549
For the provided `PyTorchJob` example setting the annotation should be similar to
550-
[`TFJob`](/docs/components/training/tftraining/#what-is-tfjob)
550+
[`TFJob`](/docs/components/training/user-guides/tensorflow/#what-is-tfjob)
551551

552552
1. Deploy the example:
553553

‎content/en/docs/components/katib/overview.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ Katib has these CRD examples in upstream:
127127

128128
- [Kubernetes `Job`](https://kubernetes.io/docs/concepts/workloads/controllers/job/)
129129

130-
- [Kubeflow `TFJob`](/docs/components/training/tftraining/)
130+
- [Kubeflow `TFJob`](/docs/components/training/user-guides/tensorflow/)
131131

132-
- [Kubeflow `PyTorchJob`](/docs/components/training/pytorch/)
132+
- [Kubeflow `PyTorchJob`](/docs/components/training/user-guides/pytorch/)
133133

134-
- [Kubeflow `MXJob`](/docs/components/training/mxnet)
134+
- [Kubeflow `MXJob`](/docs/components/training/user-guides/mxnet/)
135135

136-
- [Kubeflow `XGBoostJob`](/docs/components/training/xgboost)
136+
- [Kubeflow `XGBoostJob`](/docs/components/training/user-guides/xgboost/)
137137

138-
- [Kubeflow `MPIJob`](/docs/components/training/mpi)
138+
- [Kubeflow `MPIJob`](/docs/components/training/user-guides/mpi/)
139139

140140
- [Tekton `Pipelines`](https://github.com/kubeflow/katib/tree/master/examples/v1beta1/tekton)
141141

‎content/en/docs/components/katib/trial-template.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ Katib has these CRD examples in upstream:
1616

1717
- [Kubernetes `Job`](https://kubernetes.io/docs/concepts/workloads/controllers/job/)
1818

19-
- [Kubeflow `TFJob`](/docs/components/training/tftraining/)
19+
- [Kubeflow `TFJob`](/docs/components/training/user-guides/tensorflow/)
2020

21-
- [Kubeflow `PyTorchJob`](/docs/components/training/pytorch/)
21+
- [Kubeflow `PyTorchJob`](/docs/components/training/user-guides/pytorch/)
2222

23-
- [Kubeflow `MXJob`](/docs/components/training/mxnet)
23+
- [Kubeflow `MXJob`](/docs/components/training/user-guides/mxnet)
2424

25-
- [Kubeflow `XGBoostJob`](/docs/components/training/xgboost)
25+
- [Kubeflow `XGBoostJob`](/docs/components/training/user-guides/xgboost)
2626

27-
- [Kubeflow `MPIJob`](/docs/components/training/mpi)
27+
- [Kubeflow `MPIJob`](/docs/components/training/user-guides/mpi)
2828

2929
- [Tekton `Pipelines`](https://github.com/kubeflow/katib/tree/master/examples/v1beta1/tekton)
3030

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
+++
2+
title = "Getting Started"
3+
description = "Get started with Training Operator"
4+
weight = 30
5+
+++
6+
7+
This guide describes how to get started with Training Operator and run a few simple examples.
8+
9+
## Prerequisites
10+
11+
You need to install the following components to run examples:
12+
13+
- Training Operator [installed](/docs/components/training/installation/#installing-training-operator).
14+
- Training Python SDK [installed](/docs/components/training/installation/#installing-training-python-sdk).
15+
16+
## Getting Started with PyTorchJob
17+
18+
You can create your first Training Operator distributed PyTorchJob using Python SDK. Define the
19+
training function that implements end-to-end model training. Each Worker will execute this
20+
function on the appropriate Kubernetes Pod. Usually, this function contains logic to
21+
download dataset, create model, and train the model.
22+
23+
Training Operator will automatically set `WORLD_SIZE` and `RANK` for the appropriate PyTorchJob
24+
worker to perform [PyTorch Distributed Data Parallel (DDP)](https://pytorch.org/tutorials/intermediate/ddp_tutorial.html).
25+
26+
For example:
27+
28+
```python
29+
def train_func():
30+
import torch
31+
import torch.nn.functional as F
32+
from torch.utils.data import DistributedSampler
33+
from torchvision import datasets, transforms
34+
35+
# [1] Setup PyTorch DDP. WORLD_SIZE and RANK environments will be set by Training Operator.
36+
torch.distributed.init_process_group(backend="nccl")
37+
Distributor = torch.nn.parallel.DistributedDataParallel
38+
39+
# [2] Create PyTorch CNN Model.
40+
class Net(torch.nn.Module):
41+
def __init__(self):
42+
super(Net, self).__init__()
43+
self.conv1 = torch.nn.Conv2d(1, 20, 5, 1)
44+
self.conv2 = torch.nn.Conv2d(20, 50, 5, 1)
45+
self.fc1 = torch.nn.Linear(4 * 4 * 50, 500)
46+
self.fc2 = torch.nn.Linear(500, 10)
47+
48+
def forward(self, x):
49+
x = F.relu(self.conv1(x))
50+
x = F.max_pool2d(x, 2, 2)
51+
x = F.relu(self.conv2(x))
52+
x = F.max_pool2d(x, 2, 2)
53+
x = x.view(-1, 4 * 4 * 50)
54+
x = F.relu(self.fc1(x))
55+
x = self.fc2(x)
56+
return F.log_softmax(x, dim=1)
57+
58+
# [3] Attach model to GPU and distributor.
59+
device = "cuda"
60+
model = Net().to(device)
61+
model = Distributor(model)
62+
optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.5)
63+
64+
# [4] Setup FashionMNIST dataloader and distribute data across PyTorchJob workers.
65+
dataset = datasets.FashionMNIST(
66+
"./data",
67+
download=True,
68+
train=True,
69+
transform=transforms.Compose([transforms.ToTensor()]),
70+
)
71+
train_loader = torch.utils.data.DataLoader(
72+
dataset=dataset,
73+
batch_size=128,
74+
sampler=DistributedSampler(dataset),
75+
)
76+
77+
# [5] Start model Training.
78+
for epoch in range(3):
79+
for batch_idx, (data, target) in enumerate(train_loader):
80+
# Attach Tensors to the device.
81+
data = data.to(device)
82+
target = target.to(device)
83+
84+
optimizer.zero_grad()
85+
output = model(data)
86+
loss = F.nll_loss(output, target)
87+
loss.backward()
88+
optimizer.step()
89+
if batch_idx % 10 == 0:
90+
print(
91+
"Train Epoch: {} [{}/{} ({:.0f}%)]\tloss={:.4f}".format(
92+
epoch,
93+
batch_idx * len(data),
94+
len(train_loader.dataset),
95+
100.0 * batch_idx / len(train_loader),
96+
loss.item(),
97+
)
98+
)
99+
100+
101+
from kubeflow.training import TrainingClient
102+
103+
# Start PyTorchJob with 3 Workers and 1 GPUs per Worker.
104+
TrainingClient().create_job(
105+
name="pytorch-ddp",
106+
train_func=train_func,
107+
num_workers=3,
108+
resources_per_worker={"gpu": "1"},
109+
)
110+
```
111+
112+
## Getting Started with TFJob
113+
114+
Similar to PyTorchJob example, you can use the Python SDK to create your first distributed
115+
TensorFlow job. Run the following script to create TFJob with pre-created Docker image:
116+
`docker.io/kubeflow/tf-mnist-with-summaries:latest` that contains
117+
[distributed TensorFlow code](https://github.com/kubeflow/training-operator/tree/e6b4300f9dfebb5c2a3269641c828add367688ee/examples/tensorflow/mnist_with_summaries):
118+
119+
```python
120+
from kubeflow.training import TrainingClient
121+
122+
TrainingClient().create_job(
123+
name="tensorflow-dist",
124+
job_kind="TFJob",
125+
base_image="docker.io/kubeflow/tf-mnist-with-summaries:latest",
126+
num_workers=3,
127+
)
128+
```
129+
130+
Run the following API to get logs from your TFJob:
131+
132+
```python
133+
TrainingClient().get_job_logs(
134+
name="tensorflow-dist",
135+
job_kind="TFJob",
136+
follow=True,
137+
)
138+
```
139+
140+
## Next steps
141+
142+
- Run [FashionMNIST example](https://github.com/kubeflow/training-operator/blob/7345e33b333ba5084127efe027774dd7bed8f6e6/examples/pytorch/image-classification/Train-CNN-with-FashionMNIST.ipynb) with using Training Operator Python SDK.
143+
144+
- Learn more about [the PyTorchJob APIs](/docs/components/training/user-guides/pytorch/).

‎content/en/docs/components/training/images/ml-lifecycle-training-operator.drawio.svg‎

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
+++
2+
title = "Installation"
3+
description = "How to install Training Operator"
4+
weight = 20
5+
+++
6+
7+
This guide describes how to install Training Operator on your Kubernetes cluster.
8+
Training Operator is a lightweight Kubernetes controller that orchestrates appropriate Kubernetes
9+
workloads to perform distributed ML training and fine-tuning.
10+
11+
## Prerequisites
12+
13+
These are minimal requirements to install Training Operator:
14+
15+
- Kubernetes >= 1.27
16+
- `kubectl` >= 1.27
17+
18+
## Installing Training Operator
19+
20+
You can skip these steps if you have already
21+
[installed Kubeflow platform](https://www.kubeflow.org/docs/started/installing-kubeflow/#how-to-install-kubeflow)
22+
using manifests or package distributions. Kubeflow platform includes Training Operator.
23+
24+
You can install Training Operator as a standalone component.
25+
26+
Run the following command to install the stable release of Training Operator: `v1.7.0`
27+
28+
```shell
29+
kubectl apply -k "github.com/kubeflow/training-operator.git/manifests/overlays/standalone?ref=v1.7.0"
30+
```
31+
32+
Run the following command to install the latest changes of Training Operator:
33+
34+
```shell
35+
kubectl apply -k "github.com/kubeflow/training-operator.git/manifests/overlays/standalone?ref=master"
36+
```
37+
38+
After installing Training Operator, you can verify that controller is running as follows:
39+
40+
```shell
41+
$ kubectl get pods -n kubeflow
42+
43+
NAME READY STATUS RESTARTS AGE
44+
training-operator-658c68d697-46zmn 1/1 Running 0 90s
45+
```
46+
47+
Run this command to check installed Kubernetes CRDs for each supported ML framework:
48+
49+
```shell
50+
$ kubectl get crd
51+
52+
mpijobs.kubeflow.org 2023-06-09T00:31:07Z
53+
mxjobs.kubeflow.org 2023-06-09T00:31:05Z
54+
paddlejobs.kubeflow.org 2023-06-09T00:31:09Z
55+
pytorchjobs.kubeflow.org 2023-06-09T00:31:06Z
56+
tfjobs.kubeflow.org 2023-06-09T00:31:04Z
57+
xgboostjobs.kubeflow.org 2023-06-09T00:31:04Z
58+
```
59+
60+
## Installing Training Python SDK
61+
62+
Training Operator [implements Python SDK](https://pypi.org/project/kubeflow-training/)
63+
to simplify creation of distributed training and fine-tuning jobs for Data Scientists.
64+
65+
Run the following command to install the stable release of Training Operator SDK:
66+
67+
```shell
68+
pip install -U kubeflow-training
69+
```
70+
71+
You can also install the Python SDK using the specific GitHub commit, for example:
72+
73+
```shell
74+
pip install git+https://github.com/kubeflow/training-operator.git@7345e33b333ba5084127efe027774dd7bed8f6e6#subdirectory=sdk/python
75+
```
76+
77+
### Install Python SDK with Fine-Tuning Capabilities
78+
79+
If you want to use `train` API for LLM fine-tuning with Training Operator, install the Python SDK
80+
with the additional packages from HuggingFace:
81+
82+
```shell
83+
pip install -U kubeflow-training[huggingface]
84+
```
85+
86+
## Next steps
87+
88+
Run your first Training Operator Job by following the [Getting Started guide](/docs/components/training/getting-started/).

0 commit comments

Comments
 (0)