-
Notifications
You must be signed in to change notification settings - Fork 582
Fix muon moe dimension numbers #4843
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,14 @@ def test_scale_is_excluded(self): | |
| def test_bias_is_excluded(self): | ||
| self.assertIsNone(muon_utils.transform_logic(("decoder", "dense", "bias"))) | ||
|
|
||
| def test_bias_variant_is_excluded(self): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you help explain a little bit why those bias to be excluded? or add a comment there? Also, for a model/config, are you consider all bias? for instance, wondering why GptOss only excludes wo_bias?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am under the impression that all kind of biases need to be excluded. These unittests are just some examples of bias tensors. I think all bias needs to be excluded. GPTOss is just an example to test the code. |
||
| # Bias names (e.g., in MoE with mlp_bias=True) are excluded across all expert projections. | ||
| self.assertIsNone(muon_utils.transform_logic(("decoder", "moe_block", "wi_0_bias"))) | ||
| self.assertIsNone(muon_utils.transform_logic(("decoder", "GptOssMlp", "wi_0_bias"))) | ||
| self.assertIsNone(muon_utils.transform_logic(("decoder", "GptOssMlp", "wi_1_bias"))) | ||
| self.assertIsNone(muon_utils.transform_logic(("decoder", "GptOssMlp", "wo_bias"))) | ||
| self.assertIsNone(muon_utils.transform_logic(("decoder", "mlp", "mlp_bias"))) | ||
|
|
||
| def test_embedding_is_excluded(self): | ||
| self.assertIsNone(muon_utils.transform_logic(("token_embedder", "embedding"))) | ||
|
|
||
|
|
@@ -69,9 +77,27 @@ def test_moe_wi_1_uses_last_two_axes(self): | |
| def test_moe_wo_uses_last_two_axes(self): | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "MoeBlock_0", "wo")), mdn((-2,), (-1,))) | ||
|
|
||
| def test_moe_prefused_wi_uses_last_two_axes(self): | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "MoeBlock_0", "wi")), mdn((-2,), (-1,))) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "routed_experts", "wi")), mdn((-2,), (-1,))) | ||
|
|
||
| def test_qwen3_next_moe_routed_experts(self): | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "mlp", "routed_experts", "wi_0")), mdn((-2,), (-1,))) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "mlp", "routed_experts", "wi_1")), mdn((-2,), (-1,))) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "mlp", "routed_experts", "wo")), mdn((-2,), (-1,))) | ||
|
|
||
| def test_qwen3_moe_block(self): | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "moe_block", "wi_0")), mdn((-2,), (-1,))) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "moe_block", "wo")), mdn((-2,), (-1,))) | ||
|
|
||
| def test_gpt_oss_mlp_moe(self): | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "GptOssMlp", "wi_0")), mdn((-2,), (-1,))) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "GptOssMlp", "wo")), mdn((-2,), (-1,))) | ||
|
|
||
| def test_moe_gate_falls_through_to_standard(self): | ||
| # 'gate' is inside MoeBlock_0 but not one of (wi_0, wi_1, wo) → standard. | ||
| # 'gate' is inside MoeBlock_0 but not one of (wi, wi_0, wi_1, wo) → standard. | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "MoeBlock_0", "gate", "kernel")), mdn((0,), (-1,))) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "routed_experts", "gate", "kernel")), mdn((0,), (-1,))) | ||
|
|
||
| # --- 2.2 Self-attention --- | ||
| def test_self_attention_out_projection(self): | ||
|
|
@@ -119,6 +145,18 @@ def test_deepseek_v4_self_attention_grouped_projection(self): | |
| # and output on out_features_per_group (-1) | ||
| self.assertEqual(muon_utils.transform_logic(("decoder", "self_attention", "o_a_proj")), mdn((-2,), (-1,))) | ||
|
|
||
| def test_deepseek_v4_position_bias_is_standard_weight(self): | ||
| # position_bias in DeepSeek V4 compressed attention is a 2D weight matrix (not a 1D bias vector), | ||
| # so it receives standard Muon dimension numbers mdn((0,), (-1,)). | ||
| self.assertEqual( | ||
| muon_utils.transform_logic(("decoder", "self_attention", "csa_compressor", "position_bias")), | ||
| mdn((0,), (-1,)), | ||
| ) | ||
| self.assertEqual( | ||
| muon_utils.transform_logic(("decoder", "self_attention", "hca_compressor", "position_bias")), | ||
| mdn((0,), (-1,)), | ||
| ) | ||
|
|
||
|
|
||
| class TestGetTransformTree(unittest.TestCase): | ||
| """Tests for get_transform_tree: recursive dict walk that applies transform_logic.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low: Extracting the MoE block names and expert kernel names into variables improves code readability and makes it easier to extend with other MoE architectures in the future.