Skip to content

Commit 0c66163

Browse files
authored
[Loader][BugFix] Fix some parameters place on CPU in PaddleOCR-VL (#5413)
* [BugFix] Fix some parameter place on CPU in PaddleOCR-VL * clean log * fix codestyle
1 parent c3a8a16 commit 0c66163

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

fastdeploy/model_executor/models/paddleocr_vl/projector.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import paddle
2121
import paddle.nn as nn
2222

23+
from fastdeploy.model_executor.utils import h2d_copy
24+
2325

2426
class GELUActivation(nn.Layer):
2527
"""
@@ -97,6 +99,8 @@ def forward(self, image_features, image_grid_thw):
9799

98100
def weight_loader(self, param, loaded_weight, loaded_shard_id: Optional[str] = None):
99101
loaded_weight = loaded_weight.transpose([1, 0])
102+
if not param._is_initialized():
103+
param.initialize()
100104
assert param.shape == loaded_weight.shape, (
101105
f" Attempted to load weight ({loaded_weight.shape}) " f"into parameter ({param.shape})"
102106
)
@@ -106,4 +110,4 @@ def weight_loader(self, param, loaded_weight, loaded_shard_id: Optional[str] = N
106110
loaded_weight = loaded_weight.view(param.dtype)
107111
else:
108112
loaded_weight = loaded_weight.cast(param.dtype)
109-
param.copy_(loaded_weight, False)
113+
h2d_copy(param, loaded_weight)

fastdeploy/model_executor/models/paddleocr_vl/siglip.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def qkv_weight_loader(self, param, loaded_weight, loaded_shard_id: Optional[str]
100100

101101
def out_proj_weight_loader(self, param, loaded_weight, loaded_shard_id: Optional[str] = None):
102102
loaded_weight = loaded_weight.transpose([1, 0])
103+
if not param._is_initialized():
104+
param.initialize()
103105
assert param.shape == loaded_weight.shape, (
104106
f" Attempted to load weight ({loaded_weight.shape}) " f"into parameter ({param.shape})"
105107
)
@@ -109,7 +111,7 @@ def out_proj_weight_loader(self, param, loaded_weight, loaded_shard_id: Optional
109111
loaded_weight = loaded_weight.view(param.dtype)
110112
else:
111113
loaded_weight = loaded_weight.cast(param.dtype)
112-
param.copy_(loaded_weight, False)
114+
h2d_copy(param, loaded_weight)
113115

114116
def forward(
115117
self,
@@ -287,6 +289,8 @@ def __init__(self, config):
287289

288290
def weight_loader(self, param, loaded_weight, loaded_shard_id: Optional[str] = None):
289291
loaded_weight = loaded_weight.transpose([1, 0])
292+
if not param._is_initialized():
293+
param.initialize()
290294
assert param.shape == loaded_weight.shape, (
291295
f" Attempted to load weight ({loaded_weight.shape}) " f"into parameter ({param.shape})"
292296
)
@@ -296,7 +300,7 @@ def weight_loader(self, param, loaded_weight, loaded_shard_id: Optional[str] = N
296300
loaded_weight = loaded_weight.view(param.dtype)
297301
else:
298302
loaded_weight = loaded_weight.cast(param.dtype)
299-
param.copy_(loaded_weight, False)
303+
h2d_copy(param, loaded_weight)
300304

301305
def forward(self, hidden_states: paddle.Tensor) -> paddle.Tensor:
302306
hidden_states = self.fc1(hidden_states)

0 commit comments

Comments
 (0)