Skip to content

Commit

Permalink
Fix the CPU HRNet Nuclio function
Browse files Browse the repository at this point in the history
It was broken for two reasons:

* Due to some changes on the PyTorch website, the old way of installing the
  PyTorch packages now installs the ROCm version rather than the CPU version
  (and it doesn't work doe to a missing dependency).

* The newest version of NumPy doesn't work with HRNet due to the latter's usage
  of `np.int`.

Fix these problems, and in addition, rework the build recipe to avoid installing
unneeded packages. Altogether, the changes massively shrink the Docker image size
(from ~14 GB to ~2 GB).

I didn't update the GPU version, because a) the first issue doesn't affect
it, b) the second issue is already fixed in it, and c) I don't have a GPU to
test it on.
  • Loading branch information
SpecLad committed May 15, 2023
1 parent 2a41d59 commit 70d2c99
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions serverless/pytorch/saic-vul/hrnet/nuclio/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,28 @@ spec:

directives:
preCopy:
- kind: ENV
value: DEBIAN_FRONTEND=noninteractive
- kind: RUN
value: apt-get update && apt-get install software-properties-common -y
- kind: RUN
value: add-apt-repository ppa:deadsnakes/ppa
- kind: RUN
value: apt remove python* -y
- kind: RUN
value: apt-get update && apt-get install -y --no-install-recommends build-essential git curl libglib2.0-0 software-properties-common python3 python3.6-dev python3-pip python3-tk
- kind: RUN
value: ln -s /usr/bin/pip3 /usr/local/bin/pip && ln -s /usr/bin/python3 /usr/bin/python
value: |-
apt-get update \
&& apt-get install -y --no-install-recommends \
git libgl1-mesa-glx libglib2.0-0 python3 python3-pip python-is-python3 \
&& rm -rf /var/lib/apt/lists/*
- kind: RUN
value: pip3 install --upgrade pip
- kind: WORKDIR
value: /opt/nuclio
- kind: RUN
value: git clone https://github.com/saic-vul/ritm_interactive_segmentation.git hrnet
- kind: WORKDIR
value: /opt/nuclio/hrnet
- kind: RUN
value: apt-get install -y --no-install-recommends wget
- kind: RUN
value: wget https://github.com/saic-vul/ritm_interactive_segmentation/releases/download/v1.0/coco_lvis_h18_itermask.pth
- kind: RUN
value: pip3 install setuptools
- kind: RUN
value: pip3 install -r requirements.txt
- kind: RUN
value: apt update && apt install -y libgl1-mesa-glx
- kind: RUN
value: pip3 uninstall torch torch vision -y
value: git clone https://github.com/saic-vul/ritm_interactive_segmentation.git /opt/nuclio/hrnet
- kind: ADD
value: >-
https://github.com/saic-vul/ritm_interactive_segmentation/releases/download/v1.0/coco_lvis_h18_itermask.pth
/opt/nuclio/hrnet/
- kind: RUN
value: pip install torch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
# NumPy is capped due to https://github.com/SamsungLabs/ritm_interactive_segmentation/issues/36
value: |-
pip3 install --no-cache-dir \
-r /opt/nuclio/hrnet/requirements.txt \
torch==1.8.1+cpu torchvision==0.9.1+cpu \
'numpy<1.24' \
--extra-index-url=https://download.pytorch.org/whl/cpu
- kind: WORKDIR
value: /opt/nuclio

Expand Down

0 comments on commit 70d2c99

Please sign in to comment.