rxnn 0.1.52__py3-none-any.whl → 0.1.53__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rxnn/transformers/moe.py
CHANGED
@@ -23,20 +23,21 @@ class MoeRouter(nn.Module):
|
|
23
23
|
|
24
24
|
def calculate_aux_loss(self, top_k_indices: torch.Tensor, probs: torch.Tensor) -> torch.Tensor:
|
25
25
|
# Get shapes
|
26
|
-
|
26
|
+
T, K = top_k_indices.shape # Batch, Sequence length, Top-K
|
27
27
|
|
28
28
|
# 1. Compute expert selection mask (one-hot encoded)
|
29
29
|
expert_mask = F.one_hot(top_k_indices, self.num_experts).float() # (B, S, K, E)
|
30
30
|
|
31
31
|
# 2. Total number of times each expert is selected
|
32
|
-
expert_usage = expert_mask.sum(dim=(0, 1
|
32
|
+
expert_usage = expert_mask.sum(dim=(0, 1)) # (E,)
|
33
33
|
|
34
34
|
# 3. Fraction of tokens assigned to each expert
|
35
|
-
|
36
|
-
fraction_expert = expert_usage /
|
35
|
+
total_selections = T * K
|
36
|
+
fraction_expert = expert_usage / (total_selections + 1e-6) # (E,)
|
37
37
|
|
38
38
|
# 4. Sum of probabilities for each expert's selected tokens
|
39
|
-
|
39
|
+
probs_expanded = probs.unsqueeze(1).expand(-1, K, -1) # (B_K, K, E)
|
40
|
+
sum_probs = (probs_expanded * expert_mask).sum(dim=(0, 1))
|
40
41
|
|
41
42
|
# 5. Average probability per expert (avoid division by zero)
|
42
43
|
avg_probs = sum_probs / expert_usage.clamp(min=1e-6) # (E,)
|
@@ -21,11 +21,11 @@ rxnn/transformers/ff.py,sha256=jJnuBDsnnX5uYC_WZH8cXAYrMnz0P-iX7MwcPivjRtI,2533
|
|
21
21
|
rxnn/transformers/layers.py,sha256=OX8CsFY9A7uqH1SLwyexR_5BNlwheYrJHCGXjF8Q7HU,7186
|
22
22
|
rxnn/transformers/mask.py,sha256=J0cfLVLt3SzS2ra3KcY4khrkhI975Dw4CjpUi3Sn25s,419
|
23
23
|
rxnn/transformers/models.py,sha256=QFzBrOR7tDp9d_T0HoIukBMfEbLxsCictV5p3e2ilxg,7552
|
24
|
-
rxnn/transformers/moe.py,sha256=
|
24
|
+
rxnn/transformers/moe.py,sha256=j6jEx6Ip0zttlUZKKn82azxo95lkLZs-H2GLSMD88hY,5859
|
25
25
|
rxnn/transformers/positional.py,sha256=2l38RS0Dini3f6Z3LUHr3XwWzg1UK7fO2C6wazWDAYU,4292
|
26
26
|
rxnn/transformers/sampler.py,sha256=poWBpxg1iuK5gEJtxHkk5VVfS9V48hs2Olqdhy_Gw8c,6548
|
27
27
|
rxnn/utils.py,sha256=d5U8i5ukovgDyqiycc2AoxObTz_eF_bgo2MKvdtJ98s,467
|
28
|
-
rxnn-0.1.
|
29
|
-
rxnn-0.1.
|
30
|
-
rxnn-0.1.
|
31
|
-
rxnn-0.1.
|
28
|
+
rxnn-0.1.53.dist-info/LICENSE,sha256=C8coDFIUYuOcke4JLPwTqahQUCyXyGq6WOaigOkx8tY,11275
|
29
|
+
rxnn-0.1.53.dist-info/METADATA,sha256=fwifQgrfowidD4AR5Pl952-P42HwtA3Tuq6d5RAM6QI,16627
|
30
|
+
rxnn-0.1.53.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
31
|
+
rxnn-0.1.53.dist-info/RECORD,,
|
File without changes
|
File without changes
|