Skip to content

Conversation

@SigureMo
Copy link
Member

@SigureMo SigureMo commented Dec 6, 2025

Motivation

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

LazyGuard 下的参数是未初始化的,而 uninit_tensor.copy_(data) 结果会是 CPU 的,这导致了 OCR 里的参数加载后基本都是 CPU 的

此前使用了 get_tensor 强制 H2D,因此即便没有初始化仍然正确放在 GPU

但是 #4532 移除了 get_tensor,这就导致这些参数最后都在 CPU,性能惨不忍睹

另外 #4532 影响面不确定,本 PR 只测了 OCR 模型,其他的建议都查查

Modifications

补全 OCR 中缺失的针对未初始化参数的 init 逻辑,并统一使用 h2d_copy

不过这个 h2d_copy 名字感觉不太合适啊,看着像强制 h2d,但是实现并不是

Usage or Command

python -m fastdeploy.entrypoints.openai.api_server \
        --model /root/paddlejob/tmpspace/MODELS/PaddlePaddle/PaddleOCR-VL \
        --port 8295 \
        --metrics-port 8296 \
        --engine-worker-queue-port 8297 \
        --cache-queue-port 55660 \
        --max-model-len 16384 \
        --max-num-batched-tokens 16384 \
        --gpu-memory-utilization 0.7 \
        --max-num-seqs 256 \
        --workers 2 \
        --graph-optimization-config '{"graph_opt_level":0, "use_cudagraph":true}'

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • 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.
  • 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.

Copilot AI review requested due to automatic review settings December 6, 2025 01:14
@paddle-bot
Copy link

paddle-bot bot commented Dec 6, 2025

Thanks for your contribution!

@SigureMo SigureMo changed the title [BugFix] Fix some parameter place on CPU in PaddleOCR-VL [BugFix] Fix some parameters place on CPU in PaddleOCR-VL Dec 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

此 PR 修复了 PaddleOCR-VL 模型加载时参数被错误放置在 CPU 上的问题。由于 PR #4532 移除了 get_tensor 的强制 H2D 调用,导致 LazyGuard 下未初始化的参数在使用 copy_ 后仍停留在 CPU,严重影响性能。

主要变更

  • 在所有 weight_loader 方法中添加参数初始化检查,确保未初始化的参数先调用 initialize()
  • 统一使用 h2d_copy 替代 param.copy_ 以保证正确的设备放置
  • 修复了 3 个不同的 weight_loader 方法(SiglipAttention.out_proj_weight_loader、SiglipMLP.weight_loader、Projector.weight_loader)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
fastdeploy/model_executor/models/paddleocr_vl/siglip.py 为 SiglipAttention 和 SiglipMLP 的 weight_loader 添加参数初始化逻辑,并替换为 h2d_copy;新增 get_tensor 导入但未使用
fastdeploy/model_executor/models/paddleocr_vl/projector.py 为 Projector 的 weight_loader 添加参数初始化逻辑,并替换为 h2d_copy

import paddle.nn.functional as F
from paddleformers.transformers.model_utils import PretrainedModel

from fastdeploy.model_executor.layers.utils import get_tensor
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_tensor import is unused in this file. Since PR #4532 removed the usage of get_tensor and this PR replaces it with h2d_copy (which internally calls get_tensor when needed), this import can be safely removed.

Suggested change
from fastdeploy.model_executor.layers.utils import get_tensor

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@f6eb4dc). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...eploy/model_executor/models/paddleocr_vl/siglip.py 66.66% 0 Missing and 2 partials ⚠️
...oy/model_executor/models/paddleocr_vl/projector.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #5413   +/-   ##
==========================================
  Coverage           ?   58.26%           
==========================================
  Files              ?      327           
  Lines              ?    40566           
  Branches           ?     6157           
==========================================
  Hits               ?    23636           
  Misses             ?    15098           
  Partials           ?     1832           
Flag Coverage Δ
GPU 58.26% <70.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo SigureMo changed the title [BugFix] Fix some parameters place on CPU in PaddleOCR-VL [Loader][BugFix] Fix some parameters place on CPU in PaddleOCR-VL Dec 6, 2025
@Jiang-Jia-Jun Jiang-Jia-Jun merged commit 0c66163 into PaddlePaddle:develop Dec 8, 2025
15 of 17 checks passed
Jiang-Jia-Jun pushed a commit that referenced this pull request Dec 8, 2025
…dleOCR-VL (#5413) (#5414)

* [BugFix] Fix some parameter place on CPU in PaddleOCR-VL

* clean log

* fix codestyle
@SigureMo SigureMo deleted the ocr/fix-paramter-place-on-cpu branch December 8, 2025 02:13
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.

4 participants