Skip to content

Commit

Permalink
Replace flake with ruff (EleutherAI#154)
Browse files Browse the repository at this point in the history
* add ruff

* explicit reexport

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add back __all__

* add docstring for ruff

* add explicit reexports

* add readme

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: James Chua <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 5, 2023
1 parent 0f9ba11 commit 90755b6
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ repos:
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: '6.0.0'
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.257'
hooks:
- id: flake8
args: ["--ignore=E203,F401,W503", --max-line-length=88]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ We use [pyright](https://github.com/microsoft/pyright), which is built into the
pyright
```

### Run the linter
We use [ruff](https://beta.ruff.rs/docs/). It is installed as a pre-commit hook, so you don't have to run it manually.
If you want to run it manually, you can do so with:
```bash
ruff . --fix
```

### Contributing to this repository

If you work on a new feature / fix or some other code task, make sure to create an issue and assign it to yourself (Maybe, even share it in the elk channel of Eleuther's Discord with a small note). In this way, others know you are working on the issue and people won't do the same thing twice 👍 Also others can contact you easily.
2 changes: 2 additions & 0 deletions elk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .extraction import extract_hiddens, Extract

__all__ = ["extract_hiddens", "Extract"]
1 change: 0 additions & 1 deletion elk/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Main entry point for `elk`."""

from dataclasses import dataclass
from pathlib import Path
from typing import Union

from simple_parsing import ArgumentParser
Expand Down
14 changes: 2 additions & 12 deletions elk/evaluation/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import csv
import os
from dataclasses import dataclass
from functools import partial
from pathlib import Path
from typing import Callable, Literal, Optional, cast
from typing import Callable, Literal, Optional

import torch
import torch.multiprocessing as mp
from simple_parsing.helpers import Serializable, field
from torch import Tensor
from tqdm.auto import tqdm

from datasets import DatasetDict
from elk.evaluation.evaluate_log import EvalLog
from elk.extraction.extraction import Extract
from elk.run import Run
from elk.training import Reporter

from ..files import elk_reporter_dir, memorably_named_dir
from ..training.preprocessing import normalize
from ..files import elk_reporter_dir
from ..utils import (
assert_type,
int16_to_float32,
select_train_val_splits,
select_usable_devices,
)

Expand Down
12 changes: 12 additions & 0 deletions elk/extraction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
from .extraction import Extract, extract_hiddens, extract
from .generator import _GeneratorConfig, _GeneratorBuilder
from .prompt_loading import PromptConfig, load_prompts

__all__ = [
"BalancedSampler",
"FewShotSampler",
"Extract",
"extract_hiddens",
"extract",
"_GeneratorConfig",
"_GeneratorBuilder",
"PromptConfig",
"load_prompts",
]
1 change: 0 additions & 1 deletion elk/extraction/balanced_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from ..utils import infer_label_column
from ..utils.typing import assert_type
from collections import deque
from dataclasses import dataclass
from datasets import IterableDataset, Features
from itertools import cycle
from random import Random
Expand Down
1 change: 0 additions & 1 deletion elk/extraction/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from ..utils import (
assert_type,
infer_label_column,
select_train_val_splits,
select_usable_devices,
)
Expand Down
Empty file.
4 changes: 0 additions & 4 deletions elk/extraction/prompt_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
from .balanced_sampler import FewShotSampler
from dataclasses import dataclass
from datasets import (
interleave_datasets,
load_dataset,
ClassLabel,
Dataset,
Features,
IterableDataset,
Sequence,
)
from datasets.distributed import split_dataset_by_node
from random import Random
Expand Down
2 changes: 2 additions & 0 deletions elk/promptsource/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .templates import DatasetTemplates, Template

__all__ = ["DatasetTemplates", "Template"]
11 changes: 11 additions & 0 deletions elk/training/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
from .ccs_reporter import CcsReporter, CcsReporterConfig
from .eigen_reporter import EigenReporter, EigenReporterConfig
from .reporter import OptimConfig, Reporter, ReporterConfig


__all__ = [
"Reporter",
"ReporterConfig",
"CcsReporter",
"CcsReporterConfig",
"EigenReporter",
"EigenReporterConfig",
"OptimConfig",
]
2 changes: 1 addition & 1 deletion elk/training/ccs_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclasses import dataclass, field
from torch import Tensor
from torch.nn.functional import binary_cross_entropy as bce
from typing import cast, Literal, NamedTuple, Optional
from typing import cast, Literal, Optional
import math
import torch
import torch.nn as nn
Expand Down
1 change: 0 additions & 1 deletion elk/training/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from torch import Tensor
from typing import Optional
import torch
import warnings


@dataclass
Expand Down
13 changes: 13 additions & 0 deletions elk/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@
from .gpu_utils import select_usable_devices
from .tree_utils import pytree_map
from .typing import assert_type, float32_to_int16, int16_to_float32

__all__ = [
"binarize",
"get_columns_all_equal",
"infer_label_column",
"infer_num_classes",
"float32_to_int16",
"int16_to_float32",
"select_train_val_splits",
"select_usable_devices",
"pytree_map",
"assert_type",
]
4 changes: 1 addition & 3 deletions elk/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
Value,
)
from random import Random
import torch
from typing import Iterable, Optional, List, Any
import numpy as np
from typing import Iterable, List, Any
import copy


Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ testpaths = ["tests"]

[tool.setuptools.packages.find]
include = ["elk*"]

[tool.ruff]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes
# See https://beta.ruff.rs/docs/rules/ for more possible rules
select = ["E", "F"]
# Same as Black.
line-length = 88
# Avoid automatically removing unused imports in __init__.py files.
# Such imports will be flagged with a dedicated message suggesting
# that the import is either added to the module's __all__ symbol
ignore-init-module-imports = true
1 change: 0 additions & 1 deletion tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from random import Random
import math
import numpy as np
import pytest
import torch


Expand Down
1 change: 0 additions & 1 deletion tests/test_smoke_elicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from elk import Extract
from elk.extraction import PromptConfig
from elk.training import CcsReporterConfig, EigenReporterConfig
from elk.training import train
from elk.training.train import Elicit


Expand Down

0 comments on commit 90755b6

Please sign in to comment.