Skip to content

Add Qwen3 Moe #2260

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

kanpuriyanawab
Copy link
Collaborator

No description provided.

@kanpuriyanawab kanpuriyanawab self-assigned this May 19, 2025
Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

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

Thanks! Took an initial pass. Let's try to clean up the config and state passing.

No passing an index down the layer stack, plus data structures that apply to the whole layer stack.

self,
num_query_heads,
num_key_value_heads,
layer_index,
Copy link
Member

Choose a reason for hiding this comment

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

This layer index is gross, let's remove it. Handle the args properly in the backbone and pass the correct sliding_window_size to this layer and the decoder layer above it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since it's an Moe, layer index is not just used for sliding window but for experts

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced this passing of layer_index, decoder_sparse_step and mlp_only_layers with a single boolean switch:

https://github.com/kanpuriyanawab/keras-nlp/blob/730a9c41e95a74906a041d8933b8d7738391b438/keras_hub/src/models/qwen3_moe/qwen3_moe_backbone.py#L129-L156

model(input_data)
"""

def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

In general, let's make sure we prune this list down just to the config options we need.

sliding_window_size=32768,
output_router_logits=False,
router_aux_loss_coefficient=0.001,
mlp_only_layers=[],
Copy link
Member

Choose a reason for hiding this comment

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

Fine to have something like this for the toplevel, but let's pass something more direct to each decoder layer (so we don't need to pass the index down). Make sure to document if we keep it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but let's pass something more direct to each decoder layer

what do you suggest?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants