Skip to content

Commit

Permalink
Fix logging in the TransT serverless function
Browse files Browse the repository at this point in the history
The Docker image for this function includes Conda, and uses `conda run` to
run the Nuclio processor. Unfortunately, `conda run` buffers the entire output
of the child process until that process exits, and since the processor never exits,
its logs are never printed (and slowly consume memory).

Conda is actually completely useless here, so just get rid of it, which fixes
the problem.

In addition, apply a few other improvements:

* Synchronize the PyTorch and TransT versions between the CPU and GPU
  variants.

* Replace `opencv-python` with `opencv-python-headless`, which has fewer
  dependencies.

* Use the `ADD` command instead of wget.

Altogether, these improvements shave ~780 MB off the size of the CPU image
(didn't check for the GPU one).
  • Loading branch information
SpecLad committed Jun 13, 2023
1 parent 3b3f9ca commit cf3efbf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 61 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- \[API\] The `predefined` sorting method for task data uploads (<https://github.com/opencv/cvat/pull/5083>)
- Allowed slashes in export filenames. (<https://github.com/opencv/cvat/pull/6265>)
- Dataset export error with `outside` property of tracks (<https://github.com/opencv/cvat/issues/5971>)
- Broken logging in the TransT serverless function
(<https://github.com/opencv/cvat/pull/6290>)

## \[2.4.5] - 2023-06-02
### Added
Expand Down
48 changes: 17 additions & 31 deletions serverless/pytorch/dschoerk/transt/nuclio/function-gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,28 @@ spec:

directives:
preCopy:
- kind: ENV
value: PATH="/root/miniconda3/bin:${PATH}"
- kind: ARG
value: PATH="/root/miniconda3/bin:${PATH}"
- kind: RUN
value: rm -f /etc/apt/sources.list.d/cuda.list /etc/apt/sources.list.d/nvidia-ml.list
- kind: RUN
value: apt update && apt install -y --no-install-recommends wget git ca-certificates libglib2.0-0 libgl1 && rm -rf /var/lib/apt/lists/* # libxrender1 libxext6
- kind: RUN
value: wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh &&
chmod +x Miniconda3-latest-Linux-x86_64.sh && bash Miniconda3-latest-Linux-x86_64.sh -b &&
rm -f Miniconda3-latest-Linux-x86_64.sh
value: |-
apt update \
&& apt install -y --no-install-recommends \
git \
ca-certificates \
python-is-python3 \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
- kind: WORKDIR
value: /opt/nuclio
- kind: RUN
value: conda create -y -n transt python=3.8
- kind: SHELL
value: '["conda", "run", "-n", "transt", "/bin/bash", "-c"]'
- kind: RUN
value: git clone https://github.com/dschoerk/TransT trans-t

- kind: RUN
value: pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 -f https://download.pytorch.org/whl/torch_stable.html

- kind: RUN
value: pip install jsonpickle opencv-python

- kind: RUN
value: wget --no-check-certificate 'https://drive.google.com/uc?id=1Pq0sK-9jmbLAVtgB9-dPDc2pipCxYdM5' -O /transt.pth

- kind: RUN
value: apt remove -y git wget
value: git clone --depth 1 --branch v1.0 https://github.com/dschoerk/TransT trans-t
- kind: RUN
value: cd trans-t
- kind: ENTRYPOINT
value: '["conda", "run", "-n", "transt"]'
value: |-
pip install \
jsonpickle opencv-python-headless \
torch==1.7.1+cu110 torchvision==0.8.2+cu110 \
--extra-index-url https://download.pytorch.org/whl/cu110
- kind: ADD
value: https://drive.google.com/uc?id=1Pq0sK-9jmbLAVtgB9-dPDc2pipCxYdM5 /transt.pth

triggers:
myHttpTrigger:
Expand Down
46 changes: 16 additions & 30 deletions serverless/pytorch/dschoerk/transt/nuclio/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,28 @@ spec:

directives:
preCopy:
- kind: ENV
value: PATH="/root/miniconda3/bin:${PATH}"
- kind: ARG
value: PATH="/root/miniconda3/bin:${PATH}"
- kind: RUN
value: rm -f /etc/apt/sources.list.d/cuda.list /etc/apt/sources.list.d/nvidia-ml.list
- kind: RUN
value: apt update && apt install -y --no-install-recommends wget git ca-certificates libglib2.0-0 libgl1 && rm -rf /var/lib/apt/lists/* # libxrender1 libxext6
- kind: RUN
value: wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh &&
chmod +x Miniconda3-latest-Linux-x86_64.sh && bash Miniconda3-latest-Linux-x86_64.sh -b &&
rm -f Miniconda3-latest-Linux-x86_64.sh
value: |-
apt update \
&& apt install -y --no-install-recommends \
git \
ca-certificates \
python-is-python3 \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
- kind: WORKDIR
value: /opt/nuclio
- kind: RUN
value: conda create -y -n transt python=3.8
- kind: SHELL
value: '["conda", "run", "-n", "transt", "/bin/bash", "-c"]'
- kind: RUN
value: git clone --depth 1 --branch v1.0 https://github.com/dschoerk/TransT trans-t

- kind: RUN
value: pip install torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

- kind: RUN
value: pip install jsonpickle opencv-python

- kind: RUN
value: wget --no-check-certificate 'https://drive.google.com/uc?id=1Pq0sK-9jmbLAVtgB9-dPDc2pipCxYdM5' -O /transt.pth

- kind: RUN
value: apt remove -y git wget
- kind: RUN
value: cd trans-t
- kind: ENTRYPOINT
value: '["conda", "run", "-n", "transt"]'
value: |-
pip install \
jsonpickle opencv-python-headless \
torch==1.7.1+cpu torchvision==0.8.2+cpu \
--extra-index-url https://download.pytorch.org/whl/cpu
- kind: ADD
value: https://drive.google.com/uc?id=1Pq0sK-9jmbLAVtgB9-dPDc2pipCxYdM5 /transt.pth

triggers:
myHttpTrigger:
Expand Down

0 comments on commit cf3efbf

Please sign in to comment.