Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker build #6

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 35 additions & 0 deletions README.docker.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions demo.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/root/dbg_img.png:what color is the couch?
36 changes: 36 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions uio/test/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from functools import partial
from jax import grad, lax
import jax.numpy as jnp
14 changes: 14 additions & 0 deletions uio/test/run.py
Original file line number Diff line number Diff line change
@@ -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 >>>')
9 changes: 9 additions & 0 deletions uioi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: uioi
channels:
- defaults
- conda-forge
- nvidia
- anaconda
dependencies:
- python=3.9
- cudnn
Binary file added unifiedIO-paper.pdf
Binary file not shown.