Repository navigation
Conversation
Verify the server prompt before appending completions and reuse serializable media references in training features.
kevssim
left a comment
There was a problem hiding this comment.
🤖 本 review 由 AI 生成,仅供参考,请结合实际情况判断。
拼接前校验 prompt 的思路是对的,但当前实现假设所有后端返回的都是展开后的 prompt_token_ids,这会导致 sglang 服务端的多模态采样全部失败(见行内评论)。另外请确认训练 feature 里附带 wire_media 是否必要。
| if media and response.prompt_token_ids != list(item.feature['input_ids']): | ||
| raise ValueError('Remote sampler prompt_token_ids do not match the expanded training prompt. ' | ||
| 'Check that the training and sampler media processors use the same settings.') |
There was a problem hiding this comment.
🤖 以下为 AI review 意见,供参考。
[P1] 服务端为 sglang 时,多模态采样会被这个校验全部拦下
这里把 response.prompt_token_ids 当作引擎展开后的 prompt,但只有 vLLM 后端是这样(vllm_sampler.py:363 也依赖这一点)。sglang 引擎返回的是传入的原始 id:prompt_token_ids = request.get('input_ids')(sglang_engine.py:223),也就是未展开的 engine_input_ids。服务端支持 sampler_type='sglang' 和 'sglang_async'(server/config/application_spec.py:85)。因此连接 sglang 服务端时,只要有图片或视频,即使两侧预处理完全一致,这里也一定抛出 ValueError。这条路径在本 PR 之前是可用的。
建议在服务端只是原样返回输入时跳过校验,只校验真正展开过的 prompt:
| if media and response.prompt_token_ids != list(item.feature['input_ids']): | |
| raise ValueError('Remote sampler prompt_token_ids do not match the expanded training prompt. ' | |
| 'Check that the training and sampler media processors use the same settings.') | |
| if media: | |
| server_ids = list(response.prompt_token_ids or ()) | |
| # sglang echoes the collapsed ids it was given; only an expanded prompt can be checked. | |
| if server_ids != list(item.engine_input_ids) and server_ids != list(item.feature['input_ids']): | |
| raise ValueError('Remote sampler prompt_token_ids do not match the expanded training prompt. ' | |
| 'Check that the training and sampler media processors use the same settings.') |
| stop_reason=seq.stop_reason, tokens=tokens, logprobs=seq.logprobs, | ||
| decoded=self.template.decode(tokens), new_input_feature=dict(completion.state.feature), | ||
| decoded=self.template.decode(tokens), | ||
| new_input_feature={**completion.state.feature, **wire_media}, |
There was a problem hiding this comment.
🤖 以下为 AI review 意见,供参考。
[P2] 每条采样序列的训练 feature 都会多带一份 base64 图片
{**completion.state.feature, **wire_media} 会把所有图片的 base64 PNG 写进每个 SampledSequence 的 new_input_feature。而 feature 里已经有 pixel_values。每个 prompt 采样 n 条时,后续训练请求里每张图都会多上传 n 份。请确认训练侧是否会读取 feature 里的 images。如果只是为了替换原始数据集字典、避免 HTTP 校验报错,可以只覆盖 feature 里已有的键:
new_input_feature={**completion.state.feature,
**{k: v for k, v in wire_media.items() if k in completion.state.feature}},6ad4831 to
3c1f4ec
Compare
Yunnglin
left a comment
There was a problem hiding this comment.
修复采样和训练 prompt 不一致的问题值得合。当前版本需要先处理新版 Client 连接旧版 SGLang Server 的兼容性。
我用同一组多模态输入和模拟响应对比了 6ad48312 与 3c1f4eca。旧版 SGLang 返回请求里的未展开 token ID,并且没有 prompt_token_ids_echoed。上一版 Client 可继续采样,当前版把缺失字段当成 False,用展开后的训练前缀校验,直接抛出 ValueError。
建议区分字段缺失与服务端显式返回 False。对新版 vLLM 仍逐 token 校验展开后的 prompt,同时为旧版 SGLang 保留兼容路径。请补上无标记的旧 SGLang、有标记的新版 SGLang、以及 vLLM 展开 token 匹配和不匹配的回归测试,再跑一次真实图文采样到训练的链路,确认媒体字段也能走通。
|
@Yunnglin 已修复新版 Client 连接旧版 SGLang Server 的兼容问题。旧服务缺少 prompt_token_ids_echoed 时,允许回显请求里的未展开 ID。新版 SGLang 显式返回 True 时,按请求 ID 校验。新版 vLLM 显式返回 False 时,仍逐 token 校验展开后的训练前缀。 增加unit test相关测试,全部通过。 |
|
@werwrewe 感谢修复,我也复跑了 Client 兼容性和请求格式的测试,这部分通过了。 合入前能否在当前提交上补一次真实的图文采样到训练?用一条包含原始图片字段的数据集样本,通过 Client 请求真实 vLLM 服务,确认采样返回的 一条样本就够。请贴一下提交、模型、vLLM 版本和这两步的结果。如果已经跑过,直接补现有的结果即可。 |
Verify the server prompt before appending completions and reuse serializable media references in training features.
PR type
PR information
图文 GRPO 采样返回后,客户端会把生成的回答拼到本地训练前缀上。如果 vLLM 实际使用的 prompt 与训练前缀存在差异,采样时记录的 logprobs 就会对应另一份输入。后续训练请求中的图片字段也可能保留数据集的原始字典,触发 HTTP 参数校验错误。
改动
prompt_token_ids与训练侧展开后的input_ids,发现差异时直接报错。