Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/dvclive/fastai.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,30 @@ def __init__(
model_file: Optional[str] = None,
with_opt: bool = False,
live: Optional[Live] = None,
**kwargs
**kwargs,
):
super().__init__()
self.model_file = model_file
self.with_opt = with_opt
self.live = live if live is not None else Live(**kwargs)
self.freeze_stage_ended = False

def before_fit(self):
if hasattr(self, "lr_finder") or hasattr(self, "gather_preds"):
return
params = {
"model": type(self.learn.model).__qualname__,
"batch_size": getattr(self.dls, "bs", None),
"batch_per_epoch": len(getattr(self.dls, "train", [])),
"frozen": bool(getattr(self.opt, "frozen_idx", -1)),
"frozen_idx": getattr(self.opt, "frozen_idx", -1),
"transforms": f"{getattr(self.dls, 'tfms', None)}",
Comment on lines +45 to +50
Copy link
Contributor Author

@daavoo daavoo Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex000kim Asked for your review since I know you use fastai.

Do you think these params are relevant enough for being "autologged"? Some missing?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add n_epoch and base_lr.
In general, you can log optimizer's hyperparams as done in wandb and comet integrations:

}
self.live.log_params(params)

def after_epoch(self):
if hasattr(self, "lr_finder") or hasattr(self, "gather_preds"):
return
logged_metrics = False
for key, value in zip(
self.learn.recorder.metric_names, self.learn.recorder.log
Expand Down
7 changes: 6 additions & 1 deletion tests/test_frameworks/test_fastai.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ def test_fastai_callback(tmp_dir, data_loader, mocker):
learn.fit_one_cycle(2, cbs=[callback])
spy.assert_called_once()

assert os.path.exists(live.dir)
assert (tmp_dir / live.dir).exists()
assert (tmp_dir / live.params_file).exists()
assert (tmp_dir / live.params_file).read_text() == (
"model: TabularModel\nbatch_size: 2\nbatch_per_epoch: 2\nfrozen: false"
"\nfrozen_idx: 0\ntransforms: None\n"
)

metrics_path = tmp_dir / live.plots_dir / Metric.subfolder
train_path = metrics_path / "train"
Expand Down