Skip to content

Commit 1233af7

Browse files
committed
add dockerfile at root and update docs/benchmark to include docker instructions
1 parent 4c74b72 commit 1233af7

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM nvidia/cuda:11.2.1-base-ubuntu20.04
2+
RUN apt-get update && \
3+
apt-get install --no-install-recommends --no-install-suggests -y \
4+
curl python3 python3-pip
5+
WORKDIR /lambda_diffusers
6+
COPY . .
7+
RUN pip3 install --no-cache-dir -r requirements.txt
8+
CMD ["python3", "-u", "scripts/benchmark.py", "--samples", "1,2,4,8,16"]

docs/benchmark.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ Interestingly, such a difference may not imply artifacts in half-precision's out
8888

8989
You can use this [Lambda Diffusers](https://github.com/LambdaLabsML/lambda-diffusers) repository to reproduce the results presented in this article.
9090

91-
## Setup
91+
### From your local machine
92+
93+
#### Setup
9294

9395
Before running the benchmark, make sure you have completed the repository [installation steps](../README.md#installation).
9496

@@ -99,7 +101,7 @@ You will then need to set the huggingface access token:
99101
export ACCESS_TOKEN=<hf_...>
100102
```
101103

102-
## Usage
104+
#### Usage
103105

104106
Launch the `benchmark.py` script to append benchmark results to the existing [benchmark.csv](../benchmark.csv) results file:
105107
```
@@ -109,4 +111,72 @@ python ./scripts/benchmark.py
109111
Lauch the `benchmark_quality.py` script to compare the output of single-precision and half-precision models:
110112
```
111113
python ./scripts/benchmark_quality.py
112-
```
114+
```
115+
116+
117+
### From a docker container
118+
119+
The following instructions show how to run the benchmarking program from a docker container on Ubuntu.
120+
121+
## Prerequisites
122+
123+
### Get a huggingface access token
124+
125+
Create a huggingface account.
126+
Get a [huggingface access token](https://huggingface.co/docs/hub/security-tokens).
127+
128+
### Install NVIDIA docker
129+
130+
This section can be skipped if the environment already uses [Lambda Stack](https://lambdalabs.com/lambda-stack-deep-learning-software) or if the experiments are running on a [Lambda cloud](https://lambdalabs.com/service/gpu-cloud) instance as docker and `nvidia-container-toolkit` comes pre-installed in these cases.
131+
132+
We first install docker:
133+
```
134+
# Install
135+
sudo apt-get update
136+
sudo apt-get remove docker docker-engine docker.io -y
137+
sudo apt install containerd -y
138+
sudo apt install docker.io -y
139+
sudo systemctl start docker
140+
sudo systemctl enable docker
141+
# Test install
142+
docker --version
143+
# Put the user in the docker group
144+
sudo usermod -a -G docker $USER
145+
newgrp docker
146+
```
147+
148+
We install requirements to run docker containers leveraging NVIDIA GPUs:
149+
```
150+
# Install
151+
sudo apt install curl
152+
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
153+
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
154+
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
155+
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
156+
sudo systemctl restart docker
157+
# Test install
158+
sudo docker run --rm --gpus all nvidia/cuda:11.2.1-base-ubuntu20.04 nvidia-smi
159+
```
160+
161+
162+
3. Build the benchmark docker image
163+
164+
```
165+
docker build -t benchmark -f ./benchmarking/Dockerfile .
166+
```
167+
168+
## Running the benchmark
169+
170+
Set the HuggingFace access token as environment variable:
171+
```
172+
export ACCESS_TOKEN=<your-hugging-face-access-token-here>
173+
```
174+
175+
Run the benchmark program from the container and export the output `.csv` file to the host:
176+
```
177+
containerid=$(docker run --gpus all -e ACCESS_TOKEN=${ACCESS_TOKEN} -d --entrypoint "python3" benchmark:latest scripts/benchmark.py --samples=1,2,4,8,16) && \
178+
docker wait ${containerid} && \
179+
docker cp ${containerid}:/lambda_diffusers/benchmark_tmp.csv ./benchmark_tmp.csv
180+
```
181+
182+
*Note that the arguments `scripts/benchmark.py --samples=1,2,4,8,16` can be changed to point to a different script or use different arguments.*

0 commit comments

Comments
 (0)