KVL-DPO
Overview
KVL-DPO is a 15.1B parameter Vision-Language Model that extends KVL through Direct Preference Optimization (DPO) training. This model was fine-tuned using the VLFeedback dataset to better align with human preferences in visual-language understanding tasks.
Model Architecture
| Component | Details |
|---|---|
| Base Model | amoeba04/KVL |
| Original Foundation | InternVL3_5-14B-Pretrained |
| Vision Encoder | InternViT-300M (0.3B parameters) |
| Language Model | Qwen3-14B (14.8B parameters) |
| Total Parameters | 15.1B |
| Precision | BF16 |
| Architecture | ViT-MLP-LLM (InternVL Chat) |
Training Details
DPO Training Configuration
- Training Type: Direct Preference Optimization (DPO)
- Base Model: amoeba04/KVL
- Training Dataset: MMInstruction/VLFeedback
- Framework: ms-swift
About VLFeedback Dataset
VLFeedback is a large-scale preference dataset for vision-language models containing:
- 80K+ preference pairs for visual instruction following
- Human-annotated preferences comparing model responses
- Diverse visual-language tasks including VQA, image captioning, and visual reasoning
Training Lineage
- Stage 1 (SFT): InternVL3_5-14B-Pretrained → KVL (trained on ~4M multimodal samples)
- Stage 2 (DPO): KVL → KVL-DPO (aligned using VLFeedback)
Quick Start
Requirements
pip install transformers>=4.52.1 torch torchvision timm
pip install flash-attn --no-build-isolation # Optional but recommended
Basic Usage
import torch
from transformers import AutoTokenizer, AutoModel
from PIL import Image
import torchvision.transforms as T
from torchvision.transforms.functional import InterpolationMode
IMAGENET_MEAN = (0.485, 0.456, 0.406)
IMAGENET_STD = (0.229, 0.224, 0.225)
def build_transform(input_size):
return T.Compose([
T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
T.ToTensor(),
T.Normalize(mean=IMAGENET_MEAN, std=IMAGENET_STD)
])
def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
best_ratio_diff = float('inf')
best_ratio = (1, 1)
area = width * height
for ratio in target_ratios:
target_aspect_ratio = ratio[0] / ratio[1]
ratio_diff = abs(aspect_ratio - target_aspect_ratio)
if ratio_diff < best_ratio_diff:
best_ratio_diff = ratio_diff
best_ratio = ratio
elif ratio_diff == best_ratio_diff:
if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
best_ratio = ratio
return best_ratio
def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
orig_width, orig_height = image.size
aspect_ratio = orig_width / orig_height
target_ratios = set(
(i, j) for n in range(min_num, max_num + 1)
for i in range(1, n + 1) for j in range(1, n + 1)
if i * j <= max_num and i * j >= min_num
)
target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
target_aspect_ratio = find_closest_aspect_ratio(
aspect_ratio, target_ratios, orig_width, orig_height, image_size
)
target_width = image_size * target_aspect_ratio[0]
target_height = image_size * target_aspect_ratio[1]
blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
resized_img = image.resize((target_width, target_height))
processed_images = []
for i in range(blocks):
box = (
(i % (target_width // image_size)) * image_size,
(i // (target_width // image_size)) * image_size,
((i % (target_width // image_size)) + 1) * image_size,
((i // (target_width // image_size)) + 1) * image_size
)
split_img = resized_img.crop(box)
processed_images.append(split_img)
if use_thumbnail and len(processed_images) != 1:
thumbnail_img = image.resize((image_size, image_size))
processed_images.append(thumbnail_img)
return processed_images
def load_image(image_file, input_size=448, max_num=12):
image = Image.open(image_file).convert('RGB')
transform = build_transform(input_size=input_size)
images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
pixel_values = [transform(img) for img in images]
pixel_values = torch.stack(pixel_values)
return pixel_values
# Load model
model_path = "amoeba04/KVL-DPO"
model = AutoModel.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
use_flash_attn=True,
trust_remote_code=True
).eval().cuda()
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, use_fast=False)
# Inference
image = load_image('your_image.jpg').to(torch.bfloat16).cuda()
generation_config = dict(max_new_tokens=1024, do_sample=False)
question = '<image>\nDescribe this image in detail.'
response = model.chat(tokenizer, image, question, generation_config)
print(response)
Multi-GPU Inference
model = AutoModel.from_pretrained(
"amoeba04/KVL-DPO",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
use_flash_attn=True,
trust_remote_code=True,
device_map="auto" # Automatic multi-GPU distribution
).eval()
Evaluation with VLMEvalKit
The model is fully compatible with VLMEvalKit.
Register in vlmeval/config.py:
from functools import partial
from vlmeval.vlm import InternVLChat
# Add to ungrouped dict
"KVL-DPO": partial(InternVLChat, model_path="amoeba04/KVL-DPO", max_new_tokens=16384, version="V2.0"),
Run evaluation:
python run.py --data MMBench_DEV_EN --model KVL-DPO --verbose
Intended Use
- Scientific Document Understanding: Analyzing figures, tables, and diagrams from scientific papers
- Medical Image Analysis: Radiology, pathology, and endoscopy image interpretation
- Visual Question Answering: General and domain-specific VQA tasks
- Chain-of-Thought Reasoning: Complex visual reasoning with step-by-step explanations
Acknowledgments
- InternVL Team - Excellent base model
- ms-swift - Training framework
- MMInstruction - VLFeedback dataset
- All dataset creators for their valuable contributions
License
This model is released under the Apache 2.0 License.
- Downloads last month
- 15