|
| 1 | +# Deploying Image-to-Image Service |
| 2 | + |
| 3 | +This document provides a comprehensive guide to deploying the Image-to-Image microservice pipeline on Intel platforms. |
| 4 | + |
| 5 | +This guide covers two deployment methods: |
| 6 | + |
| 7 | +- [🚀 1. Quick Start with Docker Compose](#-1-quick-start-with-docker-compose): The recommended method for a fast and easy setup. |
| 8 | +- [🚀 2. Manual Step-by-Step Deployment (Advanced)](#-2-manual-step-by-step-deployment-advanced): For users who want to build and run the container individually. |
| 9 | + |
| 10 | +## 🚀 1. Quick Start with Docker Compose |
| 11 | + |
| 12 | +This method uses Docker Compose to start the service with a single command. It is the fastest and easiest way to get the service running. |
| 13 | + |
| 14 | +### 1.1. Access the Code |
| 15 | + |
| 16 | +Clone the repository and navigate to the deployment directory: |
| 17 | + |
| 18 | +```bash |
| 19 | +git clone https://github.com/opea-project/GenAIComps.git |
| 20 | +cd GenAIComps/comps/image2image/deployment/docker_compose |
| 21 | +``` |
| 22 | + |
| 23 | +### 1.2. Set Hugging Face Token |
| 24 | + |
| 25 | +Set your Hugging Face token as an environment variable. This is required to download the Stable Diffusion model. |
| 26 | + |
| 27 | +```bash |
| 28 | +export HF_TOKEN=<your huggingface token> |
| 29 | +``` |
| 30 | + |
| 31 | +### 1.3. Deploy the Service |
| 32 | + |
| 33 | +Choose the command corresponding to your target platform. |
| 34 | + |
| 35 | +- **For Intel® Xeon® CPU:** |
| 36 | + |
| 37 | + ```bash |
| 38 | + docker compose -f compose.yaml up image2image -d |
| 39 | + ``` |
| 40 | + |
| 41 | +- **For Intel® Gaudi® 2 HPU:** |
| 42 | + ```bash |
| 43 | + docker compose -f compose.yaml up image2image-gaudi -d |
| 44 | + ``` |
| 45 | + |
| 46 | +### 1.4. Validate the Service |
| 47 | + |
| 48 | +Once the container is running, you can validate the service. **Note:** Run this command from the root of the `GenAIComps` repository. |
| 49 | + |
| 50 | +```bash |
| 51 | +export ip_address=$(hostname -I | awk '{print $1}') |
| 52 | +curl http://${ip_address}:9389/v1/image2image -XPOST \ |
| 53 | +-d '{"image": "https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/aa_xl/000000009.png", "prompt":"a photo of an astronaut riding a horse on mars", "num_images_per_prompt":1}' \ |
| 54 | +-H 'Content-Type: application/json' |
| 55 | +``` |
| 56 | + |
| 57 | +The expected output will be a JSON object containing the generated image data. |
| 58 | + |
| 59 | +### 1.5. Clean Up the Deployment |
| 60 | + |
| 61 | +To stop and remove the containers, run the following command from the `comps/image2image/deployment/docker_compose` directory: |
| 62 | + |
| 63 | +```bash |
| 64 | +docker compose down |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## 🚀 2. Manual Step-by-Step Deployment (Advanced) |
| 70 | + |
| 71 | +This section provides detailed instructions for building the Docker image and running the microservice container individually. |
| 72 | + |
| 73 | +### 2.1. Clone the Repository |
| 74 | + |
| 75 | +If you haven't already, clone the repository and navigate to the root directory: |
| 76 | + |
| 77 | +```bash |
| 78 | +git clone https://github.com/opea-project/GenAIComps.git |
| 79 | +cd GenAIComps |
| 80 | +``` |
| 81 | + |
| 82 | +### 2.2. Build the Docker Image |
| 83 | + |
| 84 | +- **For Intel® Xeon® CPU:** |
| 85 | + ```bash |
| 86 | + docker build -t opea/image2image:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/image2image/src/Dockerfile . |
| 87 | + ``` |
| 88 | +- **For Intel® Gaudi® 2 HPU:** |
| 89 | + ```bash |
| 90 | + docker build -t opea/image2image-gaudi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/image2image/src/Dockerfile.intel_hpu . |
| 91 | + ``` |
| 92 | + |
| 93 | +### 2.3. Configure Environment Variables |
| 94 | + |
| 95 | +Set the necessary environment variables for the container. |
| 96 | + |
| 97 | +- **For both Intel® Xeon® and Intel® Gaudi® 2 HPU:** |
| 98 | + |
| 99 | + ```bash |
| 100 | + export ip_address=$(hostname -I | awk '{print $1}') |
| 101 | + export HF_TOKEN=<your huggingface token> |
| 102 | + # SDXL is an example, you can use other compatible models. |
| 103 | + export MODEL=stabilityai/stable-diffusion-xl-refiner-1.0 |
| 104 | + ``` |
| 105 | + |
| 106 | +### 2.4. Run the Microservice Container |
| 107 | + |
| 108 | +#### 2.4.1. Run Image-to-Image Microservice on Xeon |
| 109 | + |
| 110 | +```bash |
| 111 | +docker run -d --name "image2image-service" --ipc=host -p 9389:9389 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HF_TOKEN=$HF_TOKEN -e MODEL=$MODEL opea/image2image:latest |
| 112 | +``` |
| 113 | + |
| 114 | +#### 2.4.2. Run Image-to-Image Microservice on Gaudi |
| 115 | + |
| 116 | +```bash |
| 117 | +docker run -d --name "image2image-gaudi-service" -p 9389:9389 --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HF_TOKEN=$HF_TOKEN -e MODEL=$MODEL opea/image2image-gaudi:latest |
| 118 | +``` |
| 119 | + |
| 120 | +### 2.5. Validate the Service |
| 121 | + |
| 122 | +After starting the container, test the service endpoint. Make sure you are in the root directory of the `GenAIComps` repository. |
| 123 | + |
| 124 | +```bash |
| 125 | +# The ip_address variable should be set from step 2.3 |
| 126 | +curl http://${ip_address}:9389/v1/image2image -XPOST \ |
| 127 | +-d '{"image": "https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/aa_xl/000000009.png", "prompt":"a photo of an astronaut riding a horse on mars", "num_images_per_prompt":1}' \ |
| 128 | +-H 'Content-Type: application/json' |
| 129 | +``` |
| 130 | + |
| 131 | +You should see a successful response containing the generated image data. |
| 132 | + |
| 133 | +### 2.6. Clean Up the Deployment |
| 134 | + |
| 135 | +To stop and remove the container you started manually, use the `docker stop` and `docker rm` commands. |
| 136 | + |
| 137 | +- **For Intel® Xeon® CPU:** |
| 138 | + |
| 139 | + ```bash |
| 140 | + docker stop image2image-service |
| 141 | + docker rm image2image-service |
| 142 | + ``` |
| 143 | + |
| 144 | +- **For Intel® Gaudi® 2 HPU:** |
| 145 | + ```bash |
| 146 | + docker stop image2image-gaudi-service |
| 147 | + docker rm image2image-gaudi-service |
| 148 | + ``` |
0 commit comments