Skip to content

Commit

Permalink
Update repo to isort v5 (huggingface#6686)
Browse files Browse the repository at this point in the history
* Run new isort

* More changes

* Update CI, CONTRIBUTING and benchmarks
  • Loading branch information
sgugger authored Aug 24, 2020
1 parent d329c9b commit a573777
Show file tree
Hide file tree
Showing 89 changed files with 561 additions and 578 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ jobs:
- v0.3-code_quality-{{ checksum "setup.py" }}
- v0.3-{{ checksum "setup.py" }}
- run: pip install --upgrade pip
# we need a version of isort with https://github.com/timothycrosley/isort/pull/1000
- run: pip install git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort
- run: pip install isort
- run: pip install .[tf,torch,quality]
- save_cache:
key: v0.3-code_quality-{{ checksum "setup.py" }}
Expand Down
6 changes: 0 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ Follow these steps to start contributing:
it with `pip uninstall transformers` before reinstalling it in editable
mode with the `-e` flag.)

Right now, we need an unreleased version of `isort` to avoid a
[bug](https://github.com/timothycrosley/isort/pull/1000):

```bash
$ pip install -U git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort
```
5. Develop the features on your branch.

As you work on the features, you should make sure that the test suite
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

quality:
black --check --line-length 119 --target-version py35 examples templates tests src utils
isort --check-only --recursive examples templates tests src utils
isort --check-only examples templates tests src utils
flake8 examples templates tests src utils
python utils/check_repo.py

# Format source code automatically

style:
black --line-length 119 --target-version py35 examples templates tests src utils
isort --recursive examples templates tests src utils
isort examples templates tests src utils

# Run tests for the library

Expand Down
2 changes: 1 addition & 1 deletion examples/adversarial/utils_hans.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from typing import List, Optional, Union

import tqdm
from filelock import FileLock

from filelock import FileLock
from transformers import (
BartTokenizer,
BartTokenizerFast,
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-choice/utils_multiple_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from typing import List, Optional

import tqdm
from filelock import FileLock

from filelock import FileLock
from transformers import PreTrainedTokenizer, is_tf_available, is_torch_available


Expand Down
3 changes: 2 additions & 1 deletion examples/seq2seq/bertabs/run_summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ def evaluate(args):
reference_summaries = []
generated_summaries = []

import rouge
import nltk

import rouge

nltk.download("punkt")
rouge_evaluator = rouge.Rouge(
metrics=["rouge-n", "rouge-l"],
Expand Down
22 changes: 11 additions & 11 deletions examples/seq2seq/distillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

try:
from .finetune import SummarizationModule, TranslationModule
from .initialization_utils import init_student, copy_layers
from .finetune import main as ft_main
from .initialization_utils import copy_layers, init_student
from .utils import (
use_task_specific_params,
pickle_load,
freeze_params,
assert_all_frozen,
any_requires_grad,
assert_all_frozen,
calculate_bleu_score,
freeze_params,
pickle_load,
use_task_specific_params,
)
from .finetune import main as ft_main
except ImportError:
from finetune import SummarizationModule, TranslationModule
from finetune import main as ft_main
from initialization_utils import init_student, copy_layers
from initialization_utils import copy_layers, init_student
from utils import (
use_task_specific_params,
pickle_load,
freeze_params,
assert_all_frozen,
any_requires_grad,
assert_all_frozen,
calculate_bleu_score,
freeze_params,
pickle_load,
use_task_specific_params,
)


Expand Down
41 changes: 20 additions & 21 deletions examples/seq2seq/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,43 @@


try:
from .callbacks import Seq2SeqLoggingCallback, get_checkpoint_callback, get_early_stopping_callback
from .utils import (
ROUGE_KEYS,
Seq2SeqDataset,
TranslationDataset,
assert_all_frozen,
use_task_specific_params,
lmap,
calculate_bleu_score,
calculate_rouge,
flatten_list,
pickle_save,
save_git_info,
save_json,
freeze_params,
calculate_rouge,
get_git_info,
ROUGE_KEYS,
calculate_bleu_score,
Seq2SeqDataset,
TranslationDataset,
label_smoothed_nll_loss,
lmap,
pickle_save,
save_git_info,
save_json,
use_task_specific_params,
)

from .callbacks import Seq2SeqLoggingCallback, get_checkpoint_callback, get_early_stopping_callback
except ImportError:
from callbacks import Seq2SeqLoggingCallback, get_checkpoint_callback, get_early_stopping_callback
from utils import (
ROUGE_KEYS,
Seq2SeqDataset,
TranslationDataset,
assert_all_frozen,
use_task_specific_params,
lmap,
calculate_bleu_score,
calculate_rouge,
flatten_list,
pickle_save,
save_git_info,
save_json,
freeze_params,
calculate_rouge,
get_git_info,
ROUGE_KEYS,
calculate_bleu_score,
label_smoothed_nll_loss,
lmap,
pickle_save,
save_git_info,
save_json,
use_task_specific_params,
)
from callbacks import Seq2SeqLoggingCallback, get_checkpoint_callback, get_early_stopping_callback

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions examples/seq2seq/run_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@


try:
from .utils import calculate_rouge, use_task_specific_params, calculate_bleu_score, trim_batch
from .utils import calculate_bleu_score, calculate_rouge, trim_batch, use_task_specific_params
except ImportError:
from utils import calculate_rouge, use_task_specific_params, calculate_bleu_score, trim_batch
from utils import calculate_bleu_score, calculate_rouge, trim_batch, use_task_specific_params

DEFAULT_DEVICE = "cuda" if torch.cuda.is_available() else "cpu"

Expand Down
2 changes: 1 addition & 1 deletion examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
if SRC_DIRS is not None:
import run_generation
import run_glue
import run_pl_glue
import run_language_modeling
import run_pl_glue
import run_squad


Expand Down
1 change: 0 additions & 1 deletion examples/token-classification/utils_ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from typing import List, Optional, Union

from filelock import FileLock

from transformers import PreTrainedTokenizer, is_tf_available, is_torch_available


Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[isort]
default_section = FIRSTPARTY
ensure_newline_before_comments = True
force_grid_wrap = 0
include_trailing_comma = True
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@
extras["testing"] = ["pytest", "pytest-xdist", "timeout-decorator", "psutil"]
# sphinx-rtd-theme==0.5.0 introduced big changes in the style.
extras["docs"] = ["recommonmark", "sphinx", "sphinx-markdown-tables", "sphinx-rtd-theme==0.4.3", "sphinx-copybutton"]
extras["quality"] = [
"black",
# "isort",
"isort @ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort",
"flake8",
]
extras["quality"] = ["black", "isort >= 5", "flake8"]
extras["dev"] = extras["testing"] + extras["quality"] + extras["ja"] + ["scikit-learn", "tensorflow", "torch"]

setup(
Expand Down
Loading

0 comments on commit a573777

Please sign in to comment.