Spaces:
Sleeping
Sleeping
Update evo_transformer.py
Browse files- evo_transformer.py +7 -14
evo_transformer.py
CHANGED
@@ -1,16 +1,20 @@
|
|
1 |
# evo_transformer.py
|
2 |
import random
|
3 |
-
import json
|
4 |
|
5 |
class EvoTransformer:
|
6 |
def __init__(self, config=None):
|
7 |
-
self.
|
8 |
"layers": 4,
|
9 |
"attention_heads": 4,
|
10 |
"ffn_dim": 1024,
|
11 |
"dropout": 0.1,
|
12 |
"memory": False,
|
13 |
}
|
|
|
|
|
|
|
|
|
|
|
14 |
self.history = [self.config.copy()]
|
15 |
|
16 |
def mutate(self):
|
@@ -43,15 +47,4 @@ class EvoTransformer:
|
|
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
|
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
|
|
|
1 |
# evo_transformer.py
|
2 |
import random
|
|
|
3 |
|
4 |
class EvoTransformer:
|
5 |
def __init__(self, config=None):
|
6 |
+
self.default_config = {
|
7 |
"layers": 4,
|
8 |
"attention_heads": 4,
|
9 |
"ffn_dim": 1024,
|
10 |
"dropout": 0.1,
|
11 |
"memory": False,
|
12 |
}
|
13 |
+
self.config = config or self.default_config.copy()
|
14 |
+
self.history = [self.config.copy()]
|
15 |
+
|
16 |
+
def reset(self):
|
17 |
+
self.config = self.default_config.copy()
|
18 |
self.history = [self.config.copy()]
|
19 |
|
20 |
def mutate(self):
|
|
|
47 |
return {"accuracy": score, "params": self.estimate_params()}
|
48 |
|
49 |
def estimate_params(self):
|
50 |
+
return round(10 + self.config["layers"] * self.config["ffn_dim"] * 1.0, 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|