diff --git a/INSTALL.md b/INSTALL.md index 63bbad9..f7dd30d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -54,3 +54,15 @@ docker compose up docker compose run -i --entrypoint /bin/bash igpt ``` + +## A note on dependencies: + +CUDA, torch, and opencv are notorious for version incompatibilities (mostly due to binaries being built against specific versions), so here's a quick checklist: + +1. `opencv` libraries should always have specified version numbers, and there should only ever be one set on the system + +2. `cuda` libraries should always have specified version numbers, but can exist independently using conda + +3. `torch` libraries should always have specified version numbers, especially for torchvision [here](https://pypi.org/project/torchvision/) and torchaudio [here](https://pytorch.org/audio/main/installation.html); always check `pytorch` and `python` versions before building + +If deploying as Swarm or via Kubernetes, note that the build directory should have access to tty, and individual clients should be paired with individual gpus or gpu partitions. See [here](https://docs.nvidia.com/datacenter/tesla/mig-user-guide/index.html). diff --git a/docker/Dockerfile b/docker/Dockerfile index 75db0bd..e00e59d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,21 +2,25 @@ FROM continuumio/anaconda3 RUN git clone https://github.com/OpenGVLab/InternGPT.git WORKDIR InternGPT + SHELL ["/bin/bash", "-c"] RUN conda init bash RUN source "/opt/conda/bin/activate" RUN conda create -n igpt python=3.8 RUN source activate igpt -RUN apt-get clean && apt-get update && apt-get -y install --no-install-recommends gcc g++ libjpeg-dev libpng-dev zlib1g-dev build-essential +RUN apt-get clean && apt-get update && apt-get -y install --no-install-recommends gcc g++ libjpeg-dev libpng-dev zlib1g-dev build-essential libgl1-mesa-glx libxml2 RUN cp /opt/conda/envs/igpt/lib/libstdc++.so.6 /usr/lib/x86_64-linux-gnu -RUN conda install pytorch pytorch-cuda=11.7 cudatoolkit -c pytorch -c nvidia + +RUN conda update -n base -c defaults conda +RUN conda install pytorch pytorch-cuda=11.7 cudatoolkit=11.7 -c pytorch -c nvidia +RUN conda install -c conda-forge cudatoolkit-dev=11.7 +RUN conda install -c numba llvmlite numba RUN pip install -r requirements.txt RUN pip install git+https://github.com/facebookresearch/detectron2.git RUN pip install mediapipe -RUN pip install imageio-ffmpeg RUN pip uninstall -y opencv-python RUN pip uninstall -y opencv-python-headless @@ -25,12 +29,9 @@ RUN pip uninstall -y opencv-contrib-python-headless RUN pip install opencv-python-headless==4.6.0.66 RUN pip install opencv-contrib-python==4.6.0.66 -RUN apt-get -y install libgl1-mesa-glx -RUN apt-get -y install libxml2 +RUN conda install torchvision=0.14.0 torchaudio=0.13.0 -c pytorch -RUN conda install -c conda-forge cudatoolkit-dev -RUN conda install --channel=numba llvmlite -RUN conda install -c numba numba +RUN git pull EXPOSE 7862 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 42b0280..7fecf13 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,27 +1,27 @@ services: igpt: - build: . image: "igpt" container_name: "igpt" restart: "unless-stopped" ports: - "7862:7862" volumes: - - /path/to/model_zoo:/InternGPT/model_zoo - - /path/to/certificate:/InternGPT/certificate + - /data/InternGPT/model_zoo:/InternGPT/model_zoo + - /data/InternGPT/certificate:/InternGPT/certificate + - /data/InternGPT/checkpoints:/InternGPT/checkpoints + - /data/InternGPT/.EasyOCR:/root/.EasyOCR/model + - /data/stable-diffusion-webui-docker/data/image_output:/InternGPT/image entrypoint: "python" deploy: resources: reservations: devices: - driver: nvidia - count: 1 + count: all capabilities: [gpu] command: - "-u" - "app.py" - "--load" - - "StyleGAN_cuda:0" - - "--tab" - - "DragGAN" + - "HuskyVQA_cuda:0,SegmentAnything_cuda:0,Anything2Image_cuda:0" - "--https" diff --git a/iGPT/models/image.py b/iGPT/models/image.py index 66334b7..83fa5c5 100644 --- a/iGPT/models/image.py +++ b/iGPT/models/image.py @@ -670,7 +670,7 @@ def inference_by_mask(self, inputs): mask_img.save(filaname, "PNG") return filaname - def segment_by_mask(self, mask, features): + def segment_by_mask(self, mask, features=None): random.seed(GLOBAL_SEED) idxs = np.nonzero(mask) num_points = min(max(1, int(len(idxs[0]) * 0.01)), 16) @@ -681,12 +681,19 @@ def segment_by_mask(self, mask, features): points = np.array(new_mask).reshape(2, -1).transpose(1, 0)[:, ::-1] labels = np.array([1] * num_points) - res_masks, scores, _ = self.predictor.predict( - features=features, - point_coords=points, - point_labels=labels, - multimask_output=True, - ) + if features is None: + res_masks, scores, _ = self.predictor.predict( + point_coords=points, + point_labels=labels, + multimask_output=True, + ) + else: + res_masks, scores, _ = self.predictor.predict( + features=features, + point_coords=points, + point_labels=labels, + multimask_output=True, + ) return res_masks[np.argmax(scores), :, :]