Qwen2-VL论文阅读笔记

第1章介绍
论文亮点:
1、 the Naive Dynamic Resolution mechanism
2、Multimodal Rotary Position Embedding (M-RoPE) 2D Rotary Position Embedding
3、统一图片和视频的处理范式、增i强视觉感知能力
4、LVLMs的scaling laws:2B、8B、72B
5、 dynamic resolution training

通用的方法: visual encoder→cross-modal connector→LL
其他提高的方法有
larger model architectures
higher-resolution images
advanced techniques:MoE、 model ensembles、more sophisticated connectors

qwen2vl的能力:
State-of-the-art understanding across various resolutions and aspect ratios
Comprehension of extended-duration videos (20 min+)
Robust agent capabilities for device operation

第2章方法
675M的ViT适配不同大小的LLM

Naive Dynamic Resolution - 用2D-RoPE取代绝对位置编码 推理阶段的序列长度是可控的 【推理阶段的不定长的vision tokens是怎么处理的?】
224 * 224 分辨率 在 patch_size=14 的ViT下 会被处理成 224/14/2 = 8 8x8=64 64 + 2 成为 66个tokens

Multimodal Rotary Position Embedding (M-RoPE) - temporal, height, and width
视频:序列帧
In scenarios where the model’s input encompasses multiple modalities, position numbering for
each modality is initialized by incrementing the maximum position ID of the preceding modality by one.

Unified Image and Video Understanding
每秒视频分成两帧、 综合 深度为2的 3D convolutions、允许模型处理 3D tubes、从而处理更多视频帧而不用增加序列长度。
保持一致性、每张图片被视为两个相同帧。
动态调整每个视频帧的分辨率,每个视频的tokens限制在 16384。

2.2 训练
遵从qwenvl的三阶段:用image-text单独训练ViT、解冻所有参数训练理解能力、最后冻住ViT只训练LLM遵循格式化数据
训练数据集:image-text pairs, ocr, 交错的图文文章,vqa、video对话,图片知识等

预训练初始阶段:600B tokens

第一个预训练阶段:600B tokens 位置编码:RoPE-2D ViT (DFN派生)
预训练阶段目的: 学习 图文关系、通过ocr的图像文本上下文识别、图片分类任务。 有助于核心 视觉文本相关性和对齐能力训练。

第二个预训练阶段:800B tokens的 图像相关数据 增加图像文本的细微理解;视觉问答数据集增强了 图片问答的能力。多任务数据集、纯文本数据集同样重要。

整个预训练、用了1.4Ttokens,有图片、也有文本。 但在训练阶段,只用文本监督。【怎么理解? 我理解这是第三个阶段、格式学习阶段】

微调阶段,用ChatML格式 instruction-following 包括文本和多模态对话数据(image question-answering, document
parsing, multi-image comparison, video comprehension, video stream dialogue, and agent-based interactions)

2.2.1 数据格式
Dialogue Data
<|vision_start|> and <|vision_end|>
<|im_start|> and <|im_end|>

Visual Grounding
<|box_start|> and <|box_end|> “(Xtop left, Ytop left),(Xbottom right, Ybottom right)”. [0, 1000)
<|object_ref_start|> and <|object_ref_end|>

Visual Agent.【UI Operations, Robotic Control, Games, and Navigation】
analyzes the observations, performs reasoning and planning, executes the selected actions, and interacts
with the environment to acquire new observations

2.3 多模态模型基础设施
存储、并行、 软件(torch 2.1.2, cuda 11.8)
flash attention、LN、RMSNorm、Adam

3 实验


qwenvl 和 qwen2vl的配置对比
“max_position_embeddings”: 8192,32768
“num_attention_heads”: 32,28
“num_hidden_layers”: 32,28
“architectures”: [
“QWenLMHeadModel” Qwen2VLForConditionalGeneration
],
“torch_dtype”: “bfloat16”,bfloat16
transformers_version": “4.31.0”,4.41.2
“image_size”: 448, 无
“patch_size”: 14,14
“in_chans”: 无,3,
mrope_section 无 ,有


原生动态分辨率:不同大小图片被转换为动态数量的tokens、最小只占4个tokens

多模态旋转位置嵌入 M-ROPE:将原始旋转嵌入分解为代表时间、高度和宽度的三个部分。(时间、高度、宽度)

捕捉和整合 一维文本序列、二维视觉图像以及三维视频的位置信息。

qwen-vl-utils

224224分辨率 通过 patch_size为14的ViT得到 1616的patches,然后用MLP将22压缩成1个token、前后拼上<|vision_start|>、<|vision_end|> 得到 88+2 = 66个tokens。

论文: a vision transformer for any aspect ratio and resolution

推理阶段:不同分辨率的图像被打包成一个序列,具有打包长度控制以限制GPU内存使用。 [最长的图像token是 16384 个]

2D-RoPE 获得两个维度的图片位置信息

统一图片和视频理解:为了一致性,每个图像都被视为两个相同帧; 图片和视频混合训练

平衡长视频处理的计算需求与整体训练效率,我们动态调整每个视频帧的分辨率,限制每个标记的总数 视频到16384

训练模式和qwenvl一样、三阶段。先训vit、再全训、最后训llm

### Qwen2-7B-Instruct Model Information and Usage #### Overview of the Qwen2-VL-7B-Instruct Model The Qwen2-VL-7B-Instruct model is a large-scale, multi-modal language model designed to handle various natural language processing tasks with enhanced capabilities in understanding visual content. This model has been pre-trained on extensive datasets that include both textual and image data, making it suitable for applications requiring cross-modal reasoning. #### Installation and Setup To use this specific version of the Qwen2 series, one needs first to ensure proper installation by cloning or downloading the necessary files from an accessible repository. Given potential issues accessing certain websites due to geographical restrictions, users should consider using alternative mirrors such as `https://hf-mirror.com` instead of attempting direct access through sites like Hugging Face[^3]. For setting up locally: 1. Install required tools including `huggingface_hub`. 2. Set environment variables appropriately. 3. Execute commands similar to: ```bash huggingface-cli download Qwen/Qwen2-VL-7B-Instruct --local-dir ./Qwen_VL_7B_Instruct ``` This command will fetch all relevant components needed for running inference against the specified variant of the Qwen family models. #### Fine-Tuning Process Fine-tuning allows adapting pretrained weights into more specialized domains without starting training anew. For instance, when working specifically within the context provided earlier regarding Qwen2-VL, adjustments can be made via LoRA (Low-Rank Adaptation), which modifies only parts of existing parameters while keeping others fixed during optimization processes[^1]. #### Running Inference Locally Once everything is set up correctly, performing offline predictions becomes straightforward once dependencies are resolved. An example workflow might involve loading saved checkpoints followed by passing input prompts through them until outputs meet desired criteria[^2]: ```python from transformers import AutoModelForCausalLM, AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("./Qwen_VL_7B_Instruct") model = AutoModelForCausalLM.from_pretrained("./Qwen_VL_7B_Instruct") input_text = "Your prompt here" inputs = tokenizer(input_text, return_tensors="pt") outputs = model.generate(**inputs) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` --related questions-- 1. What preprocessing steps must be taken before feeding images alongside text inputs? 2. How does performance compare between different quantization levels offered by GPTQ? 3. Are there any particular hardware requirements recommended for efficient deployment? 4. Can you provide examples where fine-tuned versions outperform general-purpose ones significantly?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值