datacomp/teaching_arithmetic
0
1# Documentation: https://huggingface.co/docs/hub/spaces-sdks-docker2FROM python:3.93 4# Create a non-root user and allow them to have appropriate permissions5# on our Space content6RUN useradd -m -u 1000 user7 8COPY --chown=user ./requirements.txt /requirements.txt9COPY --chown=user ./train.sh /train.sh10COPY --chown=user ./upload_results.py /upload_results.py11COPY --chown=user ./pause_space.py /pause_space.py12 13RUN chmod +x /train.sh14# May not need to do this. Just tired of permissions errors and going wild.15RUN chmod +x /upload_results.py16RUN chmod +x /pause_space.py17 18# Make the working directory for user.19RUN mkdir /app20 21# Start installing stuff as root so it doesn't complain about install permissions.22#RUN pip install --no-cache-dir --upgrade pip23RUN pip install --no-cache-dir --upgrade -r /requirements.txt24# Clone into the working directory for the user.25RUN git clone https://github.com/lee-ny/teaching_arithmetic.git /app/teaching_arithmetic26#&& cd teaching_arithmetic && pip install -e .27 28# Copy all files we have into the user's working directory.29COPY --chown=user . /app30# Kept getting permission denied errors when running train.py, which tries to31# create the out directory. Just doing this to try to help that.32RUN mkdir /app/teaching_arithmetic/out33RUN chmod -R 777 /app/34 35# Switch to the user profile.36# This will help make sure the permissions of the cloned git stuff37# don't require root privileges (I am guessing).38USER user39 40# Switch to the /app working directory.41WORKDIR /app42 43# Permissions. Permissions. Already did this. Doing it again anyway.44RUN chmod +x train.sh45RUN chmod +x upload_results.py46RUN chmod +x pause_space.py47 48# Expose the secret so it can be used later.49RUN --mount=type=secret,id=DATACOMP_TOKEN50#,mode=0444,required=true \51 52# Could also use CMD. Example:53# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]54ENTRYPOINT ["/train.sh"]55 56 57 58 59# Keeping these as FYI, commented out, as they are other things we could do.60#ENV PATH="/home/user/.local/bin:/opt/conda/bin:$PATH"61#ENV HOME="/home/user"62#WORKDIR $HOME/app63# We now install with requirements.txt64#ARG PYTORCH_VERSION=2.1.065#ARG PYTHON_VERSION=3.9 #8.1066#ARG CUDA_VERSION=11.867#ARG CU_DNN=8.5.0.9668#ARG MAMBA_VERSION=24.3.0-069#ARG CUDA_CHANNEL=nvidia70#ARG INSTALL_CHANNEL=pytorch71# Automatically set by buildx72#ARG TARGETPLATFORM73# Updating basic dependencies we'll be using.74#RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \75# build-essential \76# ca-certificates \77# ccache \78# curl \79# python3 \80# python3-pip \81# git && \82# rm -rf /var/lib/apt/lists/*83# Installing conda, translating Docker's TARGETPLATFORM into mamba arches84#RUN case ${TARGETPLATFORM} in \85# "linux/arm64") MAMBA_ARCH=aarch64 ;; \86# *) MAMBA_ARCH=x86_64 ;; \87# esac && \88# curl -fsSL -v -o ~/mambaforge.sh -O "https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-${MAMBA_ARCH}.sh"89#RUN chmod +x ~/mambaforge.sh && \90# bash ~/mambaforge.sh -b -p /opt/conda && \91# rm ~/mambaforge.sh92# Installing pytorch93# On arm64 we exit with an error code94#RUN case ${TARGETPLATFORM} in \95# "linux/arm64") exit 1 ;; \96# *) /opt/conda/bin/conda update -y conda && \97# /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y "python=${PYTHON_VERSION}" "pytorch=$PYTORCH_VERSION" "pytorch-cuda=$(echo $CUDA_VERSION | cut -d'.' -f 1-2)" ;; \98# esac && \99# /opt/conda/bin/conda clean -ya100# Expose the secret DEBUG at buildtime and use its value as git remote URL101#RUN --mount=type=secret,id=DEBUG,mode=0444,required=true \102# git init && \103# git remote add origin $(cat /run/secrets/DEBUG)104 