Skip to content

Commit 92eaf77

Browse files
first version of dockerfile and workflow
1 parent a147137 commit 92eaf77

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

Diff for: .github/workflows/build.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build Docker Images
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
onmt_version:
7+
description: "OpenNMT version"
8+
required: true
9+
type: string
10+
# to facilitate initial tests in PR
11+
push:
12+
branches:
13+
- "docker"
14+
15+
run-name: ${{ format('{0}:{1}', github.workflow, inputs.onmt_version) }}
16+
17+
env:
18+
ONMT_VERSION: ${{ inputs.onmt_version || 'test' }}
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-22.04
23+
strategy:
24+
matrix:
25+
cuda_version: [11.8.0, 12.1.0]
26+
permissions:
27+
id-token: write
28+
contents: read
29+
steps:
30+
- name: Checkout opennmt repo
31+
uses: actions/checkout@v4
32+
- name: Login to ghcr
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ghcr.io
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
- name: Build
39+
run: |
40+
docker/build.sh ${{ env.ONMT_VERSION }} ${{ matrix.cuda_version}}

Diff for: docker/Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG CUDA_VERSION=11.8.0
2+
FROM nvidia/cuda:$CUDA_VERSION-devel-ubuntu22.04
3+
4+
RUN apt-get update && apt-get install -y locales gcc g++ python3-dev
5+
RUN apt-get update && apt-get install -y \
6+
git \
7+
python3-pip \
8+
python3-dev \
9+
libprotobuf-dev \
10+
libprotobuf-c-dev
11+
12+
RUN pip3 install --upgrade pip
13+
RUN pip3 install packaging
14+
15+
# Install torch
16+
RUN CU=$(echo "${CUDA_VERSION%.*}" | sed 's/\.//g'); pip3 install torch --index-url "https://download.pytorch.org/whl/cu$CU"
17+
18+
# Install apex
19+
RUN mkdir /setup
20+
WORKDIR /setup
21+
RUN git clone https://github.com/nvidia/apex
22+
WORKDIR /setup/apex
23+
RUN pip3 install ninja
24+
ENV TORCH_CUDA_ARCH_LIST="6.0;6.1;6.2;7.0;7.5;8.6"
25+
RUN pip3 install -v --no-build-isolation \
26+
--config-settings --global-option="--cpp_ext" \
27+
--config-settings --global-option="--cuda_ext" \
28+
--config-settings --global-option="--deprecated_fused_adam" \
29+
--global-option="--xentropy" \
30+
--global-option="--fast_multihead_attn" \
31+
./
32+
33+
COPY . /opennmt-py
34+
WORKDIR /opennmt-py
35+
RUN pip install -e .
36+
37+
WORKDIR /
38+
39+
ENTRYPOINT /bin/bash

Diff for: docker/build.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
#
3+
# Build and push version X of OpenNMT-py with CUDA Y:
4+
# ./build.sh X Y
5+
6+
set -e
7+
8+
# allow user to run this script from anywhere
9+
# from https://stackoverflow.com/a/246128
10+
# one-liner which will give you the full directory name
11+
# of the script no matter where it is being called from
12+
unset CDPATH
13+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
14+
15+
ROOT_DIR=$DIR/..
16+
cd $ROOT_DIR
17+
18+
ONMT_VERSION="$1"
19+
CUDA_VERSION="$2"
20+
[ -z "$CUDA_VERSION" ] && CUDA_VERSION="11.8.0"
21+
22+
IMAGE="ghcr.io/opennmt/opennmt-py"
23+
TAG="$ONMT_VERSION-ubuntu22.04-cuda${CUDA_VERSION%.*}"
24+
25+
echo "Building $IMAGE:$TAG with CUDA_VERSION=$CUDA_VERSION"
26+
27+
docker build -t $IMAGE:$TAG --progress=plain -f docker/Dockerfile --build-arg CUDA_VERSION=$CUDA_VERSION .
28+
docker push $IMAGE:$TAG

0 commit comments

Comments
 (0)