Skip to content

Commit

Permalink
Studio dvcyaml (#709)
Browse files Browse the repository at this point in the history
* drop dvc.yaml prefix from studio plots

* refactor

* drop .dvc files

* dvc version bump
  • Loading branch information
Dave Berenbaum authored Sep 14, 2023
1 parent a539c8e commit f6001f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,6 @@ dmypy.json
# Cython debug symbols
cython_debug/

.dvc/
.dvcignore
src/dvclive/_dvclive_version.py
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"dvc>=3.17.0",
"dvc>=3.20.0",
"dvc-render>=0.5.0,<1.0",
"dvc-studio-client>=0.15.0,<1",
"funcy",
Expand Down
19 changes: 5 additions & 14 deletions src/dvclive/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ def _cast_to_numbers(datapoints):
return datapoints


def _adapt_plot_name(live, name):
def _adapt_path(live, name):
if live._dvc_repo is not None:
name = rel_path(name, live._dvc_repo.root_dir)
if os.path.isfile(live.dvc_file):
dvc_file = live.dvc_file
if live._dvc_repo is not None:
dvc_file = rel_path(live.dvc_file, live._dvc_repo.root_dir)
name = f"{dvc_file}::{name}"
return name


Expand All @@ -56,9 +51,7 @@ def _adapt_image(image_path):

def _adapt_images(live):
return {
_adapt_plot_name(live, image.output_path): {
"image": _adapt_image(image.output_path)
}
_adapt_path(live, image.output_path): {"image": _adapt_image(image.output_path)}
for image in live._images.values()
if image.step > live._latest_studio_step
}
Expand All @@ -67,21 +60,19 @@ def _adapt_images(live):
def get_studio_updates(live):
if os.path.isfile(live.params_file):
params_file = live.params_file
if live._dvc_repo is not None:
params_file = rel_path(params_file, live._dvc_repo.root_dir)
params_file = _adapt_path(live, params_file)
params = {params_file: load_yaml(live.params_file)}
else:
params = {}

plots, metrics = parse_metrics(live)

metrics_file = live.metrics_file
if live._dvc_repo is not None:
metrics_file = rel_path(metrics_file, live._dvc_repo.root_dir)
metrics_file = _adapt_path(live, metrics_file)
metrics = {metrics_file: {"data": metrics}}

plots = {
_adapt_plot_name(live, name): _adapt_plot_datapoints(live, plot)
_adapt_path(live, name): _adapt_plot_datapoints(live, plot)
for name, plot in plots.items()
}
plots = {k: {"data": v} for k, v in plots.items()}
Expand Down
24 changes: 7 additions & 17 deletions tests/test_post_to_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post):
live = Live()
live.log_param("fooparam", 1)

dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix()
foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix()

mocked_post, _ = mocked_studio_post
Expand All @@ -54,7 +53,7 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post):
"data",
exp_name=live._exp_name,
step=0,
plots={f"{dvc_path}::{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}},
plots={f"{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}},
),
)

Expand All @@ -67,7 +66,7 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post):
"data",
exp_name=live._exp_name,
step=1,
plots={f"{dvc_path}::{foo_path}": {"data": [{"step": 1, "foo": 2.0}]}},
plots={f"{foo_path}": {"data": [{"step": 1, "foo": 2.0}]}},
),
)

Expand All @@ -89,7 +88,6 @@ def test_post_to_studio_failed_data_request(

live = Live()

dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix()
foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix()

error_response = mocker.MagicMock()
Expand All @@ -108,7 +106,7 @@ def test_post_to_studio_failed_data_request(
exp_name=live._exp_name,
step=1,
plots={
f"{dvc_path}::{foo_path}": {
f"{foo_path}": {
"data": [{"step": 0, "foo": 1.0}, {"step": 1, "foo": 2.0}]
}
},
Expand Down Expand Up @@ -207,7 +205,6 @@ def test_post_to_studio_shorten_names(tmp_dir, mocked_dvc_repo, mocked_studio_po
live.log_metric("eval/loss", 1)
live.next_step()

dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix()
plots_path = Path(live.plots_dir)
loss_path = (plots_path / Metric.subfolder / "eval/loss.tsv").as_posix()

Expand All @@ -217,7 +214,7 @@ def test_post_to_studio_shorten_names(tmp_dir, mocked_dvc_repo, mocked_studio_po
"data",
exp_name=live._exp_name,
step=0,
plots={f"{dvc_path}::{loss_path}": {"data": [{"step": 0, "loss": 1.0}]}},
plots={f"{loss_path}": {"data": [{"step": 0, "loss": 1.0}]}},
),
)

Expand Down Expand Up @@ -252,7 +249,6 @@ def test_post_to_studio_inside_subdir(
live.log_metric("foo", 1)
live.next_step()

dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix()
foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix()

mocked_post.assert_called_with(
Expand All @@ -262,9 +258,7 @@ def test_post_to_studio_inside_subdir(
baseline_sha=live._baseline_rev,
exp_name=live._exp_name,
step=0,
plots={
f"{dvc_path}::subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}
},
plots={f"subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}},
),
)

Expand All @@ -285,7 +279,6 @@ def test_post_to_studio_inside_subdir_dvc_exp(
live.log_metric("foo", 1)
live.next_step()

dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix()
foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix()

mocked_post.assert_called_with(
Expand All @@ -295,9 +288,7 @@ def test_post_to_studio_inside_subdir_dvc_exp(
baseline_sha=live._baseline_rev,
exp_name=live._exp_name,
step=0,
plots={
f"{dvc_path}::subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}
},
plots={f"subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}},
),
)

Expand Down Expand Up @@ -342,7 +333,6 @@ def test_post_to_studio_images(tmp_dir, mocked_dvc_repo, mocked_studio_post):
live.log_image("foo.png", ImagePIL.new("RGB", (10, 10), (0, 0, 0)))
live.next_step()

dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix()
foo_path = (Path(live.plots_dir) / Image.subfolder / "foo.png").as_posix()

mocked_post.assert_called_with(
Expand All @@ -352,7 +342,7 @@ def test_post_to_studio_images(tmp_dir, mocked_dvc_repo, mocked_studio_post):
baseline_sha=live._baseline_rev,
exp_name=live._exp_name,
step=0,
plots={f"{dvc_path}::{foo_path}": {"image": _adapt_image(foo_path)}},
plots={f"{foo_path}": {"image": _adapt_image(foo_path)}},
),
)

Expand Down

0 comments on commit f6001f4

Please sign in to comment.