Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Support V2PE in pre-training, fine-tuning, and inference for InternVL.
Modification
V2PE utils
Added the file
internvl_chat/internvl/v2pe_utils.py
.It includes the
get_rope_pos_id
function, which calculates position ids required for V2PE,and a
V2PE
module that can replace the conventional RoPE mechanism.Pre-training and Fine-tuning
Modified the following files to support V2PE in training and fine-tuning:
internvl_chat/internvl/train/internvl_chat_pretrain.py
internvl_chat/internvl/train/internvl_chat_finetune.py
Specifically:
ModelArguments
andLazySupervisedDataset
to support V2PE.concat_pad_data_collator
ininternvl_chat/internvl/patch/pad_data_collator.py
to support passing position ids as lists (to preserve float precision when using V2PE).
Model
InternVLChat
internvl_chat/internvl/model/internvl_chat/configuration_internvl_chat.py
to support passing V2PE-related arguments via config.
InternVLChatModel.forward()
andInternVLChatModel.chat()
in
internvl_chat/internvl/model/internvl_chat/modeling_internvl_chat.py
to support V2PE usage during both training and inference.
InternLM2
internvl_chat/internvl/model/internlm2/configuration_internlm2.py
to support V2PE-related config arguments.
InternLM2Attention._init_rope()
,InternLM2Attention.forward()
,and
InternLM2FlashAttention2.forward()
ininternvl_chat/internvl/model/internlm2/modeling_internlm2.py
to support replacing RoPE with the V2PE module.