HemanM commited on
Commit
87324d5
Β·
verified Β·
1 Parent(s): fd0302f

Update watchdog.py

Browse files
Files changed (1) hide show
  1. watchdog.py +20 -11
watchdog.py CHANGED
@@ -50,10 +50,10 @@ def fetch_training_data(tokenizer):
50
 
51
  def get_architecture_summary(model):
52
  summary = {
53
- "Layers": getattr(model, "num_layers", "N/A"),
54
- "Attention Heads": getattr(model, "num_heads", "N/A"),
55
- "FFN Dim": getattr(model, "ffn_dim", "N/A"),
56
- "Memory Enabled": getattr(model, "use_memory", "N/A"),
57
  }
58
  return "\n".join(f"{k}: {v}" for k, v in summary.items())
59
 
@@ -65,7 +65,16 @@ def retrain_model():
65
  if input_ids is None or len(input_ids) < 2:
66
  return "⚠️ Not enough data to retrain.", None, "Please log more feedback first."
67
 
68
- config = EvoTransformerConfig()
 
 
 
 
 
 
 
 
 
69
  model = EvoTransformerForClassification(config)
70
  model.train()
71
 
@@ -80,10 +89,10 @@ def retrain_model():
80
  optimizer.step()
81
  print(f"Epoch {epoch+1}: Loss = {loss.item():.4f}")
82
 
83
- # Simulate accuracy (replace this with actual eval in the future)
84
- accuracy = 1.0 # Replace with real evaluation later
85
 
86
- # Save accuracy to evolution log
87
  log_path = "trained_model/evolution_log.json"
88
  os.makedirs("trained_model", exist_ok=True)
89
 
@@ -98,11 +107,11 @@ def retrain_model():
98
  with open(log_path, "w") as f:
99
  json.dump(history, f)
100
 
101
- # Save trained model
102
  model.save_pretrained("trained_model")
103
  print("βœ… EvoTransformer retrained and saved.")
104
 
105
- # Reload the updated model for summary + plot
106
  updated_model = load_model()
107
  arch_text = get_architecture_summary(updated_model)
108
  plot = evolution_accuracy_plot()
@@ -113,6 +122,6 @@ def retrain_model():
113
  print(f"❌ Retraining failed: {e}")
114
  return "❌ Error", None, f"Retrain failed: {e}"
115
 
116
- # Support direct script run
117
  if __name__ == "__main__":
118
  retrain_model()
 
50
 
51
  def get_architecture_summary(model):
52
  summary = {
53
+ "Layers": getattr(model.config, "num_layers", "N/A"),
54
+ "Attention Heads": getattr(model.config, "num_heads", "N/A"),
55
+ "FFN Dim": getattr(model.config, "ffn_dim", "N/A"),
56
+ "Memory Enabled": getattr(model.config, "use_memory", "N/A"),
57
  }
58
  return "\n".join(f"{k}: {v}" for k, v in summary.items())
59
 
 
65
  if input_ids is None or len(input_ids) < 2:
66
  return "⚠️ Not enough data to retrain.", None, "Please log more feedback first."
67
 
68
+ # βœ… Explicitly define architecture details
69
+ config = EvoTransformerConfig(
70
+ hidden_size=384,
71
+ num_layers=6,
72
+ num_labels=2,
73
+ num_heads=6,
74
+ ffn_dim=1024,
75
+ use_memory=False
76
+ )
77
+
78
  model = EvoTransformerForClassification(config)
79
  model.train()
80
 
 
89
  optimizer.step()
90
  print(f"Epoch {epoch+1}: Loss = {loss.item():.4f}")
91
 
92
+ # Simulate accuracy (placeholder)
93
+ accuracy = 1.0
94
 
95
+ # Log evolution accuracy
96
  log_path = "trained_model/evolution_log.json"
97
  os.makedirs("trained_model", exist_ok=True)
98
 
 
107
  with open(log_path, "w") as f:
108
  json.dump(history, f)
109
 
110
+ # Save model
111
  model.save_pretrained("trained_model")
112
  print("βœ… EvoTransformer retrained and saved.")
113
 
114
+ # Reload and return dashboard updates
115
  updated_model = load_model()
116
  arch_text = get_architecture_summary(updated_model)
117
  plot = evolution_accuracy_plot()
 
122
  print(f"❌ Retraining failed: {e}")
123
  return "❌ Error", None, f"Retrain failed: {e}"
124
 
125
+ # Allow direct script run
126
  if __name__ == "__main__":
127
  retrain_model()