Downloads · 30 days
5
18% of all-time downloads
dohoon0508/Dohoon_Qwen2-VL-7B-Instruct_ForAju
Dohoon_Qwen2-VL-7B-Instruct_ForAju is a text generation model from dohoon0508. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
단일 멀티모달 모델(이미지 캡션, VQA, 수학 추론, 문맥 QA, 요약)을 별도의 작업 분기(task-branching) 없이 단일 프롬프트 라우팅 로직으로 처리하도록 Qwen/Qwen2-VL-7B-Instruct 모델에 LoRA(QLoRA)를 적용해 미세조정한 어댑터 가중치입니다.
Downloads · 30 days
5
18% of all-time downloads
All-time downloads
28
Public
Repo size
334 MB
Likes
0
Public
Click a slice to open those files.
.safetensors323 MB · 95%
From the Hugging Face model README
단일 멀티모달 모델(이미지 캡션, VQA, 수학 추론, 문맥 QA, 요약)을 별도의 작업 분기(task-branching) 없이 단일 프롬프트 라우팅 로직으로 처리하도록 Qwen/Qwen2-VL-7B-Instruct 모델에 LoRA(QLoRA)를 적용해 미세조정한 어댑터 가중치입니다.
이 저장소는 어댑터 가중치만 포함하며, 원본 베이스 모델은 포함하지 않습니다.
Qwen/Qwen2-VL-7B-Instruct다음은 transformers와 peft 라이브러리를 사용하여 베이스 모델에 본 어댑터를 로드하는 방법입니다.
from transformers import AutoProcessor, AutoModelForCausalLM
from peft import PeftModel
import torch
base_id = "Qwen/Qwen2-VL-7B-Instruct"
adapter_id = "dohoon0508/Dohoon_Qwen2-VL-7B-Instruct_ForAju"
# 프로세서 및 4-bit 양자화된 베이스 모델 로드
processor = AutoProcessor.from_pretrained(base_id, trust_remote_code=True)
base_model = AutoModelForCausalLM.from_pretrained(
base_id,
device_map="auto",
trust_remote_code=True,
torch_dtype=torch.bfloat16, # or torch.float16
load_in_4bit=True
)
# 어댑터(LoRA) 가중치 적용
model = PeftModel.from_pretrained(base_model, adapter_id)
model.eval()
# 추론 예시 (VQA)
# from PIL import Image
# import requests
# image_url = "[https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/bee.JPG](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/bee.JPG)"
# image = Image.open(requests.get(image_url, stream=True).raw).convert("RGB")
# question = "Question: What is the main subject in this image?"
# messages = [
# {"role": "system", "content": [{"type": "text", "text": "You are a multimodal assistant..."}]}, # 실제 사용하는 시스템 프롬프트 적용
# {"role": "user", "content": [{"type": "image"}, {"type": "text", "text": question}]}
# ]
# prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# enc = processor(text=prompt, images=[image], return_tensors="pt")
# out = model.generate(**{k: v.to(model.device) for k, v in enc.items()}, max_new_tokens=128)
# generated_text = processor.batch_decode(out, skip_special_tokens=True)[0]
# print(generated_text)
📁 파일 구성
adapter_model.safetensors: LoRA 어댑터 가중치 파일
adapter_config.json: 어댑터 설정 파일
README.md: 모델 카드
tokenizer.json, tokenizer.model, tokenizer_config.json, processor_config.json 등 기타 설정 파일
🔬 학습 개요
튜닝 방식: QLoRA (4-bit NormalFloat) + LoRA
LoRA 대상 모듈: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
LoRA 하이퍼파라미터:
r = 32
lora_alpha = 16
lora_dropout = 0.05
비전 타워: 완전 동결 (Frozen)
학습 하이퍼파라미터:
per_device_train_batch_size = 1
gradient_accumulation_steps = 16
learning_rate = 1e-4 (Cosine 스케줄러)
warmup_ratio = 0.03
정밀도: bf16 (사용 가능 시) / fp16
데이터: 대회 제공 멀티태스크 데이터 (.parquet)
프롬프트: 고정된 단일 시스템 프롬프트 + (이미지/텍스트 + 질문) 형태로 구성하여 태스크 분기 없음
라벨링: 손실 계산 시 프롬프트에 해당하는 토큰은 -100으로 마스킹하여 정답 토큰에만 loss 반영
🧠 추론 메모
디코딩:
Greedy Search (do_sample=False, num_beams=1)
no_repeat_ngram_size = 4
repetition_penalty = 1.05
동적 생성 제어:
태스크 종류(Captioning, Summarization 등)에 따라 최대 생성 토큰 수를 동적으로 조절
문장 부호(., !, ?) 개수를 감지하여 지정된 문장 수에 도달하면 생성을 조기 중단하는 StopOnSentenceCount 기준 적용
후처리:
금칙어("I'm sorry", "As an AI" 등) 제거
수학 문제의 경우, 정답을 #### {answer} 형식으로 추출/강제
VQA 응답은 간결성을 위해 첫 문장만 사용
✅ 권장 사용 범위
이미지 캡셔닝, VQA, 텍스트 요약 등 다양한 멀티모달 지시(Instruction)를 단일 모델로 처리하는 연구/실험
별도의 라우팅 로직 없이 프롬프트만으로 태스크를 구분하는 모델의 능력 분석
LoRA/QLoRA를 활용한 대규모 언어 모델(LLM)의 효율적 파인튜닝 사례 연구
⚠️ 제한 및 주의사항
생성 모델의 특성상 사실과 다른 정보(Hallucination)나 오해의 소지가 있는 내용을 생성할 수 있습니다.
민감하거나 안전/윤리적 요구사항이 중요한 도메인에 적용할 경우, 반드시 추가적인 필터링 또는 가드레일 장치가 필요합니다.
베이스 모델(Qwen/Qwen2-VL-7B-Instruct) 및 학습 데이터의 원본 라이선스와 약관을 준수해야 합니다.
🔗 참고
Base model: Qwen/Qwen2-VL-7B-Instruct
프로젝트 저장소: https://github.com/dohoon0508/ajukaggle