Dockerfile.rocm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # default base image
  2. ARG BASE_IMAGE="rocm/pytorch:rocm6.0_ubuntu20.04_py3.9_pytorch_2.1.1"
  3. FROM $BASE_IMAGE
  4. ARG BASE_IMAGE="rocm/pytorch:rocm6.0_ubuntu20.04_py3.9_pytorch_2.1.1"
  5. RUN echo "Base image is $BASE_IMAGE"
  6. # BASE_IMAGE for ROCm_5.7: "rocm/pytorch:rocm5.7_ubuntu22.04_py3.10_pytorch_2.0.1"
  7. # BASE_IMAGE for ROCm_6.0: "rocm/pytorch:rocm6.0_ubuntu20.04_py3.9_pytorch_2.1.1"
  8. ARG FA_GFX_ARCHS="gfx90a;gfx942"
  9. RUN echo "FA_GFX_ARCHS is $FA_GFX_ARCHS"
  10. ARG FA_BRANCH="ae7928c"
  11. RUN echo "FA_BRANCH is $FA_BRANCH"
  12. # whether to build flash-attention
  13. # if 0, will not build flash attention
  14. # this is useful for gfx target where flash-attention is not supported
  15. # In that case, we need to use the python reference attention implementation in aphrodite
  16. ARG BUILD_FA="1"
  17. # whether to build triton on rocm
  18. ARG BUILD_TRITON="1"
  19. # Install some basic utilities
  20. RUN apt-get update && apt-get install python3 python3-pip -y
  21. # Install some basic utilities
  22. RUN apt-get update && apt-get install -y \
  23. curl \
  24. ca-certificates \
  25. sudo \
  26. git \
  27. bzip2 \
  28. libx11-6 \
  29. build-essential \
  30. wget \
  31. unzip \
  32. nvidia-cuda-toolkit \
  33. tmux \
  34. && rm -rf /var/lib/apt/lists/*
  35. ### Mount Point ###
  36. # When launching the container, mount the code directory to /app
  37. ARG APP_MOUNT=/aphrodite-workspace
  38. VOLUME [ ${APP_MOUNT} ]
  39. WORKDIR ${APP_MOUNT}
  40. RUN python3 -m pip install --upgrade pip
  41. RUN python3 -m pip install --no-cache-dir fastapi ninja tokenizers pandas
  42. ENV LLVM_SYMBOLIZER_PATH=/opt/rocm/llvm/bin/llvm-symbolizer
  43. ENV PATH=$PATH:/opt/rocm/bin:/libtorch/bin:
  44. ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib/:/libtorch/lib:
  45. ENV CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/libtorch/include:/libtorch/include/torch/csrc/api/include/:/opt/rocm/include/:
  46. # Allow build servers to limit ninja build jobs. For reference
  47. # see https://github.com/PygmalionAI/aphrodite-engine/wiki/1.-Installation#build-from-source
  48. ARG MAX_JOBS
  49. ENV MAX_JOBS=${MAX_JOBS}
  50. # Install ROCm flash-attention
  51. RUN if [ "$BUILD_FA" = "1" ]; then \
  52. mkdir libs \
  53. && cd libs \
  54. && git clone https://github.com/ROCm/flash-attention.git \
  55. && cd flash-attention \
  56. && git checkout ${FA_BRANCH} \
  57. && git submodule update --init \
  58. && export GPU_ARCHS=${FA_GFX_ARCHS} \
  59. && if [ "$BASE_IMAGE" = "rocm/pytorch:rocm5.7_ubuntu22.04_py3.10_pytorch_2.0.1" ]; then \
  60. patch /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/utils/hipify/hipify_python.py hipify_patch.patch; fi \
  61. && python3 setup.py install \
  62. && cd ..; \
  63. fi
  64. # Error related to odd state for numpy 1.20.3 where there is no METADATA etc, but an extra LICENSES_bundled.txt.
  65. # Manually removed it so that later steps of numpy upgrade can continue
  66. RUN if [ "$BASE_IMAGE" = "rocm/pytorch:rocm6.0_ubuntu20.04_py3.9_pytorch_2.1.1" ]; then \
  67. rm -rf /opt/conda/envs/py_3.9/lib/python3.9/site-packages/numpy-1.20.3.dist-info/; fi
  68. # build triton
  69. RUN if [ "$BUILD_TRITON" = "1" ]; then \
  70. mkdir -p libs \
  71. && cd libs \
  72. && pip uninstall -y triton \
  73. && git clone https://github.com/ROCm/triton.git \
  74. && cd triton/python \
  75. && pip3 install . \
  76. && cd ../..; \
  77. fi
  78. WORKDIR /aphrodite-workspace
  79. COPY . .
  80. RUN python3 -m pip install --upgrade pip numba
  81. # make sure punica kernels are built (for LoRA)
  82. ENV APHRODITE_INSTALL_PUNICA_KERNELS=1
  83. # make sure hadamard kernels aren't build
  84. ENV APHRODITE_INSTALL_HADAMARD_KERNELS=0
  85. RUN --mount=type=cache,target=/root/.cache/pip \
  86. pip install -U -r requirements-rocm.txt \
  87. && patch /opt/rocm/include/hip/amd_detail/amd_hip_bf16.h ./rocm_patch/rocm_bf16.patch \
  88. && python3 setup.py install \
  89. && cp build/lib.linux-x86_64-cpython-39/aphrodite/_C.cpython-39-x86_64-linux-gnu.so aphrodite/ \
  90. && cd ..
  91. RUN python3 -m pip install --upgrade pip
  92. RUN python3 -m pip install --no-cache-dir ray[all]==2.9.3
  93. # Service UID needs write access to $HOME to create temporary folders, see #458
  94. RUN chown 1000:1000 ${HOME}
  95. CMD ["/bin/bash"]