diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db045c5b..88bad25d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -10,17 +10,17 @@ repos: # The promptsource templates spuriously fail without this args: ["--unsafe"] - id: check-added-large-files -- repo: https://github.com/psf/black - rev: 23.7.0 +- repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.5.1 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.0.278' + rev: 'v0.16.5' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/codespell-project/codespell - rev: v2.2.5 + rev: v2.4.3 hooks: - id: codespell # The promptsource templates spuriously get flagged without this diff --git a/elk/extraction/extraction.py b/elk/extraction/extraction.py index 9c082c52..1cf3bf44 100644 --- a/elk/extraction/extraction.py +++ b/elk/extraction/extraction.py @@ -1,4 +1,5 @@ """Functions for extracting the hidden states of a model.""" + import os from collections import defaultdict from dataclasses import InitVar, dataclass, replace diff --git a/elk/metrics/eval.py b/elk/metrics/eval.py index 8c837e8f..834dc1a9 100644 --- a/elk/metrics/eval.py +++ b/elk/metrics/eval.py @@ -73,7 +73,7 @@ def evaluate_preds( Returns: dict: A dictionary containing the accuracy, AUROC, and ECE. """ - (n, v) = y_logits.shape + n, v = y_logits.shape assert y_true.shape == (n,) if ensembling == "full": diff --git a/elk/plotting/visualize.py b/elk/plotting/visualize.py index 85eedd43..93fbd650 100644 --- a/elk/plotting/visualize.py +++ b/elk/plotting/visualize.py @@ -78,9 +78,9 @@ def render( y=dataset_data["auroc_estimate"], mode="lines", name=ensemble, - showlegend=False - if dataset_name != unique_datasets[0] - else True, + showlegend=( + False if dataset_name != unique_datasets[0] else True + ), line=dict(color=color_map[ensemble]), ), row=row, diff --git a/elk/promptsource/templates.py b/elk/promptsource/templates.py index 7d4c0b84..8d93a40c 100644 --- a/elk/promptsource/templates.py +++ b/elk/promptsource/templates.py @@ -215,9 +215,11 @@ def _escape_pipe(cls, example): # Replaces any occurrences of the "|||" separator in the example, which # which will be replaced back after splitting protected_example = { - key: value.replace("|||", cls.pipe_protector) - if isinstance(value, str) - else value + key: ( + value.replace("|||", cls.pipe_protector) + if isinstance(value, str) + else value + ) for key, value in example.items() } return protected_example diff --git a/elk/training/platt_scaling.py b/elk/training/platt_scaling.py index 278d8d95..70dd87c3 100644 --- a/elk/training/platt_scaling.py +++ b/elk/training/platt_scaling.py @@ -12,8 +12,7 @@ class PlattMixin(ABC): scale: nn.Parameter @abstractmethod - def __call__(self, *args: Any, **kwds: Any) -> Any: - ... + def __call__(self, *args: Any, **kwds: Any) -> Any: ... def platt_scale(self, labels: Tensor, hiddens: Tensor, max_iter: int = 100): """Fit the scale and bias terms to data with LBFGS. diff --git a/elk/training/supervised.py b/elk/training/supervised.py index b3f10064..fd3495f7 100644 --- a/elk/training/supervised.py +++ b/elk/training/supervised.py @@ -21,7 +21,7 @@ def train_supervised( leace = None for train_data in data.values(): - (n, v, d) = train_data.hiddens.shape + n, v, d = train_data.hiddens.shape train_h = rearrange(train_data.hiddens, "n v d -> (n v) d") if erase_paraphrases and v > 1: diff --git a/elk/training/train.py b/elk/training/train.py index baa21991..f4e96f51 100644 --- a/elk/training/train.py +++ b/elk/training/train.py @@ -64,7 +64,7 @@ def apply_to_layer( val_dict = self.prepare_data(device, layer, "val") first_train_data, *rest = train_dict.values() - (_, v, d) = first_train_data.hiddens.shape + _, v, d = first_train_data.hiddens.shape if not all(other_data.hiddens.shape[-1] == d for other_data in rest): raise ValueError("All datasets must have the same hidden state size")