-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackfill_forks.py
More file actions
49 lines (41 loc) · 1.71 KB
/
Copy pathbackfill_forks.py
File metadata and controls
49 lines (41 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import os
# Add BE to path
sys.path.append(os.path.join(os.path.dirname(__file__), 'BE'))
from database import SessionLocal
from models import TrainingRun, ModelFork
def backfill():
db = SessionLocal()
try:
runs = db.query(TrainingRun).filter(TrainingRun.model_fork_id == None).all()
print(f"Found {len(runs)} runs without a fork.")
for run in runs:
base_model_name = run.base_model_name or "Legacy / Unknown"
fork_name = f"Default {base_model_name} Fork"
# Find or create fork
fork = db.query(ModelFork).filter_by(base_model_name=base_model_name, fork_name=fork_name).first()
if not fork:
fork = ModelFork(
base_model_name=base_model_name,
fork_name=fork_name,
description="Auto-generated default fork for legacy runs",
active_model_path=run.best_model_path # use the latest run's model path for the fork if newly created
)
db.add(fork)
db.commit()
db.refresh(fork)
print(f"Created fork: {fork_name}")
else:
# Update active model path if this run is newer (assuming chronological processing)
fork.active_model_path = run.best_model_path
db.commit()
run.model_fork_id = fork.id
run.selected_fork_name = fork.fork_name
db.commit()
print(f"Mapped run {run.id} to fork {fork.id}")
except Exception as e:
print(f"Error: {e}")
finally:
db.close()
if __name__ == "__main__":
backfill()