Skip to content

【Inference Optimize】optimize DeepSeek_v3 #3349

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

chang-wenbin
Copy link
Collaborator

@chang-wenbin chang-wenbin commented Aug 12, 2025

Eliminate redundant calculations

      fmha_out = None
        # NOTE: (changwenbin) Bring out the public calculation in PD MIX to avoid repeated calculation.
        query = self.q_a_proj(hidden_states)
        query = self.q_a_layernorm(query)
        query = self.q_b_proj(query)
        query = query.reshape([-1, self.num_attention_heads_tp, self.qk_head_dim])
        query_nope, query_pe = query.split([self.qk_nope_head_dim, self.qk_rope_head_dim], axis=-1)
        compressed_kv = self.kv_a_proj_with_mqa(hidden_states)
        compressed_kv, key_pe = compressed_kv.split([self.kv_lora_rank, self.qk_rope_head_dim], axis=-1)
        key_pe = key_pe.reshape([-1, 1, self.qk_rope_head_dim])
        compressed_kv = self.kv_a_layernorm(compressed_kv)
        query_pe, key_pe = self.rotary_emb(position_ids, query_pe, key_pe)

encoder using FA3
you need export FLAGS_flash_attn_version=3

Copy link

paddle-bot bot commented Aug 12, 2025

Thanks for your contribution!

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.

2 participants