From 36f5854f3fecdc35f088edb935040c4478c84d8c Mon Sep 17 00:00:00 2001 From: Zach Dunton Date: Mon, 15 Jan 2024 22:35:33 +0100 Subject: [PATCH 1/8] Dockerfile changes to build for ROCm --- Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6c5e27457382..9059b08922a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -ARG GO_VERSION=1.21 ARG IMAGE_TYPE=extras ARG BASE_IMAGE=ubuntu:22.04 @@ -6,6 +5,9 @@ ARG BASE_IMAGE=ubuntu:22.04 FROM ${BASE_IMAGE} as requirements-core ARG GO_VERSION=1.21.7 + +FROM golang:$GO_VERSION as requirements-core + ARG BUILD_TYPE ARG CUDA_MAJOR_VERSION=11 ARG CUDA_MINOR_VERSION=7 @@ -44,6 +46,10 @@ RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ ENV PATH /usr/local/cuda/bin:${PATH} +# HipBLAS requirements +ENV PATH /opt/rocm/bin:${PATH} +ENV ROCM_PATH=/opt/rocm + # OpenBLAS requirements and stable diffusion RUN apt-get install -y \ libopenblas-dev \ @@ -70,7 +76,7 @@ RUN curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmo apt-get install -y conda && apt-get clean ENV PATH="/root/.cargo/bin:${PATH}" -RUN pip install --upgrade pip +RUN apt-get install -y python3-pip && apt-get clean RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN apt-get install -y espeak-ng espeak && apt-get clean From 53352c037f6a5393bf652f75a7fd8ee17dae5490 Mon Sep 17 00:00:00 2001 From: Zach Dunton Date: Tue, 23 Jan 2024 20:16:39 +0100 Subject: [PATCH 2/8] Adjust linker flags for ROCm --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c63d46f86662..f0d4c30f848b 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ ifeq ($(BUILD_TYPE),hipblas) GPU_TARGETS ?= gfx900,gfx90a,gfx1030,gfx1031,gfx1100 AMDGPU_TARGETS ?= "$(GPU_TARGETS)" CMAKE_ARGS+=-DLLAMA_HIPBLAS=ON -DAMDGPU_TARGETS="$(AMDGPU_TARGETS)" -DGPU_TARGETS="$(GPU_TARGETS)" - CGO_LDFLAGS += -O3 --rtlib=compiler-rt -unwindlib=libgcc -lhipblas -lrocblas --hip-link + CGO_LDFLAGS += -O3 --rtlib=compiler-rt -unwindlib=libgcc -lhipblas -lrocblas --hip-link -L${ROCM_HOME}/lib/llvm/lib endif ifeq ($(BUILD_TYPE),metal) From 8fbb453b4534efd17b507ea44afd32e33b3cca87 Mon Sep 17 00:00:00 2001 From: Zach Dunton Date: Wed, 24 Jan 2024 00:50:47 +0100 Subject: [PATCH 3/8] Update conda env for diffusers and transformers to use ROCm pytorch --- Dockerfile | 1 + .../transformers/transformers-rocm.yml | 109 ++++++++++++++++++ backend/python/diffusers/Makefile | 8 +- backend/python/diffusers/diffusers-rocm.yml | 64 ++++++++++ backend/python/diffusers/diffusers.yml | 2 +- 5 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 backend/python/common-env/transformers/transformers-rocm.yml create mode 100644 backend/python/diffusers/diffusers-rocm.yml diff --git a/Dockerfile b/Dockerfile index 9059b08922a9..15e0cec01206 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,7 @@ ENV PATH /usr/local/cuda/bin:${PATH} # HipBLAS requirements ENV PATH /opt/rocm/bin:${PATH} ENV ROCM_PATH=/opt/rocm +ENV LD_LIBRARY_PATH=/opt/rocm/lib:/opt/rocm/llvm/lib # OpenBLAS requirements and stable diffusion RUN apt-get install -y \ diff --git a/backend/python/common-env/transformers/transformers-rocm.yml b/backend/python/common-env/transformers/transformers-rocm.yml new file mode 100644 index 000000000000..1f5d223623c3 --- /dev/null +++ b/backend/python/common-env/transformers/transformers-rocm.yml @@ -0,0 +1,109 @@ +name: transformers +channels: + - defaults +dependencies: + - _libgcc_mutex=0.1=main + - _openmp_mutex=5.1=1_gnu + - bzip2=1.0.8=h7b6447c_0 + - ca-certificates=2023.08.22=h06a4308_0 + - ld_impl_linux-64=2.38=h1181459_1 + - libffi=3.4.4=h6a678d5_0 + - libgcc-ng=11.2.0=h1234567_1 + - libgomp=11.2.0=h1234567_1 + - libstdcxx-ng=11.2.0=h1234567_1 + - libuuid=1.41.5=h5eee18b_0 + - ncurses=6.4=h6a678d5_0 + - openssl=3.0.11=h7f8727e_2 + - pip=23.2.1=py311h06a4308_0 + - python=3.11.5=h955ad1f_0 + - readline=8.2=h5eee18b_0 + - setuptools=68.0.0=py311h06a4308_0 + - sqlite=3.41.2=h5eee18b_0 + - tk=8.6.12=h1ccaba5_0 + - wheel=0.41.2=py311h06a4308_0 + - xz=5.4.2=h5eee18b_0 + - zlib=1.2.13=h5eee18b_0 + - pip: + - --pre + - --extra-index-url https://download.pytorch.org/whl/nightly/ + - accelerate==0.23.0 + - aiohttp==3.8.5 + - aiosignal==1.3.1 + - async-timeout==4.0.3 + - attrs==23.1.0 + - bark==0.1.5 + - boto3==1.28.61 + - botocore==1.31.61 + - certifi==2023.7.22 + - TTS==0.22.0 + - charset-normalizer==3.3.0 + - datasets==2.14.5 + - sentence-transformers==2.2.2 + - sentencepiece==0.1.99 + - dill==0.3.7 + - einops==0.7.0 + - encodec==0.1.1 + - filelock==3.12.4 + - frozenlist==1.4.0 + - fsspec==2023.6.0 + - funcy==2.0 + - grpcio==1.59.0 + - huggingface-hub + - idna==3.4 + - jinja2==3.1.2 + - jmespath==1.0.1 + - markupsafe==2.1.3 + - mpmath==1.3.0 + - multidict==6.0.4 + - multiprocess==0.70.15 + - networkx + - numpy==1.26.0 + - packaging==23.2 + - pandas + - peft==0.5.0 + - protobuf==4.24.4 + - psutil==5.9.5 + - pyarrow==13.0.0 + - python-dateutil==2.8.2 + - pytz==2023.3.post1 + - pyyaml==6.0.1 + - regex==2023.10.3 + - requests==2.31.0 + - rouge==1.0.1 + - s3transfer==0.7.0 + - safetensors==0.3.3 + - scipy==1.11.3 + - six==1.16.0 + - sympy==1.12 + - tokenizers + - torch + - torchaudio + - tqdm==4.66.1 + - triton==2.1.0 + - typing-extensions==4.8.0 + - tzdata==2023.3 + - auto-gptq==0.6.0 + - urllib3==1.26.17 + - xxhash==3.4.1 + - yarl==1.9.2 + - soundfile + - langid + - wget + - unidecode + - pyopenjtalk-prebuilt + - pypinyin + - inflect + - cn2an + - jieba + - eng_to_ipa + - openai-whisper + - matplotlib + - gradio==3.41.2 + - nltk + - sudachipy + - sudachidict_core + - vocos + - vllm==0.2.7 + - transformers>=4.36.0 # Required for Mixtral. + - xformers==0.0.23.post1 +prefix: /opt/conda/envs/transformers diff --git a/backend/python/diffusers/Makefile b/backend/python/diffusers/Makefile index 4ec03c710359..70a62b60daa9 100644 --- a/backend/python/diffusers/Makefile +++ b/backend/python/diffusers/Makefile @@ -1,4 +1,8 @@ -CONDA_ENV_PATH = "diffusers.yml" +export CONDA_ENV_PATH = "diffusers.yml" + +ifeq ($(BUILD_TYPE), hipblas) +export CONDA_ENV_PATH = "diffusers-rocm.yml" +endif .PHONY: diffusers diffusers: @@ -12,4 +16,4 @@ run: @echo "Diffusers run." test: - bash test.sh \ No newline at end of file + bash test.sh diff --git a/backend/python/diffusers/diffusers-rocm.yml b/backend/python/diffusers/diffusers-rocm.yml new file mode 100644 index 000000000000..f261701dbb36 --- /dev/null +++ b/backend/python/diffusers/diffusers-rocm.yml @@ -0,0 +1,64 @@ +name: diffusers +channels: + - defaults +dependencies: + - _libgcc_mutex=0.1=main + - _openmp_mutex=5.1=1_gnu + - bzip2=1.0.8=h7b6447c_0 + - ca-certificates=2023.08.22=h06a4308_0 + - ld_impl_linux-64=2.38=h1181459_1 + - libffi=3.4.4=h6a678d5_0 + - libgcc-ng=11.2.0=h1234567_1 + - libgomp=11.2.0=h1234567_1 + - libstdcxx-ng=11.2.0=h1234567_1 + - libuuid=1.41.5=h5eee18b_0 + - ncurses=6.4=h6a678d5_0 + - openssl=3.0.11=h7f8727e_2 + - pip=23.2.1=py311h06a4308_0 + - python=3.11.5=h955ad1f_0 + - readline=8.2=h5eee18b_0 + - setuptools=68.0.0=py311h06a4308_0 + - sqlite=3.41.2=h5eee18b_0 + - tk=8.6.12=h1ccaba5_0 + - tzdata=2023c=h04d1e81_0 + - wheel=0.41.2=py311h06a4308_0 + - xz=5.4.2=h5eee18b_0 + - zlib=1.2.13=h5eee18b_0 + - pip: + - --pre + - --extra-index-url https://download.pytorch.org/whl/nightly/ + - accelerate>=0.11.0 + - certifi==2023.7.22 + - charset-normalizer==3.3.0 + - compel==2.0.2 + - diffusers==0.24.0 + - filelock==3.12.4 + - fsspec==2023.9.2 + - grpcio==1.59.0 + - huggingface-hub>=0.19.4 + - idna==3.4 + - importlib-metadata==6.8.0 + - jinja2==3.1.2 + - markupsafe==2.1.3 + - mpmath==1.3.0 + - networkx==3.1 + - numpy==1.26.0 + - omegaconf + - packaging==23.2 + - pillow==10.0.1 + - protobuf==4.24.4 + - psutil==5.9.5 + - pyparsing==3.1.1 + - pyyaml==6.0.1 + - regex==2023.10.3 + - requests==2.31.0 + - safetensors==0.4.0 + - sympy==1.12 + - tqdm==4.66.1 + - transformers>=4.25.1 + - triton==2.1.0 + - typing-extensions==4.8.0 + - urllib3==2.0.6 + - zipp==3.17.0 + - torch +prefix: /opt/conda/envs/diffusers diff --git a/backend/python/diffusers/diffusers.yml b/backend/python/diffusers/diffusers.yml index a37f41d9c439..b1a7d9f971b2 100644 --- a/backend/python/diffusers/diffusers.yml +++ b/backend/python/diffusers/diffusers.yml @@ -71,4 +71,4 @@ dependencies: - typing-extensions==4.8.0 - urllib3==2.0.6 - zipp==3.17.0 -prefix: /opt/conda/envs/diffusers \ No newline at end of file +prefix: /opt/conda/envs/diffusers From 2a8477c989c94c8a9389676b1507d15d6b71d84c Mon Sep 17 00:00:00 2001 From: Zach Dunton Date: Wed, 24 Jan 2024 01:12:32 +0100 Subject: [PATCH 4/8] Update transformers conda env for ROCm --- backend/python/common-env/transformers/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/python/common-env/transformers/Makefile b/backend/python/common-env/transformers/Makefile index 47a5ba25db91..1cd71ab177d3 100644 --- a/backend/python/common-env/transformers/Makefile +++ b/backend/python/common-env/transformers/Makefile @@ -4,6 +4,10 @@ ifeq ($(BUILD_TYPE), cublas) CONDA_ENV_PATH = "transformers-nvidia.yml" endif +ifeq ($(BUILD_TYPE), hipblas) + CONDA_ENV_PATH = "transformers-rocm.yml" +endif + .PHONY: transformers transformers: @echo "Installing $(CONDA_ENV_PATH)..." From e70b3860d36b279f0ebadfd63cdd96649ed93458 Mon Sep 17 00:00:00 2001 From: mudler Date: Wed, 14 Feb 2024 23:38:12 +0100 Subject: [PATCH 5/8] ci: build hipblas images --- .github/workflows/image-pr.yml | 8 ++++++++ .github/workflows/image.yml | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 2 ++ 3 files changed, 42 insertions(+) diff --git a/.github/workflows/image-pr.yml b/.github/workflows/image-pr.yml index ae8bd070a125..793353dbe952 100644 --- a/.github/workflows/image-pr.yml +++ b/.github/workflows/image-pr.yml @@ -51,6 +51,14 @@ jobs: image-type: 'extras' runs-on: 'arc-runner-set' base-image: "ubuntu:22.04" + - build-type: 'hipblas' + platforms: 'linux/amd64' + tag-latest: 'false' + tag-suffix: '-hipblas' + ffmpeg: 'false' + image-type: 'extras' + base-image: "rocm/dev-ubuntu-22.04:6.0-complete" + runs-on: 'ubuntu-latest' core-image-build: uses: ./.github/workflows/image_build.yml with: diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index ac61deeca6e8..ee509a9d7711 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -103,6 +103,22 @@ jobs: image-type: 'extras' base-image: "ubuntu:22.04" runs-on: 'arc-runner-set' + - build-type: 'hipblas' + platforms: 'linux/amd64' + tag-latest: 'false' + tag-suffix: '-hipblas-ffmpeg' + ffmpeg: 'true' + image-type: 'extras' + base-image: "rocm/dev-ubuntu-22.04:6.0-complete" + runs-on: 'ubuntu-latest' + - build-type: 'hipblas' + platforms: 'linux/amd64' + tag-latest: 'false' + tag-suffix: '-hipblas' + ffmpeg: 'false' + image-type: 'extras' + base-image: "rocm/dev-ubuntu-22.04:6.0-complete" + runs-on: 'ubuntu-latest' core-image-build: uses: ./.github/workflows/image_build.yml with: @@ -124,6 +140,22 @@ jobs: strategy: matrix: include: + - build-type: 'hipblas' + platforms: 'linux/amd64' + tag-latest: 'false' + tag-suffix: '-hipblas-ffmpeg-core' + ffmpeg: 'true' + image-type: 'core' + base-image: "rocm/dev-ubuntu-22.04:6.0-complete" + runs-on: 'ubuntu-latest' + - build-type: 'hipblas' + platforms: 'linux/amd64' + tag-latest: 'false' + tag-suffix: '-hipblas-core' + ffmpeg: 'false' + image-type: 'core' + base-image: "rocm/dev-ubuntu-22.04:6.0-complete" + runs-on: 'ubuntu-latest' - build-type: '' platforms: 'linux/amd64' tag-latest: 'false' diff --git a/Dockerfile b/Dockerfile index 15e0cec01206..92b6a3f45da6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,6 +78,8 @@ RUN curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmo ENV PATH="/root/.cargo/bin:${PATH}" RUN apt-get install -y python3-pip && apt-get clean +RUN pip install --upgrade pip + RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN apt-get install -y espeak-ng espeak && apt-get clean From 97fd4213ea82488dd360b56c8382f71664bf4eb5 Mon Sep 17 00:00:00 2001 From: mudler Date: Wed, 14 Feb 2024 23:47:59 +0100 Subject: [PATCH 6/8] fixup rebase --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 92b6a3f45da6..d784bc29959e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,9 +5,6 @@ ARG BASE_IMAGE=ubuntu:22.04 FROM ${BASE_IMAGE} as requirements-core ARG GO_VERSION=1.21.7 - -FROM golang:$GO_VERSION as requirements-core - ARG BUILD_TYPE ARG CUDA_MAJOR_VERSION=11 ARG CUDA_MINOR_VERSION=7 From 853d8d1840654277ef8710ff7a231acf1aedc2ab Mon Sep 17 00:00:00 2001 From: mudler Date: Thu, 15 Feb 2024 17:53:48 +0100 Subject: [PATCH 7/8] use self-hosted Signed-off-by: mudler --- .github/workflows/image-pr.yml | 2 +- .github/workflows/image.yml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/image-pr.yml b/.github/workflows/image-pr.yml index 793353dbe952..527a8479ee39 100644 --- a/.github/workflows/image-pr.yml +++ b/.github/workflows/image-pr.yml @@ -58,7 +58,7 @@ jobs: ffmpeg: 'false' image-type: 'extras' base-image: "rocm/dev-ubuntu-22.04:6.0-complete" - runs-on: 'ubuntu-latest' + runs-on: 'arc-runner-set' core-image-build: uses: ./.github/workflows/image_build.yml with: diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index ee509a9d7711..830528a1a18a 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -110,7 +110,7 @@ jobs: ffmpeg: 'true' image-type: 'extras' base-image: "rocm/dev-ubuntu-22.04:6.0-complete" - runs-on: 'ubuntu-latest' + runs-on: 'arc-runner-set' - build-type: 'hipblas' platforms: 'linux/amd64' tag-latest: 'false' @@ -118,7 +118,7 @@ jobs: ffmpeg: 'false' image-type: 'extras' base-image: "rocm/dev-ubuntu-22.04:6.0-complete" - runs-on: 'ubuntu-latest' + runs-on: 'arc-runner-set' core-image-build: uses: ./.github/workflows/image_build.yml with: @@ -147,7 +147,7 @@ jobs: ffmpeg: 'true' image-type: 'core' base-image: "rocm/dev-ubuntu-22.04:6.0-complete" - runs-on: 'ubuntu-latest' + runs-on: 'arc-runner-set' - build-type: 'hipblas' platforms: 'linux/amd64' tag-latest: 'false' @@ -155,7 +155,7 @@ jobs: ffmpeg: 'false' image-type: 'core' base-image: "rocm/dev-ubuntu-22.04:6.0-complete" - runs-on: 'ubuntu-latest' + runs-on: 'arc-runner-set' - build-type: '' platforms: 'linux/amd64' tag-latest: 'false' From 752033ff828e3ab97e1c498362c025aafec9d80f Mon Sep 17 00:00:00 2001 From: mudler Date: Thu, 15 Feb 2024 17:56:16 +0100 Subject: [PATCH 8/8] specify LD_LIBRARY_PATH only when BUILD_TYPE=hipblas --- Dockerfile | 3 +-- Makefile | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d784bc29959e..a04a866ec7d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,12 +41,11 @@ RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ apt-get install -y cuda-nvcc-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcurand-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcusparse-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcusolver-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} && apt-get clean \ ; fi +# Cuda ENV PATH /usr/local/cuda/bin:${PATH} # HipBLAS requirements ENV PATH /opt/rocm/bin:${PATH} -ENV ROCM_PATH=/opt/rocm -ENV LD_LIBRARY_PATH=/opt/rocm/lib:/opt/rocm/llvm/lib # OpenBLAS requirements and stable diffusion RUN apt-get install -y \ diff --git a/Makefile b/Makefile index f0d4c30f848b..31434e50a949 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,8 @@ endif ifeq ($(BUILD_TYPE),hipblas) ROCM_HOME ?= /opt/rocm + ROCM_PATH ?= /opt/rocm + LD_LIBRARY_PATH ?= /opt/rocm/lib:/opt/rocm/llvm/lib export CXX=$(ROCM_HOME)/llvm/bin/clang++ export CC=$(ROCM_HOME)/llvm/bin/clang # llama-ggml has no hipblas support, so override it here.