-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pytorch): Support elastic training #1453
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e704497
chore: Update codegen and vendor
gaocegege be25172
fix: Update git config
gaocegege 04538cc
fix: Codegen
gaocegege 3790fd2
feat: Add elastic examples
gaocegege 284e980
chore: Update go mod
gaocegege fd03f1b
chore: Update manifest
gaocegege 00a5c89
feat: Implement elstic policy
gaocegege 8e2db9c
chore: Update vendor
gaocegege 877110d
chore: Update swagger
gaocegege 2940450
fix: Address comments
gaocegege File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -i https://mirror.sjtu.edu.cn/pypi/web/simple 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: gaocegege/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 -i https://mirror.sjtu.edu.cn/pypi/web/simple classy-vision | ||
gaocegege marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
gaocegege marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can share one. And u do not need one if you are using c10d