Skip to content

Commit bcc3d5e

Browse files
Merge pull request #78 from graphcore-research/docker-dev
Add docker dev setup and update requirements
2 parents 445ff24 + 7a1f767 commit bcc3d5e

File tree

19 files changed

+127
-210
lines changed

19 files changed

+127
-210
lines changed

.devcontainer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile"
4+
},
5+
"workspaceFolder": "/home/developer/unit-scaling",
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"ms-python.python",
10+
"ms-toolsai.jupyter"
11+
],
12+
"settings": {
13+
"terminal.integrated.defaultProfile.linux": "zsh",
14+
"terminal.integrated.profiles.linux": { "zsh": { "path": "/bin/zsh" } }
15+
}
16+
}
17+
},
18+
"mounts": [
19+
"source=${localEnv:HOME}/.ssh,target=/home/developer/.ssh,type=bind,readonly=true",
20+
"source=${localEnv:HOME}/.gitconfig,target=/home/developer/.gitconfig,type=bind,readonly=true",
21+
"source=${localWorkspaceFolder},target=/home/developer/unit-scaling,type=bind"
22+
],
23+
"remoteUser": "developer"
24+
}

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!requirements*.txt

.github/workflows/ci-ipu.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ jobs:
1515
runs-on: ubuntu-latest
1616
timeout-minutes: 10
1717
steps:
18-
- uses: actions/checkout@v3
19-
- name: Install dependencies
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Build Docker Image
2022
run: |
21-
sudo apt-get update
22-
sudo apt-get install -y git
23-
pip install -r requirements-dev.txt
23+
docker build -t unit-scaling-dev:latest .
24+
2425
- name: Run CI
25-
run: ./dev ci
26+
run: docker run --rm -v $(pwd):/home/developer/unit-scaling unit-scaling-dev:latest ./dev ci
27+
2628
- name: Publish documentation
2729
if: ${{github.ref == 'refs/heads/main'}}
2830
uses: Cecilapp/GitHub-Pages-deploy@v3

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Use PyTorch base image
2+
FROM pytorch/pytorch:latest
3+
4+
# Install additional dependencies
5+
RUN apt-get update && apt-get install -y \
6+
git \
7+
vim \
8+
sudo \
9+
make \
10+
g++ \
11+
zsh \
12+
&& chsh -s /bin/zsh \
13+
&& apt-get clean && rm -rf /var/lib/apt/lists/* # cleanup (smaller image)
14+
15+
# Configure a non-root user with sudo privileges
16+
ARG USERNAME=developer # Change this to preferred username
17+
ARG USER_UID=1001
18+
ARG USER_GID=$USER_UID
19+
RUN groupadd --gid $USER_GID $USERNAME \
20+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
21+
&& echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
22+
&& chmod 0440 /etc/sudoers.d/$USERNAME
23+
USER $USERNAME
24+
25+
# Set working directory
26+
WORKDIR /home/$USERNAME/unit-scaling
27+
28+
# Puts pip install libs on $PATH & sets correct locale
29+
ENV PATH="$PATH:/home/$USERNAME/.local/bin" \
30+
LC_ALL=C.UTF-8
31+
32+
# Install Python dependencies
33+
COPY requirements-dev.txt .
34+
RUN pip install -r requirements-dev.txt
35+
36+
# Creates basic .zshrc
37+
RUN sudo cp /etc/zsh/newuser.zshrc.recommended /home/$USERNAME/.zshrc
38+
39+
CMD ["/bin/zsh"]

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ To install the `unit-scaling` library, run:
1717
pip install git+https://github.com/graphcore-research/unit-scaling.git
1818
```
1919

20-
For development on this repository, see [docs/development.md](docs/development.md).
20+
## Development
21+
22+
For development in this repository, we recommend using the provided docker container.
23+
This image can be built and entered interactively using:
24+
25+
```sh
26+
docker build -t unit-scaling-dev:latest .
27+
docker run -it --rm --user developer:developer -v $(pwd):/home/developer/unit-scaling unit-scaling-dev:latest
28+
# To use git within the container, add `-v ~/.ssh:/home/developer/.ssh:ro -v ~/.gitconfig:/home/developer/.gitconfig:ro`.
29+
```
30+
31+
For vscode users, this repo also contains a `.devcontainer.json` file, which enables the container to be used as a full-featured IDE (see the [Dev Container docs](https://code.visualstudio.com/docs/devcontainers/containers) for details on how to use this feature).
32+
33+
Key development functionality is contained within the `./dev` script. This includes running unit tests, linting, formatting, documentation generation and more. Run `./dev --help` for the available options. Running `./dev` without arguments is equivalent to using the `--ci` option, which runs all of the available dev checks. This is the test used for GitHub CI.
34+
35+
We encourage pull requests from the community. Please reach out to us with any questions about contributing.
2136

2237
## What is u-μP?
2338

analysis/almost_scaled_dot_product_attention/demo_transformer.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
from torch import nn, Tensor
1111
import tqdm
1212

13-
try:
14-
import poptorch
15-
16-
poptorch_available = True
17-
except ModuleNotFoundError:
18-
poptorch_available = False
19-
2013

2114
class Config(dict):
2215
def __init__(self, *args: Any, **kwargs: Any):
@@ -132,7 +125,7 @@ def forward(self, indices: Tensor) -> Tensor:
132125
)
133126

134127

135-
def train_cpu() -> Tensor:
128+
def train() -> Tensor:
136129
model = Model()
137130
opt = torch.optim.Adam(model.parameters(), lr=CONFIG.lr)
138131
losses = []
@@ -143,26 +136,3 @@ def train_cpu() -> Tensor:
143136
opt.step()
144137
losses.append(float(loss))
145138
return torch.tensor(losses)
146-
147-
148-
def train_ipu() -> Tensor:
149-
model = Model()
150-
options = poptorch.Options()
151-
options.showCompilationProgressBar(False)
152-
opt = torch.optim.Adam(model.parameters(), lr=CONFIG.lr)
153-
session = poptorch.trainingModel(model, options, opt)
154-
try:
155-
return torch.tensor(
156-
[
157-
float(session(batch.int()))
158-
for batch in tqdm.tqdm(
159-
islice(batches(), CONFIG.steps), total=CONFIG.steps
160-
)
161-
]
162-
)
163-
finally:
164-
session.destroy()
165-
166-
167-
def train() -> Tensor:
168-
return train_ipu() if poptorch_available else train_cpu()

docs/development.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs/user_guide.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ The advantage of using a unit-scaled model is as follows:
5555
scales have stayed within range for all unit-scaled models tested thus far.
5656
3. This can enable the use of smaller, more efficient number formats out-of-the-box,
5757
such as FP16 and even FP8.
58-
4. As the behaviour of some ops depends on scale, unit-scaling a model can change its
59-
training dynamics slightly. In some experiments this has been shown to lead to
60-
loss decreasing faster, though further work is needed to validate this.
61-
62-
For a more in-depth treatment of unit scaling, see our paper
63-
`Unit Scaling: Out-of-the-Box Low-Precision Training (ICML, 2023)
64-
<https://arxiv.org/abs/2303.11257>`_.
6558

6659

6760
How to unit-scale a model

requirements-dev-ipu.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)