8000 KIE bench 추가 (VQA 단독모델, full benchmark) by ts-kim · Pull Request #15 · UpstageAI/lmms-eval · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

KIE bench 추가 (VQA 단독모델, full benchmark) #15

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

Merged
merged 10 commits into from
May 6, 2025
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ lmms_eval/tasks/vatex/__pycache__/utils.cpython-310.pyc
lmms_eval/tasks/mlvu/__pycache__/utils.cpython-310.pyc

scripts/
.env
.env
UpScore_results/
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,19 @@ scripts/run_eval.sh \
--tasks docvqa \
--gpu_ids 0,1,2,3 \
--port 35001
```
```


### (Optional) KIE_bench 사용을 위한 추가 설정
- `pdf2image` 파이썬 라이브러리 사용을 위해 `poppler-utils` 설치가 필요합니다.
```
apt-get install poppler-utils
```

- Dataset 전처리 (KIE-bench -> KIE-bench huggingface version)
- 주의: 이를 통해 생성된 KIE-bench huggingface version에는 일부 정보가 실제 Upstage huggingface uploaded version과 다를 수 있습니다. (다른 부분은 코드 참고) 하지만 사용되지 않는 부분이기에 최신 버전의 KIE bench를 빠르게 적용하기 위해 전처리 코드를 작성하였습니다. 최신 버전의 KIE-bench가 huggingface에 업로드 되어 있는 경우, 해당 데이터를 다운로드 받아 사용하시기 바랍니다.
```
# 1. 코드 내 base_path 변수 수정
# 2. 아래 코드 실행
python preprocessor/KIE_bench_to_HF_dataset.py
```
3 changes: 1 addition & 2 deletions lmms_eval/api/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,9 @@ def concat_tar_parts(tar_parts, output_tar):
dataset_kwargs.pop("create_link")

if dataset_kwargs is not None and "load_from_disk" in dataset_kwargs and dataset_kwargs["load_from_disk"]:
dataset_kwargs.pop("load_from_disk")
# using local task in offline environment, need to process the online dataset into local format via
# `ds = load_datasets("lmms-lab/MMMU")`
self.dataset = datasets.load_from_disk(path=self.DATASET_PATH, name=self.DATASET_NAME)
self.dataset = datasets.load_from_disk(dataset_path=self.DATASET_PATH)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 lmms-eval 최신 코드를 적용하신 것 같은데 맞을까요?

나중에 최신 main 으로 rebase 한번 해야겠군요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다.
말씀하신대로 똑같은 fix가 적용되어 있던데, main rebase작업 자체도 큰 일 같아 일단 해당 부분만 처리해두었습니다

else:
self.dataset = datasets.load_dataset(
path=self.DATASET_PATH,
Expand Down
5 changes: 3 additions & 2 deletions lmms_eval/models/docvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def get_config(pretrained):

self._batch_size_per_gpu = int(batch_size)
self._image_token = self.config.components.lm.image_token
self._eos_token = self.config.test.get("stop_token", None)
assert self._eos_token is not None, "test.stop_token (e.g., <|im_end|>) in training_config.yaml is not set!"

# 2. accelerator 초기화
accelerator_kwargs = InitProcessGroupKwargs(timeout=timedelta(weeks=52))
Expand All @@ -74,6 +72,9 @@ def get_config(pretrained):
test=True,
)
self._model.eval()
self._eos_token = self.config.test.get("stop_token", None)
assert self._eos_token is not None, "test.stop_token (e.g., <|im_end|>) in training_config.yaml is not set!"

self._eos_token_id = self.tokenizer.convert_tokens_to_ids(self._eos_token)

# 4. DeepSpeed 설정 초기화 및 accelerator 적용
Expand Down
40 changes: 40 additions & 0 deletions lmms_eval/tasks/KIE_bench/KIE_bench_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
task: "KIE_bench"
test_split: test

# Dataset configuration options
dataset_path: "/app/docfm/datasets/benchmark/key_information_extraction/v3.1_HuggingFace"
dataset_name: "KIE_bench"
dataset_kwargs:
load_from_disk: true
process_docs: null

# Prompting / in-context formatting options
doc_to_visual: !function utils.KIE_bench_doc_to_visual
doc_to_text: !function utils.KIE_bench_doc_to_text
doc_to_target: !function utils.KIE_bench_doc_to_target
doc_to_choice: null

# Generation settings
output_type: generate_until
generation_kwargs: {}

# Post-processing and metrics
process_results: !function utils.KIE_bench_process_results
metric_list:
- metric: UpScore
aggregation: !function utils.KIE_bench_aggregate_results
higher_is_better: true


# Model-specific prompt configurations
lmms_eval_specific_kwargs:
default:
pre_prompt: "Extract information from the given image based on this schema: "
Copy link
Collaborator
@hancheolcho hancheolcho Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마지막에 \n이 필요할까요?

밑에 utils.py 를 보면 pre_prompt, question, post_prompt를 구분자 없이 붙이고 있는데, post_prompt는 맨 앞에 \n이 있더라구요.
question은 아마 strip된 텍스트일테니, pre_prompt 끝에 \n을 붙여줘야하나?라는 궁금증이 들었습니다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n이 들어간 이유

기존의 프롬프트는 info-extractor-engine 의 main branch에서 가져온 것인데요.

EXTRACT_USER_PROMPT = """Content to analyze: {content}

1. If you cannot find the information or the value is not mentioned, return nothing.
2. If you can find more than one value for a key, return all the values in an array.
3. Return the value only if the given key’s value exists in the provided content. If it does not exist, return empty string."""

위와 같이 정의되어있습니다. 여기에서 빈 줄을 따라 만들었기에 '\n'이 포함된 형태로 사용되었습니다.

  • content: 문서 HTML

고려해야할 점

schema 포함 여부에 따른 프롬프트 변화

기존에는 LLM의 평가를 위한 프롬프트이고 schema는 formatting을 위한 자료로서 따로 입력되는 형태였다면, lmms-eval에서는 VLM을 평가하기 위한 프롬프트이고, schema가 포함되어야 합니다.

모델 입력 별도 입력
기존 HTML, 프롬프트 schema
lmms-eval 이미지, 프롬프트, schema

이러한 문제를 해결하기 위해 lmms-eval 에서는 [이미지][pre prompt - schema - post prompt] 형태로 입력했습니다.

schema 이후 줄바꿈을 해야하는가?

  • 콜론 뒤에 나타나는 내용과 1,2,3으로 표시되는 조건들을 구분하기 위해 있으면 좋겠다는 것이 제 의견입니다.

post_prompt: "\n1. If you cannot find the information or the value is not mentioned, return nothing.\n2. If you can find more than one value for a key, return all the values in an array.\n3. Return the value only if the given key’s value exists in the provided content. If it does not exist, return empty string."
metadata:
- version: 0.0


# Additional metadata
metadata:
- version: 0.0
Empty file.
Loading
Loading
0