Skip to content

Commit

Permalink
fix ccocr import problem and args nproc conflict with --nproc-per-node
Browse files Browse the repository at this point in the history
  • Loading branch information
FangXinyu-0913 committed Jan 10, 2025
1 parent 27dd622 commit a0b5551
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/en/EvalByLMDeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ lmdeploy serve api_server OpenGVLab/InternVL2-8B --model-name InternVL2-8B
## Step 2: Evaluation

```bash
python run.py --data MMStar --model lmdeploy --verbose --nproc 64
python run.py --data MMStar --model lmdeploy --verbose --api_nproc 64
```
2 changes: 1 addition & 1 deletion docs/en/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ We use `run.py` for evaluation. To use the script, you can use `$VLMEvalKit/run.
- `--data (list[str])`: Set the dataset names that are supported in VLMEvalKit (names can be found in the codebase README).
- `--model (list[str])`: Set the VLM names that are supported in VLMEvalKit (defined in `supported_VLM` in `vlmeval/config.py`).
- `--mode (str, default to 'all', choices are ['all', 'infer'])`: When `mode` set to "all", will perform both inference and evaluation; when set to "infer", will only perform the inference.
- `--nproc (int, default to 4)`: The number of threads for OpenAI API calling.
- `--api_nproc (int, default to 4)`: The number of threads for OpenAI API calling.
- `--work-dir (str, default to '.')`: The directory to save evaluation results.

**Command for Evaluating Image Benchmarks **
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/EvalByLMDeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ lmdeploy serve api_server OpenGVLab/InternVL2-8B --model-name InternVL2-8B
## 第2步 评测

```bash
python run.py --data MMStar --model InternVL2-8B --verbose --nproc 64
python run.py --data MMStar --model InternVL2-8B --verbose --api_nproc 64
```
2 changes: 1 addition & 1 deletion docs/zh-CN/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pip install -e .
- `--data (list[str])`: 设置在 VLMEvalKit 中支持的数据集名称(可以在代码库首页的 README 中找到支持的数据集列表)
- `--model (list[str])`: 设置在 VLMEvalKit 中支持的 VLM 名称(在 `vlmeval/config.py` 中的 `supported_VLM` 中定义)
- `--mode (str, 默认值为 'all', 可选值为 ['all', 'infer'])`:当 mode 设置为 "all" 时,将执行推理和评估;当设置为 "infer" 时,只执行推理
- `--nproc (int, 默认值为 4)`: 调用 API 的线程数
- `--api_nproc (int, 默认值为 4)`: 调用 API 的线程数
- `--work-dir (str, default to '.')`: 存放测试结果的目录

**用于评测图像多模态评测集的命令**
Expand Down
10 changes: 5 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def parse_args():
# Infer + Eval or Infer Only
parser.add_argument('--mode', type=str, default='all', choices=['all', 'infer'])
# API Kwargs, Apply to API VLMs and Judge API LLMs
parser.add_argument('--nproc', type=int, default=4, help='Parallel API calling')
parser.add_argument('--api_nproc', type=int, default=4, help='Parallel API calling')
parser.add_argument('--retry', type=int, default=None, help='retry numbers for API VLMs')
# Explicitly Set the Judge Model
parser.add_argument('--judge', type=str, default=None)
Expand Down Expand Up @@ -285,15 +285,15 @@ def main():
dataset=dataset,
result_file_name=result_file_base,
verbose=args.verbose,
api_nproc=args.nproc)
api_nproc=args.api_nproc)
elif dataset.TYPE == 'MT':
model = infer_data_job_mt(
model,
work_dir=pred_root,
model_name=model_name,
dataset=dataset,
verbose=args.verbose,
api_nproc=args.nproc,
api_nproc=args.api_nproc,
ignore_failed=args.ignore)
else:
model = infer_data_job(
Expand All @@ -302,13 +302,13 @@ def main():
model_name=model_name,
dataset=dataset,
verbose=args.verbose,
api_nproc=args.nproc,
api_nproc=args.api_nproc,
ignore_failed=args.ignore)

# Set the judge kwargs first before evaluation or dumping

judge_kwargs = {
'nproc': args.nproc,
'nproc': args.api_nproc,
'verbose': args.verbose,
'retry': args.retry if args.retry is not None else 3
}
Expand Down
13 changes: 6 additions & 7 deletions vlmeval/dataset/image_ccocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
from functools import partial
import pandas as pd

try:
from .utils.ccocr_evaluator import evaluator_map_info as ccocr_evaluator_map
except ImportError as err:
import warnings
warnings.warn('The dependency of CCOCR evaluator is not properly installed')
warnings.warn(f'{type(err)}: {err}')

from .image_base import ImageBaseDataset
from ..smp import *

Expand Down Expand Up @@ -176,6 +169,12 @@ def evaluate(self, eval_file, **judge_kwargs):
data_name = set([str(x) for x in df['split']]).pop()

data_info = {"op": op_name, "group": group_name, "dataset": data_name, "num": len(gt_info)}
try:
from .utils.ccocr_evaluator import evaluator_map_info as ccocr_evaluator_map
except ImportError as err:
import warnings
warnings.warn('The dependency of CCOCR evaluator is not properly installed')
warnings.warn(f'{type(err)}: {err}')
eval_func = ccocr_evaluator_map.get(group_name, None)
if eval_func is None:
raise ValueError("error: evaluator not defined for: {}".format(group_name))
Expand Down
2 changes: 1 addition & 1 deletion vlmeval/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def extract_dataset(file_name):

dataset = extract_dataset(data_file)
assert dataset is not None, f'Cannot infer dataset name from {data_file}'
kwargs = {'nproc': args.nproc}
kwargs = {'nproc': args.api_nproc}
if args.judge is not None:
kwargs['model'] = args.judge
if args.retry is not None:
Expand Down

0 comments on commit a0b5551

Please sign in to comment.