Update modeling_super_linear.py
Browse files- modeling_super_linear.py +12 -1
modeling_super_linear.py
CHANGED
|
@@ -356,6 +356,8 @@ class SparseNoisyMoE(nn.Module):
|
|
| 356 |
load_balancing_loss = self.calculate_load_balancing_loss(self.gate_outputs, batch_size)
|
| 357 |
|
| 358 |
expert_probs = F.softmax(self.gate_outputs, dim=1)
|
|
|
|
|
|
|
| 359 |
import matplotlib.pyplot as plt
|
| 360 |
|
| 361 |
plt.figure(figsize=(10, 6))
|
|
@@ -363,7 +365,16 @@ class SparseNoisyMoE(nn.Module):
|
|
| 363 |
plt.xlabel('Expert Index')
|
| 364 |
plt.ylabel('Probability')
|
| 365 |
plt.title('Expert Selection Probabilities')
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
plt.tight_layout()
|
| 368 |
plt.savefig('expert_probabilities.png')
|
| 369 |
plt.close()
|
|
|
|
| 356 |
load_balancing_loss = self.calculate_load_balancing_loss(self.gate_outputs, batch_size)
|
| 357 |
|
| 358 |
expert_probs = F.softmax(self.gate_outputs, dim=1)
|
| 359 |
+
expert_probs = expert_probs[1,:]
|
| 360 |
+
# Plot the expert probabilities
|
| 361 |
import matplotlib.pyplot as plt
|
| 362 |
|
| 363 |
plt.figure(figsize=(10, 6))
|
|
|
|
| 365 |
plt.xlabel('Expert Index')
|
| 366 |
plt.ylabel('Probability')
|
| 367 |
plt.title('Expert Selection Probabilities')
|
| 368 |
+
|
| 369 |
+
# Create more descriptive x-axis labels
|
| 370 |
+
if hasattr(self, 'experts') and isinstance(getattr(self, 'experts', None), dict):
|
| 371 |
+
# If experts are stored in a dictionary with meaningful keys
|
| 372 |
+
expert_names = list(self.experts.keys())
|
| 373 |
+
plt.xticks(range(len(expert_probs)), expert_names, rotation=45)
|
| 374 |
+
else:
|
| 375 |
+
# Default numbering if expert names aren't available
|
| 376 |
+
plt.xticks(range(len(expert_probs)), [f'Expert {i}' for i in range(len(expert_probs))])
|
| 377 |
+
|
| 378 |
plt.tight_layout()
|
| 379 |
plt.savefig('expert_probabilities.png')
|
| 380 |
plt.close()
|