Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Docker image to run Pegasus with TensorFlow 1.15 and CUDA 10 #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM tensorflow/tensorflow:1.15.2-gpu

ARG USER=pegasus
ARG USER_UID=1000

RUN apt-get update && apt-get install -y \
wget \
git \
man \
nano

ENV CONDA_PATH /opt/conda
ENV PATH ${CONDA_PATH}/bin:${PATH}

RUN wget --quiet --no-check-certificate https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh \
&& echo "bb2e3cedd2e78a8bb6872ab3ab5b1266a90f8c7004a22d8dc2ea5effeb6a439a *Miniconda3-py37_4.8.3-Linux-x86_64.sh" | sha256sum -c - \
&& /bin/bash Miniconda3-py37_4.8.3-Linux-x86_64.sh -f -b -p ${CONDA_PATH} \
&& rm Miniconda3-py37_4.8.3-Linux-x86_64.sh \
&& echo export PATH=${CONDA_PATH}/bin:'${PATH}' > /etc/profile.d/conda.sh

RUN mkdir /src \
&& git clone https://github.com/google-research/pegasus /src/

RUN groupadd ${USER} && useradd -m -u ${USER_UID} -g ${USER} -s /bin/bash ${USER} \
&& chown -R ${USER_UID} /src \
&& chown -R ${USER_UID} ${CONDA_PATH}

USER ${USER}

# ENV PATH="/home/${USER}/.local/bin:$PATH"

ARG python_version=3.6

RUN conda config --append channels conda-forge
RUN conda install -y \
python=${python_version} \
notebook \
&& pip install --upgrade pip \
&& pip install \
six==1.14.0 \
protobuf==3.12.0 \
cloudpickle==1.2.0 \
gsutil \
&& pip install -r /src/requirements.txt

RUN mkdir /src/ckpt/

COPY docker_entrypoint.sh /src/

COPY bash.bashrc /etc/

WORKDIR /src

ENV PYTHONPATH="/src/:$PYTHONPATH"

ENTRYPOINT ["sh", "/src/docker_entrypoint.sh"]
CMD ["sh"]
23 changes: 23 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
help:
@cat Makefile

IMAGE=google/pegasus
PROJECT=pegasus
DOCKER_FILE=Dockerfile
SRC?=$(shell dirname `pwd`)
DATA?="${HOME}/Data"

build:
docker build -t $(IMAGE) -f $(DOCKER_FILE) .

bash: build
docker run --init -it --gpus all --hostname $(PROJECT)-run -v $(SRC):/src/workspace -v $(DATA):/data --mount type=volume,source=$(PROJECT)-data,target=/src/ckpt/ --name $(PROJECT)-run $(IMAGE) bash

ipython: build
docker run --init -it --gpus all --hostname $(PROJECT)-run -v $(SRC):/src/workspace -v $(DATA):/data --mount type=volume,source=$(PROJECT)-data,target=/src/ckpt/ --name $(PROJECT)-run $(IMAGE) ipython

notebook: build
docker run --init -it --gpus all --hostname $(PROJECT)-run -v $(SRC):/src/workspace -v $(DATA):/data --mount type=volume,source=$(PROJECT)-data,target=/src/ckpt/ --net=host --name $(PROJECT)-run $(IMAGE) jupyter notebook --port=8888 --ip=0.0.0.0

test: build
docker run --init -it --gpus all --hostname $(PROJECT)-run -v $(SRC):/src/workspace -v $(DATA):/data --mount type=volume,source=$(PROJECT)-data,target=/src/ckpt/ --name $(PROJECT) $(IMAGE) python3 pegasus/bin/train.py --params=aeslc_transformer --param_overrides=vocab_filename=ckpt/pegasus_ckpt/c4.unigram.newline.10pct.96000.model --train_init_checkpoint=ckpt/pegasus_ckpt/model.ckpt-1500000 --model_dir=ckpt/pegasus_ckpt/aeslc
41 changes: 41 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Using PEGASUS via Docker

This directory contains the `Dockerfile` to make it easy to get up and running with
PEGASUS via [Docker](http://www.docker.com/).

## Installing Docker

General installation instructions are
[on the Docker site](https://docs.docker.com/installation/).

## Installing GPU support

For GPU support install NVIDIA drivers (ideally the latest) and the [NVIDIA Container Toolkit](https://github.com/NVIDIA/nvidia-docker).

## Running the container

`Makefile` is used to simplify docker commands within `make` commands.

Build the container and start a bash

$ make bash

Build the container and start an iPython shell

$ make ipython

Build the container and start a Jupyter Notebook

$ make notebook

Build the container and start the finetuning test described in the repository's README:

$ make test

Mount a volume for external data sets

$ make DATA=~/mydata

Prints all make tasks

$ make help
39 changes: 39 additions & 0 deletions docker/bash.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# /etc/bash.bashrc
#

export PS1="\[\e[31m\]pegasus-docker\[\e[m\] \[\e[33m\]\w\[\e[m\] > "
export TERM=xterm-256color
alias grep="grep --color=auto"
alias ls="ls --color=auto"

echo -e "\e[1;31m"
cat<<P
__________
\______ \ ____ _________ ________ __ ______
| ___// __ \ / ___\__ \ / ___/ | \/ ___/
| | \ ___// /_/ > __ \_\___ \| | /\___ \
|____| \___ >___ (____ /____ >____//____ >
\/_____/ \/ \/ \/

P
echo -e "\e[0;33m"

if [[ $EUID -eq 0 ]]; then
cat <<WARN
WARNING: You are running this container as root, which can cause new files in
mounted volumes to be created as the root user on your host machine.

To avoid this, run the container by specifying your user's userid:

$ docker run -u \$(id -u):\$(id -g) args...
WARN
else
cat <<EXPL
You are running this container as user with ID $(id -u) and group $(id -g),
which should map to the ID and group for your user on the Docker host. Great!
EXPL
fi

# Turn off colors
echo -e "\e[m"
8 changes: 8 additions & 0 deletions docker/docker_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

if [ ! -d /src/ckpt/pegasus_ckpt/ ]
then
gsutil cp -r gs://pegasus_ckpt /src/ckpt/
fi

exec "$@"