alessandro trinca tornidor commited on
Commit
d326f12
1 Parent(s): e960bd5

ci: revert to docker sdk, bump pytorch docker image to pytorch:2.4.1-cuda12.4-cudnn9-runtime

Browse files
Files changed (3) hide show
  1. Dockerfile +207 -0
  2. README.md +1 -2
  3. pyproject.toml +2 -2
Dockerfile ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Include global ARGs at the dockerfile top
2
+ ARG ARCH="x86_64"
3
+ ARG LAMBDA_TASK_ROOT="/var/task"
4
+ ARG FASTAPI_STATIC="${LAMBDA_TASK_ROOT}/static"
5
+ ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
6
+ ARG POETRY_NO_INTERACTION=1
7
+ ARG POETRY_VIRTUALENVS_IN_PROJECT=1
8
+ ARG POETRY_VIRTUALENVS_CREATE=1
9
+ ARG POETRY_CACHE_DIR=/tmp/poetry_cache
10
+ ARG DEPENDENCY_GROUP=fastapi
11
+
12
+
13
+ FROM pytorch/pytorch:2.4.1-cuda12.4-cudnn9-runtime as builder_global
14
+
15
+ LABEL authors="alessandro@trinca.tornidor.com"
16
+
17
+ ARG ARCH
18
+ ARG LAMBDA_TASK_ROOT
19
+ ARG PYTHONPATH
20
+ ARG POETRY_NO_INTERACTION
21
+ ARG POETRY_VIRTUALENVS_IN_PROJECT
22
+ ARG POETRY_VIRTUALENVS_CREATE
23
+ ARG POETRY_CACHE_DIR
24
+ ARG DEPENDENCY_GROUP
25
+
26
+ RUN echo "ARCH: $ARCH ..."
27
+
28
+ RUN echo "ARG POETRY_CACHE_DIR: ${POETRY_CACHE_DIR} ..."
29
+ RUN echo "ARG PYTHONPATH: $PYTHONPATH ..."
30
+ RUN test -n ${DEPENDENCY_GROUP:?}
31
+ RUN echo "python DEPENDENCY_GROUP: ${DEPENDENCY_GROUP} ..."
32
+ RUN echo "arg dep:"
33
+
34
+ # Set working directory to function root directory
35
+ WORKDIR ${LAMBDA_TASK_ROOT}
36
+ COPY requirements_poetry.txt pyproject.toml poetry.lock README.md ${LAMBDA_TASK_ROOT}/
37
+
38
+ RUN cat /etc/lsb-release
39
+ # avoid segment-geospatial exception caused by missing libGL.so.1 library
40
+ RUN echo "BUILDER: check libz.s* before start" && ls -l /usr/lib/${ARCH}-linux-gnu/libz.so*
41
+
42
+ RUN apt update && apt upgrade -y && apt install -y libgl1 curl python3-pip git-lfs && apt clean
43
+ COPY ./dockerfiles/apt_preferences_ubuntu /etc/apt/preferences
44
+ COPY ./dockerfiles/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources
45
+ #RUN echo "run update noble..."
46
+ #RUN apt update
47
+ #RUN apt update && apt install -t noble zlib1g -y
48
+ RUN git lfs install
49
+ RUN echo "BUILDER: check libz.s* after install from trixie" && ls -l /usr/lib/${ARCH}-linux-gnu/libz.so*
50
+
51
+ RUN ls -l /etc/apt/sources* /etc/apt/preferences*
52
+
53
+ # poetry installation path is NOT within ${LAMBDA_TASK_ROOT}: not needed for runtime docker image
54
+ RUN python -m pip install -r ${LAMBDA_TASK_ROOT}/requirements_poetry.txt
55
+
56
+ RUN which poetry && poetry --version && poetry config --list
57
+ RUN poetry config virtualenvs.path ${LAMBDA_TASK_ROOT}
58
+ RUN poetry config installer.max-workers 7
59
+ RUN echo "# poetry config --list #" && poetry config --list
60
+ RUN ls -ld ${LAMBDA_TASK_ROOT}/
61
+ #RUN . ${LAMBDA_TASK_ROOT}/.venv/bin/activate && ${LAMBDA_TASK_ROOT}/.venv/bin/python --version && ${LAMBDA_TASK_ROOT}/.venv/bin/python -m pip install pip wheel setuptools --upgrade
62
+ RUN poetry run python -m pip install pip wheel setuptools --upgrade
63
+ RUN poetry install --with ${DEPENDENCY_GROUP} --no-root --no-cache
64
+
65
+ RUN git clone https://huggingface.co/aletrn/sam-quantized/ ${LAMBDA_TASK_ROOT}/sam-quantized
66
+ RUN git clone -n --depth=1 --filter=tree:0 https://huggingface.co/spaces/aletrn/lisa-on-cuda ${LAMBDA_TASK_ROOT}/lisa-on-cuda && \
67
+ cd ${LAMBDA_TASK_ROOT}/lisa-on-cuda && \
68
+ git sparse-checkout set --no-cone resources && \
69
+ git checkout
70
+ WORKDIR ${LAMBDA_TASK_ROOT}
71
+ RUN ls -l ${LAMBDA_TASK_ROOT}/*
72
+
73
+
74
+ FROM pytorch/pytorch:2.4.1-cuda12.4-cudnn9-runtime as runtime
75
+
76
+ ARG ARCH
77
+ ARG LAMBDA_TASK_ROOT
78
+
79
+ ENV VIRTUAL_ENV=${LAMBDA_TASK_ROOT}/.venv \
80
+ PATH="${LAMBDA_TASK_ROOT}/.venv/bin:$PATH"
81
+
82
+ RUN echo "COPY --from=builder_global /usr/lib/${ARCH}-linux-gnu/libGL.so* /usr/lib/${ARCH}-linux-gnu/"
83
+ COPY --from=builder_global /usr/lib/${ARCH}-linux-gnu/libGL.so* /usr/lib/${ARCH}-linux-gnu/
84
+ RUN echo "RUNTIME: check libz.s* before upgrade" && ls -l /usr/lib/${ARCH}-linux-gnu/libz.so*
85
+ RUN echo "RUNTIME: remove libz.s* to force upgrade" && rm /usr/lib/${ARCH}-linux-gnu/libz.so*
86
+ COPY --from=builder_global /usr/lib/${ARCH}-linux-gnu/libz.so* /usr/lib/${ARCH}-linux-gnu/
87
+ RUN echo "RUNTIME: check libz.s* after copy" && ls -l /usr/lib/${ARCH}-linux-gnu/libz.so*
88
+ COPY --from=builder_global ${LAMBDA_TASK_ROOT}/.venv ${LAMBDA_TASK_ROOT}/.venv
89
+
90
+ RUN echo "new LAMBDA_TASK_ROOT after hidden venv copy => ${LAMBDA_TASK_ROOT}"
91
+ RUN ls -ld ${LAMBDA_TASK_ROOT}/
92
+ RUN ls -lA ${LAMBDA_TASK_ROOT}/
93
+ RUN echo "content of LAMBDA_TASK_ROOT/.venv => ${LAMBDA_TASK_ROOT}/.venv"
94
+ RUN ls -ld ${LAMBDA_TASK_ROOT}/.venv
95
+ RUN ls -lA ${LAMBDA_TASK_ROOT}/.venv
96
+
97
+
98
+ ### conditional section
99
+ FROM node:20-slim AS node_fastapi
100
+
101
+ ARG DEPENDENCY_GROUP
102
+ ENV PNPM_HOME="/pnpm"
103
+ ENV PATH="$PNPM_HOME:$PATH"
104
+
105
+ RUN corepack enable
106
+
107
+ COPY ./static /appnode
108
+ WORKDIR /appnode
109
+ # RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then echo "pnpm store path:" && pnpm store path; fi
110
+ RUN ls -l /appnode
111
+ RUN ls -l /appnode/list_files.html
112
+
113
+
114
+ FROM node_fastapi AS node_prod_deps
115
+
116
+ ARG DEPENDENCY_GROUP
117
+ RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
118
+ pnpm install --prod --frozen-lockfile; else \
119
+ echo "DEPENDENCY_GROUP 1: ${DEPENDENCY_GROUP} ..."; fi
120
+ # here multiple conditions concatenated to avoid failing on check
121
+ RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then if [ ! -d /appnode/node_modules ]; then \
122
+ echo "no node_modules folder" && exit 1; fi; fi
123
+
124
+
125
+ FROM node_fastapi AS node_build
126
+
127
+ ARG DEPENDENCY_GROUP
128
+ ARG VITE__MAP_DESCRIPTION
129
+ ARG VITE__SAMGIS_SPACE
130
+ RUN echo "VITE__MAP_DESCRIPTION:" ${VITE__MAP_DESCRIPTION}
131
+ RUN echo "VITE__SAMGIS_SPACE:" ${VITE__SAMGIS_SPACE}
132
+
133
+ RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
134
+ pnpm install --frozen-lockfile; else \
135
+ echo "DEPENDENCY_GROUP 2: ${DEPENDENCY_GROUP} ..."; fi
136
+ RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then pnpm build; fi
137
+ RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
138
+ pnpm tailwindcss -i /appnode/src/input.css -o /appnode/dist/output.css; fi
139
+ RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then if [ ! -d /appnode/dist ]; then echo "no dist folder" && exit 1; fi; fi
140
+
141
+
142
+ FROM runtime
143
+ ARG FASTAPI_STATIC
144
+
145
+ RUN echo "show disk space, df -h ..."
146
+ RUN df -h
147
+ RUN echo "creating FASTAPI_STATIC folder: ${FASTAPI_STATIC}, use `mkdir -p` to avoid failure if missing parent folder ..."
148
+ RUN mkdir -p ${FASTAPI_STATIC}
149
+
150
+ COPY --from=builder_global ${LAMBDA_TASK_ROOT}/sam-quantized/machine_learning_models \
151
+ ${LAMBDA_TASK_ROOT}/machine_learning_models
152
+ RUN ls -ld ${LAMBDA_TASK_ROOT}/machine_learning_models
153
+ RUN ls -lh ${LAMBDA_TASK_ROOT}/machine_learning_models
154
+ COPY --from=builder_global ${LAMBDA_TASK_ROOT}/lisa-on-cuda/resources ${LAMBDA_TASK_ROOT}/resources
155
+ COPY --from=node_prod_deps /appnode/node_modules* ${FASTAPI_STATIC}/node_modules
156
+ COPY --from=node_build /appnode/dist* ${FASTAPI_STATIC}/dist
157
+ COPY --from=node_build /appnode/list_files.html ${FASTAPI_STATIC}/list_files.html
158
+ RUN ls -l ${FASTAPI_STATIC}/
159
+ RUN ls -l ${FASTAPI_STATIC}/list_files.html
160
+
161
+
162
+ # Include global arg in this stage of the build
163
+ ARG LAMBDA_TASK_ROOT="/var/task"
164
+ ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
165
+ ENV VIRTUAL_ENV=${LAMBDA_TASK_ROOT}/.venv \
166
+ PATH="${LAMBDA_TASK_ROOT}/.venv/bin:$PATH"
167
+ ENV IS_AWS_LAMBDA=""
168
+
169
+ # Set working directory to function root directory
170
+ WORKDIR ${LAMBDA_TASK_ROOT}
171
+
172
+ COPY samgis_lisa_on_cuda ${LAMBDA_TASK_ROOT}/samgis_lisa_on_cuda
173
+ COPY wrappers ${LAMBDA_TASK_ROOT}/wrappers
174
+ COPY scripts ${LAMBDA_TASK_ROOT}/scripts
175
+ RUN chmod +x ${LAMBDA_TASK_ROOT}/scripts/entrypoint.sh
176
+ RUN chmod +x ${LAMBDA_TASK_ROOT}/scripts/docker_entrypoint.sh
177
+ RUN ls -l ${LAMBDA_TASK_ROOT}/scripts/entrypoint.sh ${LAMBDA_TASK_ROOT}/scripts/docker_entrypoint.sh
178
+
179
+ RUN ls -l /usr/bin/which
180
+ RUN /usr/bin/which python
181
+ RUN python --version
182
+ RUN echo "PYTHONPATH: ${PYTHONPATH}."
183
+ RUN echo "PATH: ${PATH}."
184
+ RUN echo "LAMBDA_TASK_ROOT: ${LAMBDA_TASK_ROOT}."
185
+ RUN ls -l ${LAMBDA_TASK_ROOT}
186
+ RUN ls -ld ${LAMBDA_TASK_ROOT}
187
+ RUN ls -l ${LAMBDA_TASK_ROOT}/machine_learning_models
188
+ RUN python -c "import sys; print(sys.path)"
189
+ RUN python -c "import cv2"
190
+ RUN python -c "import fastapi"
191
+ RUN python -c "import geopandas"
192
+ RUN python -c "import loguru"
193
+ RUN python -c "import rasterio"
194
+ RUN python -c "import uvicorn"
195
+ RUN df -h
196
+ RUN ls -l ${LAMBDA_TASK_ROOT}/samgis_lisa_on_cuda/
197
+ RUN ls -l ${LAMBDA_TASK_ROOT}/wrappers/
198
+ RUN echo "LAMBDA_TASK_ROOT /static/:"
199
+ RUN ls -l ${LAMBDA_TASK_ROOT}/static/ || true
200
+ RUN ls -l ${LAMBDA_TASK_ROOT}/static/dist || true
201
+ RUN ls -l ${LAMBDA_TASK_ROOT}/static/node_modules || true
202
+ RUN echo "FASTAPI_STATIC:"
203
+ RUN ls -l ${FASTAPI_STATIC}/ || true
204
+ RUN ls -l ${FASTAPI_STATIC}/dist || true
205
+ RUN ls -l ${FASTAPI_STATIC}/node_modules || true
206
+
207
+ CMD ["/var/task/scripts/docker_entrypoint.sh"]
README.md CHANGED
@@ -3,8 +3,7 @@ title: SamGIS - LISA on CUDA
3
  emoji: 🗺️
4
  colorFrom: red
5
  colorTo: blue
6
- sdk: gradio
7
- sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: true
10
  license: mit
 
3
  emoji: 🗺️
4
  colorFrom: red
5
  colorTo: blue
6
+ sdk: docker
 
7
  app_file: app.py
8
  pinned: true
9
  license: mit
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
  [tool.poetry]
2
  name = "samgis-lisa-on-cuda"
3
- version = "1.5.0"
4
  description = "A VLM backend for machine learning instance segmentation on geospatial data that uses LISA (Reasoning Segmentation via Large Language Model). This demo uses a dedicated GPU."
5
  authors = ["alessandro trinca tornidor <alessandro@trinca.tornidor.com>"]
6
  license = "MIT license"
@@ -9,7 +9,7 @@ package-mode = false
9
 
10
  [metadata]
11
  name = "samgis-lisa-on-cuda"
12
- version = "1.5.0"
13
 
14
  [tool.poetry.dependencies]
15
  python = ">=3.10,<3.11"
 
1
  [tool.poetry]
2
  name = "samgis-lisa-on-cuda"
3
+ version = "1.5.6"
4
  description = "A VLM backend for machine learning instance segmentation on geospatial data that uses LISA (Reasoning Segmentation via Large Language Model). This demo uses a dedicated GPU."
5
  authors = ["alessandro trinca tornidor <alessandro@trinca.tornidor.com>"]
6
  license = "MIT license"
 
9
 
10
  [metadata]
11
  name = "samgis-lisa-on-cuda"
12
+ version = "1.5.6"
13
 
14
  [tool.poetry.dependencies]
15
  python = ">=3.10,<3.11"