Skip to content

Commit 658be31

Browse files
Skip set weight[padding_idx] to zero for Embedding when weight is not initialized (#76204)
1 parent d4d996d commit 658be31

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

python/paddle/nn/layer/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,11 @@ def __init__(
18681868
if self._weight_attr is None:
18691869
self.weight.stop_gradient = _freeze
18701870

1871-
if in_dynamic_mode() and padding_idx != -1:
1871+
if (
1872+
in_dynamic_mode()
1873+
and padding_idx != -1
1874+
and self.weight._is_initialized()
1875+
):
18721876
with paddle.no_grad():
18731877
self.weight[padding_idx] = 0.0
18741878

0 commit comments

Comments
 (0)