Unverified Commit 65b8761d authored by Baber Abbasi's avatar Baber Abbasi Committed by GitHub
Browse files

Switch Linting to `ruff` (#1166)

* add ruff and isort. remove black and flake8

* remove unnecessary dependencies

* remove dependency from table

* change order

* ran ruff

* check 3.9

* exclude evaluator

* update CI workflow

* use ruff config in pyproject.toml

* test

* add isort rules to ruff

* sort imports

* import `make_table`

* try stages for no-commit-to-branch

* turn on mypy for pre-commit

* test

* test

* test

* change no-commit-to-branch to default

* nits

* fixed dependency
parent 21d4ae98
from lm_eval.decontamination.archiver import Reader
import os
import glob
import json
import os
from functools import reduce
import glob
import tqdm
import tqdm
from tqdm_multiprocess import TqdmMultiProcessPool
from lm_eval.decontamination.archiver import Reader
def get_file_stats(file_path, tqdm_func, global_tqdm):
reader = Reader()
......
......@@ -15,18 +15,18 @@ Arguments
import argparse
import glob
import logging
import os
from pathlib import Path
import re
import shutil
from pathlib import Path
from tqdm import tqdm
from tqdm_multiprocess import TqdmMultiProcessPool
from tqdm_multiprocess.logger import setup_logger_tqdm
from scripts.clean_training_data.archiver import TextReader, TextArchive
from scripts.clean_training_data.archiver import TextArchive, TextReader
import logging
from tqdm_multiprocess.logger import setup_logger_tqdm
logger = logging.getLogger(__name__)
......@@ -35,7 +35,6 @@ logger = logging.getLogger(__name__)
def process_bucket(
bucket_file_path, processed_directory, move_dir, tqdm_func, global_tqdm
):
bucket_id = re.sub("\D", "", os.path.basename(bucket_file_path)) # noqa: W605
done_file = os.path.join(
processed_directory, f"ngram_bucket_processing_{bucket_id}.done"
......@@ -96,7 +95,7 @@ def process_bucket(
def process_sorted_buckets(working_directory, move_dir, process_count):
bucket_file_paths = glob.glob(os.path.join(working_directory, f"*.bkt.txt.sorted"))
bucket_file_paths = glob.glob(os.path.join(working_directory, "*.bkt.txt.sorted"))
processed_directory = os.path.join(working_directory, "processed")
os.makedirs(processed_directory, exist_ok=True)
......@@ -123,7 +122,6 @@ parser.add_argument("-move", "--move_dir", default="")
parser.add_argument("-procs", "--process_count", type=int, default=4)
if __name__ == "__main__":
logfile_path = "process13grams.log"
setup_logger_tqdm(logfile_path)
......
......@@ -8,18 +8,18 @@ Arguments
directory and the unsorted buckets are removed after.
"""
import glob
import argparse
import glob
import logging
import os
import signal
from signal import SIGINT
import subprocess
from signal import SIGINT
from tqdm import tqdm
import logging
from tqdm_multiprocess.logger import setup_logger_tqdm
logger = logging.getLogger(__name__)
terminate = False
......@@ -31,7 +31,7 @@ def handler(signal_received, frame):
def sort_13_gram_buckets(working_directory):
bucket_file_paths = glob.glob(os.path.join(working_directory, f"*.bkt.txt"))
bucket_file_paths = glob.glob(os.path.join(working_directory, "*.bkt.txt"))
for bucket_file_path in tqdm(bucket_file_paths, dynamic_ncols=True):
sorted_file_path = bucket_file_path + ".sorted"
......@@ -49,7 +49,6 @@ parser = argparse.ArgumentParser(description="sort 13gram buckets")
parser.add_argument("-dir", "--working_directory", default="")
if __name__ == "__main__":
version = 1.00
print(f"Running version {version}")
......
import random
import transformers
from lm_eval import tasks, evaluator
from lm_eval import evaluator, tasks
from lm_eval.base import LM
......
from lm_eval import tasks
from itertools import islice
from lm_eval import tasks
ct = 3
for (
......
import transformers
import random
import torch
import torch.nn.functional as F
import random
import transformers
random.seed(42)
......
......@@ -2,10 +2,11 @@
Usage:
python make_table_tasks.py --output <markdown_filename>
"""
import json
import logging
from pytablewriter import MarkdownTableWriter, LatexTableWriter
import os
import json
from pytablewriter import LatexTableWriter, MarkdownTableWriter
logging.basicConfig(level=logging.INFO)
......
......@@ -4,9 +4,11 @@ Usage:
"""
import argparse
import logging
from lm_eval import tasks
from pytablewriter import MarkdownTableWriter
from lm_eval import tasks
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
......
import argparse
import os
from typing import Dict, List, Tuple
import numpy as np
import lm_eval.evaluator
from lm_eval import tasks
from lm_eval import utils
import scipy.stats
from typing import Tuple, Dict, List
import pandas as pd
import scipy.stats
import torch
import os
import lm_eval.evaluator
from lm_eval import tasks, utils
os.environ["TOKENIZERS_PARALLELISM"] = "false"
eval_logger = utils.eval_logger
......
......@@ -5,7 +5,7 @@ import subprocess
import time
from pathlib import Path
from lm_eval import evaluator, utils
from lm_eval import utils
from lm_eval.api.registry import ALL_TASKS
......@@ -136,14 +136,16 @@ def main():
args = parse_args()
args.branches = (
args.branches.split(",") if type(args.branches) == str else args.branches
args.branches.split(",") if isinstance(args.branches, str) else args.branches
)
args.models = (
args.models.split(",") if isinstance(args.models, str) else args.models
)
args.models = args.models.split(",") if type(args.models) == str else args.models
args.tasks = (
ALL_TASKS
if args.tasks == "all_tasks"
else utils.pattern_match(args.tasks.split(","), ALL_TASKS)
if type(args.tasks) == str
if isinstance(args.tasks, str)
else args.tasks
)
......
import argparse
import numpy as np
import json
import os
import random
import numpy as np
from lm_eval import tasks
from lm_eval.utils import join_iters, eval_logger
from lm_eval.tasks import initialize_tasks, include_path
from lm_eval.tasks import include_path, initialize_tasks
from lm_eval.utils import eval_logger, join_iters
EXAMPLE_DIVIDER = "!!@@##@@!! -- Example {i}\n"
......
import setuptools
# This is to make sure that the package supports editable installs
setuptools.setup()
import unittest
from unittest.mock import patch
import hashlib
import json
import os
import pickle
from lm_eval.models.gguf import GGUFLM
import unittest
from unittest.mock import patch
from lm_eval.api.instance import Instance
from lm_eval.models.gguf import GGUFLM
base_url = "https://matthoffner-ggml-llm-api.hf.space"
......
from __future__ import annotations
import pytest
import sys
from pathlib import Path
import numpy as np
from lm_eval.models.huggingface import HFLM
from lm_eval.api.instance import Instance
import lm_eval.tasks as tasks
import sys
import torch
import lm_eval.tasks as tasks
from lm_eval.api.instance import Instance
from lm_eval.models.huggingface import HFLM
tasks.initialize_tasks()
......@@ -106,9 +109,10 @@ class Test_HFLM:
f.write("\n".join(str(x) for x in _res))
assert np.allclose(_res, _RES, atol=1e-2)
# check indices for Multiple Choice
argmax_RES, argmax_res = np.argmax(
np.array(_RES).reshape(-1, 4), axis=1
), np.argmax(np.array(_res).reshape(-1, 4), axis=1)
argmax_RES, argmax_res = (
np.argmax(np.array(_RES).reshape(-1, 4), axis=1),
np.argmax(np.array(_res).reshape(-1, 4), axis=1),
)
assert (argmax_RES == argmax_res).all()
def test_generate_until(self) -> None:
......
import pytest
from typing import List
from lm_eval.api.instance import Instance
import lm_eval.tasks as tasks
import sys
import pytest
import torch
import lm_eval.tasks as tasks
from lm_eval.api.instance import Instance
@pytest.mark.skip(reason="requires CUDA")
class TEST_VLLM:
......
import os
# import lm_eval.base as base
import lm_eval.api.registry as registry
import lm_eval.tasks as tasks
from typing import List
import pytest
# import lm_eval.models as models
import lm_eval.api as api
import lm_eval.evaluator as evaluator
from typing import List
import random
import pytest
import lm_eval.tasks as tasks
tasks.initialize_tasks()
......
import re
from collections import defaultdict
from lm_eval.decontamination.janitor import (
Janitor,
form_ngrams,
word_ngrams,
split_indices,
word_ngrams,
word_ngrams_indices,
)
......@@ -81,7 +80,6 @@ def test_split_indices():
def test_word_ngrams_indices():
sequence = (
"Hello my name is Bob, I like eating pizza, chicken, chips and ice cream. Maybe I should eat some"
" more salad but it's so booooring. I just... like eating pizza, chicken, chips and ice cream so much."
......@@ -119,9 +117,9 @@ def test_word_ngrams_indices():
# Assumptions from GPT3 Paper:
# the 200 characters to remove include punctuation and is actually a half-window
# All tests below initially test without any registered contaminants, expecting the same sequence back.
def test_janitor1():
# First test using a 1gram and expected the first block before the filth to have some remaining
# characters, but the second block should be completely removed.
......@@ -165,7 +163,6 @@ def test_janitor1():
def test_janitor2():
# Second test using a 1gram and expected the first block before the filth to have some remaining
# characters, and the second block is longer then 200 characters so should also have some remaining.
......@@ -214,7 +211,6 @@ def test_janitor2():
def test_janitor3():
# Same test as above but with a 6gram.
sequence = (
......@@ -262,7 +258,6 @@ def test_janitor3():
def test_janitor4():
# This test adds another block to that from the previous. The middle block should be entirely
# removed as the 200 characters are removed from each side.
......@@ -318,7 +313,6 @@ def test_janitor4():
def test_janitor5():
# Same as above but using multiple different filth 6grams.
sequence = (
......@@ -374,7 +368,6 @@ def test_janitor5():
def test_janitor6():
# Same as above but now we add 10 filths and expect the same result, the following test does 11.
sequence = (
......@@ -438,7 +431,6 @@ def test_janitor6():
def test_janitor7():
# Same as above but now we add 9 filths and expect the same result, the following test does 10.
sequence = (
......
import random
import pytest
import lm_eval.api.metrics as metrics
import random
def test_bootstrapping():
......
from itertools import islice
import pytest
from .utils import new_tasks
import lm_eval.tasks as tasks
from lm_eval.api.task import ConfigurableTask
from .utils import new_tasks
tasks.initialize_tasks()
# Default Task
TASKS = ["arc_easy"]
......
import random
import lm_eval.tasks
import lm_eval.models
import lm_eval.tasks
def test_description():
......@@ -14,7 +15,6 @@ def test_description():
task_dict = lm_eval.tasks.get_task_dict(task_names)
for task_name, task in task_dict.items():
# patch description field in task (# TODO: make this much more cleaned up)
task._config.description = description_dict[task_name]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment