Skip to content

Commit 84cf93f

Browse files
Enhance dynamic configuration updates to include dependent variable adjustments
Bug where dynamic values did not update fixed this way
1 parent b857105 commit 84cf93f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

vulnscan/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def update(self, updates):
7575
"""
7676
Update any configuration variable dynamically.
7777
Accepts a dict or a list of (key, value) pairs.
78+
Also updates dependent variables if their base values change.
7879
Example:
7980
cfg.update({'BATCH_SIZE': 32, 'LR': 5e-4})
8081
cfg.update([('BATCH_SIZE', 32), ('LR', 5e-4)])
@@ -90,3 +91,12 @@ def update(self, updates):
9091
setattr(self, key, value)
9192
else:
9293
raise AttributeError(f"TrainingConfig has no attribute '{key}'")
94+
# Update dependent variables if their base values changed
95+
if 'MODEL_NAME' in dict(items) or 'CACHE_DIR' in dict(items) or 'MODEL_ROUND' in dict(items):
96+
self.LOG_FILE = f"{self.CACHE_DIR}/{self.MODEL_NAME}/training.log"
97+
self.EMBED_CACHE_DIR = f"{self.CACHE_DIR}/{self.MODEL_NAME}/round_{self.MODEL_ROUND}/embeddings"
98+
self.writer = SummaryWriter(log_dir=f"{self.CACHE_DIR}/{self.MODEL_NAME}/round_{self.MODEL_ROUND}/tensorboard_logs")
99+
os.makedirs(self.EMBED_CACHE_DIR, exist_ok=True)
100+
if 'CACHE_DIR' in dict(items):
101+
self.DATA_CACHE_DIR = f"{self.CACHE_DIR}/dataset"
102+
os.makedirs(self.DATA_CACHE_DIR, exist_ok=True)

0 commit comments

Comments
 (0)