Update app.py
Browse files
app.py
CHANGED
|
@@ -1118,6 +1118,10 @@ Apache 2.0 (inherited from original model)
|
|
| 1118 |
# μ
λ‘λ μ κ²μ¦ ν¨μ (μ κ·!)
|
| 1119 |
# =====================================================
|
| 1120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1121 |
def verify_phoenix_model_before_upload(model_path: str) -> Tuple[bool, str, Dict]:
|
| 1122 |
"""
|
| 1123 |
Upload μ PHOENIX λͺ¨λΈ κ²μ¦
|
|
@@ -1128,13 +1132,33 @@ def verify_phoenix_model_before_upload(model_path: str) -> Tuple[bool, str, Dict
|
|
| 1128 |
print("\nπ§ͺ Pre-upload Verification...")
|
| 1129 |
|
| 1130 |
try:
|
| 1131 |
-
# 1. νμΌ μ‘΄μ¬ νμΈ
|
| 1132 |
model_path = Path(model_path)
|
| 1133 |
-
required_files = ['config.json', 'modeling_phoenix.py', 'pytorch_model.bin', 'README.md']
|
| 1134 |
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1138 |
|
| 1139 |
print(" β
All required files present")
|
| 1140 |
|
|
@@ -1251,6 +1275,7 @@ def verify_phoenix_model_before_upload(model_path: str) -> Tuple[bool, str, Dict
|
|
| 1251 |
'total_layers': total_layers,
|
| 1252 |
'retention_rate': retention_rate,
|
| 1253 |
'generation_quality': avg_score,
|
|
|
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
print("\nβ
Pre-upload verification PASSED!")
|
|
@@ -1264,137 +1289,7 @@ def verify_phoenix_model_before_upload(model_path: str) -> Tuple[bool, str, Dict
|
|
| 1264 |
|
| 1265 |
|
| 1266 |
# =====================================================
|
| 1267 |
-
#
|
| 1268 |
-
# =====================================================
|
| 1269 |
-
|
| 1270 |
-
class ExperimentDatabase:
|
| 1271 |
-
"""SQLite database with migration support"""
|
| 1272 |
-
|
| 1273 |
-
def __init__(self, db_path: str):
|
| 1274 |
-
self.db_path = db_path
|
| 1275 |
-
self.init_database()
|
| 1276 |
-
self.migrate_database()
|
| 1277 |
-
|
| 1278 |
-
def init_database(self):
|
| 1279 |
-
with sqlite3.connect(self.db_path) as conn:
|
| 1280 |
-
cursor = conn.cursor()
|
| 1281 |
-
cursor.execute("""
|
| 1282 |
-
CREATE TABLE IF NOT EXISTS experiments (
|
| 1283 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1284 |
-
model_type TEXT NOT NULL,
|
| 1285 |
-
sequence_length INTEGER,
|
| 1286 |
-
use_hierarchical BOOLEAN,
|
| 1287 |
-
attention_replaced BOOLEAN,
|
| 1288 |
-
layers_converted INTEGER,
|
| 1289 |
-
total_layers INTEGER,
|
| 1290 |
-
elapsed_time REAL,
|
| 1291 |
-
memory_mb REAL,
|
| 1292 |
-
throughput REAL,
|
| 1293 |
-
config_json TEXT,
|
| 1294 |
-
metrics_json TEXT,
|
| 1295 |
-
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
| 1296 |
-
)
|
| 1297 |
-
""")
|
| 1298 |
-
|
| 1299 |
-
cursor.execute("""
|
| 1300 |
-
CREATE TABLE IF NOT EXISTS burning_history (
|
| 1301 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1302 |
-
model_url TEXT NOT NULL,
|
| 1303 |
-
output_path TEXT NOT NULL,
|
| 1304 |
-
hub_url TEXT,
|
| 1305 |
-
use_hierarchical BOOLEAN,
|
| 1306 |
-
dataset_used BOOLEAN,
|
| 1307 |
-
conversion_rate REAL,
|
| 1308 |
-
training_steps INTEGER,
|
| 1309 |
-
final_loss REAL,
|
| 1310 |
-
evaluation_score REAL,
|
| 1311 |
-
verification_passed BOOLEAN,
|
| 1312 |
-
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
| 1313 |
-
)
|
| 1314 |
-
""")
|
| 1315 |
-
conn.commit()
|
| 1316 |
-
|
| 1317 |
-
def migrate_database(self):
|
| 1318 |
-
with sqlite3.connect(self.db_path) as conn:
|
| 1319 |
-
cursor = conn.cursor()
|
| 1320 |
-
cursor.execute("PRAGMA table_info(burning_history)")
|
| 1321 |
-
columns = [col[1] for col in cursor.fetchall()]
|
| 1322 |
-
|
| 1323 |
-
if 'hub_url' not in columns:
|
| 1324 |
-
print("π Migrating database: Adding hub_url column...")
|
| 1325 |
-
cursor.execute("ALTER TABLE burning_history ADD COLUMN hub_url TEXT")
|
| 1326 |
-
|
| 1327 |
-
if 'verification_passed' not in columns:
|
| 1328 |
-
print("π Migrating database: Adding verification_passed column...")
|
| 1329 |
-
cursor.execute("ALTER TABLE burning_history ADD COLUMN verification_passed BOOLEAN DEFAULT 0")
|
| 1330 |
-
|
| 1331 |
-
conn.commit()
|
| 1332 |
-
print("β
Database migration complete!")
|
| 1333 |
-
|
| 1334 |
-
def save_experiment(self, config: Dict, metrics: Dict) -> int:
|
| 1335 |
-
with sqlite3.connect(self.db_path) as conn:
|
| 1336 |
-
cursor = conn.cursor()
|
| 1337 |
-
cursor.execute("""
|
| 1338 |
-
INSERT INTO experiments (
|
| 1339 |
-
model_type, sequence_length, use_hierarchical,
|
| 1340 |
-
attention_replaced, layers_converted, total_layers,
|
| 1341 |
-
elapsed_time, memory_mb, throughput,
|
| 1342 |
-
config_json, metrics_json
|
| 1343 |
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 1344 |
-
""", (
|
| 1345 |
-
config.get('model_type'),
|
| 1346 |
-
config.get('sequence_length'),
|
| 1347 |
-
config.get('use_hierarchical'),
|
| 1348 |
-
config.get('attention_replaced'),
|
| 1349 |
-
config.get('layers_converted'),
|
| 1350 |
-
config.get('total_layers'),
|
| 1351 |
-
metrics.get('elapsed_time'),
|
| 1352 |
-
metrics.get('memory_mb'),
|
| 1353 |
-
metrics.get('throughput'),
|
| 1354 |
-
json.dumps(config),
|
| 1355 |
-
json.dumps(metrics)
|
| 1356 |
-
))
|
| 1357 |
-
conn.commit()
|
| 1358 |
-
return cursor.lastrowid
|
| 1359 |
-
|
| 1360 |
-
def save_burning(self, burning_info: Dict) -> int:
|
| 1361 |
-
with sqlite3.connect(self.db_path) as conn:
|
| 1362 |
-
cursor = conn.cursor()
|
| 1363 |
-
cursor.execute("""
|
| 1364 |
-
INSERT INTO burning_history (
|
| 1365 |
-
model_url, output_path, hub_url, use_hierarchical,
|
| 1366 |
-
dataset_used, conversion_rate, training_steps,
|
| 1367 |
-
final_loss, evaluation_score, verification_passed
|
| 1368 |
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 1369 |
-
""", (
|
| 1370 |
-
burning_info.get('model_url'),
|
| 1371 |
-
burning_info.get('output_path'),
|
| 1372 |
-
burning_info.get('hub_url'),
|
| 1373 |
-
burning_info.get('use_hierarchical'),
|
| 1374 |
-
burning_info.get('dataset_used'),
|
| 1375 |
-
burning_info.get('conversion_rate'),
|
| 1376 |
-
burning_info.get('training_steps', 0),
|
| 1377 |
-
burning_info.get('final_loss'),
|
| 1378 |
-
burning_info.get('evaluation_score'),
|
| 1379 |
-
burning_info.get('verification_passed', False),
|
| 1380 |
-
))
|
| 1381 |
-
conn.commit()
|
| 1382 |
-
return cursor.lastrowid
|
| 1383 |
-
|
| 1384 |
-
def get_burning_history(self, limit: int = 20) -> List[Dict]:
|
| 1385 |
-
with sqlite3.connect(self.db_path) as conn:
|
| 1386 |
-
conn.row_factory = sqlite3.Row
|
| 1387 |
-
cursor = conn.cursor()
|
| 1388 |
-
cursor.execute("SELECT * FROM burning_history ORDER BY timestamp DESC LIMIT ?", (limit,))
|
| 1389 |
-
return [dict(row) for row in cursor.fetchall()]
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
# =====================================================
|
| 1393 |
-
# HuggingFace Hub Upload (κ²μ¦ ν΅ν©!)
|
| 1394 |
-
# =====================================================
|
| 1395 |
-
|
| 1396 |
-
# =====================================================
|
| 1397 |
-
# HuggingFace Hub Upload (κ°μ !)
|
| 1398 |
# =====================================================
|
| 1399 |
|
| 1400 |
def upload_to_huggingface_hub(
|
|
@@ -1445,6 +1340,7 @@ def upload_to_huggingface_hub(
|
|
| 1445 |
print(f"β
Pre-upload verification PASSED!")
|
| 1446 |
print(f" Retention Rate: {metrics.get('retention_rate', 0)*100:.1f}%")
|
| 1447 |
print(f" Generation Quality: {metrics.get('generation_quality', 0):.2f}/1.00")
|
|
|
|
| 1448 |
else:
|
| 1449 |
print("\nβ οΈ Skipping pre-upload verification")
|
| 1450 |
|
|
@@ -1493,13 +1389,18 @@ def upload_to_huggingface_hub(
|
|
| 1493 |
print(f"\nπ€ Uploading files to HuggingFace Hub...")
|
| 1494 |
print(f" This may take a few minutes depending on model size...")
|
| 1495 |
|
| 1496 |
-
|
| 1497 |
-
|
| 1498 |
-
|
| 1499 |
-
|
| 1500 |
-
|
| 1501 |
-
|
| 1502 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1503 |
|
| 1504 |
print(f"β
All required files present")
|
| 1505 |
|
|
@@ -1539,6 +1440,135 @@ def upload_to_huggingface_hub(
|
|
| 1539 |
return False, "", f"β Upload failed: {str(e)}\n\nFull error:\n{error_msg}"
|
| 1540 |
|
| 1541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1542 |
# =====================================================
|
| 1543 |
# λͺ¨λΈ λ²λ UI ν¨μ (κ°μ !)
|
| 1544 |
# =====================================================
|
|
|
|
| 1118 |
# μ
λ‘λ μ κ²μ¦ ν¨μ (μ κ·!)
|
| 1119 |
# =====================================================
|
| 1120 |
|
| 1121 |
+
# =====================================================
|
| 1122 |
+
# μ
λ‘λ μ κ²μ¦ ν¨μ (μμ !)
|
| 1123 |
+
# =====================================================
|
| 1124 |
+
|
| 1125 |
def verify_phoenix_model_before_upload(model_path: str) -> Tuple[bool, str, Dict]:
|
| 1126 |
"""
|
| 1127 |
Upload μ PHOENIX λͺ¨λΈ κ²μ¦
|
|
|
|
| 1132 |
print("\nπ§ͺ Pre-upload Verification...")
|
| 1133 |
|
| 1134 |
try:
|
| 1135 |
+
# 1. νμΌ μ‘΄μ¬ νμΈ (safetensors OR pytorch_model.bin)
|
| 1136 |
model_path = Path(model_path)
|
|
|
|
| 1137 |
|
| 1138 |
+
# νμ νμΌ μ²΄ν¬ (λͺ¨λΈ κ°μ€μΉλ λ μ€ νλλ§ μμΌλ©΄ λ¨)
|
| 1139 |
+
config_exists = (model_path / 'config.json').exists()
|
| 1140 |
+
modeling_exists = (model_path / 'modeling_phoenix.py').exists()
|
| 1141 |
+
readme_exists = (model_path / 'README.md').exists()
|
| 1142 |
+
|
| 1143 |
+
# λͺ¨λΈ κ°μ€μΉ νμΌ νμΈ (safetensors μ°μ )
|
| 1144 |
+
safetensors_exists = (model_path / 'model.safetensors').exists()
|
| 1145 |
+
pytorch_bin_exists = (model_path / 'pytorch_model.bin').exists()
|
| 1146 |
+
model_weights_exist = safetensors_exists or pytorch_bin_exists
|
| 1147 |
+
|
| 1148 |
+
print(f" π File Check:")
|
| 1149 |
+
print(f" config.json: {'β
' if config_exists else 'β'}")
|
| 1150 |
+
print(f" modeling_phoenix.py: {'β
' if modeling_exists else 'β'}")
|
| 1151 |
+
print(f" README.md: {'β
' if readme_exists else 'β'}")
|
| 1152 |
+
print(f" model weights: {'β
(safetensors)' if safetensors_exists else 'β
(pytorch_model.bin)' if pytorch_bin_exists else 'β'}")
|
| 1153 |
+
|
| 1154 |
+
if not config_exists:
|
| 1155 |
+
return False, "β Missing file: config.json", {}
|
| 1156 |
+
if not modeling_exists:
|
| 1157 |
+
return False, "β Missing file: modeling_phoenix.py", {}
|
| 1158 |
+
if not readme_exists:
|
| 1159 |
+
return False, "β Missing file: README.md", {}
|
| 1160 |
+
if not model_weights_exist:
|
| 1161 |
+
return False, "β Missing model weights (need model.safetensors or pytorch_model.bin)", {}
|
| 1162 |
|
| 1163 |
print(" β
All required files present")
|
| 1164 |
|
|
|
|
| 1275 |
'total_layers': total_layers,
|
| 1276 |
'retention_rate': retention_rate,
|
| 1277 |
'generation_quality': avg_score,
|
| 1278 |
+
'model_format': 'safetensors' if safetensors_exists else 'pytorch_bin'
|
| 1279 |
}
|
| 1280 |
|
| 1281 |
print("\nβ
Pre-upload verification PASSED!")
|
|
|
|
| 1289 |
|
| 1290 |
|
| 1291 |
# =====================================================
|
| 1292 |
+
# HuggingFace Hub Upload (μμ !)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1293 |
# =====================================================
|
| 1294 |
|
| 1295 |
def upload_to_huggingface_hub(
|
|
|
|
| 1340 |
print(f"β
Pre-upload verification PASSED!")
|
| 1341 |
print(f" Retention Rate: {metrics.get('retention_rate', 0)*100:.1f}%")
|
| 1342 |
print(f" Generation Quality: {metrics.get('generation_quality', 0):.2f}/1.00")
|
| 1343 |
+
print(f" Model Format: {metrics.get('model_format', 'unknown')}")
|
| 1344 |
else:
|
| 1345 |
print("\nβ οΈ Skipping pre-upload verification")
|
| 1346 |
|
|
|
|
| 1389 |
print(f"\nπ€ Uploading files to HuggingFace Hub...")
|
| 1390 |
print(f" This may take a few minutes depending on model size...")
|
| 1391 |
|
| 1392 |
+
# νμ νμΌ μ²΄ν¬ (safetensors OR pytorch_model.bin)
|
| 1393 |
+
config_exists = (model_path / 'config.json').exists()
|
| 1394 |
+
modeling_exists = (model_path / 'modeling_phoenix.py').exists()
|
| 1395 |
+
safetensors_exists = (model_path / 'model.safetensors').exists()
|
| 1396 |
+
pytorch_bin_exists = (model_path / 'pytorch_model.bin').exists()
|
| 1397 |
+
|
| 1398 |
+
if not config_exists:
|
| 1399 |
+
return False, "", "β config.json not found"
|
| 1400 |
+
if not modeling_exists:
|
| 1401 |
+
return False, "", "β modeling_phoenix.py not found"
|
| 1402 |
+
if not (safetensors_exists or pytorch_bin_exists):
|
| 1403 |
+
return False, "", "β Model weights not found (need model.safetensors or pytorch_model.bin)"
|
| 1404 |
|
| 1405 |
print(f"β
All required files present")
|
| 1406 |
|
|
|
|
| 1440 |
return False, "", f"β Upload failed: {str(e)}\n\nFull error:\n{error_msg}"
|
| 1441 |
|
| 1442 |
|
| 1443 |
+
# =====================================================
|
| 1444 |
+
# λ°μ΄ν°λ² μ΄μ€
|
| 1445 |
+
# =====================================================
|
| 1446 |
+
|
| 1447 |
+
class ExperimentDatabase:
|
| 1448 |
+
"""SQLite database with migration support"""
|
| 1449 |
+
|
| 1450 |
+
def __init__(self, db_path: str):
|
| 1451 |
+
self.db_path = db_path
|
| 1452 |
+
self.init_database()
|
| 1453 |
+
self.migrate_database()
|
| 1454 |
+
|
| 1455 |
+
def init_database(self):
|
| 1456 |
+
with sqlite3.connect(self.db_path) as conn:
|
| 1457 |
+
cursor = conn.cursor()
|
| 1458 |
+
cursor.execute("""
|
| 1459 |
+
CREATE TABLE IF NOT EXISTS experiments (
|
| 1460 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1461 |
+
model_type TEXT NOT NULL,
|
| 1462 |
+
sequence_length INTEGER,
|
| 1463 |
+
use_hierarchical BOOLEAN,
|
| 1464 |
+
attention_replaced BOOLEAN,
|
| 1465 |
+
layers_converted INTEGER,
|
| 1466 |
+
total_layers INTEGER,
|
| 1467 |
+
elapsed_time REAL,
|
| 1468 |
+
memory_mb REAL,
|
| 1469 |
+
throughput REAL,
|
| 1470 |
+
config_json TEXT,
|
| 1471 |
+
metrics_json TEXT,
|
| 1472 |
+
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
| 1473 |
+
)
|
| 1474 |
+
""")
|
| 1475 |
+
|
| 1476 |
+
cursor.execute("""
|
| 1477 |
+
CREATE TABLE IF NOT EXISTS burning_history (
|
| 1478 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1479 |
+
model_url TEXT NOT NULL,
|
| 1480 |
+
output_path TEXT NOT NULL,
|
| 1481 |
+
hub_url TEXT,
|
| 1482 |
+
use_hierarchical BOOLEAN,
|
| 1483 |
+
dataset_used BOOLEAN,
|
| 1484 |
+
conversion_rate REAL,
|
| 1485 |
+
training_steps INTEGER,
|
| 1486 |
+
final_loss REAL,
|
| 1487 |
+
evaluation_score REAL,
|
| 1488 |
+
verification_passed BOOLEAN,
|
| 1489 |
+
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
| 1490 |
+
)
|
| 1491 |
+
""")
|
| 1492 |
+
conn.commit()
|
| 1493 |
+
|
| 1494 |
+
def migrate_database(self):
|
| 1495 |
+
with sqlite3.connect(self.db_path) as conn:
|
| 1496 |
+
cursor = conn.cursor()
|
| 1497 |
+
cursor.execute("PRAGMA table_info(burning_history)")
|
| 1498 |
+
columns = [col[1] for col in cursor.fetchall()]
|
| 1499 |
+
|
| 1500 |
+
if 'hub_url' not in columns:
|
| 1501 |
+
print("π Migrating database: Adding hub_url column...")
|
| 1502 |
+
cursor.execute("ALTER TABLE burning_history ADD COLUMN hub_url TEXT")
|
| 1503 |
+
|
| 1504 |
+
if 'verification_passed' not in columns:
|
| 1505 |
+
print("π Migrating database: Adding verification_passed column...")
|
| 1506 |
+
cursor.execute("ALTER TABLE burning_history ADD COLUMN verification_passed BOOLEAN DEFAULT 0")
|
| 1507 |
+
|
| 1508 |
+
conn.commit()
|
| 1509 |
+
print("β
Database migration complete!")
|
| 1510 |
+
|
| 1511 |
+
def save_experiment(self, config: Dict, metrics: Dict) -> int:
|
| 1512 |
+
with sqlite3.connect(self.db_path) as conn:
|
| 1513 |
+
cursor = conn.cursor()
|
| 1514 |
+
cursor.execute("""
|
| 1515 |
+
INSERT INTO experiments (
|
| 1516 |
+
model_type, sequence_length, use_hierarchical,
|
| 1517 |
+
attention_replaced, layers_converted, total_layers,
|
| 1518 |
+
elapsed_time, memory_mb, throughput,
|
| 1519 |
+
config_json, metrics_json
|
| 1520 |
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 1521 |
+
""", (
|
| 1522 |
+
config.get('model_type'),
|
| 1523 |
+
config.get('sequence_length'),
|
| 1524 |
+
config.get('use_hierarchical'),
|
| 1525 |
+
config.get('attention_replaced'),
|
| 1526 |
+
config.get('layers_converted'),
|
| 1527 |
+
config.get('total_layers'),
|
| 1528 |
+
metrics.get('elapsed_time'),
|
| 1529 |
+
metrics.get('memory_mb'),
|
| 1530 |
+
metrics.get('throughput'),
|
| 1531 |
+
json.dumps(config),
|
| 1532 |
+
json.dumps(metrics)
|
| 1533 |
+
))
|
| 1534 |
+
conn.commit()
|
| 1535 |
+
return cursor.lastrowid
|
| 1536 |
+
|
| 1537 |
+
def save_burning(self, burning_info: Dict) -> int:
|
| 1538 |
+
with sqlite3.connect(self.db_path) as conn:
|
| 1539 |
+
cursor = conn.cursor()
|
| 1540 |
+
cursor.execute("""
|
| 1541 |
+
INSERT INTO burning_history (
|
| 1542 |
+
model_url, output_path, hub_url, use_hierarchical,
|
| 1543 |
+
dataset_used, conversion_rate, training_steps,
|
| 1544 |
+
final_loss, evaluation_score, verification_passed
|
| 1545 |
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 1546 |
+
""", (
|
| 1547 |
+
burning_info.get('model_url'),
|
| 1548 |
+
burning_info.get('output_path'),
|
| 1549 |
+
burning_info.get('hub_url'),
|
| 1550 |
+
burning_info.get('use_hierarchical'),
|
| 1551 |
+
burning_info.get('dataset_used'),
|
| 1552 |
+
burning_info.get('conversion_rate'),
|
| 1553 |
+
burning_info.get('training_steps', 0),
|
| 1554 |
+
burning_info.get('final_loss'),
|
| 1555 |
+
burning_info.get('evaluation_score'),
|
| 1556 |
+
burning_info.get('verification_passed', False),
|
| 1557 |
+
))
|
| 1558 |
+
conn.commit()
|
| 1559 |
+
return cursor.lastrowid
|
| 1560 |
+
|
| 1561 |
+
def get_burning_history(self, limit: int = 20) -> List[Dict]:
|
| 1562 |
+
with sqlite3.connect(self.db_path) as conn:
|
| 1563 |
+
conn.row_factory = sqlite3.Row
|
| 1564 |
+
cursor = conn.cursor()
|
| 1565 |
+
cursor.execute("SELECT * FROM burning_history ORDER BY timestamp DESC LIMIT ?", (limit,))
|
| 1566 |
+
return [dict(row) for row in cursor.fetchall()]
|
| 1567 |
+
|
| 1568 |
+
|
| 1569 |
+
|
| 1570 |
+
|
| 1571 |
+
|
| 1572 |
# =====================================================
|
| 1573 |
# λͺ¨λΈ λ²λ UI ν¨μ (κ°μ !)
|
| 1574 |
# =====================================================
|