Last active
December 3, 2024 05:11
-
-
Save muaiyadh/d99923375f5d35b5b08e8369705fa41a to your computer and use it in GitHub Desktop.
Building CTranslate2 for Python 3.10 from arlo-phoenix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile for building CTranslate2 with ROCm support for Python 3.10 | |
# Tested with ROCm 6.2 and AMD RX 7900 XT (gfx1100) | |
# Source: https://github.com/arlo-phoenix/CTranslate2-rocm | |
FROM rocm/pytorch | |
# Set working directory for build | |
WORKDIR /build | |
# Activate conda environment for the rest of the commands | |
SHELL ["conda", "run", "-n", "py_3.10", "/bin/bash", "-c"] | |
RUN git clone https://github.com/arlo-phoenix/CTranslate2-rocm.git --recurse-submodules | |
WORKDIR /build/CTranslate2-rocm | |
# Optional: set the ROCm architecture | |
ENV PYTORCH_ROCM_ARCH=gfx1100 | |
RUN CLANG_CMAKE_CXX_COMPILER=clang++ CXX=clang++ HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \ | |
cmake -S . -B build -DWITH_MKL=OFF -DWITH_HIP=ON -DCMAKE_HIP_ARCHITECTURES=$PYTORCH_ROCM_ARCH -DBUILD_TESTS=ON -DWITH_CUDNN=ON | |
RUN cmake --build build -- -j8 | |
# Install compiled files | |
WORKDIR /build/CTranslate2-rocm/build | |
RUN cmake --install . --prefix /usr/local | |
RUN ldconfig | |
WORKDIR /build/CTranslate2-rocm/python | |
RUN pip install -r install_requirements.txt | |
# Modify setup.py as required | |
RUN sed -i 's|include_dirs = \[pybind11.get_include()\]|include_dirs = [pybind11.get_include(), "../include"]|' setup.py | |
RUN sed -i 's|library_dirs = \[\]|library_dirs = ["/usr/local/lib"]|' setup.py | |
RUN cp ../build/libctranslate2.so /usr/local/lib/ | |
RUN python setup.py bdist_wheel | |
RUN pip install dist/*.whl | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends libomp-dev && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* | |
# Create directory for user mounting | |
RUN mkdir -p /dockerx | |
# Set to run with conda environment initialized | |
ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "py_3.10", "/bin/bash"] | |
## Build using: | |
# docker build -t ctranslate2-rocm . | |
## Run using: | |
# docker run -it \ | |
# --network=host # Allows network access | |
# --device=/dev/kfd # ROCm kernel driver | |
# --device=/dev/dri # Direct rendering | |
# --group-add=video # GPU access | |
# --ipc=host # Shared memory | |
# --cap-add=SYS_PTRACE # For debugging | |
# --security-opt seccomp=unconfined \ | |
# --shm-size 8G # Shared memory size | |
# -v $HOME/dockerx:/dockerx # Mount local directory | |
# -w /dockerx # Set working directory | |
# ctranslate2-rocm | |
## Test the installation: | |
# python3 -c "import ctranslate2; print(ctranslate2.__version__)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment