-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pytorch): Support elastic training (#1453)
* chore: Update codegen and vendor Signed-off-by: Ce Gao <ce.gao@outlook.com> * fix: Update git config Signed-off-by: Ce Gao <ce.gao@outlook.com> * fix: Codegen Signed-off-by: Ce Gao <ce.gao@outlook.com> * feat: Add elastic examples Signed-off-by: Ce Gao <ce.gao@outlook.com> * chore: Update go mod Signed-off-by: Ce Gao <ce.gao@outlook.com> * chore: Update manifest Signed-off-by: Ce Gao <ce.gao@outlook.com> * feat: Implement elstic policy Signed-off-by: Ce Gao <ce.gao@outlook.com> * chore: Update vendor Signed-off-by: Ce Gao <ce.gao@outlook.com> * chore: Update swagger Signed-off-by: Ce Gao <ce.gao@outlook.com> * fix: Address comments Signed-off-by: Ce Gao <ce.gao@outlook.com>
- Loading branch information
Showing
62 changed files
with
3,997 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.8-buster | ||
WORKDIR /workspace | ||
RUN pip install torch==1.10.0 numpy | ||
# TODO Replace this with the PIP version when available | ||
ADD echo.py echo.py | ||
ENV PYTHONPATH /workspace | ||
ENV ALLOW_NONE_AUTHENTICATION yes | ||
ENTRYPOINT ["python", "-m", "torch.distributed.run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
import io | ||
import os | ||
import pprint | ||
import sys | ||
import time | ||
|
||
import torch.distributed as dist | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
env_dict = { | ||
k: os.environ[k] | ||
for k in ( | ||
"LOCAL_RANK", | ||
"RANK", | ||
"GROUP_RANK", | ||
"WORLD_SIZE", | ||
"MASTER_ADDR", | ||
"MASTER_PORT", | ||
"TORCHELASTIC_RESTART_COUNT", | ||
"TORCHELASTIC_MAX_RESTARTS", | ||
) | ||
} | ||
|
||
with io.StringIO() as buff: | ||
print("======================================================", file=buff) | ||
print( | ||
f"Environment variables set by the agent on PID {os.getpid()}:", file=buff | ||
) | ||
pprint.pprint(env_dict, stream=buff) | ||
print("======================================================", file=buff) | ||
print(buff.getvalue()) | ||
sys.stdout.flush() | ||
|
||
dist.init_process_group(backend="gloo") | ||
dist.barrier() | ||
|
||
print( | ||
( | ||
f"On PID {os.getpid()}, after init process group, " | ||
f"rank={dist.get_rank()}, world_size = {dist.get_world_size()}\n" | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apiVersion: "kubeflow.org/v1" | ||
kind: PyTorchJob | ||
metadata: | ||
name: elastic-example-echo | ||
spec: | ||
elasticPolicy: | ||
rdzvBackend: c10d | ||
minReplicas: 1 | ||
maxReplicas: 2 | ||
maxRestarts: 100 | ||
pytorchReplicaSpecs: | ||
Worker: | ||
replicas: 2 | ||
template: | ||
spec: | ||
containers: | ||
- name: pytorch | ||
image: kubeflow/pytorch-elastic-example-echo:1.0.0 | ||
imagePullPolicy: IfNotPresent | ||
env: | ||
- name: LOGLEVEL | ||
value: DEBUG | ||
command: | ||
- python | ||
- -m | ||
- torch.distributed.run | ||
- --rdzv_backend=c10d | ||
- ./echo.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: etcd-client | ||
spec: | ||
ports: | ||
- name: etcd-client-port | ||
port: 2379 | ||
protocol: TCP | ||
targetPort: 2379 | ||
selector: | ||
app: etcd | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
labels: | ||
app: etcd | ||
etcd_node: etcd-server | ||
name: etcd-server | ||
spec: | ||
containers: | ||
- command: | ||
- /usr/local/bin/etcd | ||
- --data-dir | ||
- /var/lib/etcd | ||
- --enable-v2 | ||
- --name | ||
- etcd-server | ||
- --initial-advertise-peer-urls | ||
- http://etcd-server:2380 | ||
- --listen-peer-urls | ||
- http://0.0.0.0:2380 | ||
- --listen-client-urls | ||
- http://0.0.0.0:2379 | ||
- --advertise-client-urls | ||
- http://etcd-server:2379 | ||
- --initial-cluster | ||
- etcd-server=http://etcd-server:2380 | ||
- --initial-cluster-state | ||
- new | ||
image: quay.io/coreos/etcd:latest | ||
name: etcd-server | ||
ports: | ||
- containerPort: 2379 | ||
name: client | ||
protocol: TCP | ||
- containerPort: 2380 | ||
name: server | ||
protocol: TCP | ||
restartPolicy: Always | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
etcd_node: etcd-server | ||
name: etcd-server | ||
spec: | ||
ports: | ||
- name: client | ||
port: 2379 | ||
protocol: TCP | ||
targetPort: 2379 | ||
- name: server | ||
port: 2380 | ||
protocol: TCP | ||
targetPort: 2380 | ||
selector: | ||
etcd_node: etcd-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
ARG BASE_IMAGE=pytorch/pytorch:1.10.0-cuda11.3-cudnn8-runtime | ||
FROM $BASE_IMAGE | ||
|
||
# install utilities and dependencies | ||
RUN pip install classy-vision | ||
|
||
WORKDIR /workspace | ||
|
||
# download imagenet tiny for data | ||
RUN apt-get -q update && apt-get -q install -y wget unzip | ||
RUN wget -q http://cs231n.stanford.edu/tiny-imagenet-200.zip && unzip -q tiny-imagenet-200.zip -d data && rm tiny-imagenet-200.zip | ||
|
||
COPY . ./examples | ||
RUN chmod -R u+x ./examples/bin | ||
ENV PATH=/workspace/examples/bin:${PATH} | ||
|
||
# create a template classy project in /workspace/classy_vision | ||
# (see https://classyvision.ai/#quickstart) | ||
RUN classy-project classy_vision | ||
|
||
USER root | ||
ENTRYPOINT ["python", "-m", "torch.distributed.run"] | ||
CMD ["--help"] |
Oops, something went wrong.