From 0d572b1c70a8d97755d0b7f934e5743f54b53d99 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:30:21 +0000 Subject: [PATCH 1/4] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.9 → v0.3.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.9...v0.3.4) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0) - [github.com/kynan/nbstripout: 0.6.1 → 0.7.1](https://github.com/kynan/nbstripout/compare/0.6.1...0.7.1) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8efbd96..8a0b571 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,14 +7,14 @@ default_install_hook_types: [pre-commit, commit-msg] repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.3.4 hooks: - id: ruff args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 + rev: v1.9.0 hooks: - id: mypy @@ -39,7 +39,7 @@ repos: args: [--check-filenames] - repo: https://github.com/kynan/nbstripout - rev: 0.6.1 + rev: 0.7.1 hooks: - id: nbstripout args: [--drop-empty-cells, --keep-output] From 2cfdf408842d02a2c180ecb5300fbcfda853d4a0 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 1 Apr 2024 20:24:06 +0200 Subject: [PATCH 2/4] migrate ruff config --- paper/references.bib | 8 ++++---- pyproject.toml | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/paper/references.bib b/paper/references.bib index 722a886..87705fb 100644 --- a/paper/references.bib +++ b/paper/references.bib @@ -11,7 +11,7 @@ @online{biewald_weights_2020 date = {2020}, url = {https://docs.wandb.ai/company/academics}, urldate = {2022-08-21}, - organization = {{Use Weights \& Biases for free to track experiments, collaborate, and publish results}} + organization = {Use Weights \& Biases for free to track experiments, collaborate, and publish results} } @software{bradbury_jax_2018, @@ -29,7 +29,7 @@ @software{developers_tensorflow_2022 doi = {10.5281/zenodo.6574269}, url = {https://zenodo.org/record/6574269}, urldate = {2022-08-21}, - organization = {{Zenodo}} + organization = {Zenodo} } @online{fey_fast_2019, @@ -55,7 +55,7 @@ @article{harris_array_2020 volume = {585}, number = {7825}, pages = {357--362}, - publisher = {{Nature Publishing Group}}, + publisher = {Nature Publishing Group}, issn = {1476-4687}, doi = {10.1038/s41586-020-2649-2}, url = {https://www.nature.com/articles/s41586-020-2649-2}, @@ -72,7 +72,7 @@ @article{jumper_highly_2021 volume = {596}, number = {7873}, pages = {583--589}, - publisher = {{Nature Publishing Group}}, + publisher = {Nature Publishing Group}, issn = {1476-4687}, doi = {10.1038/s41586-021-03819-2}, url = {https://www.nature.com/articles/s41586-021-03819-2}, diff --git a/pyproject.toml b/pyproject.toml index d5d1a4a..2f08ecb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,9 +65,11 @@ warn_unused_ignores = true [tool.ruff] target-version = "py38" include = ["**/pyproject.toml", "*.ipynb", "*.py", "*.pyi"] + +[tool.ruff.lint] select = ["ALL"] ignore = [ - "ANN101", + "ANN101", # Missing type annotation for self in method "ANN401", "ARG001", "C901", @@ -87,7 +89,7 @@ ignore = [ ] pydocstyle.convention = "google" -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/*" = ["D103", "D104", "INP001", "S101"] "__init__.py" = ["F401"] "examples/*" = ["D102", "D103", "D107", "E402", "FA102"] From 9f4feaefdb5979feb431e3119c5e3b7914a17cbc Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 1 Apr 2024 20:24:26 +0200 Subject: [PATCH 3/4] ruff fixes --- examples/functorch_mlp_ensemble.ipynb | 10 ++++++++-- examples/wandb_integration.ipynb | 14 ++++++++++---- tests/test_reduce.py | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/examples/functorch_mlp_ensemble.ipynb b/examples/functorch_mlp_ensemble.ipynb index b30753c..ebf520b 100644 --- a/examples/functorch_mlp_ensemble.ipynb +++ b/examples/functorch_mlp_ensemble.ipynb @@ -164,7 +164,8 @@ "\n", " plt.scatter(*points.T, c=labels)\n", " plt.gca().set(xlabel=\"x\", ylabel=\"y\", title=f\"{noise_std=}\")\n", - " plt.show()" + " plt.show()\n", + "\n" ] }, { @@ -297,6 +298,8 @@ ], "source": [ "# If so, the loss should decrease with step count.\n", + "\n", + "\n", "metrics = {}\n", "for step in range(n_train_steps):\n", " loss, acc, weights = train_step_fn(weights, points, labels)\n", @@ -310,7 +313,8 @@ "ax.set_ylabel(\"loss\", color=\"tab:blue\")\n", "ax2 = ax.twinx()\n", "ax2.plot(list(metrics), [v[\"acc\"] for v in metrics.values()], color=\"red\")\n", - "ax2.set_ylabel(\"accuracy\", color=\"tab:red\")" + "ax2.set_ylabel(\"accuracy\", color=\"tab:red\")\n", + "\n" ] }, { @@ -352,6 +356,8 @@ "source": [ "# at the same time! Note that metrics like losses and accuracies are all tuples here,\n", "# one scalar per model.\n", + "\n", + "\n", "parallel_train_step_fn = functorch.vmap(train_step_fn, in_dims=(0, None, None))\n", "batched_weights = initialize_ensemble(n_models=5)\n", "for step in tqdm(range(n_train_steps), desc=\"training MLP ensemble\"):\n", diff --git a/examples/wandb_integration.ipynb b/examples/wandb_integration.ipynb index f0343e8..8ec35bf 100644 --- a/examples/wandb_integration.ipynb +++ b/examples/wandb_integration.ipynb @@ -183,7 +183,8 @@ " \"learning_rate\": 0.005,\n", " \"dataset\": \"MNIST\",\n", " \"architecture\": \"CNN\",\n", - "}" + "}\n", + "\n" ] }, { @@ -281,7 +282,8 @@ " out = self.layer1(x)\n", " out = self.layer2(out)\n", " out = out.reshape(out.size(0), -1)\n", - " return self.fc(out)" + " return self.fc(out)\n", + "\n" ] }, { @@ -371,7 +373,8 @@ " wandb.log(\n", " {\"epoch\": epoch, \"loss\": loss, \"accuracy\": accuracy},\n", " step=sample_count,\n", - " )" + " )\n", + "\n" ] }, { @@ -474,6 +477,8 @@ "outputs": [], "source": [ "# Make the data\n", + "\n", + "\n", "train_set, test_set = (\n", " torchvision.datasets.MNIST(\n", " root=\".\",\n", @@ -515,7 +520,8 @@ "\n", " wandb.finish()\n", "\n", - " return model" + " return model\n", + "\n" ] }, { diff --git a/tests/test_reduce.py b/tests/test_reduce.py index 9d7c0c4..ead5e62 100644 --- a/tests/test_reduce.py +++ b/tests/test_reduce.py @@ -13,8 +13,9 @@ def generate_sample_data( n_tags: int = 1, n_runs: int = 10, n_steps: int = 5 ) -> dict[str, pd.DataFrame]: events_dict = {} + rng = np.random.default_rng() for idx in range(n_tags): - data = np.random.random((n_steps, n_runs)) + data = rng.random((n_steps, n_runs)) df_rand = pd.DataFrame(data, columns=[f"run_{j}" for j in range(n_runs)]) events_dict[f"tag_{idx}"] = df_rand return events_dict From f4f678b3cea167f4b1d33ccc54c1906a449054e0 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 1 Apr 2024 20:24:56 +0200 Subject: [PATCH 4/4] fix missing raise for ValueError in _rm_rf_or_raise and fix dict.fromkeys bug --- tensorboard_reducer/write.py | 2 +- tests/test_reduce.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorboard_reducer/write.py b/tensorboard_reducer/write.py index dc4179b..939fa2c 100644 --- a/tensorboard_reducer/write.py +++ b/tensorboard_reducer/write.py @@ -33,7 +33,7 @@ def _rm_rf_or_raise(path: str, overwrite: bool) -> None: if overwrite and (is_data_file or is_tb_dir): os.system(f"rm -rf {path}") # noqa: S605 elif overwrite: - ValueError( + raise ValueError( f"Received the overwrite flag but the content of '{path}' does not " "look like it was written by this program. Please make sure you really " f"want to delete '{path}' and then do so manually." diff --git a/tests/test_reduce.py b/tests/test_reduce.py index ead5e62..92c3776 100644 --- a/tests/test_reduce.py +++ b/tests/test_reduce.py @@ -93,4 +93,4 @@ def test_reduce_events_dimensions(n_tags: int, n_runs: int, n_steps: int) -> Non @pytest.mark.parametrize("reduce_ops", [["mean"], ["max", "min"], ["std", "median"]]) def test_reduce_events_empty_input(reduce_ops: Sequence[str]) -> None: reduced_events = reduce_events({}, reduce_ops) - assert reduced_events == dict.fromkeys(reduce_ops, {}) + assert reduced_events == {op: {} for op in reduce_ops}