diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..becfe13 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM nvidia/cuda:11.7.0-devel-ubuntu20.04 +LABEL name="unified-io-inference" + +WORKDIR /root/.conda +WORKDIR /root +RUN apt-get update && apt-get -y install wget nano +RUN wget \ + https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + && bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda \ + && rm -f Miniconda3-latest-Linux-x86_64.sh +ENV PATH=/opt/conda/bin:${PATH} +RUN bash -c "conda update -n base -c defaults conda" + +RUN wget -nv https://ai2-prior-uio.s3.us-west-2.amazonaws.com/public/model-weights-bin/xl_1000k.bin \ + -O xl.bin +RUN wget -nv https://ai2-prior-uio.s3.us-west-2.amazonaws.com/public/model-weights-bin/large_1000k.bin \ + -O large.bin +RUN wget -nv https://ai2-prior-uio.s3.us-west-2.amazonaws.com/public/model-weights-bin/base_1000k.bin \ + -O base.bin +RUN wget -nv https://ai2-prior-uio.s3.us-west-2.amazonaws.com/public/model-weights-bin/small_1000k.bin \ + -O small.bin +RUN wget -nv https://farm2.staticflickr.com/1362/1261465554_95741e918b_z.jpg -O dbg_img.png + +COPY uioi.yml . +RUN bash -c "conda env create -f uioi.yml" +COPY requirements.txt . +RUN bash -c ". activate uioi && pip install --upgrade pip \ + && pip install --upgrade "jax[cuda]" \ + -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html \ + && python3 -m pip install -r requirements.txt" + +COPY . . +RUN bash -c ". activate uioi && python ./uio/test/check.py" +ENV INPUT_FILE=demo.list +ENTRYPOINT bash -c ". activate uioi && python ./run.py xl xl.bin $INPUT_FILE" diff --git a/README.docker.md b/README.docker.md new file mode 100644 index 0000000..192c1f7 --- /dev/null +++ b/README.docker.md @@ -0,0 +1,35 @@ + +## Docker +To build a docker image: +```bash +docker build -t unified-io-inference . +``` +To run the docker demo: +``` +docker run -it --gpus=1 unified-io-inference +INFO:absl:Setting up model... +... +INFO:absl:Model is ready +INFO:absl:Running model text_inputs=['what color is the sofa?'] +green +``` + +To run a list of queries construct an input file where each line is a file path +and a text input, separated by `:`. See example: [demo.list](https://github.com/isi-vista/unified-io-inference/blob/docker-build/demo.list) + +Prepare a directory containing image files. `cd` to that directory. +The steps below will write example input files and docker execution with the +host images mounted to the `/image-data` directory. + +``` +ls -1 | grep -E 'jpg|png' > files.txt +awk '{print "/image-data/" $0 ":What-does-the-image-describe?"}' ./files.txt > caption.txt +awk '{print "/image-data/" $0 ":Locate all objects in the image."}' ./files.txt > locate.txt + +#Choose an input file to process: +export INPUT_FILE=[caption.txt or locate.txt or other] +export HOSTPATH=$(pwd) + +docker run -it --gpus=1 -e INPUT_FILE=/image-data/${INPUT_FILE} \ + -v /${HOSTPATH}:/image-data unified-io-inference +``` diff --git a/README.md b/README.md index e1fb781..27d8143 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ Then it can be run with: jupyter notebook demo.ipynb ``` +## Docker +To build and run a unified-io-inference docker image see: README.docker.md ## Just-in-time compilation By default `ModelRunner` compiles the underlying inference calls the first time they are used, diff --git a/demo.list b/demo.list new file mode 100644 index 0000000..8d64f07 --- /dev/null +++ b/demo.list @@ -0,0 +1 @@ +/root/dbg_img.png:what color is the couch? diff --git a/run.py b/run.py new file mode 100644 index 0000000..ba722e3 --- /dev/null +++ b/run.py @@ -0,0 +1,36 @@ +import argparse +from os.path import exists +from PIL import Image +from uio import runner +from uio.configs import CONFIGS +import numpy as np +from absl import logging +import warnings +# flax kicks up a lot of future warnings at the moment, ignore them +warnings.simplefilter(action='ignore', category=FutureWarning) + +# To see INFO messages from `ModelRunner` +logging.set_verbosity(logging.INFO) + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("model_size", choices=list(CONFIGS)) + parser.add_argument("model_weights") + parser.add_argument("input_file") + args = parser.parse_args() + + model = runner.ModelRunner(args.model_size, args.model_weights) + input_file = open(args.input_file, 'r') + lines = input_file.readlines() + for line in lines: + image_path, question = line.strip().split(":") + print(image_path) + print(question) + with Image.open(image_path) as img: + image = np.array(img.convert('RGB')) + output = model.vqa(image, question) + print(output["text"]) + + +if __name__ == "__main__": + main() diff --git a/uio/test/check.py b/uio/test/check.py new file mode 100644 index 0000000..4cd937d --- /dev/null +++ b/uio/test/check.py @@ -0,0 +1,3 @@ +from functools import partial +from jax import grad, lax +import jax.numpy as jnp diff --git a/uio/test/run.py b/uio/test/run.py new file mode 100644 index 0000000..fba0ff5 --- /dev/null +++ b/uio/test/run.py @@ -0,0 +1,14 @@ +from functools import partial +from jax import grad, lax +import jax.numpy as jnp +import jax as jax +print('<<< jax test >>>') +print(jax.devices()) + +def tanh(x): # Define a function + y = jnp.exp(-2.0 * x) + return (1.0 - y) / (1.0 + y) + +grad_tanh = grad(tanh) # Obtain its gradient function +print(grad_tanh(1.0)) +print('<<< end >>>') diff --git a/uioi.yml b/uioi.yml new file mode 100644 index 0000000..b721b04 --- /dev/null +++ b/uioi.yml @@ -0,0 +1,9 @@ +name: uioi +channels: + - defaults + - conda-forge + - nvidia + - anaconda +dependencies: + - python=3.9 + - cudnn diff --git a/unifiedIO-paper.pdf b/unifiedIO-paper.pdf new file mode 100644 index 0000000..139c793 Binary files /dev/null and b/unifiedIO-paper.pdf differ