Skip to content

Commit 943270a

Browse files
author
LIT team
committed
Merge pull request #1546 from PAIR-code:lit-on-gcp
PiperOrigin-RevId: 686309136
2 parents 6a01845 + 4d04799 commit 943270a

26 files changed

+816
-409
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ jobs:
4545
uses: actions/setup-python@v4
4646
with:
4747
python-version: ${{ matrix.python-version }}
48-
- name: Install Python dependencies
49-
run: python -m pip install -r requirements.txt
50-
- name: Install LIT package
51-
run: python -m pip install -e .
48+
- name: Install LIT package with testing dependencies
49+
run: python -m pip install -e '.[test]'
5250
- name: Test LIT
53-
run: |
54-
python -m pip install pytest
55-
pytest -v
51+
run: pytest -v
5652
- name: Setup Node ${{ matrix.node-version }}
5753
uses: actions/setup-node@v2
5854
with:
@@ -73,4 +69,5 @@ jobs:
7369
- name: Build Docker image
7470
uses: docker/build-push-action@v4
7571
with:
72+
target: lit-nlp-prod
7673
tags: lit-nlp:ci-${{ github.sha }}

Dockerfile

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,51 @@
1414
# ==============================================================================
1515
# Use the official lightweight Python image.
1616
# https://hub.docker.com/_/python
17-
FROM python:3.10-slim
17+
18+
# ---- LIT Base Container ----
19+
20+
FROM python:3.11-slim AS lit-nlp-base
1821

1922
# Update Ubuntu packages and install basic utils
2023
RUN apt-get update
2124
RUN apt-get install -y wget curl gnupg2 gcc g++ git
2225

26+
# Copy local code to the container image.
27+
ENV APP_HOME=/app
28+
WORKDIR $APP_HOME
29+
30+
COPY ./lit_nlp/examples/gunicorn_config.py ./
31+
32+
33+
34+
# ---- LIT Container for Hosted Demos ----
35+
36+
FROM lit-nlp-base AS lit-nlp-prod
37+
38+
RUN python -m pip install 'lit-nlp[examples-descai]'
39+
40+
WORKDIR $APP_HOME
41+
ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"]
42+
43+
44+
45+
# ---- LIT Container for Developing and Testing Hosted Demos ----
46+
47+
FROM lit-nlp-base AS lit-nlp-dev
48+
2349
# Install yarn
2450
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
2551
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \
2652
tee /etc/apt/sources.list.d/yarn.list
2753
RUN apt update && apt -y install yarn
2854

29-
# Copy local code to the container image.
30-
ENV APP_HOME=/app
31-
WORKDIR $APP_HOME
32-
3355
# Set up python environment with production dependencies
3456
# This step is slow as it installs many packages.
35-
COPY ./requirements*.txt ./
36-
RUN python -m pip install -r requirements.txt
57+
COPY requirements.txt \
58+
requirements_examples_common.txt \
59+
requirements_examples_descai.txt \
60+
./
61+
RUN python -m pip install -r requirements_examples_descai.txt
3762

3863
# Copy the rest of the lit_nlp package
3964
COPY . ./
@@ -47,7 +72,4 @@ RUN yarn && yarn build && rm -rf node_modules/*
4772
# Note that the config file supports configuring the LIT demo that is launched
4873
# via the DEMO_NAME and DEMO_PORT environment variables.
4974
WORKDIR $APP_HOME
50-
ENTRYPOINT [ \
51-
"gunicorn", \
52-
"--config=lit_nlp/examples/gunicorn_config.py" \
53-
]
75+
ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"]

lit_nlp/examples/gcp/Dockerfile

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
# Use the official lightweight Python image.
16+
# https://hub.docker.com/_/python
17+
18+
# ---- LIT on GCP Base Images ----
19+
20+
FROM python:3.11-slim AS lit-gcp-app-server-base
21+
22+
# Update Ubuntu packages and install basic utils
23+
RUN apt-get update
24+
RUN apt-get install -y wget curl gnupg2 gcc g++ git
25+
26+
# Copy local code to the container image.
27+
ENV APP_HOME=/app
28+
WORKDIR $APP_HOME
29+
30+
COPY ./lit_nlp/examples/gcp/server_gunicorn_config.py ./gunicorn_config.py
31+
32+
33+
34+
FROM nvidia/cuda:12.5.1-base-ubuntu22.04 AS lit-gcp-model-server-base
35+
ENV DEBIAN_FRONTEND=noninteractive
36+
ENV LANG=C.UTF-8
37+
38+
ARG PYTHON_VERSION=python3.11
39+
40+
RUN apt-get update
41+
42+
# Install the CUDA Keyring package
43+
# See https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#network-repo-installation-for-ubuntu
44+
RUN apt-get install -y curl gnupg ca-certificates
45+
RUN curl https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb \
46+
-o cuda-keyring_1.1-1_all.deb
47+
RUN dpkg -i cuda-keyring_1.1-1_all.deb
48+
49+
# Install system and CUDA packages
50+
RUN apt-get install -y --no-install-recommends \
51+
cuda-command-line-tools-12-3 \
52+
cuda-cudart-dev-12-3 \
53+
cuda-nvcc-12-3 \
54+
cuda-cupti-12-3 \
55+
cuda-nvprune-12-3 \
56+
cuda-libraries-12-3 \
57+
cuda-nvrtc-12-3 \
58+
libcufft-12-3 \
59+
libcurand-12-3 \
60+
libcusolver-12-3 \
61+
libcusparse-12-3 \
62+
libcublas-12-3 \
63+
libcudnn8=8.9.6.50-1+cuda12.2 \
64+
libnvinfer-plugin8=8.6.1.6-1+cuda12.0 \
65+
libnvinfer8=8.6.1.6-1+cuda12.0 \
66+
build-essential \
67+
pkg-config \
68+
software-properties-common \
69+
unzip
70+
71+
# Install Python 3.11
72+
RUN apt-get install -y --no-install-recommends \
73+
$PYTHON_VERSION \
74+
$PYTHON_VERSION-venv \
75+
$PYTHON_VERSION-distutils \
76+
$PYTHON_VERSION-dev
77+
RUN ln -sf /usr/bin/$PYTHON_VERSION /usr/bin/python3
78+
RUN ln -sf /usr/bin/$PYTHON_VERSION /usr/bin/python
79+
80+
# Install pip
81+
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
82+
RUN python3 get-pip.py
83+
RUN python3 -m pip install --no-cache-dir --upgrade pip
84+
85+
RUN apt-get clean
86+
RUN rm -rf /var/lib/apt/lists/*
87+
88+
COPY ./lit_nlp/examples/gcp/model_server_gunicorn_config.py ./
89+
90+
91+
92+
# ---- LIT on GCP Production Images ----
93+
94+
FROM lit-gcp-app-server-base AS lit-gcp-app-server
95+
96+
RUN python -m pip install 'lit-nlp[examples-genai]'
97+
ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"]
98+
99+
100+
101+
FROM lit-gcp-model-server-base AS lit-gcp-model-server
102+
103+
RUN python -m pip install 'lit-nlp[examples-genai]'
104+
ENTRYPOINT ["gunicorn", "--config=model_server_gunicorn_config.py"]
105+
106+
107+
108+
# ---- LIT on GCP Development Images ----
109+
110+
FROM lit-gcp-app-server-base AS lit-gcp-app-server-dev
111+
112+
# Install yarn
113+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
114+
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \
115+
tee /etc/apt/sources.list.d/yarn.list
116+
RUN apt update && apt -y install yarn
117+
118+
# Set up python environment with production dependencies
119+
# This step is slow as it installs many packages.
120+
COPY requirements.txt \
121+
requirements_examples_common.txt \
122+
requirements_examples_genai.txt \
123+
./
124+
RUN python -m pip install -r requirements_examples_genai.txt
125+
126+
# Copy the rest of the lit_nlp package
127+
COPY . ./
128+
129+
# Build front-end with yarn
130+
WORKDIR $APP_HOME/lit_nlp/client
131+
ENV NODE_OPTIONS="--openssl-legacy-provider"
132+
RUN yarn && yarn build && rm -rf node_modules/*
133+
134+
# Run LIT server
135+
# Note that the config file supports configuring the LIT demo that is launched
136+
# via the DEMO_NAME and DEMO_PORT environment variables.
137+
WORKDIR $APP_HOME
138+
ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"]
139+
140+
141+
142+
FROM lit-gcp-model-server-base AS lit-gcp-model-server-dev
143+
ENV APP_HOME=/app
144+
WORKDIR $APP_HOME
145+
146+
# Install Node.js v18 (the base image ships with Node.js v12)
147+
# See https://github.com/nodesource/distributions
148+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
149+
RUN bash nodesource_setup.sh
150+
RUN apt-get install -y nodejs
151+
152+
# Install yarn
153+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
154+
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \
155+
tee /etc/apt/sources.list.d/yarn.list
156+
RUN apt update && apt -y install yarn
157+
158+
COPY requirements.txt \
159+
requirements_examples_common.txt \
160+
requirements_examples_genai.txt \
161+
./
162+
RUN python -m pip install -r requirements_examples_genai.txt
163+
164+
# Copy the rest of the lit_nlp package
165+
COPY . ./
166+
167+
# Build front-end with yarn
168+
WORKDIR $APP_HOME/lit_nlp/client
169+
ENV NODE_OPTIONS="--openssl-legacy-provider"
170+
RUN yarn && yarn build && rm -rf node_modules/*
171+
172+
WORKDIR $APP_HOME
173+
ENTRYPOINT ["gunicorn", "--config=model_server_gunicorn_config.py"]

lit_nlp/examples/gcp/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Using LLMs in LIT on Google Cloud Platform
2+
3+
## Developing
4+
5+
### Use a virtual environment
6+
7+
```shell
8+
# Create and activate the virtual environment
9+
python3 -m venv ~/.venvs/lit-on-gcp
10+
source ~/.venvs/lit-on-gcp/bin/activate
11+
12+
# Install the requirements and LIT in editable mode
13+
pip install -f ./lit_nlp/examples/gcp/requirements.txt
14+
pip install -e .
15+
16+
# Optionally, install tetsing requirements
17+
pip install -f ./requirements_test.txt
18+
pytest pytest lit_nlp/examples/gcp
19+
```
20+
21+
### Build the Docker image
22+
23+
```shell
24+
docker build -f ./lit_nlp/examples/gcp/Dockerfile -t lit-app:gcp-dev .
25+
```
26+
27+
### Run GPT-2 in a Docker container
28+
29+
```shell
30+
# Runs GPT-2 in Keras on PyTorch
31+
docker run --rm -p 5432:5432 -e MODEL_CONFIG=gpt2:gpt2_base_en lit-app:gcp-dev
32+
```
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,10 +13,14 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16-
-r ../../../requirements_core.txt
16+
"""Constants used across the Model Server and LIT Server code surfaces."""
1717

18-
keras>=3.1.0
19-
keras-nlp>=0.9.0
20-
tensorflow-text>=2.10.0
21-
torch>=2.0.0
22-
transformers>=4.27.1
18+
import enum
19+
20+
21+
class LlmHTTPEndpoints(enum.Enum):
22+
"""Names of HTTP endpoints provided by the Model Server conainer."""
23+
24+
GENERATE = 'predict'
25+
SALIENCE = 'salience'
26+
TOKENIZE = 'tokenize'

0 commit comments

Comments
 (0)