Views
No views yet
qwenvl directory contains the following components:train/trainer.py: Main trainer updated from Huggingface Trainertrain_qwen.py: Main file for trainingargument.py: Dataclasses for model, data and training argumentsdata/__init__.py: Contains datasets configsdata_processor.py: Data processing module for QwenVL modelsrope2d.py: Provide RoPE implementationtoolsprocess_bbox.ipynb: Convert bbox into QwenVL format. If you have grounding data, please refer this file to tranform your data.pack_data.py: Pack data into even length buckets.torch==2.6.0torchvision==0.21.0transformers==4.57.0.dev0deepspeed==0.17.1flash_attn==2.7.4.post1triton==3.2.0accelerate==1.7.0torchcodec==0.2peft==0.17.1image/video: Contains path to the media file (required)<image> for image understanding tasks<video> for video understanding tasksconversations: contains the questions and answers1{
2 "image": "images/001.jpg",
3 "conversations": [
4 {
5 "from": "human",
6 "value": "<image>\nWhat's the main object in this picture?"
7 },
8 {
9 "from": "gpt",
10 "value": "A red apple on a wooden table"
11 }
12 ]
13}1{
2 "image": ["cats/001.jpg", "cats/002.jpg"],
3 "conversations": [
4 {
5 "from": "human",
6 "value": "<image>\n<image>\nWhat are the differences between these two cats?"
7 },
8 {
9 "from": "gpt",
10 "value": "The first cat is an orange tabby with short fur and green eyes, while the second is a gray Siamese with blue eyes and pointed coloration. They also appear to be in different environments - the first is indoors on a couch, the second is outdoors in a garden."
11 }
12 ]
13}1{
2 "video": "videos/005.mp4",
3 "conversations": [
4 {
5 "from": "human",
6 "value": "<video>\nWhat caused the blue object to move?\nOptions:\n(A) Gravity\n(B) Collision\n(C) Magnetic force"
7 },
8 {
9 "from": "gpt",
10 "value": "Answer: (B) Collision"
11 }
12 ]
13}1{
2 "image": "demo/COCO_train2014_000000580957.jpg",
3 "conversations": [
4 {
5 "from": "human",
6 "value": "<image>\nLocate house in this image and output the bbox coordinates in JSON format."
7 },
8 {
9 "from": "gpt",
10 "value": "{\n"bbox_2d": [135, 114, 1016, 672]\n}"
11 }
12 ]
13}1[
2 {
3 "image": "images/001.jpg",
4 "conversations": [
5 {
6 "from": "human",
7 "value": "<image>\nWhat's the main object in this picture?"
8 },
9 {
10 "from": "gpt",
11 "value": "A red apple on a wooden table"
12 }
13 ]
14 },
15 {
16 "image": "images/002.jpg",
17 "conversations": [
18 {
19 "from": "human",
20 "value": "<image>\nWhat's the main object in this picture?"
21 },
22 {
23 "from": "gpt",
24 "value": "A green orange on a plastic table"
25 }
26 ]
27 }
28]demo/single_images.json and demo/video.json and these json files could be used for training.data/__init__.py:1DATASET_NAME = {
2 "annotation_path": "/path/to/annotations.json",
3 "data_path": "/path/to/image/data", # Can be empty if paths are in annotations
4}data_dict:1data_dict = {
2 "your_dataset_name": DATASET_NAME,
3 # ... other datasets
4}%X to the dataset name:"dataset_name%50" will sample 50% of the data"dataset_name%20" will sample 20% of the data1MY_DATASET = {
2 "annotation_path": "/data/my_dataset/annotations.json",
3 "data_path": "/data/my_dataset/images/",
4}
5
6data_dict = {
7 "my_dataset": MY_DATASET,
8 "cambrian_737k": CAMBRIAN_737K, # existing dataset
9}1dataset_names = ["my_dataset%50"] # Will use 50% of your dataset
2configs = data_list(dataset_names)annotation_path should point to a JSON or JSONL file containing your dataset annotations.data_path can be left empty if the image paths in the annotations are absolute.nyu-visionx/Cambrian-10M, lmms-lab/LLaVA-NeXT-Data, FreedomIntelligence/ALLaVA-4V, TIGER-Lab/VisualWebInstruct.<image> tag in the question must correspond to exactly one image file<video> tags must correspond to video filestools/check_image.py.1#!/bin/bash
2# Complete QwenVL Training Launch Script with Full Parameter Documentation
3
4# ======================
5# Distributed Configuration
6# ======================
7MASTER_ADDR="127.0.0.1" # [Required] Master node IP for multi-GPU training
8MASTER_PORT=$(shuf -i 20000-29999 -n 1) # Random port to avoid conflicts
9NPROC_PER_NODE=$(nvidia-smi --list-gpus | wc -l) # Automatically detects available GPUs
10
11# ======================
12# Path Configuration
13# ======================
14MODEL_PATH="/path/to/Qwen2.5-VL-3B-Instruct" # [ModelArguments] Pretrained model path
15OUTPUT_DIR="./checkpoints" # Directory for saving checkpoints
16CACHE_DIR="./cache" # [TrainingArguments] Cache directory for models
17
18# ======================
19# Model Configuration
20# ======================
21DATASETS="your_dataset%100" # [DataArguments] Dataset with sampling rate
22
23# ======================
24# Training Hyperparameters
25# ======================
26torchrun --nproc_per_node=$NPROC_PER_NODE \
27 --master_addr=$MASTER_ADDR \
28 --master_port=$MASTER_PORT \
29 qwenvl/train/train_qwen.py \
30 # Core Arguments
31 --model_name_or_path $MODEL_PATH \ # [ModelArguments] Model identifier
32 --tune_mm_llm True \ # [TrainingArguments] Train LLM or not
33 --tune_mm_vision False \ # [TrainingArguments] Train VIT or not
34 --tune_mm_mlp False \ # [TrainingArguments] Train MLP or not
35 --dataset_use $DATASETS \ # [DataArguments] Dataset specification
36 --output_dir $OUTPUT_DIR \ # Output directory for checkpoints
37 --cache_dir $CACHE_DIR \ # [TrainingArguments] Model cache location
38
39 # Precision & Memory
40 --bf16 \ # Use bfloat16 precision (Ampere+ GPUs)
41 --per_device_train_batch_size 4 \ # Batch size per GPU
42 --gradient_accumulation_steps 4 \ # Effective batch size multiplier
43
44 # Learning Rate Configuration
45 --learning_rate 2e-7 \ # Base learning rate
46 --mm_projector_lr 1e-5 \ # [TrainingArguments] Projector-specific LR
47 --vision_tower_lr 1e-6 \ # [TrainingArguments] Vision encoder LR
48 --optim adamw_torch \ # [TrainingArguments] Optimizer selection
49
50 # Sequence Configuration
51 --model_max_length 4096 \ # [TrainingArguments] Max sequence length
52 --data_flatten True \ # [DataArguments] Concatenate batch sequences
53 --data_packing True \ # [DataArguments] Using packing data
54
55 # Image Processing
56 --max_pixels 576\*28\*28 \ # [DataArguments] Max image pixels (H*W) for image
57 --min_pixels 16\*28\*28 \ # [DataArguments] Min image pixels for image
58 # Video Processing
59 --video_fps 2 \ # [DataArguments] video fps
60 --video_max_frames 8 \ # [DataArguments] Max frames per video
61 --video_min_frames 4 \ # [DataArguments] Min frames per video
62 --video_max_pixels 1664\*28\*28 \ # [DataArguments] Max pixels per video
63 --video_min_pixels 256\*28\*28 \ # [DataArguments] Min pixels per video
64
65 # Training Schedule
66 --num_train_epochs 3 \ # Total training epochs
67 --warmup_ratio 0.03 \ # LR warmup proportion
68 --lr_scheduler_type "cosine" \ # Learning rate schedule
69 --weight_decay 0.01 \ # L2 regularization strength
70
71 # Logging & Checkpoints
72 --logging_steps 10 \ # Log metrics interval
73 --save_steps 500 \ # Checkpoint save interval
74 --save_total_limit 3 \ # Max checkpoints to keep
75
76 # Lora Config
77 --lora_enable True \ # [TrainingArguments] Enable LoRA
78 --lora_r 8 \ # [TrainingArguments] LoRA r
79 --lora_alpha 16 \ # [TrainingArguments] LoRA alpha
80 --lora_dropout 0.0 \ # [TrainingArguments] LoRA dropout
81
82 # Advanced Options
83 --deepspeed zero3.json \ # DeepSpeed configurationtune_mm_vision, tune_mm_mlp, tune_mm_llm). If trained with both image and video data, tune_mm_vision should be False: tune_mm_vision=Falsedata_flatten flag means data in a batch are concat into one sequencedata_packing requires preprocess with tools/pack_data.py--max_pixels and --min_pixels should be properly setscripts/sft_32b.sh"_attn_implementation": "flash_attention_2", could be add in the config.json of the model to use flash attention.