Skip to content

Commit

Permalink
refactor: make example easily be added
Browse files Browse the repository at this point in the history
  • Loading branch information
luoluoter committed Apr 16, 2024
1 parent 6ac69b6 commit 5c65b29
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 69 deletions.
24 changes: 12 additions & 12 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ reComputer supports a list of examples from [jetson-ai-lab](https://www.jetson-a

All examples that can be run:

| Example | Type | Model Size | Image Size | Command | Device |
| ---------------------- | ------------------------ | ---------- | ---------- | -------------------------------------------- | -------- |
| text-generation-webui | Text (LLM) | 3.9GB | 14.8GB | `reComputer run text-generation-webui` | |
| LLaMA | Text (LLM) | 1.5GB | 10.5GB | `reComputer run Sheared-LLaMA-2.7B-ShareGPT` | |
| llava-v1.5 | Text + Vision (VLM) | 13GB | 14.4GB | `reComputer run llava-v1.5-7b` | |
| llava-v1.6 | Text + Vision (VLM) | 13GB | 20.3GB | `reComputer run llava-v1.6-vicuna-7b` | |
| LLaVA | Text + Vision (VLM) | 13GB | 14.4GB | `reComputer run llava` | |
| Live LLaVA | Text + Vision (VLM) | 13GB | 20.3GB | `reComputer run live-llava` | USB-CAM* |
| stable-diffusion-webui | Image Generation | 3.97G | 7.3GB | `reComputer run stable-diffusion-webui` | |
| nanoowl | Vision Transformers(ViT) | 613MB | 15.1GB | `reComputer run nanoowl` | USB-CAM* |
| nanodb | Vector Database | 76GB | 7.0GB | `reComputer run nanodb` | |
| whisper | Audio | 1.5GB | 6.0GB | `reComputer run whisper` | USB-CAM* |
| Example | Type | Model Size | Image Size | Command | Device |
| ------------------------------------------------ | ------------------------ | ---------- | ---------- | -------------------------------------------- | -------- |
| text-generation-webui | Text (LLM) | 3.9GB | 14.8GB | `reComputer run text-generation-webui` | |
| LLaMA | Text (LLM) | 1.5GB | 10.5GB | `reComputer run Sheared-LLaMA-2.7B-ShareGPT` | |
| llava-v1.5 | Text + Vision (VLM) | 13GB | 14.4GB | `reComputer run llava-v1.5-7b` | |
| llava-v1.6 | Text + Vision (VLM) | 13GB | 20.3GB | `reComputer run llava-v1.6-vicuna-7b` | |
| LLaVA | Text + Vision (VLM) | 13GB | 14.4GB | `reComputer run llava` | |
| Live LLaVA | Text + Vision (VLM) | 13GB | 20.3GB | `reComputer run live-llava` | USB-CAM* |
| stable-diffusion-webui | Image Generation | 3.97G | 7.3GB | `reComputer run stable-diffusion-webui` | |
| nanoowl | Vision Transformers(ViT) | 613MB | 15.1GB | `reComputer run nanoowl` | USB-CAM* |
| [nanodb](../reComputer/scripts/nanodb/readme.md) | Vector Database | 76GB | 7.0GB | `reComputer run nanodb` | |
| whisper | Audio | 1.5GB | 6.0GB | `reComputer run whisper` | USB-CAM* |

> Note: You should have enough space to run example, like `llava-v1.5`, at least `27.4GB` totally
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ namespaces = true
where = ["."]

[tool.setuptools.package-data]
"reComputer.scripts" = ["*.sh"]
"reComputer.scripts" = ["**/*"]
21 changes: 20 additions & 1 deletion reComputer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,36 @@ def script(name):
return script_path


def list_all_examples(folder_path):
directory_names = []
for item in os.listdir(folder_path):
item_path = os.path.join(folder_path, item)
if os.path.isdir(item_path):
directory_names.append(item)
return directory_names


def run_script():
# TODO: maybe use python instead of shell is better

if len(sys.argv) == 3:
if sys.argv[1] == "run":
example_name = sys.argv[2]
# TODO: maybe use python instead of shell is better
subprocess.run(["bash", script("run.sh"), example_name])
else:
print("Only Support `run` for now. try `reComputer run llava` .")
elif len(sys.argv) == 2:
if sys.argv[1] == "check":
subprocess.run(["bash", script("check.sh")])
if sys.argv[1] == "list":
example_folder = os.path.join(os.path.dirname(__file__), "scripts")
directories = list_all_examples(example_folder)
print("example list:")
index = 1
for directory in directories:
print("{:03d}".format(index), "|", directory)
index += 1
print("-end-")
else:
print("Only Support `check` for now. try `reComputer check` .")
else:
Expand Down
5 changes: 5 additions & 0 deletions reComputer/scripts/Sheared-LLaMA-2.7B-ShareGPT/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

./run.sh $(./autotag local_llm) \
python3 -m local_llm.chat --api=mlc \
--model princeton-nlp/Sheared-LLaMA-2.7B-ShareGPT
File renamed without changes.
5 changes: 5 additions & 0 deletions reComputer/scripts/llava-v1.5-7b/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
./run.sh $(./autotag llava) \
python3 -m llava.serve.cli \
--model-path liuhaotian/llava-v1.5-7b \
--image-file /data/images/hoover.jpg
6 changes: 6 additions & 0 deletions reComputer/scripts/llava-v1.6-vicuna-7b/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
./run.sh $(./autotag local_llm) \
python3 -m local_llm --api=mlc \
--model liuhaotian/llava-v1.6-vicuna-7b \
--max-context-len 768 \
--max-new-tokens 128
6 changes: 6 additions & 0 deletions reComputer/scripts/llava/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

./run.sh $(./autotag llava) \
python3 -m llava.serve.cli \
--model-path liuhaotian/llava-v1.5-7b \
--image-file /data/images/hoover.jpg
10 changes: 10 additions & 0 deletions reComputer/scripts/nanodb/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# NanoDB

## ref

- <https://www.jetson-ai-lab.com/tutorial_nanodb.html>

## access

- using in machine, try `http:https://127.0.0.1:7860` in browser.
- using in other pc, make sure you know jetson's IP and try `http:https://<<Jetson's IP>>:7860` in browser.
File renamed without changes.
3 changes: 3 additions & 0 deletions reComputer/scripts/nanoowl/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./run.sh $(./autotag nanoowl) bash -c "ls /dev/video* && cd examples/tree_demo && python3 tree_demo.py ../../data/owl_image_encoder_patch32.engine"
66 changes: 11 additions & 55 deletions reComputer/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,73 +45,29 @@ check_disk_space() {

echo "run example:$1"
BASE_PATH=/home/$USER/reComputer

echo "----example init----"
mkdir -p $BASE_PATH/
JETSON_REPO_PATH="$BASE_PATH/jetson-containers"
BASE_JETSON_LAB_GIT="https://github.com/dusty-nv/jetson-containers/tree/d1573a3e8d7ba3fef36ebb23a7391e60eaf64db7"
if [ -d $JETSON_REPO_PATH ]; then
echo "jetson-ai-lab existed."
else
echo "jetson-ai-lab does not installed. start init..."
cd $BASE_PATH/
git clone --depth=1 https://github.com/dusty-nv/jetson-containers
git clone --depth=1 $BASE_JETSON_LAB_GIT
cd $JETSON_REPO_PATH
sudo apt update; sudo apt install -y python3-pip
pip3 install -r requirements.txt
fi

echo "----example start----"
cd $JETSON_REPO_PATH
case "$1" in
"llava")
./run.sh $(./autotag llava) \
python3 -m llava.serve.cli \
--model-path liuhaotian/llava-v1.5-7b \
--image-file /data/images/hoover.jpg
;;
"llava-v1.5-7b")
./run.sh $(./autotag llava) \
python3 -m llava.serve.cli \
--model-path liuhaotian/llava-v1.5-7b \
--image-file /data/images/hoover.jpg
;;
"llava-v1.6-vicuna-7b")
./run.sh $(./autotag local_llm) \
python3 -m local_llm --api=mlc \
--model liuhaotian/llava-v1.6-vicuna-7b \
--max-context-len 768 \
--max-new-tokens 128
;;
"Sheared-LLaMA-2.7B-ShareGPT")
./run.sh $(./autotag local_llm) \
python3 -m local_llm.chat --api=mlc \
--model princeton-nlp/Sheared-LLaMA-2.7B-ShareGPT
;;
"text-generation-webui")
# download llm model
./run.sh --workdir=/opt/text-generation-webui $(./autotag text-generation-webui) /bin/bash -c \
'python3 download-model.py --output=/data/models/text-generation-webui TheBloke/Llama-2-7b-Chat-GPTQ'
# run text-generation-webui
./run.sh $(./autotag text-generation-webui)
;;
"stable-diffusion-webui")
./run.sh $(./autotag stable-diffusion-webui)
;;
"nanoowl")
./run.sh $(./autotag nanoowl) bash -c "ls /dev/video* && cd examples/tree_demo && python3 tree_demo.py ../../data/owl_image_encoder_patch32.engine"
;;
"whisper")
./run.sh $(./autotag whisper)
;;
"nanodb")
script_dir=$(dirname "$0")
bash $script_dir/nanodb.sh
;;
"live-llava")
script_dir=$(dirname "$0")
bash $script_dir/live-llava.sh
;;
*)
echo "Unknown example"
# handle unknown
;;
esac
script_dir=$(dirname "$0")
start_script=$script_dir/$1/run.sh
if [ -f $start_script ]; then
bash $start_script
else
echo "ERROR: Example[$1] Not Found."
fi
echo "----example done----"
3 changes: 3 additions & 0 deletions reComputer/scripts/stable-diffusion-webui/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./run.sh $(./autotag stable-diffusion-webui)
8 changes: 8 additions & 0 deletions reComputer/scripts/text-generation-webui/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# download llm model
./run.sh --workdir=/opt/text-generation-webui $(./autotag text-generation-webui) /bin/bash -c \
'python3 download-model.py --output=/data/models/text-generation-webui TheBloke/Llama-2-7b-Chat-GPTQ'

# run text-generation-webui
./run.sh $(./autotag text-generation-webui)
3 changes: 3 additions & 0 deletions reComputer/scripts/whisper/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./run.sh $(./autotag whisper)

0 comments on commit 5c65b29

Please sign in to comment.