From 0e1ee4b92d8fcf0f97a407e8e7764ed9f2ba0c14 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 6 Feb 2024 14:18:18 +0100 Subject: [PATCH] Use Ruff for formatting too (#2400) Co-authored-by: Zach Mueller --- CONTRIBUTING.md | 4 ++-- Makefile | 6 +++--- pyproject.toml | 10 ++++++---- setup.py | 30 ++++++++++++++++++++++++----- src/accelerate/utils/megatron_lm.py | 4 +--- tests/test_tracking.py | 1 + 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3edd1c4770..592252db4e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -152,7 +152,7 @@ Follow these steps to start contributing: $ make test ``` - `accelerate` relies on `black` and `ruff` to format its source code + `accelerate` relies on `ruff` to format its source code consistently. After you make changes, apply automatic style corrections and code verifications that can't be automated in one go with: @@ -235,4 +235,4 @@ $ python -m pytest -sv ./tests In fact, that's how `make test` is implemented (sans the `pip install` line)! You can specify a smaller set of tests in order to test only the feature -you're working on. \ No newline at end of file +you're working on. diff --git a/Makefile b/Makefile index a880b2996ae..511b6b2a408 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: quality style test docs utils -check_dirs := tests src examples benchmarks utils +check_dirs := . # Check that source code meets quality standards @@ -12,14 +12,14 @@ extra_quality_checks: # this target runs checks on all files quality: - black --required-version 23 --check $(check_dirs) ruff $(check_dirs) + ruff format --check $(check_dirs) doc-builder style src/accelerate docs/source --max_len 119 --check_only # Format source code automatically and check is there are any problems left that need manual fixing style: - black --required-version 23 $(check_dirs) ruff $(check_dirs) --fix + ruff format $(check_dirs) doc-builder style src/accelerate docs/source --max_len 119 # Run tests for the library diff --git a/pyproject.toml b/pyproject.toml index 1f50f3fb42b..4590c41db79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,3 @@ -[tool.black] -line-length = 119 -target-version = ['py37'] - [tool.ruff] # Never enforce `E501` (line length violations). ignore = ["E501", "E741", "W605"] @@ -11,7 +7,13 @@ line-length = 119 # Ignore import violations in all `__init__.py` files. [tool.ruff.per-file-ignores] "__init__.py" = ["E402", "F401", "F403", "F811"] +"manim_animations/*" = ["ALL"] [tool.ruff.isort] lines-after-imports = 2 known-first-party = ["accelerate"] + +[tool.ruff.format] +exclude = [ + "manim_animations/*" +] diff --git a/setup.py b/setup.py index ef8263c671d..39d0c9cf2f2 100644 --- a/setup.py +++ b/setup.py @@ -12,15 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import setup -from setuptools import find_packages +from setuptools import find_packages, setup + extras = {} -extras["quality"] = ["black ~= 23.1", "ruff >= 0.0.241", "hf-doc-builder >= 0.3.0", "urllib3 < 2.0.0"] +extras["quality"] = [ + "black ~= 23.1", # hf-doc-builder has a hidden dependency on `black` + "hf-doc-builder >= 0.3.0", + "ruff ~= 0.1.15", +] extras["docs"] = [] extras["test_prod"] = ["pytest", "pytest-xdist", "pytest-subtests", "parameterized"] extras["test_dev"] = [ - "datasets", "evaluate", "transformers", "scipy", "scikit-learn", "deepspeed<0.13.0", "tqdm", "bitsandbytes", "timm" + "datasets", + "evaluate", + "transformers", + "scipy", + "scikit-learn", + "deepspeed<0.13.0", + "tqdm", + "bitsandbytes", + "timm", ] extras["testing"] = extras["test_prod"] + extras["test_dev"] extras["rich"] = ["rich"] @@ -54,7 +66,15 @@ ] }, python_requires=">=3.8.0", - install_requires=["numpy>=1.17", "packaging>=20.0", "psutil", "pyyaml", "torch>=1.10.0", "huggingface_hub", "safetensors>=0.3.1"], + install_requires=[ + "numpy>=1.17", + "packaging>=20.0", + "psutil", + "pyyaml", + "torch>=1.10.0", + "huggingface_hub", + "safetensors>=0.3.1", + ], extras_require=extras, classifiers=[ "Development Status :: 5 - Production/Stable", diff --git a/src/accelerate/utils/megatron_lm.py b/src/accelerate/utils/megatron_lm.py index 2c7f68fdc48..80d138babfd 100644 --- a/src/accelerate/utils/megatron_lm.py +++ b/src/accelerate/utils/megatron_lm.py @@ -846,9 +846,7 @@ def initialize(accelerator, extra_args_provider=None, args_defaults={}): if args.rank == 0: print( "WARNING: overriding default arguments for {key}:{v} \ - with {key}:{v2}".format( - key=key, v=getattr(args, key), v2=value - ), + with {key}:{v2}".format(key=key, v=getattr(args, key), v2=value), flush=True, ) setattr(args, key, value) diff --git a/tests/test_tracking.py b/tests/test_tracking.py index 3264ca13160..500b484387a 100644 --- a/tests/test_tracking.py +++ b/tests/test_tracking.py @@ -407,6 +407,7 @@ def test_log_table_pandas(self): class MyCustomTracker(GeneralTracker): "Basic tracker that writes to a csv for testing" + _col_names = [ "total_loss", "iteration",