Spaces:
Sleeping
Sleeping
Update diagrams.py
Browse files- diagrams.py +23 -18
diagrams.py
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
import matplotlib.pyplot as plt
|
2 |
-
import tempfile
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
for i in range(layer_count):
|
12 |
-
ax.add_patch(plt.Rectangle((i * 1.5, 0.5), 1.2, 1, edgecolor='black', facecolor='skyblue'))
|
13 |
-
ax.text(i * 1.5 + 0.6, 1, f"Layer {i+1}", ha='center', va='center')
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
1 |
import matplotlib.pyplot as plt
|
|
|
2 |
|
3 |
+
def plot_architecture_diagram(config):
|
4 |
+
try:
|
5 |
+
fig, ax = plt.subplots(figsize=(6, 2)) # reduced size
|
6 |
+
layers = config.get("layers", 4)
|
7 |
+
heads = config.get("attention_heads", 4)
|
8 |
+
ffn = config.get("ffn_dim", 1024)
|
9 |
+
mem = config.get("memory", False)
|
|
|
|
|
|
|
10 |
|
11 |
+
labels = []
|
12 |
+
for i in range(layers):
|
13 |
+
lbl = f"L{i+1}\n{heads}H\n{ffn}F"
|
14 |
+
if mem and i == layers // 2:
|
15 |
+
lbl += "\nMem"
|
16 |
+
labels.append(lbl)
|
17 |
|
18 |
+
ax.plot(range(layers), [1] * layers, "o-", linewidth=2)
|
19 |
+
for i, label in enumerate(labels):
|
20 |
+
ax.text(i, 1.02, label, ha="center", fontsize=8)
|
21 |
|
22 |
+
ax.set_ylim(0.9, 1.15)
|
23 |
+
ax.axis("off")
|
24 |
+
|
25 |
+
fig.savefig("architecture_diagram.png", bbox_inches="tight", dpi=150)
|
26 |
+
plt.close(fig)
|
27 |
+
except Exception as e:
|
28 |
+
print("⚠️ Diagram plot error:", e)
|