文件最后提交记录最后更新时间
[Docs] Modify current repository URLs to relative paths Co-authored-by: AZe_404<wangze62@h-partners.com> # message auto-generated for no-merge-commit merge: !2360 merge chg_branch_2600 into 26.0.0 [Docs] Modify current repository URLs to relative paths Created-by: AZe_404 Commit-by: AZe_404 Merged-by: ascend-robot Description: ## What this PR does / why we need it? 1. 拉取代码修改为拉取26.0.0分支,包括之前未指定版本的MindSpeed Core 2. 将MM仓库内的链接修改为相对路径访问 ## Does this PR introduce any user-facing change? Please describe whether the PR will result in any user-facing usage changes. If there is related documentation, please specify its path. ## How was this patch tested? Please explain how to verify the correctness and effectiveness of this feature, as well as its usage constraints and limitations. See merge request: Ascend/MindSpeed-MM!23601 个月前
!1363 [Docs]Pytorch version update to 2.7.1 Merge pull request !1363 from zs-Derrick/master 9 个月前
!1363 [Docs]Pytorch version update to 2.7.1 Merge pull request !1363 from zs-Derrick/master 9 个月前
[Docs] Document corrections Co-authored-by: js1234567<jiangshuo9@h-partners.com> # message auto-generated for no-merge-commit merge: !2108 merge master into master [Docs] Document corrections Created-by: js1234567 Commit-by: js1234567 Merged-by: ascend-robot Description: ## Motivation Document corrections: 1. 添加2.3.0配套信息 2. 中英文标点问题 3. 链接版本更新 4. CANN8.5.0版本配置环境变量刷新, 涉及环境变量设置需全面排查修改 ## Modification Readme.md ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [x] The new code needs to comply with the Clean Code specification. - [x] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/MindSpeed-MM!21083 个月前
[Docs] Document corrections Co-authored-by: js1234567<jiangshuo9@h-partners.com> # message auto-generated for no-merge-commit merge: !2108 merge master into master [Docs] Document corrections Created-by: js1234567 Commit-by: js1234567 Merged-by: ascend-robot Description: ## Motivation Document corrections: 1. 添加2.3.0配套信息 2. 中英文标点问题 3. 链接版本更新 4. CANN8.5.0版本配置环境变量刷新, 涉及环境变量设置需全面排查修改 ## Modification Readme.md ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [x] The new code needs to comply with the Clean Code specification. - [x] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/MindSpeed-MM!21083 个月前
!1049 [Refactor]adapt mindspeed012 Merge pull request !1049 from 王泽/adapt012 9 个月前
[Docs] Document corrections Co-authored-by: js1234567<jiangshuo9@h-partners.com> # message auto-generated for no-merge-commit merge: !2108 merge master into master [Docs] Document corrections Created-by: js1234567 Commit-by: js1234567 Merged-by: ascend-robot Description: ## Motivation Document corrections: 1. 添加2.3.0配套信息 2. 中英文标点问题 3. 链接版本更新 4. CANN8.5.0版本配置环境变量刷新, 涉及环境变量设置需全面排查修改 ## Modification Readme.md ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [x] The new code needs to comply with the Clean Code specification. - [x] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/MindSpeed-MM!21083 个月前
!1416 [Modify]Update the finetune script of interpl to run pretrain-vlm Merge pull request !1416 from OrangeSoda/internvl_new_script_validate 8 个月前
!1416 [Modify]Update the finetune script of interpl to run pretrain-vlm Merge pull request !1416 from OrangeSoda/internvl_new_script_validate 8 个月前
!644 【特性】支持InternVL2.5 在线推理 Merge pull request !644 from chenhaihui/master 1 年前
README.md

InternVL2.5 使用指南

目录

版本说明

参考实现

url=https://github.com/OpenGVLab/InternVL.git
commit_id=2d57e21

变更记录

2025.02.20: 首次发布InternVL2.5模型


环境安装

【模型开发时推荐使用配套的环境版本】

请参考安装指南

1. 仓库拉取

git clone --branch 26.0.0 https://gitcode.com/Ascend/MindSpeed-MM.git
git clone https://github.com/NVIDIA/Megatron-LM.git
cd Megatron-LM
git checkout core_v0.12.1
cp -r megatron ../MindSpeed-MM/
cd ..
cd MindSpeed-MM
mkdir logs
mkdir dataset
mkdir ckpt

2. 环境搭建

# python3.10
conda create -n test python=3.10
conda activate test

# 安装 torch 和 torch_npu,注意要选择对应python版本、x86或arm的torch、torch_npu及apex包
pip install torch-2.7.1-cp310-cp310-manylinux_2_28_aarch64.whl
pip install torch_npu-2.7.1*-cp310-cp310-manylinux_2_28_aarch64.whl

# apex for Ascend 参考 https://gitcode.com/Ascend/apex
# 建议从原仓编译安装

# 安装加速库
git clone https://gitcode.com/Ascend/MindSpeed.git
cd MindSpeed
# checkout commit from MindSpeed core_r0.12.1
git checkout 5176c6f5f133111e55a404d82bd2dc14a809a6ab
pip install -r requirements.txt
pip3 install -e .
cd ..
# 安装其余依赖库
pip install -e .

权重下载及转换

1. 权重下载

从Hugging Face等网站下载开源模型权重

将模型权重保存在raw_ckpt目录下,例如raw_ckpt/InternVL2_5-78B

2. 权重转换

MindSpeed MM修改了部分原始网络的结构名称,使用mm-convert工具对原始预训练权重进行转换。该工具实现了huggingface权重和MindSpeed MM权重的转换以及PP(Pipeline Parallel)的权重切分。

mm-convert工具详细用法参考权重转换工具

# 根据实际情况修改 ascend-toolkit 路径
source /usr/local/Ascend/cann/set_env.sh

# 4B
mm-convert InternVLConverter hf_to_mm \
  --cfg.mm_dir "pretrained/InternVL2_5-4B" \
  --cfg.hf_config.hf_dir "raw_ckpt/InternVL2_5-4B" \
  --cfg.parallel_config.llm_pp_layers [[36]] \
  --cfg.parallel_config.vit_pp_layers [[24]] \
  --cfg.trust_remote_code True

# 78B
mm-convert InternVLConverter hf_to_mm \
  --cfg.mm_dir "pretrained/InternVL2_5-78B" \
  --cfg.hf_config.hf_dir "raw_ckpt/InternVL2_5-78B" \
  --cfg.parallel_config.llm_pp_layers [[0,3,6,6,6,6,6,6,6,6,6,6,5,5,5,2]] \
  --cfg.parallel_config.vit_pp_layers [[45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]] \
  --cfg.trust_remote_code True

# 其中:
# mm_dir: 转换后保存目录
# hf_dir: huggingface权重目录
# llm_pp_layers: llm在每个卡上切分的层数,注意要和model.json中配置的pipeline_num_layers一致
# vit_pp_layers: vit在每个卡上切分的层数,注意要和model.json中配置的pipeline_num_layers一致
# trust_remote_code: 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性

同步修改examples/internvl2.5/finetune_internvl2.5_*b.sh中的LOAD_PATH参数,该路径为转换后或者切分后的权重,注意与原始权重raw_ckpt/InternVL2_5-*B进行区分。

InternVL2_5-78B为例

LOAD_PATH="pretrained/InternVL2_5-78B"

数据集准备及处理

1. 数据集下载

【图片数据】

用户需自行获取并解压InternVL-Finetune数据集到dataset/playground目录下,以数据集ai2d为例,解压后的数据结构如下:

$playground
├── data
    ├── ai2d
        ├── abc_images
        ├── images
├── opensource
    ├── ai2d_train_12k.jsonl

【视频数据】

使用视频进行训练,可参考视频数据集构造自行构造视频数据集。

同时依赖Decord库读取视频,Decord安装方法如下:

【X86版安装】

pip install decord==0.6.0

【ARM版安装】

apt方式安装请参考链接

yum方式安装请参考脚本

微调

1. 准备工作

配置脚本前需要完成前置准备工作,包括:环境安装权重下载及转换数据集准备及处理,详情可查看对应章节。

2. 配置参数

【数据目录配置】

根据实际情况修改data.json中的数据集路径,包括from_pretraineddata_pathdata_folder等字段。

以InternVL2_5-78B为例,data_78B.json进行以下修改,注意tokenizer_config的权重路径为转换前的权重路径。

{
  "dataset_param": {
      ...
      "basic_parameters": {
          "data_path": "dataset/playground/opensource/ai2d_train_12k.jsonl",
          "data_folder": "dataset/playground/data/ai2d"
      },
      ...
      "tokenizer_config": {
          ...
          "from_pretrained": "raw_ckpt/InternVL2_5-78B",
          ...
      },
      ...
  },
  ...
}

【模型保存加载及日志信息配置】

根据实际情况配置examples/internvl2.5/finetune_internvl2.5_xx.sh的参数,包括加载、保存路径以及保存间隔--save-interval(注意:分布式优化器保存文件较大耗时较长,请谨慎设置保存间隔), 以InternVL2.5-78B为例:

...
# 加载路径
LOAD_PATH="ckpt/InternVL2_5-78B"
# 保存路径
SAVE_PATH="save_dir"
...
GPT_ARGS="
    ...
    --no-load-optim \  # 不加载优化器状态,若需加载请移除
    --no-load-rng \  # 不加载随机数状态,若需加载请移除
    --no-save-optim \  # 不保存优化器状态,若需保存请移除
    --no-save-rng \  # 不保存随机数状态,若需保存请移除
    ...
"
...
OUTPUT_ARGS="
    --log-interval 1 \  # 日志间隔
    --save-interval 5000 \  # 保存间隔
    ...
    --log-tps \  # 增加此参数可使能在训练中打印每步语言模块的平均序列长度,并在训练结束后计算每秒吞吐tokens量。
"

若需要加载指定迭代次数的权重、优化器等状态,需将加载路径LOAD_PATH设置为保存文件夹路径LOAD_PATH="save_dir",并修改latest_checkpointed_iteration.txt文件内容为指定迭代次数

$save_dir
   ├── latest_checkpointed_iteration.txt
   ├── ...

【单机运行配置】

配置examples/internvl2.5/finetune_internvl2.5_xx.sh参数如下

  # 根据实际情况修改 ascend-toolkit 路径
  source /usr/local/Ascend/cann/set_env.sh
  NPUS_PER_NODE=8
  MASTER_ADDR=localhost
  MASTER_PORT=6000
  NNODES=1
  NODE_RANK=0
  WORLD_SIZE=$(($NPUS_PER_NODE * $NNODES))

3. 启动微调

以InternVL2_5-78B为例,启动微调训练任务。

bash examples/internvl2.5/finetune_internvl2.5_78B.sh

推理

1. 准备工作

配置脚本前需要完成前置准备工作,包括:环境安装、权重下载及转换,详情可查看对应章节。(当前仅支持4B单卡推理)

推理权重转换命令如下:

# 根据实际情况修改 ascend-toolkit 路径
source /usr/local/Ascend/cann/set_env.sh

# 4B
mm-convert InternVLConverter hf_to_mm \
  --cfg.mm_dir "pretrained/InternVL2_5-4B" \
  --cfg.hf_config.hf_dir "raw_ckpt/InternVL2_5-4B" \
  --cfg.parallel_config.llm_pp_layers [[36]] \
  --cfg.parallel_config.vit_pp_layers [[24]] \
  --cfg.trust_remote_code True
# trust_remote_code: 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性

2. 配置参数

【参数配置】

修改inference_*B.json文件,包括infer_data_typefile_pathpromptsfrom_pretrained以及tokenizer的from_pretrained等字段。

【单图推理】

以InternVL2_5-4B为例,按实际情况修改inference_4B.json对应参数,注意tokenizer_config的权重路径为转换前的权重路径。

{
    "infer_data_type": "image",
    "file_path": "./examples/internvl2.5/view.jpg",    # 按实际情况输入图片路径
    "prompts": "Please describe the image shortly.", # 按实际情况输入提示词(支持中英文)
    "model_id": "InternVLPipeline",
    "from_pretrained": "./pretrained/InternVL2_5-4B/release/mp_rank_00/model_optim_rng.pt", # 注意路径要到.pt文件
    ...
    "tokenizer":{
        ...
        "autotokenizer_name": "AutoTokenizer",
        "from_pretrained": "raw_ckpt/InternVL2_5-4B",
        ...
    },
    ...
}

【视频推理】

以InternVL2_5-4B为例,按实际情况修改inference_4B.json对应参数,注意tokenizer_config的权重路径为转换前的权重路径。

推理demo视频下载red-panda

{
    "infer_data_type": "video",
    "file_path": "examples/internvl2.5/red-panda.mp4",    # 按实际情况输入视频路径
    "prompts": "Please describe the video shortly.", # 按实际情况输入提示词(支持中英文)
    "model_id": "InternVLPipeline",
    "from_pretrained": "./pretrained/InternVL2_5-4B/release/mp_rank_00/model_optim_rng.pt", # 注意路径要到.pt文件
    ...
    "tokenizer":{
        ...
        "autotokenizer_name": "AutoTokenizer",
        "from_pretrained": "raw_ckpt/InternVL2_5-4B",
        ...
    },
    ...
}

【启动脚本配置】 按实际情况修改inference_internvl.sh脚本,

# 根据实际情况修改 ascend-toolkit 路径
source /usr/local/Ascend/cann/set_env.sh
...
MM_MODEL="./examples/internvl2.5/inference_4B.json"

3. 启动推理

bash examples/internvl2.5/inference_internvl.sh

环境变量声明

环境变量 描述 取值说明
ASCEND_SLOG_PRINT_TO_STDOUT 是否开启日志打印 0: 关闭日志打屏
1: 开启日志打屏
ASCEND_GLOBAL_LOG_LEVEL 设置应用类日志的日志级别及各模块日志级别,仅支持调试日志 0: 对应DEBUG级别
1: 对应INFO级别
2: 对应WARNING级别
3: 对应ERROR级别
4: 对应NULL级别,不输出日志
TASK_QUEUE_ENABLE 用于控制开启task_queue算子下发队列优化的等级 0: 关闭
1: 开启Level 1优化
2: 开启Level 2优化
COMBINED_ENABLE 设置combined标志。设置为0表示关闭此功能;设置为1表示开启,用于优化非连续两个算子组合类场景 0: 关闭
1: 开启
CPU_AFFINITY_CONF 控制CPU端算子任务的处理器亲和性,即设定任务绑核 设置0或未设置: 表示不启用绑核功能
1: 表示开启粗粒度绑核
2: 表示开启细粒度绑核
HCCL_CONNECT_TIMEOUT 用于限制不同设备之间socket建链过程的超时等待时间 需要配置为整数,取值范围[120,7200],默认值为120,单位s
PYTORCH_NPU_ALLOC_CONF 控制缓存分配器行为 expandable_segments:<value>: 使能内存池扩展段功能,即虚拟内存特征
HCCL_EXEC_TIMEOUT 控制设备间执行时同步等待的时间,在该配置时间内各设备进程等待其他设备执行通信同步 需要配置为整数,取值范围[68,17340],默认值为1800,单位s
ACLNN_CACHE_LIMIT 配置单算子执行API在Host侧缓存的算子信息条目个数 需要配置为整数,取值范围[1, 10,000,000],默认值为10000
TOKENIZERS_PARALLELISM 用于控制Hugging Face的transformers库中的分词器(tokenizer)在多线程环境下的行为 False: 禁用并行分词
True: 开启并行分词
MULTI_STREAM_MEMORY_REUSE 配置多流内存复用是否开启 0: 关闭多流内存复用
1: 开启多流内存复用
NPU_ASD_ENABLE 控制是否开启Ascend Extension for PyTorch的特征值检测功能 设置0或未设置: 关闭特征值检测
1: 表示开启特征值检测,只打印异常日志,不告警
2:开启特征值检测,并告警
3:开启特征值检测,并告警,同时会在device侧info级别日志中记录过程数据
ASCEND_LAUNCH_BLOCKING 控制算子执行时是否启动同步模式 0: 采用异步方式执行
1: 强制算子采用同步模式运行
NPUS_PER_NODE 配置一个计算节点上使用的NPU数量 整数值(如 1, 8 等)

注意事项

  1. 在使用流水线并行策略进行多机训练可能会出现卡住现象,可参考此处修改。