讨论、对之前代码优化以及添加Siglip编码器 #20
Merged
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.
再次感谢您优秀的项目。
此次更新中涵盖了自己的对该项目的思考以及一些优化:
1、image_special_token 的定义以及 image_ids 的定义。
这两部分的定义长度似乎不需要根据图像编码器编码出的patch长度进行重新计算。一个理想情况是可以指定一个特殊的token,当遇见该特殊token时,即插入图像patch。
但由于minimind词表中并未为特殊token预留位置,因此直接插入特殊的token不太可行。但可以统一将其指定为一个较短的复杂token,这次实现的是'image_special_token='<'*2+'>'*2, image_ids=[30]*2+[32]*2'(指定一个正常对话不会出现的token)。这样,也不需要因为不同的图像编码器而不断改变这两个参数。
较短的token也能够为之后的遍历搜索节省大量时间。
2、对之前图像插入token的位置检测进行了进一步的优化,同时解决了之前的一些bug,这个bug曾导致无法进行单图训练。
用滑动窗口和字典进行储存加速之后检索以及插入的速度。
bug区域具体是在这一行:
.unsqueeze(0) 应该是1而不是0,因为第一维是batchsize的维度,第二维表示图像数量。
3、添加了siglip-vit-b-16的参数选择。
在源代码的基础上,添加了新的图像编码器。由于siglip通常会将图像分割成196个token,因此可能会增加模型的计算量,但几乎不影响显存。
后续训练好的权重同样也会进行更新,此次提交包括了自己的一些思考。仅供您参考。如果您能提出建议或者是意见,我也是十分感激。
期待之后与您的交流!谢谢!