Skip to content

Commit edd5ba8

Browse files
committed
feat: add manga VQA task and related utilities; update dependencies and Python version
1 parent 60a59e4 commit edd5ba8

6 files changed

Lines changed: 117 additions & 12 deletions

File tree

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

=0.11.0

Whitespace-only changes.

examples/models/vllm_qwen3vl.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/bash
2+
HF_CACHE="/data/users/mserrao/hf-cache"
3+
export CUDA_VISIBLE_DEVICES=7
4+
export HUGGIN
5+
export HF_HOME=$HF_CACHE
6+
export TRANSFORMERS_CACHE=$HF_CACHE
7+
export HF_DATASETS_CACHE=$HF_CACHE
8+
export HUGGINGFACE_HUB_CACHE=$HF_CACHE
9+
# export HF_HUB_OFFLINE=1
210

311
# Qwen3-VL Evaluation Script with vLLM Backend
412
# This script demonstrates how to evaluate Qwen3-VL models using vLLM for accelerated inference
@@ -23,20 +31,20 @@
2331
# - Qwen/Qwen3-VL-30B-A3B-Thinking
2432
# - Qwen/Qwen3-VL-235B-A22B-Instruct
2533
# - Qwen/Qwen3-VL-235B-A22B-Thinking
26-
MODEL="Qwen/Qwen3-VL-30B-A3B-Instruct"
34+
MODEL="Qwen/Qwen3-VL-2B-Instruct"
2735

2836
# Parallelization Settings
2937
# Adjust based on your GPU configuration
30-
TENSOR_PARALLEL_SIZE=4 # Number of GPUs for tensor parallelism
38+
TENSOR_PARALLEL_SIZE=1 # Number of GPUs for tensor parallelism
3139
DATA_PARALLEL_SIZE=1 # Number of GPUs for data parallelism
3240

3341
# Memory and Performance Settings
34-
GPU_MEMORY_UTILIZATION=0.85 # Fraction of GPU memory to use (0.0 - 1.0)
35-
BATCH_SIZE=64 # Batch size for evaluation
36-
42+
GPU_MEMORY_UTILIZATION=0.90 # Fraction of GPU memory to use (0.0 - 1.0)
43+
BATCH_SIZE=16 # Batch size for evaluation
44+
MAX_MODEL_LEN=$((2**15))
3745
# Task Configuration
3846
# Common tasks: mmmu_val, mme, mathvista, ai2d, etc.
39-
TASKS="mmmu_val,mme"
47+
TASKS="manga_vqa_test"
4048

4149
# Output Configuration
4250
OUTPUT_PATH="./logs/qwen3vl_vllm"
@@ -69,12 +77,14 @@ echo "Output Path: $OUTPUT_PATH"
6977
echo "=========================================="
7078

7179
# Build the command
72-
CMD="uv run python -m lmms_eval \
80+
CMD="python -m lmms_eval \
7381
--model vllm \
74-
--model_args model=${MODEL},tensor_parallel_size=${TENSOR_PARALLEL_SIZE},data_parallel_size=${DATA_PARALLEL_SIZE},gpu_memory_utilization=${GPU_MEMORY_UTILIZATION} \
82+
--model_args model=${MODEL},tensor_parallel_size=${TENSOR_PARALLEL_SIZE},data_parallel_size=${DATA_PARALLEL_SIZE},gpu_memory_utilization=${GPU_MEMORY_UTILIZATION},max_model_len=${MAX_MODEL_LEN}\
7583
--tasks ${TASKS} \
7684
--batch_size ${BATCH_SIZE} \
77-
--output_path ${OUTPUT_PATH}"
85+
--output_path ${OUTPUT_PATH} \
86+
--verbosity=DEBUG"
87+
7888

7989
# Add optional arguments
8090
if [ "$LOG_SAMPLES" = true ]; then
@@ -96,4 +106,4 @@ echo ""
96106
echo "=========================================="
97107
echo "Evaluation Complete!"
98108
echo "Results saved to: $OUTPUT_PATH"
99-
echo "=========================================="
109+
echo "=========================================="
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
dataset_path: hal-utokyo/MangaVQA
2+
# dataset_name: MangaVQA
3+
task: "manga_vqa_test"
4+
dataset_kwargs:
5+
token: True
6+
test_split: test
7+
output_type: generate_until
8+
doc_to_visual: !function utils.mangavqa_doc_to_visual
9+
doc_to_text: !function utils.mangavqa_doc_to_text
10+
doc_to_target: "answer"
11+
generation_kwargs:
12+
max_new_tokens: 32
13+
temperature: 0
14+
top_p: 1.0
15+
num_beams: 1
16+
do_sample: False
17+
process_results: !function utils.mangavqa_test_process_results
18+
metric_list:
19+
- metric: submission
20+
aggregation: !function utils.mangavqa_test_aggregate_results
21+
higher_is_better: true
22+
- metric: anls
23+
aggregation: mean
24+
higher_is_better: true
25+
- metric: f1
26+
aggregation: mean
27+
higher_is_better: true
28+
ignore_case: true
29+
ignore_punctuation: true
30+
- metric: exact_match
31+
aggregation: mean
32+
higher_is_better: true
33+
ignore_case: true
34+
ignore_punctuation: true
35+
regexes_to_ignore:
36+
- ","
37+
- "\\$"
38+
lmms_eval_specific_kwargs:
39+
default:
40+
pre_prompt: ""
41+
post_prompt: "\nAnswer the question using a single word or phrase."
42+
qwen_vl:
43+
pre_prompt: ""
44+
post_prompt: " Answer:"
45+
metadata:
46+
- version: 0.0

lmms_eval/tasks/manga_vqa/utils.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
import os
3+
4+
from PIL import Image
5+
6+
from loguru import logger
7+
8+
from lmms_eval.tasks._task_utils.file_utils import generate_submission_file
9+
10+
IMAGES_PATH = "/data-net/storage/users/evivoli/CoMix/data/datasets/Manga109/images"
11+
12+
def mangavqa_doc_to_visual(doc):
13+
book = doc["title"]
14+
image_num = doc["image_number"]
15+
16+
image = Image.open(os.path.join(IMAGES_PATH, book, f"{image_num:03d}.jpg"))
17+
18+
return [image.convert("RGB")]
19+
20+
def mangavqa_doc_to_text(doc, lmms_eval_specific_kwargs):
21+
question = doc["question"]
22+
pre_prompt = lmms_eval_specific_kwargs["pre_prompt"]
23+
post_prompt = lmms_eval_specific_kwargs["post_prompt"]
24+
return f"{pre_prompt}{question}{post_prompt}"
25+
26+
def mangavqa_test_process_results(doc, results):
27+
pred = results[0]
28+
questionId = doc["questionId"]
29+
30+
results_dict = {
31+
"anls": {"questionId": int(questionId), "answer": pred},
32+
"f1": {"questionId": int(questionId), "answer": pred},
33+
"exact_match": {"questionId": int(questionId), "answer": pred},
34+
"submission": {"questionId": int(questionId), "answer": pred},
35+
}
36+
37+
return results_dict
38+
39+
def mangavqa_test_aggregate_results(results, args):
40+
# save results as json
41+
path = generate_submission_file("docvqa_test_for_submission.json", args)
42+
with open(path, "w") as f:
43+
json.dump(results, f)
44+
logger.info(f"Results saved to {path}")
45+
46+

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3",
2020
"Operating System :: OS Independent",
2121
]
22-
requires-python = ">=3.9"
22+
requires-python = ">=3.10"
2323
dependencies = [
2424
"accelerate>=0.29.1",
2525
"black>=24.1.0",
@@ -51,7 +51,7 @@ dependencies = [
5151
"yt-dlp",
5252
"pycocoevalcap",
5353
"tqdm-multiprocess",
54-
"transformers>=4.39.2",
54+
"transformers==4.57.1",
5555
"transformers-stream-generator",
5656
"zstandard",
5757
"pillow",
@@ -74,6 +74,8 @@ dependencies = [
7474
"sentence_transformers",
7575
"python-dotenv",
7676
"qwen-vl-utils>=0.0.14",
77+
"vllm>=0.11.0",
78+
"decord>=0.6.0",
7779
]
7880

7981
[project.optional-dependencies]

0 commit comments

Comments
 (0)