HemanM commited on
Commit
4b64e0a
·
verified ·
1 Parent(s): a499eab

Update evo_architecture.py

Browse files
Files changed (1) hide show
  1. evo_architecture.py +12 -10
evo_architecture.py CHANGED
@@ -1,10 +1,10 @@
1
- # evo_architecture.py
2
-
3
  import random
4
  import json
5
  import os
6
  import uuid
7
  import csv
 
 
8
 
9
  GENOME_LOG = "genome_log.csv"
10
  BEST_GENOME_FILE = "best_genome.json"
@@ -26,13 +26,9 @@ def default_config():
26
  }
27
 
28
  def mutate_genome(base_config, exploration_rate=0.5):
29
- """Mutates the genome. Exploration rate controls how wild the mutation is (0 = minor, 1 = wild)."""
30
  config = base_config.copy()
31
  config["genome_id"] = str(uuid.uuid4())
32
-
33
- # Select mutation type
34
  mutation_type = random.choice(["num_layers", "ffn_dim", "num_heads", "memory_enabled"])
35
-
36
  if mutation_type == "memory_enabled":
37
  config["memory_enabled"] = not config["memory_enabled"]
38
  else:
@@ -40,11 +36,9 @@ def mutate_genome(base_config, exploration_rate=0.5):
40
  change = int((max_val - min_val) * exploration_rate)
41
  delta = random.randint(-change, change)
42
  config[mutation_type] = max(min_val, min(max_val, config[mutation_type] + delta))
43
-
44
  return config
45
 
46
  def log_genome(config, score=None):
47
- """Logs genome config + performance to CSV."""
48
  row = [
49
  config.get("genome_id", ""),
50
  config["num_layers"],
@@ -61,13 +55,21 @@ def log_genome(config, score=None):
61
  writer.writerow(row)
62
 
63
  def save_best_genome(config):
64
- """Saves the best-performing genome to file."""
65
  with open(BEST_GENOME_FILE, "w", encoding="utf-8") as f:
66
  json.dump(config, f)
67
 
68
  def load_best_genome():
69
- """Loads best-performing genome (if exists), else default."""
70
  if os.path.exists(BEST_GENOME_FILE):
71
  with open(BEST_GENOME_FILE, "r", encoding="utf-8") as f:
72
  return json.load(f)
73
  return default_config()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import random
2
  import json
3
  import os
4
  import uuid
5
  import csv
6
+ import torch
7
+ import torch.nn as nn
8
 
9
  GENOME_LOG = "genome_log.csv"
10
  BEST_GENOME_FILE = "best_genome.json"
 
26
  }
27
 
28
  def mutate_genome(base_config, exploration_rate=0.5):
 
29
  config = base_config.copy()
30
  config["genome_id"] = str(uuid.uuid4())
 
 
31
  mutation_type = random.choice(["num_layers", "ffn_dim", "num_heads", "memory_enabled"])
 
32
  if mutation_type == "memory_enabled":
33
  config["memory_enabled"] = not config["memory_enabled"]
34
  else:
 
36
  change = int((max_val - min_val) * exploration_rate)
37
  delta = random.randint(-change, change)
38
  config[mutation_type] = max(min_val, min(max_val, config[mutation_type] + delta))
 
39
  return config
40
 
41
  def log_genome(config, score=None):
 
42
  row = [
43
  config.get("genome_id", ""),
44
  config["num_layers"],
 
55
  writer.writerow(row)
56
 
57
  def save_best_genome(config):
 
58
  with open(BEST_GENOME_FILE, "w", encoding="utf-8") as f:
59
  json.dump(config, f)
60
 
61
  def load_best_genome():
 
62
  if os.path.exists(BEST_GENOME_FILE):
63
  with open(BEST_GENOME_FILE, "r", encoding="utf-8") as f:
64
  return json.load(f)
65
  return default_config()
66
+
67
+ # ✅ FIXED: This now exists and solves your import error
68
+ def build_model_from_config(config):
69
+ from evo_model import EvoTransformerV22
70
+ return EvoTransformerV22(
71
+ num_layers=config["num_layers"],
72
+ ffn_dim=config["ffn_dim"],
73
+ num_heads=config["num_heads"],
74
+ memory_enabled=config["memory_enabled"]
75
+ )