Skip to content

Commit

Permalink
live.set_step: Remove make_checkpoint and make_report calls. (#338)
Browse files Browse the repository at this point in the history
Call `make_report` manually in the integrations.

Closes #231
Closes #103
  • Loading branch information
daavoo committed Nov 4, 2022
1 parent eee2118 commit f29d9ec
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/dvclive/catalyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ def on_epoch_end(self, runner) -> None:
scheduler=runner.scheduler,
)
utils.save_checkpoint(checkpoint, self.model_file)
self.dvclive.make_report()
self.dvclive.next_step()
1 change: 1 addition & 0 deletions src/dvclive/fastai.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ def after_epoch(self):

if self.model_file:
self.learn.save(self.model_file)
self.dvclive.make_report()
self.dvclive.next_step()
1 change: 1 addition & 0 deletions src/dvclive/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def on_log(
logs = kwargs["logs"]
for key, value in logs.items():
self.dvclive.log(standardize_metric_name(key, __name__), value)
self.dvclive.make_report()
self.dvclive.next_step()

def on_epoch_end(
Expand Down
1 change: 1 addition & 0 deletions src/dvclive/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ def on_epoch_end(
self.model.save_weights(self.model_file)
else:
self.model.save(self.model_file)
self.dvclive.make_report()
self.dvclive.next_step()
2 changes: 1 addition & 1 deletion src/dvclive/lgbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def __call__(self, env):

if self.model_file:
env.model.save_model(self.model_file)

self.dvclive.make_report()
self.dvclive.next_step()
1 change: 1 addition & 0 deletions src/dvclive/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ def log_metrics(self, metrics: Dict[str, Any], step: Optional[int] = None):
metric_val = metric_val.cpu().detach().item()
metric_name = standardize_metric_name(metric_name, __name__)
self.experiment.log(name=metric_name, val=metric_val)
self.experiment.make_report()
self.experiment.next_step()
4 changes: 0 additions & 4 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ def set_step(self, step: int) -> None:
)
else:
self._latest_studio_step = step
else:
self.make_report()

self.make_checkpoint()

self._step = step
logger.debug(f"Step: {self._step}")
Expand Down
1 change: 1 addition & 0 deletions src/dvclive/xgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def after_iteration(self, model, epoch, evals_log):
self.dvclive.log(key, latest_metric)
if self.model_file:
model.save_model(self.model_file)
self.dvclive.make_report()
self.dvclive.next_step()
15 changes: 0 additions & 15 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,6 @@ def test_get_step_control_flow(tmp_dir):
assert values == [float(x) for x in range(10)]


def test_make_checkpoint(tmp_dir, mocker, monkeypatch):
make_checkpoint = mocker.patch("dvclive.live.make_checkpoint")

dvclive = Live()
dvclive.log("foo", 1)
dvclive.next_step()
assert not make_checkpoint.called

monkeypatch.setenv(env.DVC_CHECKPOINT, True)
dvclive = Live()
dvclive.log("foo", 1)
dvclive.next_step()
assert make_checkpoint.called


def test_logger(tmp_dir, mocker, monkeypatch):
logger = mocker.patch("dvclive.live.logger")
monkeypatch.setenv(env.DVCLIVE_LOGLEVEL, "DEBUG")
Expand Down
12 changes: 7 additions & 5 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ def test_report_init(monkeypatch, mocker):


@pytest.mark.parametrize("mode", ["html", "md"])
def test_make_report(tmp_dir, mode, mocker):
def test_make_report(tmp_dir, mode):
last_report = ""
live = Live(report=mode)
for i in range(3):
live.log("foobar", i)
live.log("foo/bar", i)
live.make_report()
live.next_step()

# Format of the report is tested in `dvc-render`
assert (tmp_dir / live.report_path).exists()
assert (tmp_dir / live.dir / "static").exists() == (mode == "md")
assert (tmp_dir / live.report_path).exists()
current_report = (tmp_dir / live.report_path).read_text()
assert last_report != current_report
last_report = current_report


@pytest.mark.vscode
Expand Down

0 comments on commit f29d9ec

Please sign in to comment.