Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/paddlefleet/transformer/transformer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,10 @@ class TransformerConfig(ModelParallelConfig):
will be set to paddlefleet.utils.scaled_init_method_normal(init_method_std) which is paddle nn
init normal with mean=0.0 and std=init_method_std / math.sqrt(2.0 * num_hidden_layers)."""

init_method_std: float = 0.02
init_method_std: float = None
"""Standard deviation of the zero mean normal for the default initialization method, not used if
init_method and output_layer_init_method are provided."""
init_method and output_layer_init_method are provided. If None, will be set to
math.sqrt(0.3333 / hidden_size)."""

embedding_init_method: callable = None
"""
Expand Down Expand Up @@ -984,6 +985,12 @@ def __post_init__(self):
details.
"""
super().__post_init__()

if self.init_method_std is None:
if self.hidden_size == 0:
self.init_method_std = 0.02
else:
self.init_method_std = math.sqrt(0.3333 / self.hidden_size)
Comment thread
DanielSun11 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 优先级:P1

这里把未显式传入的 init_method_std 改成 sqrt(0.3333 / hidden_size) 后,magic_init=False 的默认初始化语义也会变化。当前 CI 已经被这个新语义拦住:Unit test (single card)TestMagicInit::test_magic_init_false_uses_normal_init0.020832291640623696 == 0.020832291640623696,同时 H20/A100 集成测试的 GT loss 也按旧默认值对齐,初始化分布改变后出现 loss 漂移。

如果这是预期的新默认行为,请在同一个 PR 中同步更新 tests/single_card_tests/test_transformer_config.py 的断言,并重新生成/更新受影响的 H20/A100 GT loss 基线;如果不希望影响 magic_init=False,则需要把这个公式限制到对应分支。测试更新的最小形态应类似:

expected_sigma = math.sqrt(0.3333 / 768)
self.assertAlmostEqual(config.init_method_std, expected_sigma, places=6)

if self.enable_mtp_magic_send:
assert self.num_nextn_predict_layers == 1, (
"enable_mtp_magic_send only supports num_nextn_predict_layers=1"
Expand Down
Loading