Skip to content

refine fp8_utils #10848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion paddlenlp/transformers/deepseek_v2/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,6 @@ def forward(

if not (self.using_post_norm_recompute and isinstance(self.mlp, DeepseekV2MoE)):
hidden_states = self.post_attention_layernorm(hidden_states)

hidden_states = self.mlp(hidden_states)
hidden_states = residual + hidden_states

Expand Down
17 changes: 7 additions & 10 deletions paddlenlp/transformers/deepseek_v2/modeling_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@
)
from paddlenlp.transformers.moe_layer import FusionMoeNode

from ..fp8_utils import (
fp8_mlp_bwd,
fp8_mlp_bwd_norm_rc,
fp8_mlp_fwd,
fp8_mlp_fwd_norm_rc,
)
from ..fp8_utils import FP8LinearFunctionBase

__all__ = [
"DeepseekV2ForCausalLMPipe",
Expand Down Expand Up @@ -175,15 +170,17 @@ def forward(self, inputs):
with paddle.no_grad():
if self.shared_experts is not None:
if self.using_post_norm_recompute:
shared_expert_output = fp8_mlp_fwd_norm_rc(
shared_expert_output = FP8LinearFunctionBase.fp8_mlp_fwd_norm_rc(
hidden_states,
self.shared_experts.norm_weight,
self.shared_experts.norm_eps,
self.shared_experts.w1,
self.shared_experts.w2,
)
else:
shared_expert_output = fp8_mlp_fwd(hidden_states, self.shared_experts.w1, self.shared_experts.w2)
_, _, shared_expert_output = FP8LinearFunctionBase.fp8_mlp_fwd(
hidden_states, self.shared_experts.w1, self.shared_experts.w2
)
final_hidden_states = final_hidden_states + shared_expert_output

self.x = hidden_states
Expand All @@ -201,7 +198,7 @@ def backward(self, output_grad):

assert not self.send_mtp_embed, "not support have mtp have yet"
if self.using_post_norm_recompute:
dx = fp8_mlp_bwd_norm_rc(
dx = FP8LinearFunctionBase.fp8_mlp_bwd_norm_rc(
do3,
self.x,
self.shared_experts.norm_weight,
Expand All @@ -210,7 +207,7 @@ def backward(self, output_grad):
self.shared_experts.w2,
)
else:
dx = fp8_mlp_bwd(do3, self.x, self.shared_experts.w1, self.shared_experts.w2)
dx = FP8LinearFunctionBase.fp8_mlp_bwd(do3, self.x, self.shared_experts.w1, self.shared_experts.w2)

self.x = None

Expand Down
Loading
Loading