Skip to content

Commit

Permalink
Use Ruff for formatting too (#2400)
Browse files Browse the repository at this point in the history
Co-authored-by: Zach Mueller <[email protected]>
  • Loading branch information
akx and muellerzr authored Feb 6, 2024
1 parent d8a64cb commit 0e1ee4b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
you're working on.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[tool.black]
line-length = 119
target-version = ['py37']

[tool.ruff]
# Never enforce `E501` (line length violations).
ignore = ["E501", "E741", "W605"]
Expand All @@ -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/*"
]
30 changes: 25 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions src/accelerate/utils/megatron_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0e1ee4b

Please sign in to comment.