Skip to content
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

[Model] DeepseekV2 Support #499

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

saurabhkoshatwar
Copy link

@saurabhkoshatwar saurabhkoshatwar commented Dec 26, 2024

Summary

Resolves #129 Add monkeypatch to support deepseepV2 model.

Details

Ops patched:

  • rms_norm
  • swiglu
  • cross_entropy
  • fused_linear_cross_entropy

Testing Done

  • Hardware Type: NVIDIA A100-SXM4-40GB
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

@saurabhkoshatwar saurabhkoshatwar marked this pull request as draft December 26, 2024 00:58
@saurabhkoshatwar saurabhkoshatwar marked this pull request as ready for review December 31, 2024 20:42
@saurabhkoshatwar
Copy link
Author

saurabhkoshatwar commented Jan 7, 2025

@ByronHsu @yundai424 @Tcc0403 @qingquansong
As discussed in the issue, the rope implementation is different in DeepSeek.

deepseek:

    cos = cos[position_ids].unsqueeze(unsqueeze_dim)
    sin = sin[position_ids].unsqueeze(unsqueeze_dim)

    b, h, s, d = q.shape
    q = q.view(b, h, s, d // 2, 2).transpose(4, 3).reshape(b, h, s, d)

    b, h, s, d = k.shape
    k = k.view(b, h, s, d // 2, 2).transpose(4, 3).reshape(b, h, s, d)

    q_embed = (q * cos) + (rotate_half(q) * sin)
    k_embed = (k * cos) + (rotate_half(k) * sin)
    return q_embed, k_embed

llama:

    cos = cos.unsqueeze(unsqueeze_dim)
    sin = sin.unsqueeze(unsqueeze_dim)
    q_embed = (q * cos) + (rotate_half(q) * sin)
    k_embed = (k * cos) + (rotate_half(k) * sin)
    return q_embed, k_embed`

I will create a separate PR to implement the DeepSeek rope.

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.

[feat] support for DeepseekV2
2 participants