66import math
77from pathlib import Path
88
9- import matplotlib .pyplot as plt
109import matplotlib .patches as mpatches
10+ import matplotlib .pyplot as plt
1111from matplotlib .patches import FancyArrowPatch
1212
13+
1314OUT = Path (__file__ ).resolve ().parent
1415
1516
@@ -50,7 +51,9 @@ def fig_routing_topk() -> None:
5051 linewidth = 1.2 ,
5152 )
5253 )
53- ax .text (4.02 , 1.98 , "Router\n softmax + top-k" , ha = "center" , va = "center" , fontsize = 9 , color = "white" , fontweight = "bold" )
54+ ax .text (
55+ 4.02 , 1.98 , "Router\n softmax + top-k" , ha = "center" , va = "center" , fontsize = 9 , color = "white" , fontweight = "bold"
56+ )
5457
5558 # Experts
5659 ex_x = [6.0 , 7.05 , 8.1 , 9.15 ]
@@ -73,7 +76,9 @@ def fig_routing_topk() -> None:
7376 ax .text (x , 0.55 , lab .replace (" " , "\n " ), ha = "center" , va = "center" , fontsize = 7 , color = "white" )
7477
7578 # Arrows token -> router
76- ax .add_patch (FancyArrowPatch ((2.15 , ty ), (3.35 , 1.98 ), arrowstyle = "-|>" , mutation_scale = 12 , color = "#34495e" , lw = 1.4 ))
79+ ax .add_patch (
80+ FancyArrowPatch ((2.15 , ty ), (3.35 , 1.98 ), arrowstyle = "-|>" , mutation_scale = 12 , color = "#34495e" , lw = 1.4 )
81+ )
7782
7883 # Arrows router -> two experts (top-2)
7984 for x in (ex_x [1 ], ex_x [3 ]):
@@ -90,7 +95,9 @@ def fig_routing_topk() -> None:
9095 )
9196 ax .text (6.8 , 1.35 , "top-k (e.g. k=2)" , fontsize = 9 , color = "#c0392b" , fontweight = "bold" )
9297
93- ax .text (5.0 , 2.85 , "Sparse activation: only k experts compute per token" , ha = "center" , fontsize = 10 , color = "#2c3e50" )
98+ ax .text (
99+ 5.0 , 2.85 , "Sparse activation: only k experts compute per token" , ha = "center" , fontsize = 10 , color = "#2c3e50"
100+ )
94101
95102 save (fig , "moe_routing_topk.png" )
96103
@@ -532,7 +539,9 @@ def gate_inside_expert(xc: float, highlight: int) -> None:
532539 zorder = 1 ,
533540 )
534541 )
535- ax .text (c_plus [0 ], y_arrow_tip + 0.26 , "Output" , ha = "center" , va = "bottom" , fontsize = 10 , fontweight = "bold" , color = INK )
542+ ax .text (
543+ c_plus [0 ], y_arrow_tip + 0.26 , "Output" , ha = "center" , va = "bottom" , fontsize = 10 , fontweight = "bold" , color = INK
544+ )
536545
537546 # Title stacked just above Output (avoids fig.suptitle's extra vertical band).
538547 y_out_label = y_arrow_tip + 0.26
0 commit comments