From 1ca5f4f70af1ea69df9e69ba8aecc840eb4a4b11 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Wed, 28 Aug 2024 10:38:31 +0200 Subject: [PATCH] added prebuilts common image --- prebuilts/Dockerfile | 56 ++++++++++++++++++++++++++++++++++++++ prebuilts/build.sh | 1 + prebuilts/extract_build.sh | 27 ++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 prebuilts/Dockerfile create mode 100755 prebuilts/build.sh create mode 100755 prebuilts/extract_build.sh diff --git a/prebuilts/Dockerfile b/prebuilts/Dockerfile new file mode 100644 index 0000000..ab69ad7 --- /dev/null +++ b/prebuilts/Dockerfile @@ -0,0 +1,56 @@ +FROM rocm/dev-ubuntu-22.04:6.1.2 + +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONUNBUFFERED=1 \ + PYTHONIOENCODING=UTF-8 \ + + # for bitsandbytes + ROCM_ARCH="gfx1030" \ + TORCH_VERSION="rocm6.1" \ + + # for llama + CMAKE_ARGS="-DGGML_HIPBLAS=on" \ + FORCE_CMAKE=1 + + +WORKDIR /tmp + +RUN apt-get update -y +RUN apt-get install -y wget git cron cmake make software-properties-common + +# Install python3.10 +RUN add-apt-repository ppa:deadsnakes/ppa -y && apt-get update -y +RUN apt-get install -y python3.10 python3.10-dev python3.10-venv + +ENV VIRTUAL_ENV=/opt/venv +RUN python3.10 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +RUN pip3 install --upgrade pip wheel setuptools build + +# Install pytorch for rocm +RUN pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/${TORCH_VERSION} + + +# ROCM bitsandbytes +RUN apt-get install -y hipblas hipblaslt hiprand hipsparse hipcub rocthrust-dev +## Clone repo and install python requirements +RUN git clone --depth 1 -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git +WORKDIR /tmp/bitsandbytes +RUN pip3 install -r requirements-dev.txt +## Build +RUN cmake -DCOMPUTE_BACKEND=hip -S . -DBNB_ROCM_ARCH=${ROCM_ARCH} +RUN make +RUN python3.10 setup.py bdist_wheel --universal + + +# ROCM llama-cpp-python +RUN apt-get install -y hipblas hipblaslt hiprand hipsparse hipcub rocthrust-dev +## Clone repo and install python requirements +RUN git clone --recurse-submodules https://github.com/abetlen/llama-cpp-python.git +WORKDIR /tmp/llama-cpp-python +RUN python3.10 -m build --wheel + + +# Cleanup +RUN apt-get clean && pip3 cache purge diff --git a/prebuilts/build.sh b/prebuilts/build.sh new file mode 100755 index 0000000..60c4523 --- /dev/null +++ b/prebuilts/build.sh @@ -0,0 +1 @@ +docker build . -t 'prebuilts-rocm:6.1.2' -f Dockerfile diff --git a/prebuilts/extract_build.sh b/prebuilts/extract_build.sh new file mode 100755 index 0000000..38dd117 --- /dev/null +++ b/prebuilts/extract_build.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Set variables +IMAGE_NAME="prebuilts-rocm:6.1.2" +CONTAINER_NAME="prebuilts-rocm" +FILES_TO_COPY=["/tmp/bitsandbytes/dist/", "/tmp/llama-cpp-python/dist/"] +WHERE_TO_PASTE="./build_output/" + +# Run the Docker container +docker run -d --name $CONTAINER_NAME $IMAGE_NAME + +# Check if the container is running +if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then + echo "Container $CONTAINER_NAME is running." + + # Copy the files from the container to the host + for file in $FILES_TO_COPY; do + docker cp $CONTAINER_NAME:$file $WHERE_TO_PASTE + done + + echo "Files copied to $WHERE_TO_PASTE." +else + echo "Failed to start container $CONTAINER_NAME." +fi + +docker stop $CONTAINER_NAME +docker rm $CONTAINER_NAME \ No newline at end of file