From edc14676124ffd16acaef1e67fb33ce04d375280 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Sat, 12 Oct 2024 00:18:04 +0200 Subject: [PATCH 1/3] Add next call loop in qwenvl2 to queue fix --- examples/vlm/dataflow.yml | 2 +- node-hub/dora-qwenvl/dora_qwenvl/main.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/vlm/dataflow.yml b/examples/vlm/dataflow.yml index 51371b67..bfb61821 100644 --- a/examples/vlm/dataflow.yml +++ b/examples/vlm/dataflow.yml @@ -18,7 +18,7 @@ nodes: image: source: camera/image queue_size: 1 - tick: dora/timer/millis/300 + tick: dora/timer/millis/100 outputs: - text - tick diff --git a/node-hub/dora-qwenvl/dora_qwenvl/main.py b/node-hub/dora-qwenvl/dora_qwenvl/main.py index c6c735b5..71923297 100644 --- a/node-hub/dora-qwenvl/dora_qwenvl/main.py +++ b/node-hub/dora-qwenvl/dora_qwenvl/main.py @@ -101,6 +101,15 @@ def main(): event_type = event["type"] if event_type == "INPUT": + + # TODO: Remove this after https://github.com/dora-rs/dora/pull/652 + while True: + next_event = node.next(timeout=0.001) + if next_event is not None and next_event["type"] == "INPUT": + event = next_event + else: + break + event_id = event["id"] if "image" in event_id: From 9e495c5dfd33881a5c9ebd4190cc09dfaeff39ce Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Sat, 12 Oct 2024 03:13:34 +0200 Subject: [PATCH 2/3] Disable pylint fixme --- node-hub/dora-qwenvl/dora_qwenvl/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/node-hub/dora-qwenvl/dora_qwenvl/main.py b/node-hub/dora-qwenvl/dora_qwenvl/main.py index 71923297..4538c63e 100644 --- a/node-hub/dora-qwenvl/dora_qwenvl/main.py +++ b/node-hub/dora-qwenvl/dora_qwenvl/main.py @@ -102,6 +102,7 @@ def main(): if event_type == "INPUT": + # pylint: disable=fixme # TODO: Remove this after https://github.com/dora-rs/dora/pull/652 while True: next_event = node.next(timeout=0.001) From 309b40aaf097e840f55e8c975bbbaa5f30a62646 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Sun, 13 Oct 2024 06:02:07 +0200 Subject: [PATCH 3/3] Add `modelscope` to qwenvl --- node-hub/dora-qwenvl/dora_qwenvl/main.py | 17 +++++++++++++---- node-hub/dora-qwenvl/pyproject.toml | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/node-hub/dora-qwenvl/dora_qwenvl/main.py b/node-hub/dora-qwenvl/dora_qwenvl/main.py index 4538c63e..7a2b6119 100644 --- a/node-hub/dora-qwenvl/dora_qwenvl/main.py +++ b/node-hub/dora-qwenvl/dora_qwenvl/main.py @@ -5,10 +5,19 @@ from qwen_vl_utils import process_vision_info import numpy as np import pyarrow as pa from PIL import Image +from pathlib import Path import cv2 DEFAULT_PATH = "Qwen/Qwen2-VL-2B-Instruct" -CUSTOM_MODEL_PATH = os.getenv("CUSTOM_MODEL_PATH", DEFAULT_PATH) + +MODEL_NAME_OR_PATH = os.getenv("MODEL_NAME_OR_PATH", DEFAULT_PATH) + +if bool(os.getenv("MODELSCOPE")) is True: + from modelscope import snapshot_download + + if not Path(MODEL_NAME_OR_PATH).exists(): + MODEL_NAME_OR_PATH = snapshot_download(MODEL_NAME_OR_PATH) + DEFAULT_QUESTION = os.getenv( "DEFAULT_QUESTION", "Describe this image", @@ -20,14 +29,14 @@ try: import flash_attn as _ model = Qwen2VLForConditionalGeneration.from_pretrained( - CUSTOM_MODEL_PATH, + MODEL_NAME_OR_PATH, torch_dtype="auto", device_map="auto", attn_implementation="flash_attention_2", ) except (ImportError, ModuleNotFoundError): model = Qwen2VLForConditionalGeneration.from_pretrained( - CUSTOM_MODEL_PATH, + MODEL_NAME_OR_PATH, torch_dtype="auto", device_map="auto", ) @@ -38,7 +47,7 @@ if ADAPTER_PATH != "": # default processor -processor = AutoProcessor.from_pretrained(CUSTOM_MODEL_PATH) +processor = AutoProcessor.from_pretrained(MODEL_NAME_OR_PATH) def generate(frames: dict, question): diff --git a/node-hub/dora-qwenvl/pyproject.toml b/node-hub/dora-qwenvl/pyproject.toml index eac55946..f4f9f1bd 100644 --- a/node-hub/dora-qwenvl/pyproject.toml +++ b/node-hub/dora-qwenvl/pyproject.toml @@ -20,6 +20,7 @@ transformers = "^4.45" qwen-vl-utils = "^0.0.2" accelerate = "^0.33" opencv-python = ">= 4.1.1" +modelscope = "^1.18.1" # flash_attn = "^2.6.1" # Install using: pip install -U flash-attn --no-build-isolation