diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 000000000..a185235cf --- /dev/null +++ b/.style.yapf @@ -0,0 +1,13 @@ +[style] +ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT = True +ALLOW_MULTILINE_LAMBDAS = True +BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = True +COLUMN_LIMIT = 88 +COALESCE_BRACKETS = True +SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET = True +SPACES_BEFORE_COMMENT = 2 +SPLIT_BEFORE_BITWISE_OPERATOR = True +SPLIT_BEFORE_FIRST_ARGUMENT = True +SPLIT_BEFORE_LOGICAL_OPERATOR = True +SPLIT_BEFORE_NAMED_ASSIGNS = True +SPLIT_COMPLEX_COMPREHENSION = True \ No newline at end of file diff --git a/environment.yml b/environment.yml index 93f5b3857..02db0cdd1 100644 --- a/environment.yml +++ b/environment.yml @@ -1,15 +1,43 @@ -name: 8-bit +name: bnb channels: - - conda-forge - pytorch + - nvidia + - conda-forge + dependencies: - - python=3.9 - - pytest - - pytorch - - torchaudio - - torchvision - - cudatoolkit=11.1 - - typer - - ca-certificates - - certifi - - openssl + # Base + - conda-forge::python=3.8 + - pytorch::pytorch=>2.1 + - pytorch::pytorch-cuda=11.8 + - nvidia::cuda=11.8 + # Libraries + - conda-forge::accelerate + - conda-forge::einops + - conda-forge::scipy + - conda-forge::transformers + # Development + - conda-forge::pytest + - conda-forge::pytest-cases # more readable and composable parametrized tests + - conda-forge::ipython # better interactive shell + - conda-forge::debugpy # debugger-support for VSCode + - conda-forge::ruff # linting + - conda-forge::yapf # code formatting + - conda-forge::monkeytype # infer type annotations + - conda-forge::rich # better, colored tracebacks, etc + - conda-forge::pytest-sugar # better pytest output + +## ENV CREATION - steps to reproduce: +# mamba env remove -n bnb +# mamba create -y -n bnb python=3.8 # creating an empty env bypasses conda +# # and leads to much faster env resolution in the next step https://github.com/mamba-org/mamba/issues/633#issuecomment-812272143 +# mamba env update -n bnb -f environment.yml +# mamba activate bnb + +## PIP dependencies (install *after* ENV CREATION): +# pip install --no-cache-dir --no-deps lion_pytorch triton peft +## NOTE: conda peft is not up to date, so we install from pip +# cd pip install -e . ## installs bitsandbytes as editable development install from within repo root dir + +## ENV UPDATE: +# # add new packages to environment.yml, then: +# mamba env update -n bnb -f environment.yml \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 374b58cbf..74d17dd90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,34 @@ requires = [ "wheel" ] build-backend = "setuptools.build_meta" + +[tool.ruff] +src = [ + "bitsandbytes", + "tests", + "benchmarking" +] +fix = true +select = [ + "A", # prevent using keywords that clobber python builtins + "B", # bugbear: security warnings + "E", # pycodestyle + "F", # pyflakes + "I", # isort + "ISC", # implicit string concatenation + "UP", # alert you when better syntax is available in your python version + "RUF", # the ruff developer's own rules +] +target-version = "py38" +ignore = [ + "E712", # Allow using if x == False, as it's not always equivalent to if x. + "E501", # Supress line-too-long warnings: trust yapf's judgement on this one. + "F401", +] +ignore-init-module-imports = true # allow to expose in __init__.py via imports + +[tool.ruff.isort] +combine-as-imports = true +detect-same-package = true +force-sort-within-sections = true +known-first-party = ["bitsandbytes"] \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..9902b98fa --- /dev/null +++ b/pytest.ini @@ -0,0 +1,10 @@ +[pytest] +addopts = -rP + ; --cov=bitsandbytes + ; # contexts: record which test ran which line; can be seen in html coverage report + ; --cov-context=test + ; --cov-report html + +log_cli = True +log_cli_level = INFO +log_file = logs/pytest.log \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb