Upload stop_overfit_monitor.py
Browse files- stop_overfit_monitor.py +75 -0
stop_overfit_monitor.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ==============================================================================
|
| 2 |
+
# COPYRIGHT (C) 2025 KONSTANTIN VLADIMIROVICH GRABKO. ALL RIGHTS RESERVED.
|
| 3 |
+
# PATENT PENDING | CMS MANHATTAN JIRACK TECHNOLOGY
|
| 4 |
+
#
|
| 5 |
+
# This software is licensed under the Commercial License Agreement V.1.2.
|
| 6 |
+
# Any use, modification, or distribution of this code requires compliance with
|
| 7 |
+
# the terms found in the LICENSE.md file in the root directory.
|
| 8 |
+
#
|
| 9 |
+
# NO PATENTING RIGHTS: Users are strictly prohibited from filing patent claims
|
| 10 |
+
# based on the BRE or SWA architectures disclosed herein.
|
| 11 |
+
# Contact: grabko@cmsmanhattan.com | +1 (516) 777-0945
|
| 12 |
+
# ==============================================================================
|
| 13 |
+
|
| 14 |
+
# Overfitting & Drift Monitor for Ternary Models
|
| 15 |
+
|
| 16 |
+
import json
|
| 17 |
+
import os
|
| 18 |
+
import time
|
| 19 |
+
import matplotlib.pyplot as plt
|
| 20 |
+
|
| 21 |
+
LOG_FILE = "val_metrics_cms.json"
|
| 22 |
+
STOP_LOSS_THRESHOLD = 0.5 # Если разрыв между Pile и Cultural лоссом больше этого значения
|
| 23 |
+
|
| 24 |
+
def analyze_progress():
|
| 25 |
+
if not os.path.exists(LOG_FILE):
|
| 26 |
+
print(">>> Waiting for log file...")
|
| 27 |
+
return
|
| 28 |
+
|
| 29 |
+
with open(LOG_FILE, 'r') as f:
|
| 30 |
+
data = json.load(f)
|
| 31 |
+
|
| 32 |
+
if len(data) < 2:
|
| 33 |
+
return
|
| 34 |
+
|
| 35 |
+
steps = [int(d['step']) for d in data]
|
| 36 |
+
p_loss = [d['pile_loss'] for d in data]
|
| 37 |
+
c_loss = [d['cultural_loss'] for d in data]
|
| 38 |
+
|
| 39 |
+
# Расчет разрыва (Gap)
|
| 40 |
+
gap = p_loss[-1] - c_loss[-1]
|
| 41 |
+
|
| 42 |
+
print(f"\n--- CMS Status Check (Step {steps[-1]}) ---")
|
| 43 |
+
print(f"Pile Loss: {p_loss[-1]:.4f}")
|
| 44 |
+
print(f"Cultural Loss: {c_loss[-1]:.4f}")
|
| 45 |
+
print(f"Current Gap: {gap:.4f}")
|
| 46 |
+
|
| 47 |
+
# Логика предупреждений
|
| 48 |
+
if gap > STOP_LOSS_THRESHOLD:
|
| 49 |
+
print("⚠️ WARNING: Overfitting detected! Model is focusing too much on Cultural Code.")
|
| 50 |
+
print(">>> Recommendation: Reduce MIX_RATIO or stop training soon.")
|
| 51 |
+
elif gap < 0:
|
| 52 |
+
print("ℹ️ INFO: Model is still learning basic language better than your specific data.")
|
| 53 |
+
print(">>> Recommendation: Increase MIX_RATIO for faster adaptation.")
|
| 54 |
+
else:
|
| 55 |
+
print("✅ STATUS: Healthy training. General and specific knowledge are balancing.")
|
| 56 |
+
|
| 57 |
+
# Генерация графика
|
| 58 |
+
plt.figure(figsize=(10, 5))
|
| 59 |
+
plt.plot(steps, p_loss, label='General Knowledge (Pile)', color='blue', marker='o')
|
| 60 |
+
plt.plot(steps, c_loss, label='Cultural Code (Client)', color='green', marker='s')
|
| 61 |
+
plt.axhline(y=min(c_loss), color='r', linestyle='--', alpha=0.3)
|
| 62 |
+
plt.xlabel('Training Steps')
|
| 63 |
+
plt.ylabel('Loss')
|
| 64 |
+
plt.title('CMS Manhattan: Training Convergence')
|
| 65 |
+
plt.legend()
|
| 66 |
+
plt.grid(True)
|
| 67 |
+
plt.savefig('training_progress.png')
|
| 68 |
+
plt.close()
|
| 69 |
+
print(">>> Progress chart updated: training_progress.png")
|
| 70 |
+
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
print(">>> CMS Overfit Monitor active.")
|
| 73 |
+
while True:
|
| 74 |
+
analyze_progress()
|
| 75 |
+
time.sleep(300) # Проверка каждые 5 минут
|