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

Temporary fix qwenvl2 queue error #688

Merged
merged 3 commits into from
Oct 13, 2024
Merged
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
2 changes: 1 addition & 1 deletion examples/vlm/dataflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 23 additions & 4 deletions node-hub/dora-qwenvl/dora_qwenvl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
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",
Expand All @@ -20,14 +29,14 @@
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",
)
Expand All @@ -38,7 +47,7 @@


# default processor
processor = AutoProcessor.from_pretrained(CUSTOM_MODEL_PATH)
processor = AutoProcessor.from_pretrained(MODEL_NAME_OR_PATH)


def generate(frames: dict, question):
Expand Down Expand Up @@ -101,6 +110,16 @@ def main():
event_type = event["type"]

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)
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:
Expand Down
1 change: 1 addition & 0 deletions node-hub/dora-qwenvl/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading