[Florence]: Add Florence-2 model support - #4780
Conversation
|
Thanks for your contribution! |
risemeup1111
left a comment
There was a problem hiding this comment.
已复查,新提交修掉了 lint 问题,但仍有需要修正的实现与 API 约定问题,细节见 inline review comments。
| if text is None: | ||
| text = "" | ||
| if isinstance(text, str): | ||
| text = [text] | ||
| if isinstance(images, (list, tuple)) and len(images) < len(text): | ||
| raise ValueError("Each prompt must be associated with an image.") |
There was a problem hiding this comment.
优先级:P2
这里的批量校验只拦截了 len(images) < len(text),但 text is None 时会被展开成单条空串;images 是多图时,或者 text 比 images 多时,都会返回批次维度不一致的 BatchFeature。官方 Florence-2 processor 是按“一图一 prompt”处理的,这里需要把数量校验补全。
处理要求:请针对该评论进行回复(同意并已修改请回复 "Done",不同意请说明理由)。
| if text is None: | |
| text = "" | |
| if isinstance(text, str): | |
| text = [text] | |
| if isinstance(images, (list, tuple)) and len(images) < len(text): | |
| raise ValueError("Each prompt must be associated with an image.") | |
| if text is None: | |
| text = [""] * (len(images) if isinstance(images, (list, tuple)) else 1) | |
| if isinstance(text, str): | |
| text = [text] | |
| if isinstance(images, (list, tuple)): | |
| if len(images) != len(text): | |
| raise ValueError("Each prompt must be associated with an image.") | |
| elif len(text) != 1: | |
| raise ValueError("Each prompt must be associated with an image.") |
There was a problem hiding this comment.
优先级:P2
这次修复已经把 list/tuple 的等长校验补上了,但这里仍然只把 list/tuple 视为“多图输入”。如果调用方传入 batched 的 np.ndarray / paddle.Tensor,len(images) 明明能反映 batch size,却还是会走单图分支,pixel_values 和 input_ids 仍可能再次批次不一致。
建议先把 images 归一化成列表,再按归一化后的长度做等长校验,例如:
images = make_list_of_images(images)
if text is None:
text = [""] * len(images)
elif isinstance(text, str):
text = [text]
if len(images) != len(text):
raise ValueError("Each prompt must be associated with an image.")处理要求:请针对该评论进行回复(同意并已修改请回复 "Done",不同意请说明理由)。
| ) | ||
| output.image_hidden_states = image_features | ||
| return ( | ||
| output if return_dict else ((output.loss, output.logits) if output.loss is not None else (output.logits,)) |
There was a problem hiding this comment.
优先级:P1
这个分支把 return_dict=False 裁成了只返回 (loss, logits),会丢掉 past_key_values、decoder_hidden_states、encoder_last_hidden_state 等信息,和仓库里其它 seq2seq 模型的 tuple 约定不一致。调用方如果依赖 tuple 输出或缓存,这里会直接退化。
处理要求:请针对该评论修复并提交新的 commit。
| output if return_dict else ((output.loss, output.logits) if output.loss is not None else (output.logits,)) | |
| return output if return_dict else output.to_tuple() |
PaddleFormers Log Analysis
日志分析报告
失败的测试case: 根本原因分析: 修复建议:
🔄 每次 Re-run 后自动更新 |
本 PR 完成 Microsoft Florence-2-base 从 Hugging Face Transformers 到 PaddleFormers 的迁移,并对模型权重、前向精度、生成、训练和 LoRA 链路进行了验证。
1. 模型实现
模型:
microsoft/Florence-2-base支持:
2. 标准接口
新增:
Florence2ConfigFlorence2ProcessorFlorence2ForConditionalGeneration注册:
AutoConfigAutoModelForCausalLMAutoProcessor支持直接加载官方 Florence-2 checkpoint。
3. 精度与参数对齐
使用官方
microsoft/Florence-2-base权重验证:7.2956085e-059.48057e-066.1948994e-066.7234039e-054.2915344e-06额外检查了:
-100mask。4. 300-step 训练验证
使用官方 GSM8K train split,配置如下:
2e-5;0;23;三条曲线整体下降趋势一致。由于跨框架 dropout、drop-path 和 AdamW 数值实现不同,不声明 train 模式逐 step loss 完全一致。
5. 测试
新增 Florence-2 单测,覆盖:
测试结果:
6. 提交范围
本 PR 仅包含 Florence-2 模型、配置、Processor、Auto 注册和单元测试,不包含训练数据、checkpoint、临时脚本和实验输出。