Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0c6e8d5
Fix setup_env.sh with more flexible logic
juk1329 Jul 30, 2025
44f1066
Fix the .gitignore and comments in yaml files
juk1329 Jul 30, 2025
ca18e95
Add initial vlm fine-tuning pipeline copied from language model pipeline
juk1329 Jul 30, 2025
f7b7915
Add the pipeline code for vlm
juk1329 Aug 1, 2025
baec079
Simplify code and fix data download logic
juk1329 Aug 4, 2025
540c0f3
Add video data process and fix image data process
juk1329 Aug 4, 2025
2ab2eab
Fix evaluate_base_model in vlm_cli.py
juk1329 Aug 5, 2025
6a626ca
Fix configs/README.md
juk1329 Aug 5, 2025
547716f
Fix args and path
juk1329 Aug 5, 2025
f9fad93
Fix loading model and processor
juk1329 Aug 5, 2025
a21f106
Fix identify special token logic and loading processor code
juk1329 Aug 6, 2025
4cc6ea6
Fix data_collator and evaluation logic
juk1329 Aug 6, 2025
cb718c3
Fix identify special token logic
juk1329 Aug 6, 2025
7057d41
Fix model config example and print code in collate_fn.py
juk1329 Aug 6, 2025
ec66044
Simplify special token logic and fix SFTTrainer parameter
juk1329 Aug 6, 2025
92a031c
Fix evaluation and fine-tuning logic
juk1329 Aug 6, 2025
d963f35
Fix fine-tuning and evaluate code
juk1329 Aug 6, 2025
1277ee9
Fix vlm_collator_config.yaml
juk1329 Aug 6, 2025
d369792
Fix fine-tuning setting
juk1329 Aug 7, 2025
bcbee6f
Fix fine-tuning setting and simplify log print
juk1329 Aug 7, 2025
fb76303
Fix train_config.yaml
juk1329 Aug 7, 2025
02cfd23
Simplify log print code
juk1329 Aug 7, 2025
e73bae9
Fix wandb run name
juk1329 Aug 7, 2025
3861490
Fix default model loader
juk1329 Aug 11, 2025
64c6d10
Fix requirements.txt path in setup_env.sh
juk1329 Aug 11, 2025
0bf9512
Fix image data processing logic and simplify code in collate_fn.py
juk1329 Aug 11, 2025
5255361
Fix image processing logic and simplify code in evaluation.py
juk1329 Aug 12, 2025
b8e9039
Fix evaluate logic and generalize data collator
juk1329 Aug 25, 2025
b506b3f
Simplify evaluation logic in language model and refine code
juk1329 Aug 28, 2025
f8b4035
Fix collate_fn.py to generalize VLM pipeline
juk1329 Aug 28, 2025
c6d9bfd
Updated README.md and vlm_collator_config example
juk1329 Aug 29, 2025
cdb0b26
Fix chmod of setup_env.sh
juk1329 Aug 29, 2025
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
Prev Previous commit
Next Next commit
Fix identify special token logic and loading processor code
  • Loading branch information
juk1329 committed Aug 6, 2025
commit a21f106d0a5229509e1bb58ebf48ec79e2003011
24 changes: 24 additions & 0 deletions pytorch/vlm-models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@

이 프로젝트는 Vision-Language Model (VLM)에 대해 Hugging Face 데이터셋으로 파인튜닝하고 평가하는 파이프라인을 제공합니다.

**주요 특징**:

- 🤖 **자동 특수 토큰 감지**: 모델의 tokenizer에서 모든 특수 토큰을 자동으로 감지하고 설정
- 🔄 **범용 VLM 지원**: 다양한 VLM 모델 아키텍처를 자동으로 지원
- 🛡️ **안전한 설정**: 사용자의 수동 토큰 설정 오류를 방지하는 자동화 시스템
- 📊 **포괄적 평가**: VLM 태스크에 특화된 평가 지표 제공

**주요 변경사항**: 기존 Language Model 파이프라인을 VLM 파이프라인으로 전환하였습니다.

## ✨ 새로운 자동 특수 토큰 감지 시스템

**더 이상 특수 토큰을 수동으로 설정할 필요가 없습니다!**

### 🔍 자동 감지 기능

- **4단계 자동 감지**: Core tokens → Additional tokens → Visual tokens → Template compatibility
- **모델별 적응**: 각 VLM 모델의 특수 토큰을 자동으로 파악
- **안전한 처리**: 잘못된 토큰 설정으로 인한 학습 오류 방지

### 🎯 감지되는 토큰 유형

- **기본 토큰**: pad, eos, bos, unk, sep, cls, mask
- **VLM 토큰**: `<image>`, `<video>`, `<|vision_start|>`, `<|vision_end|>` 등
- **모델별 토큰**: Qwen2VL, LLaVA, PaliGemma 등의 모델 특화 토큰
- **템플릿 토큰**: apply_chat_template에서 사용되는 토큰들

## 🚀 Quick Start

### 환경 설정
Expand Down
26 changes: 21 additions & 5 deletions pytorch/vlm-models/pipeline-code/configs/vlm_collator_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,28 @@ batch_processing:
return_tensors: "pt" # 반환할 텐서 타입
padding_strategy: "longest" # 패딩 전략: longest, max_length

# 특수 토큰 설정 (모델별로 다를 수 있음)
# 특수 토큰 설정 (자동 감지 사용, 수동 설정 불필요)
special_tokens:
image_token: "<image>" # 이미지 토큰
video_token: "<video>" # 비디오 토큰 (필요시)
pad_token: null # 패드 토큰 (auto-detect)
eos_token: null # EOS 토큰 (auto-detect)
# ✨ 새로운 자동 감지 시스템 ✨
# 이제 tokenizer.special_tokens_map과 additional_special_tokens에서
# 모든 특수 토큰을 자동으로 감지하므로 수동 설정이 불필요합니다!

# 🔧 기본 동작:
# - 패드, EOS, BOS 등 core 토큰들 자동 감지
# - 이미지, 비디오 등 VLM 관련 토큰들 자동 감지
# - apply_chat_template과 호환성 자동 검증
# - 손실 계산 시 자동 마스킹 적용

# 📝 Manual override (선택사항 - 고급 사용자용)
# 자동 감지가 실패하는 경우에만 아래 섹션을 활성화하세요
manual_tokens:
enabled: false # true로 변경시 수동 토큰 설정 활성화
tokens:
[]
# 예시 (필요시에만 사용):
# - name: "custom_image_token"
# token: "<custom_image>"
# ignore_in_loss: true

# 비디오 처리 설정
video_processing:
Expand Down
35 changes: 20 additions & 15 deletions pytorch/vlm-models/pipeline-code/configs/vlm_model_config.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
# VLM Model Configuration
# 다양한 VLM 모델에 대한 클래스 매핑 설정
#
# 📝 Processor 설정 방식:
# - processor_class가 지정되지 않으면 기본적으로 AutoProcessor 사용 (권장)
# - 특수한 processor가 필요한 모델만 processor_class 명시적 지정
# - 대부분의 VLM 모델은 AutoProcessor로 충분히 호환됩니다

# 모델별 클래스 매핑
model_classes:
# Qwen2-VL 모델들
# Qwen2-VL 모델들 (특수 processor 필요)
"Qwen/Qwen2-VL-2B-Instruct":
model_class: "Qwen2VLForConditionalGeneration"
processor_class: "Qwen2VLProcessor"
processor_class: "Qwen2VLProcessor" # 특수 processor 명시적 지정
import_path: "transformers"

"Qwen/Qwen2-VL-7B-Instruct":
model_class: "Qwen2VLForConditionalGeneration"
processor_class: "Qwen2VLProcessor"
processor_class: "Qwen2VLProcessor" # 특수 processor 명시적 지정
import_path: "transformers"

# LLaVA 모델들
# LLaVA 모델들 (AutoProcessor 사용)
"llava-hf/llava-1.5-7b-hf":
model_class: "LlavaForConditionalGeneration"
processor_class: "LlavaProcessor"
import_path: "transformers"
# processor_class 미지정 -> AutoProcessor 사용

"llava-hf/llava-1.5-13b-hf":
model_class: "LlavaForConditionalGeneration"
processor_class: "LlavaProcessor"
import_path: "transformers"
# processor_class 미지정 -> AutoProcessor 사용

# InternVL 모델들
# InternVL 모델들 (AutoProcessor 사용)
"OpenGVLab/InternVL2-2B":
model_class: "InternVLChatModel"
processor_class: "InternVLChatProcessor"
import_path: "transformers"
# processor_class 미지정 -> AutoProcessor 사용

# PaliGemma 모델들
# PaliGemma 모델들 (특수 processor 필요)
"google/paligemma-3b-pt-448":
model_class: "PaliGemmaForConditionalGeneration"
processor_class: "PaliGemmaProcessor"
processor_class: "PaliGemmaProcessor" # 특수 processor 명시적 지정
import_path: "transformers"

# Phi-3-Vision 모델들
# Phi-3-Vision 모델들 (AutoProcessor 사용)
"microsoft/Phi-3-vision-128k-instruct":
model_class: "Phi3VForCausalLM"
processor_class: "Phi3VProcessor"
import_path: "transformers"
# processor_class 미지정 -> AutoProcessor 사용

# 기본 fallback 설정 (AutoModel 사용)
# 기본 fallback 설정 (VLM용 AutoModel 사용)
default_fallback:
model_class: "AutoModelForCausalLM"
processor_class: "AutoProcessor"
model_class: "AutoModelForVision2Seq"
import_path: "transformers"
# processor_class 미지정 -> AutoProcessor 사용

# 공통 로딩 파라미터
loading_params:
Expand Down
Loading