Manually Downloading Models in docker build with snapshot_download

@mostafa-samir git-lfs clone the model into the dockerfile as a buildstage. The copy --from in the next stage discards the intermediate steps form the prior stage. Here’s mine for an AWS Lambda function:

FROM public.ecr.aws/lambda/python:3.9 AS model
RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | bash
RUN yum install git-lfs -y
RUN git lfs install
RUN git clone https://huggingface.co/ccdv/lsg-bart-base-4096-wcep /tmp/model
RUN rm -rf /tmp/model/.git

FROM public.ecr.aws/lambda/python:3.9
ARG FUNCTION_DIR="/var/task"
RUN mkdir -p ${FUNCTION_DIR}
COPY summarize.py ${FUNCTION_DIR}
COPY --from=model /tmp/model ${FUNCTION_DIR}/model
RUN pip install --no-cache-dir transformers[torch]==4.21.2
CMD [ "summarize.main" ]
3 Likes