InternVL官方微调

InternVL官方微调

上进行微调

模型准备

型号名称

类型

参数

下载

尺寸

实习生VL2-1B

多层线性模型

0.9亿

🤗

1.8 GB

实习生VL2-2B

多层线性模型

2.2B

🤗

4.2 GB

实习生VL2-4B

多层线性模型

4.2B

🤗

7.8 GB

实习生VL2-8B

多层线性模型

8.1B

🤗

16 GB

实习生VL2-26B

多层线性模型

25.5亿

🤗

48 GB

实习生VL2-40B

多层线性模型

40.1B

🤗

75 GB

实习生VL2-Llama3-76B

多层线性模型

76.3B

🤗

143 GB

在开始第二次微调之前,请下载我们提供的预训练模型。   cd pretrained/ # pip install -U huggingface_hub# Download OpenGVLab/InternVL2-1Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-1B --local-dir InternVL2-1B # Download OpenGVLab/InternVL2-2Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-2B --local-dir InternVL2-2B # Download OpenGVLab/InternVL2-4Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-4B --local-dir InternVL2-4B # Download OpenGVLab/InternVL2-8Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-8B --local-dir InternVL2-8B # Download OpenGVLab/InternVL2-26Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-26B --local-dir InternVL2-26B # Download OpenGVLab/InternVL2-40Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-40B --local-dir InternVL2-40B # Download OpenGVLab/InternVL2-Llama3-76Bhuggingface-cli download --resume-download --local-dir-use-symlinks False OpenGVLab/InternVL2-Llama3-76B --local-dir InternVL2-Llama3-76B

目录结构为:   pretrained ├── InternVL2-1B ├── InternVL2-2B ├── InternVL2-4B ├── InternVL2-8B ├── InternVL2-26B ├── InternVL2-40B └── InternVL2-Llama3-76B

准备你的自定义训练数据

下载预训练模型后,准备自定义的 SFT(监督微调)数据。创建internvl_chat/shell/data/类似于JSON 文件。

JSON 文件的格式应为:   {  "your-custom-dataset-1": {    "root": "path/to/the/image/",    "annotation": "path/to/the/jsonl/annotation",    "data_augment": false,    "repeat_time": 1,    "length": "number of your data"  },  ...}

例子:   {  "sharegpt4v_instruct_gpt4-vision_cap100k": {    "root": "playground/data/",    "annotation": "playground/opensource/sharegpt4v_instruct_gpt4-vision_cap100k.jsonl",    "data_augment": false,    "repeat_time": 1,    "length": 102025  }}

对于每种具体的 JSONL(如纯文本数据、单图像数据、多图像数据、视频数据)的格式都可以按照提供的描述进行组织。

之上添加新的特定领域数据。这将增强下游能力,同时保留基础技能。当然,您也可以根据自己的需求选择仅针对新数据进行微调。

开始第二次微调     1B2B4B8B26B40B

根据您可用的 GPU 资源,使用用于 或预训练模型进行微调。

在微调之前,请将 设置--meta_path为上一步中创建的 JSON 文件的路径。这些 shell 脚本中默认的预训练模型路径是./pretrained/InternVL2-1B

在默认设置中,我冻结了视觉编码器。如果需要,您可以解冻它。通常,解冻视觉编码器将带来更好的性能。

💡 对完整的 LLM 进行微调需要 8x 32G/40G GPU,而对 LoRA 进行微调需要 2x 32G/40G GPU。

💡 这里使用的 GPU 数量和超参数仅作为示例。为了获得最佳结果,您可能需要根据可用的硬件和数据集大小调整这些设置。

微调命令:   # Using 8 GPUs, fine-tune the full LLM, cost about 30G per GPUGPUS=8 PER_DEVICE_BATCH_SIZE=1 sh shell/internvl2.0/2nd_finetune/internvl2_1b_qwen2_0_5b_dynamic_res_2nd_finetune_full.sh # Using 2 GPUs, fine-tune the LoRA, cost about 27G per GPUGPUS=2 PER_DEVICE_BATCH_SIZE=1 sh shell/internvl2.0/2nd_finetune/internvl2_1b_qwen2_0_5b_dynamic_res_2nd_finetune_lora.sh # Using 8 GPUs, fine-tune the LoRA, cost about 27G per GPUGPUS=8 PER_DEVICE_BATCH_SIZE=1 sh shell/internvl2.0/2nd_finetune/internvl2_1b_qwen2_0_5b_dynamic_res_2nd_finetune_lora.sh

如果您遇到任何问题,请告诉我,我会更新培训指南以增强其可用性。

{
  "sharegpt4v_instruct_gpt4-vision_cap100k": {
    "root": "playground/data/",
    "annotation": "playground/opensource/sharegpt4v_instruct_gpt4-vision_cap100k.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 102025
  },
  "llava_instruct_150k_zh": {
    "root": "playground/data/coco/",
    "annotation": "playground/opensource/llava_instruct_150k_zh.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 157712
  },
  "sharegpt4v_mix665k_cap23k_coco-ap9k_lcs3k_sam9k_div2k": {
    "root": "playground/data/",
    "annotation": "playground/opensource/sharegpt4v_mix665k_cap23k_coco-ap9k_lcs3k_sam9k_div2k.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 665058
  },
  "dvqa_train_200k": {
    "root": "playground/data/dvqa/",
    "annotation": "playground/opensource/dvqa_train_200k.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 200000
  },
  "chartqa_train_18k": {
    "root": "playground/data/chartqa/",
    "annotation": "playground/opensource/chartqa_train_18k.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 18317
  },
  "ai2d_train_12k": {
    "root": "playground/data/ai2d/",
    "annotation": "playground/opensource/ai2d_train_12k.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 12413
  },
  "docvqa_train_10k": {
    "root": "playground/data/docvqa/",
    "annotation": "playground/opensource/docvqa_train_10k.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 10211
  },
  "geoqa+": {
    "root": "playground/data/geoqa+/",
    "annotation": "playground/opensource/geoqa+.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 72318
  },
  "synthdog_en": {
    "root": "playground/data/synthdog-en/",
    "annotation": "playground/opensource/synthdog_en.jsonl",
    "data_augment": false,
    "repeat_time": 1,
    "length": 29765
  }
}

引文

如果您发现该项目对您的研究有用,请考虑引用:   @article{chen2023internvl,  title={InternVL: Scaling up Vision Foundation Models and Aligning for Generic Visual-Linguistic Tasks},  author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and Li, Bin and Luo, Ping and Lu, Tong and Qiao, Yu and Dai, Jifeng},  journal={arXiv preprint arXiv:2312.14238},  year={2023}}@article{chen2024far,  title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},  author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},  journal={arXiv preprint arXiv:2404.16821},  year={2024}}

Read more

深入理解 Proxy 和 Object.defineProperty

在JavaScript中,对象是一种核心的数据结构,而对对象的操作也是开发中经常遇到的任务。在这个过程中,我们经常会使用到两个重要的特性:Proxy和Object.defineProperty。这两者都允许我们在对象上进行拦截和自定义操作,但它们在实现方式、应用场景和灵活性等方面存在一些显著的区别。本文将深入比较Proxy和Object.defineProperty,包括它们的基本概念、使用示例以及适用场景,以帮助读者更好地理解和运用这两个特性。 1. Object.defineProperty 1.1 基本概念 Object.defineProperty 是 ECMAScript 5 引入的一个方法,用于直接在对象上定义新属性或修改已有属性。它的基本语法如下: javascript 代码解读复制代码Object.defineProperty(obj, prop, descriptor); 其中,obj是目标对象,prop是要定义或修改的属性名,descriptor是一个描述符对象,用于定义属性的特性。 1.2 使用示例 javascript 代码解读复制代码//

By Ne0inhk

Proxy 和 Object.defineProperty 的区别

Proxy 和 Object.defineProperty 是 JavaScript 中两个不同的特性,它们的作用也不完全相同。 Object.defineProperty 允许你在一个对象上定义一个新属性或者修改一个已有属性。通过这个方法你可以精确地定义属性的特征,比如它是否可写、可枚举、可配置等。该方法的使用场景通常是需要在一个对象上创建一个属性,然后控制这个属性的行为。 Proxy 也可以用来代理一个对象,但是相比于 Object.defineProperty,它提供了更加强大的功能。使用 Proxy 可以截获并重定义对象的基本操作,比如访问属性、赋值、函数调用等等。在这些操作被执行之前,可以通过拦截器函数对这些操作进行拦截和修改。因此,通过 Proxy,你可以完全重写一个对象的默认行为。该方法的使用场景通常是需要对一个对象的行为进行定制化,或者需要在对象上添加额外的功能。 对比 以下是 Proxy 和 Object.defineProperty 的一些区别对比: 方面ProxyObject.defineProperty语法使用 new Proxy(target,

By Ne0inhk