Skip to content

[BugFix] Validate feature shape to reject mismatched Encode versions#7131

Open
TBD1 wants to merge 1 commit intoPaddlePaddle:release/online/20251131from
TBD1:feature/resource-manager-v1-fix
Open

[BugFix] Validate feature shape to reject mismatched Encode versions#7131
TBD1 wants to merge 1 commit intoPaddlePaddle:release/online/20251131from
TBD1:feature/resource-manager-v1-fix

Conversation

@TBD1
Copy link
Copy Markdown
Collaborator

@TBD1 TBD1 commented Apr 1, 2026

Motivation

在多模态推理场景中,特征下载后需要确保形状维度的一致性。当前代码在下载 BOS 特征时,缺少对特征形状维度的验证,可能导致混合维度(如同时存在 2D 和 4D 特征)或非法维度(如 1D 特征)的输入进入后续处理流程,引发潜在的运行时错误。

本 PR 通过添加特征形状检查逻辑,在特征下载完成后立即验证形状维度的合法性,提前拦截不合规的请求并返回明确的错误信息。

Modifications

1. 新增 check_result_shape() 函数 (resource_manager_v1.py)

  • 验证所有特征必须是 2D 或 4D 形状
  • 确保同一批特征中的维度一致(不允许混合 2D 和 4D)
  • 对非法维度或不一致的情况,设置错误码 530 并记录详细错误信息
  • 错误消息包含具体的特征索引和形状信息,便于问题定位

2. 特征下载流程增强

在以下特征下载完成后调用 check_result_shape() 进行验证:

  • video_features 下载后
  • image_features 下载后

3. 单元测试覆盖 (test_resource_manager_v1.py)

新增 4 个测试用例:

  • test_check_result_shape_all_2d_success - 验证所有 2D 特征通过
  • test_check_result_shape_all_4d_success - 验证所有 4D 特征通过
  • test_check_result_shape_mixed_2d_4d_fails - 验证混合维度被拦截
  • test_check_result_shape_1d_fails - 验证非法维度被拦截

Usage or Command

无需额外命令,该修复自动应用于多模态特征下载流程。

Accuracy Tests

本 PR 不涉及模型内核或前向传播代码的修改,仅增加输入验证逻辑,不影响模型输出的准确性。

Checklist

  • Add at least a tag in the PR title.
    • Tag: [BugFix]
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results. (N/A - no model output changes)
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 1, 2026

Thanks for your contribution!

@TBD1 TBD1 changed the title [BugFix] intercept multi-encode feature requests [BugFix] Add feature shape validation Apr 1, 2026
@TBD1 TBD1 force-pushed the feature/resource-manager-v1-fix branch from 2773d66 to d888d7b Compare April 1, 2026 12:07
@TBD1 TBD1 changed the title [BugFix] Add feature shape validation [BugFix] Validate feature shape to reject mismatched Encode versions Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant