HemanM commited on
Commit
69a8269
·
verified ·
1 Parent(s): 6e375cd

Update evo_transformer.py

Browse files
Files changed (1) hide show
  1. 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
- change = round(random.uniform(-0.05, 0.05), 2)
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
- # Simulated accuracy and parameter count
45
- accuracy = round(0.8 + random.uniform(0.01, 0.15), 4)
46
- return {
47
- "accuracy": accuracy,
48
- "params": self.estimate_params()
49
- }
50
 
51
  def estimate_params(self):
52
- # Lightweight param estimate formula (not real count)
53
- multiplier = 1.0 + (0.5 if self.config["memory"] else 0.0)
54
- return int(self.config["layers"] * self.config["ffn_dim"] * multiplier)
55
-
56
- def export_csv(self):
57
- import pandas as pd
58
- df = pd.DataFrame(self.history)
59
- return df.to_csv(index=False)
60
-
61
- def export_json(self):
62
- return json.dumps(self.history, indent=2)
 
 
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