Skip to content

WIP [DeepSeek R1] Add DeepSeekV3 Base + Weight Conversion #2171

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 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix top_k usage
  • Loading branch information
DavidLandup0 committed May 2, 2025
commit 5b91b17c88c7ff62a15cbefe7ba63571b9da0f3f
2 changes: 1 addition & 1 deletion keras_hub/src/models/deepseek_r1/deepseek_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ModelArgs:
inter_dim: int = 10944
moe_inter_dim: int = 1408
# n_layers: int = 27
n_layers: int = 1
n_layers: int = 2
n_dense_layers: int = 1
n_heads: int = 16
# moe
Expand Down
2 changes: 1 addition & 1 deletion keras_hub/src/models/deepseek_r1/deepseek_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def call(self, x):

scores = ops.where(ops.expand_dims(mask, -1), scores, float("inf"))
scores = ops.reshape(scores, [scores.shape[0], -1])
indices = ops.top_k(scores, self.topk, dim=-1)[1]
indices = ops.top_k(scores, self.topk)[1]
weights = ops.take_along_axis(original_scores, indices, axis=1)
if self.score_func == "sigmoid":
weights /= ops.sum(weights, axis=-1, keepdims=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def convert_weights():

n_blocks = len(model.layers) - 3 # (3 = len(embed, head, norm))
for i in range(n_blocks):
convert_block(model.layers[i + 1], torch_weights, i + 1)
convert_block(model.layers[i + 2], torch_weights, i + 1)

# Run some tokens as a sanity check
total_tokens_generated = 0
Expand Down