Skip to content

Commit 9258722

Browse files
Add docker dev setup and update requirements
1 parent 445ff24 commit 9258722

File tree

17 files changed

+109
-163
lines changed

17 files changed

+109
-163
lines changed

.devcontainer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile"
4+
},
5+
"workspaceFolder": "/workspace",
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=${localWorkspaceFolder},target=/workspace,type=bind"
20+
]
21+
}

.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,17 +15,19 @@ jobs:
1515
runs-on: ubuntu-latest
1616
timeout-minutes: 10
1717
steps:
18+
- name: Checkout code
1819
- uses: actions/checkout@v3
19-
- name: Install dependencies
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):/workspace 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
2931
env: { GITHUB_TOKEN: "${{ github.token }}" }
3032
with:
31-
build_dir: docs/_build/html
33+
build_dir: docker run --rm -v $(pwd):/workspace unit-scaling-dev:latest docs/_build/html

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+
# Set working directory
16+
WORKDIR /workspace
17+
18+
# Install Python dependencies
19+
COPY requirements-dev.txt .
20+
RUN pip install -r requirements-dev.txt
21+
22+
# Puts pip install libs on $PATH & sets correct locale
23+
ENV PATH="$PATH:/home/$USERNAME/.local/bin" \
24+
LC_ALL=en_US.UTF-8
25+
26+
# Configure a non-root user with sudo privileges
27+
ARG USERNAME=developer # Change this to preferred username
28+
ARG USER_UID=1000
29+
ARG USER_GID=$USER_UID
30+
RUN groupadd --gid $USER_GID $USERNAME \
31+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
32+
&& echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
33+
&& chmod 0440 /etc/sudoers.d/$USERNAME
34+
USER $USERNAME
35+
36+
# Creates basic .zshrc
37+
RUN sudo cp /etc/zsh/newuser.zshrc.recommended /home/$USERNAME/.zshrc
38+
39+
CMD ["/bin/zsh"]

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For users who wish to develop using this codebase, the following setup is requir
88
python3 -m venv .venv
99
echo "export PYTHONPATH=\${PYTHONPATH}:\$(dirname \${VIRTUAL_ENV})" >> .venv/bin/activate
1010
source .venv/bin/activate
11-
pip install -r requirements-dev.txt # Or requirements-dev-ipu.txt for the ipu
11+
pip install -r requirements-dev.txt
1212
```
1313

1414
**Subsequent setup**:

requirements-dev-ipu.txt

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

requirements-dev.txt

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
-r requirements.txt
2-
black==24.3.0
3-
flake8==6.0.0
4-
isort==5.12.0
5-
mypy==1.2.0
6-
myst-parser==1.0.0
7-
pandas-stubs==2.0.2.230605
8-
pytest==7.3.1
9-
pytest-cov==4.0.0
10-
sphinx==6.2.1
11-
sphinx-rtd-theme==1.2.0
12-
transformers==4.38.0
13-
types-Pygments==2.15.0.0
14-
types-tabulate==0.9.0.2
1+
# Look in pytorch-cpu first, then pypi second
2+
--index-url https://download.pytorch.org/whl/cpu
3+
--extra-index-url=https://pypi.org/simple
4+
5+
# Same as requirements.txt, but with versions locked-in
6+
datasets==3.1.0
7+
docstring-parser==0.16
8+
einops==0.8.0
9+
numpy==2.1.3
10+
seaborn==0.13.2
11+
tabulate==0.9.0
12+
torch==2.5.1+cpu
13+
14+
# Additional dev requirements
15+
black==24.10.0
16+
flake8==7.1.1
17+
isort==5.13.2
18+
mypy==1.13.0
19+
myst-parser==4.0.0
20+
pandas-stubs==2.2.3.241009
21+
pytest==8.3.3
22+
pytest-cov==6.0.0
23+
sphinx==8.1.3
24+
sphinx-rtd-theme==3.0.1
25+
transformers==4.46.1
26+
triton==3.1.0
27+
types-Pygments==2.18.0.20240506
28+
types-tabulate==0.9.0.20240106

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
datasets
22
docstring-parser
33
einops
4-
numpy<2.0
4+
numpy
55
seaborn
66
tabulate
77
torch>=2.2

0 commit comments

Comments
 (0)