Spaces:
Sleeping
Sleeping
Update evo_transformer.py
Browse files- evo_transformer.py +15 -20
evo_transformer.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
# evo_transformer.py
|
2 |
-
|
3 |
import random
|
4 |
import json
|
5 |
|
@@ -25,8 +24,7 @@ class EvoTransformer:
|
|
25 |
elif trait == "ffn_dim":
|
26 |
new_config[trait] = random.choice([512, 1024, 2048])
|
27 |
elif trait == "dropout":
|
28 |
-
|
29 |
-
new_config[trait] = round(min(max(0.0, new_config[trait] + change), 0.5), 2)
|
30 |
elif trait == "memory":
|
31 |
new_config[trait] = not new_config[trait]
|
32 |
|
@@ -41,22 +39,19 @@ class EvoTransformer:
|
|
41 |
return self.history
|
42 |
|
43 |
def evaluate(self):
|
44 |
-
|
45 |
-
accuracy
|
46 |
-
return {
|
47 |
-
"accuracy": accuracy,
|
48 |
-
"params": self.estimate_params()
|
49 |
-
}
|
50 |
|
51 |
def estimate_params(self):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
1 |
# evo_transformer.py
|
|
|
2 |
import random
|
3 |
import json
|
4 |
|
|
|
24 |
elif trait == "ffn_dim":
|
25 |
new_config[trait] = random.choice([512, 1024, 2048])
|
26 |
elif trait == "dropout":
|
27 |
+
new_config[trait] = round(min(max(0.0, new_config[trait] + random.uniform(-0.05, 0.05)), 0.5), 2)
|
|
|
28 |
elif trait == "memory":
|
29 |
new_config[trait] = not new_config[trait]
|
30 |
|
|
|
39 |
return self.history
|
40 |
|
41 |
def evaluate(self):
|
42 |
+
score = round(random.uniform(0.85, 0.95), 4)
|
43 |
+
return {"accuracy": score, "params": self.estimate_params()}
|
|
|
|
|
|
|
|
|
44 |
|
45 |
def estimate_params(self):
|
46 |
+
return round(self.config["layers"] * self.config["ffn_dim"] * 0.001, 2)
|
47 |
+
|
48 |
+
def save_history(self):
|
49 |
+
csv_path = "evo_history.csv"
|
50 |
+
json_path = "evo_history.json"
|
51 |
+
with open(csv_path, "w") as f:
|
52 |
+
f.write("generation,layers,attention_heads,ffn_dim,dropout,memory\n")
|
53 |
+
for i, cfg in enumerate(self.history):
|
54 |
+
f.write(f"{i+1},{cfg['layers']},{cfg['attention_heads']},{cfg['ffn_dim']},{cfg['dropout']},{cfg['memory']}\n")
|
55 |
+
with open(json_path, "w") as f:
|
56 |
+
json.dump(self.history, f, indent=2)
|
57 |
+
return csv_path, json_path
|