Browse Source

Temporary fix qwenvl2 queue error (#688)

In order to get the best performance from Qwenvl2, we need to temporary
add this piece of code that is going to unqueue qwenvl queue.

This is directly linked to: https://github.com/dora-rs/dora/pull/652
which is that we currently having a queue issue within nodes for
`queue_size: 1` where the queue is actually pending older data and not
the newest one.
tags/v0.3.7rc0
Haixuan Xavier Tao GitHub 1 year ago
parent
commit
a90221d70b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 5 deletions
  1. +1
    -1
      examples/vlm/dataflow.yml
  2. +23
    -4
      node-hub/dora-qwenvl/dora_qwenvl/main.py
  3. +1
    -0
      node-hub/dora-qwenvl/pyproject.toml

+ 1
- 1
examples/vlm/dataflow.yml View File

@@ -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


+ 23
- 4
node-hub/dora-qwenvl/dora_qwenvl/main.py View File

@@ -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):
@@ -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:


+ 1
- 0
node-hub/dora-qwenvl/pyproject.toml View File

@@ -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




Loading…
Cancel
Save