Skip to content

Commit

Permalink
Refactor lvms (#1096)
Browse files Browse the repository at this point in the history
Co-authored-by: ZePan110 <ze.pan@intel.com>
  • Loading branch information
Spycsh and ZePan110 authored Jan 13, 2025
1 parent ea72c94 commit feef30b
Show file tree
Hide file tree
Showing 73 changed files with 762 additions and 704 deletions.
32 changes: 14 additions & 18 deletions .github/workflows/docker/compose/lvms-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,40 @@
# SPDX-License-Identifier: Apache-2.0

# this file should be run in the root of the repo
# Deprecated original wrappers opea/lvm-tgi, opea/lvm-llava-svc, opea/lvm-video-llama
# and merged functionalities in opea/lvm
# Original video-llama-lvm-server renamed as lvm-video-llama

services:
lvm-tgi:
lvm:
build:
dockerfile: comps/lvms/tgi-llava/Dockerfile
image: ${REGISTRY:-opea}/lvm-tgi:${TAG:-latest}
dockerfile: comps/lvms/src/Dockerfile
image: ${REGISTRY:-opea}/lvm:${TAG:-latest}
lvm-video-llama:
build:
dockerfile: comps/lvms/video-llama/Dockerfile
dockerfile: comps/lvms/src/integrations/dependency/video-llama/Dockerfile
image: ${REGISTRY:-opea}/lvm-video-llama:${TAG:-latest}
video-llama-lvm-server:
build:
dockerfile: comps/lvms/video-llama/dependency/Dockerfile
image: ${REGISTRY:-opea}/video-llama-lvm-server:${TAG:-latest}
lvm-llava:
build:
dockerfile: comps/lvms/llava/dependency/Dockerfile
dockerfile: comps/lvms/src/integrations/dependency/llava/Dockerfile
image: ${REGISTRY:-opea}/lvm-llava:${TAG:-latest}
lvm-llava-svc:
build:
dockerfile: comps/lvms/llava/Dockerfile
image: ${REGISTRY:-opea}/lvm-llava-svc:${TAG:-latest}
llava-gaudi:
build:
dockerfile: comps/lvms/llava/dependency/Dockerfile.intel_hpu
dockerfile: comps/lvms/src/integrations/dependency/llava/Dockerfile.intel_hpu
image: ${REGISTRY:-opea}/llava-gaudi:${TAG:-latest}
lvm-predictionguard:
build:
dockerfile: comps/lvms/predictionguard/Dockerfile
dockerfile: comps/lvms/src/integrations/dependency/predictionguard/Dockerfile
image: ${REGISTRY:-opea}/lvm-predictionguard:${TAG:-latest}
lvm-llama-vision:
build:
dockerfile: comps/lvms/llama-vision/Dockerfile
dockerfile: comps/lvms/src/integrations/dependency/llama-vision/Dockerfile
image: ${REGISTRY:-opea}/lvm-llama-vision:${TAG:-latest}
lvm-llama-vision-tp:
build:
dockerfile: comps/lvms/llama-vision/Dockerfile_tp
dockerfile: comps/lvms/src/integrations/dependency/llama-vision/Dockerfile_tp
image: ${REGISTRY:-opea}/lvm-llama-vision-tp:${TAG:-latest}
lvm-llama-vision-guard:
build:
dockerfile: comps/lvms/llama-vision/Dockerfile_guard
dockerfile: comps/lvms/src/integrations/dependency/llama-vision/Dockerfile_guard
image: ${REGISTRY:-opea}/lvm-llama-vision-guard:${TAG:-latest}
6 changes: 6 additions & 0 deletions comps/cores/mega/http_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Optional

from fastapi import FastAPI
from fastapi.responses import Response
from prometheus_fastapi_instrumentator import Instrumentator
from uvicorn import Config, Server

Expand Down Expand Up @@ -73,6 +74,11 @@ async def _health_check():
"""Get the health status of this GenAI microservice."""
return {"Service Title": self.title, "Service Description": self.description}

@app.get("/health")
async def _health() -> Response:
"""Health check."""
return Response(status_code=200)

@app.get(
path="/v1/statistics",
summary="Get the statistics of GenAI services",
Expand Down
2 changes: 1 addition & 1 deletion comps/dataprep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apt-get install libreoffice

## Use LVM (Large Vision Model) for Summarizing Image Data

Occasionally unstructured data will contain image data, to convert the image data to the text data, LVM can be used to summarize the image. To leverage LVM, please refer to this [readme](../lvms/llava/README.md) to start the LVM microservice first and then set the below environment variable, before starting any dataprep microservice.
Occasionally unstructured data will contain image data, to convert the image data to the text data, LVM can be used to summarize the image. To leverage LVM, please refer to this [readme](../lvms/src/README.md) to start the LVM microservice first and then set the below environment variable, before starting any dataprep microservice.

```bash
export SUMMARIZE_IMAGE_VIA_LVM=1
Expand Down
4 changes: 2 additions & 2 deletions comps/dataprep/multimodal/redis/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export PYTHONPATH=${path_to_comps}

This is required only if you are going to consume the _generate_captions_ API of this microservice as in [Section 4.3](#43-consume-generate_captions-api).

Please refer to this [readme](../../../../lvms/llava/README.md) to start the LVM microservice.
Please refer to this [readme](../../../../lvms/src/README.md) to start the LVM microservice.
After LVM is up, set up environment variables.

```bash
Expand All @@ -64,7 +64,7 @@ Please refer to this [readme](../../../../vectorstores/redis/README.md).

This is required only if you are going to consume the _generate_captions_ API of this microservice as described [here](#43-consume-generate_captions-api).

Please refer to this [readme](../../../../lvms/llava/README.md) to start the LVM microservice.
Please refer to this [readme](../../../../lvms/src/README.md) to start the LVM microservice.
After LVM is up, set up environment variables.

```bash
Expand Down
2 changes: 1 addition & 1 deletion comps/dataprep/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apt-get install libreoffice

## Use LVM (Large Vision Model) for Summarizing Image Data

Occasionally unstructured data will contain image data, to convert the image data to the text data, LVM can be used to summarize the image. To leverage LVM, please refer to this [readme](../../lvms/llava/README.md) to start the LVM microservice first and then set the below environment variable, before starting any dataprep microservice.
Occasionally unstructured data will contain image data, to convert the image data to the text data, LVM can be used to summarize the image. To leverage LVM, please refer to this [readme](../../lvms/src/README.md) to start the LVM microservice first and then set the below environment variable, before starting any dataprep microservice.

```bash
export SUMMARIZE_IMAGE_VIA_LVM=1
Expand Down
29 changes: 0 additions & 29 deletions comps/lvms/llava/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions comps/lvms/llava/__init__.py

This file was deleted.

22 changes: 0 additions & 22 deletions comps/lvms/llava/check_lvm.py

This file was deleted.

103 changes: 0 additions & 103 deletions comps/lvms/llava/lvm.py

This file was deleted.

17 changes: 0 additions & 17 deletions comps/lvms/llava/template.py

This file was deleted.

23 changes: 23 additions & 0 deletions comps/lvms/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

FROM python:3.11-slim

RUN useradd -m -s /bin/bash user && \
mkdir -p /home/user && \
chown -R user /home/user/

USER user

ENV LANG=C.UTF-8

COPY comps /home/user/comps

RUN pip install --no-cache-dir --upgrade pip setuptools && \
pip install --no-cache-dir -r /home/user/comps/lvms/src/requirements.txt

ENV PYTHONPATH=$PYTHONPATH:/home/user

WORKDIR /home/user/comps/lvms/src

ENTRYPOINT ["python", "opea_lvm_microservice.py"]
31 changes: 31 additions & 0 deletions comps/lvms/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# LVM Microservice

Visual Question and Answering is one of the multimodal tasks empowered by LVMs (Large Visual Models). This microservice supports visual Q&A by using LLaVA as the base large visual model. It accepts two inputs: a prompt and an image. It outputs the answer to the prompt about the image.

## Build Image & Run

Before this, you have to start the [dependency](./integrations/dependency/) service based on your demands.

```bash
docker build --no-cache -t opea/lvm:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/lvms/src/Dockerfile .
# Change LVM_ENDPOINT to you dependency service endpoint
docker run -d --name="test-comps-lvm" -e LVM_ENDPOINT=http://localhost:8399 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p 9399:9399 --ipc=host opea/lvm:comps
```

## Test

- LLaVA & llama-vision & PredictionGuard & TGI LLaVA

```bash
# curl with an image and a prompt
http_proxy="" curl http://localhost:9399/v1/lvm -XPOST -d '{"image": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8/5+hnoEIwDiqkL4KAcT9GO0U4BxoAAAAAElFTkSuQmCC", "prompt":"What is this?"}' -H 'Content-Type: application/json'

# curl with only the prompt
http_proxy="" curl http://localhost:9399/v1/lvm --silent --write-out "HTTPSTATUS:%{http_code}" -XPOST -d '{"image": "", "prompt":"What is deep learning?"}' -H 'Content-Type: application/json'
```

- video-llama

```bash
http_proxy="" curl -X POST http://localhost:9399/v1/lvm -d '{"video_url":"https://github.com/DAMO-NLP-SG/Video-LLaMA/raw/main/examples/silence_girl.mp4","chunk_start": 0,"chunk_duration": 9,"prompt":"What is the person doing?","max_new_tokens": 150}' -H 'Content-Type: application/json'
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ RUN git lfs install

COPY comps /home/user/comps

RUN cd /home/user/comps/lvms/llama-vision/ && \
RUN cd /home/user/comps/lvms/src/integrations/dependency/llama-vision/ && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir --upgrade Pillow

ENV PYTHONPATH=/root:/home/user

WORKDIR /home/user/comps/lvms/llama-vision/
WORKDIR /home/user/comps/lvms/src/integrations/dependency/llama-vision/

ENTRYPOINT ["python", "lvm.py"]
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ RUN git lfs install

COPY comps /home/user/comps

RUN cd /home/user/comps/lvms/llama-vision/ && \
RUN cd /home/user/comps/lvms/src/integrations/dependency/llama-vision/ && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir --upgrade Pillow

ENV PYTHONPATH=/root:/home/user

WORKDIR /home/user/comps/lvms/llama-vision/
WORKDIR /home/user/comps/lvms/src/integrations/dependency/llama-vision/

ENTRYPOINT ["python", "lvm_guard.py"]
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ COPY comps /home/user/comps
RUN pip install --no-cache-dir git+https://github.com/HabanaAI/DeepSpeed.git@1.17.1
RUN pip install --no-cache-dir git+https://github.com/huggingface/optimum-habana@v1.13.2

RUN cd /home/user/comps/lvms/llama-vision/ \
RUN cd /home/user/comps/lvms/src/integrations/dependency/llama-vision/ \
pip install --no-cache-dir --upgrade pip && \
bash update && \
pip install --no-cache-dir -r /home/user/comps/lvms/llama-vision/requirements_tp.txt
pip install --no-cache-dir -r /home/user/comps/lvms/src/integrations/dependency/llama-vision/requirements_tp.txt

ENV PYTHONPATH=/root:/home/user

WORKDIR /home/user/comps/lvms/llama-vision/
WORKDIR /home/user/comps/lvms/src/integrations/dependency/llama-vision/

ENTRYPOINT ["bash", "run_tp.sh"]
Loading

0 comments on commit feef30b

Please sign in to comment.