Skip to content

Commit

Permalink
feat: MLflow logging (#91)
Browse files Browse the repository at this point in the history
* feat: add poetry packages

#82

* feat: MLflow logging

#82

* feat: ignore model's by-product

#82

* fix: code bugs

#82

* feat: poetry add glances

#82
  • Loading branch information
2018007956 authored Mar 13, 2024
1 parent c47e7c4 commit 5f8fe28
Show file tree
Hide file tree
Showing 6 changed files with 2,403 additions and 128 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,7 @@ cython_debug/
# model
model/saved

# MLflow
mlruns

frontend/node_modules/
4 changes: 4 additions & 0 deletions model/MLProject
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: model_training
entry_points:
main:
command: "python train.py -c config.json"
21 changes: 20 additions & 1 deletion model/base/base_trainer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
from abc import abstractmethod
from numpy import inf

import mlflow

class BaseTrainer:
"""
Expand Down Expand Up @@ -53,6 +53,17 @@ def train(self):
"""
Full training logic
"""
# MLflow - parameters logging
params = {"window_size":self.config['data_loader']['args']['window_size'],
"target_day":self.config['data_loader']['args']['target_day'],
"transform_type":self.config['data_loader']['args']['transform_type'],
"batch_size":self.config['data_loader']['args']['batch_size'],
"epoch":self.config['trainer']['epochs'],
"optimizer":self.config['optimizer']['type'],
"lr":self.config['optimizer']['args']['lr'],
"scheduler":self.config['lr_scheduler']['type']}
mlflow.log_params(params)

not_improved_count = 0
for epoch in range(self.start_epoch, self.epochs + 1):
result = self._train_epoch(epoch)
Expand All @@ -61,6 +72,14 @@ def train(self):
log = {'epoch': epoch}
log.update(result)

# MLflow - metrics logging
mlflow.log_metric("loss", result['loss'])
mlflow.log_metric("accuracy", result['accuracy'])
mlflow.log_metric("top_k_acc", result['top_k_acc'])
mlflow.log_metric("val_loss", result['val_loss'])
mlflow.log_metric("val_accuracy", result['val_accuracy'])
mlflow.log_metric("val_top_k_acc", result['val_top_k_acc'])

# print logged informations to the screen
for key, value in log.items():
self.logger.info(' {:15s}: {}'.format(str(key), value))
Expand Down
Loading

0 comments on commit 5f8fe28

Please sign in to comment.