Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 8226e87

Browse files
AkshitaBepwalsh
andauthored
Making checklist optional (#5507)
* requirements and setup * allow for optional dependencies * fix script * update changelog * fix * fix format * fix * update ci * fix makefile * fix makefile * catch import errors * install everything * install all dependencies * update * add missing requirements file * oops, missing changes * fix ci, import warning * update key * fix * remove quotation marks * fix again * update cache prefix * update Makefile too * and docs too? * remove extra warnings * update dockerfile * suppress warning, mention in docs * one more fix to Dockerfile * fix test package * fix * Update README.md Co-authored-by: Pete <[email protected]> * Update README.md Co-authored-by: Pete <[email protected]> Co-authored-by: Pete <[email protected]>
1 parent a76bf1e commit 8226e87

File tree

13 files changed

+186
-62
lines changed

13 files changed

+186
-62
lines changed

.github/workflows/ci.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
TORCH_CPU_INSTALL: conda install pytorch torchvision torchaudio cpuonly -c pytorch
2323
TORCH_GPU_INSTALL: conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
2424
# Change this to invalidate existing cache.
25-
CACHE_PREFIX: v5
25+
CACHE_PREFIX: v10
2626
# Disable tokenizers parallelism because this doesn't help, and can cause issues in distributed tests.
2727
TOKENIZERS_PARALLELISM: 'false'
2828
# Disable multithreading with OMP because this can lead to dead-locks in distributed tests.
@@ -146,7 +146,7 @@ jobs:
146146
id: virtualenv-cache
147147
with:
148148
path: .venv
149-
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-${{ matrix.task.torch_platform }}-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }}
149+
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-${{ matrix.task.torch_platform }}-${{ hashFiles('setup.py') }}-${{ hashFiles('*requirements.txt') }}
150150

151151
- name: Setup virtual environment (no cache hit)
152152
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
@@ -159,7 +159,7 @@ jobs:
159159
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
160160
run: |
161161
conda activate ./.venv
162-
pip install --no-deps -e .
162+
pip install --no-deps -e .[all]
163163
make download-extras
164164
165165
- name: Pull and install models repo
@@ -170,7 +170,7 @@ jobs:
170170
conda activate ./.venv
171171
git clone https://github.com/allenai/allennlp-models.git
172172
cd allennlp-models
173-
pip install -e . -r dev-requirements.txt
173+
pip install -e .[dev,all]
174174
175175
- name: Debug info
176176
run: |
@@ -271,7 +271,7 @@ jobs:
271271
id: virtualenv-cache
272272
with:
273273
path: .venv
274-
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-cpu-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }}
274+
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-cpu-${{ hashFiles('setup.py') }}-${{ hashFiles('*requirements.txt') }}
275275

276276
- name: Setup virtual environment (no cache hit)
277277
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
@@ -284,7 +284,7 @@ jobs:
284284
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
285285
run: |
286286
conda activate ./.venv
287-
pip install --no-deps -e .
287+
pip install --no-deps -e .[all]
288288
make download-extras
289289
290290
- name: Debug info
@@ -369,7 +369,7 @@ jobs:
369369

370370
- name: Install core package
371371
run: |
372-
pip install $(ls dist/*.whl)
372+
pip install $(ls dist/*.whl)[all]
373373
374374
- name: Download NLTK prerequisites
375375
run: |
@@ -476,7 +476,7 @@ jobs:
476476
id: virtualenv-cache
477477
with:
478478
path: .venv
479-
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-cpu-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }}
479+
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-cpu-${{ hashFiles('setup.py') }}-${{ hashFiles('*requirements.txt') }}
480480

481481
- name: Setup virtual environment (no cache hit)
482482
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
@@ -489,7 +489,7 @@ jobs:
489489
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
490490
run: |
491491
conda activate ./.venv
492-
pip install --no-deps -e .
492+
pip install --no-deps -e .[all]
493493
make download-extras
494494
495495
- name: Debug info

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535

3636
### Removed
3737

38+
- Removed dependency on the overrides package
3839
- Removed Tango components, since they now live at https://github.com/allenai/tango.
39-
- Removed dependency on the `overrides` package
40+
41+
### Changed
42+
43+
- Make `checklist` an optional dependency.
4044

4145
## [v2.8.0](https://github.com/allenai/allennlp/releases/tag/v2.8.0) - 2021-11-01
4246

CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ When you're ready to contribute code to address an open issue, please follow the
7979
Once your virtual environment is activated, you can install your local clone in "editable mode" with
8080

8181
pip install -U pip setuptools wheel
82-
pip install -e .
83-
pip install -r dev-requirements.txt
82+
pip install -e .[dev,all]
8483

8584
The "editable mode" comes from the `-e` argument to `pip`, and essential just creates a symbolic link from the site-packages directory of your virtual environment to the source code in your local clone. That way any changes you make will be immediately reflected in your virtual environment.
8685

Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ WORKDIR /stage/allennlp
1717
# necessary to install the dependencies.
1818
COPY allennlp/version.py allennlp/version.py
1919
COPY setup.py .
20+
COPY requirements.txt .
21+
COPY dev-requirements.txt .
2022
RUN touch allennlp/__init__.py \
2123
&& touch README.md \
22-
&& pip install --no-cache-dir -e .
24+
&& pip install --no-cache-dir -e .[all]
2325

2426
# Now add the full package source and re-install just the package.
2527
COPY allennlp allennlp
26-
RUN pip install --no-cache-dir --no-deps -e .
28+
RUN pip install --no-cache-dir --no-deps -e .[all]
2729

2830
COPY Makefile .
2931
RUN make download-extras

Makefile

+19-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ test :
6868
--cov=$(SRC) \
6969
--cov-report=xml
7070

71+
.PHONY : test-without-checklist
72+
test-without-checklist :
73+
pytest --color=yes -v -rf --durations=40 \
74+
--cov-config=.coveragerc \
75+
--cov=$(SRC) \
76+
--cov-report=xml \
77+
--ignore-glob=*checklist*
78+
79+
.PHONY : test-checklist
80+
test-checklist :
81+
pytest --color=yes -v -rf --durations=40 \
82+
--cov-config=.coveragerc \
83+
--cov=$(SRC) \
84+
--cov-report=xml \
85+
tests/ \
86+
-k checklist
87+
88+
7189
.PHONY : gpu-tests
7290
gpu-tests : check-for-cuda
7391
pytest --color=yes -v -rf --durations=20 \
@@ -95,7 +113,7 @@ install :
95113
# python setup.py install_egg_info
96114
# Install torch ecosystem first.
97115
$(TORCH_INSTALL)
98-
pip install -e . -r dev-requirements.txt
116+
pip install -e .[dev,all]
99117
# These nltk packages are used by the 'checklist' module.
100118
$(NLTK_DOWNLOAD_CMD)
101119

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ It's recommended that you install the PyTorch ecosystem **before** installing Al
197197

198198
After that, just run `pip install allennlp`.
199199

200+
201+
200202
> ⚠️ If you're using Python 3.7 or greater, you should ensure that you don't have the PyPI version of `dataclasses` installed after running the above command, as this could cause issues on certain platforms. You can quickly check this by running `pip freeze | grep dataclasses`. If you see something like `dataclasses=0.6` in the output, then just run `pip uninstall -y dataclasses`.
201203
202204
If you need pointers on setting up an appropriate Python environment or would like to install AllenNLP using a different method, see below.
@@ -229,6 +231,13 @@ Installing the library and dependencies is simple using `pip`.
229231
pip install allennlp
230232
```
231233

234+
To install the optional dependencies, such as `checklist`, run
235+
236+
```bash
237+
pip install allennlp[checklist]
238+
```
239+
Or you can just install all optional dependencies with `pip install allennlp[all]`.
240+
232241
*Looking for bleeding edge features? You can install nightly releases directly from [pypi](https://pypi.org/project/allennlp/#history)*
233242

234243
AllenNLP installs a script when you install the python package, so you can run allennlp commands just by typing `allennlp` into a terminal. For example, you can now test your installation with `allennlp test-install`.
@@ -300,8 +309,7 @@ Create a Python 3.7 or 3.8 virtual environment, and install AllenNLP in `editabl
300309

301310
```bash
302311
pip install -U pip setuptools wheel
303-
pip install --editable .
304-
pip install -r dev-requirements.txt
312+
pip install --editable .[dev,all]
305313
```
306314

307315
This will make `allennlp` available on your system but it will use the sources from the local clone

allennlp/commands/__init__.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import sys
44
from typing import Any, Optional, Tuple, Set
5+
import warnings
56

67
from allennlp import __version__
78
from allennlp.commands.build_vocab import BuildVocab
@@ -18,10 +19,20 @@
1819
from allennlp.commands.count_instances import CountInstances
1920
from allennlp.common.plugins import import_plugins
2021
from allennlp.common.util import import_module_and_submodules
21-
from allennlp.commands.checklist import CheckList
2222

2323
logger = logging.getLogger(__name__)
2424

25+
try:
26+
"""
27+
The `allennlp checklist` command requires installation of the optional dependency `checklist`.
28+
It can be installed with `pip install allennlp[checklist]`.
29+
"""
30+
with warnings.catch_warnings():
31+
warnings.simplefilter("ignore")
32+
from allennlp.commands.checklist import CheckList
33+
except ImportError:
34+
pass
35+
2536

2637
class ArgumentParserWithDefaults(argparse.ArgumentParser):
2738
"""

allennlp/commands/checklist.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88
import argparse
99
import sys
1010
import json
11+
import logging
1112

1213

1314
from allennlp.commands.subcommand import Subcommand
1415
from allennlp.common.checks import check_for_gpu, ConfigurationError
1516
from allennlp.models.archival import load_archive
1617
from allennlp.predictors.predictor import Predictor
17-
from allennlp.confidence_checks.task_checklists.task_suite import TaskSuite
18+
19+
logger = logging.getLogger(__name__)
20+
21+
try:
22+
from allennlp.confidence_checks.task_checklists.task_suite import TaskSuite
23+
except ImportError:
24+
raise
1825

1926

2027
@Subcommand.register("checklist")
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
from allennlp.confidence_checks.task_checklists.task_suite import TaskSuite
2-
from allennlp.confidence_checks.task_checklists.sentiment_analysis_suite import (
3-
SentimentAnalysisSuite,
4-
)
5-
from allennlp.confidence_checks.task_checklists.question_answering_suite import (
6-
QuestionAnsweringSuite,
7-
)
8-
from allennlp.confidence_checks.task_checklists.textual_entailment_suite import (
9-
TextualEntailmentSuite,
10-
)
1+
import warnings
2+
3+
try:
4+
from allennlp.confidence_checks.task_checklists.task_suite import TaskSuite
5+
from allennlp.confidence_checks.task_checklists.sentiment_analysis_suite import (
6+
SentimentAnalysisSuite,
7+
)
8+
from allennlp.confidence_checks.task_checklists.question_answering_suite import (
9+
QuestionAnsweringSuite,
10+
)
11+
from allennlp.confidence_checks.task_checklists.textual_entailment_suite import (
12+
TextualEntailmentSuite,
13+
)
14+
except ImportError:
15+
warnings.warn(
16+
'To use the checklist integration you should install ``allennlp`` with the "checklist" '
17+
"extra (e.g. ``pip install allennlp[checklist]``) or just install checklist after the fact."
18+
)
19+
raise

allennlp/confidence_checks/task_checklists/task_suite.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class TaskSuite(Registrable):
2424
[Beyond Accuracy: Behavioral Testing of NLP models with CheckList (Ribeiro et al)]
2525
(https://api.semanticscholar.org/CorpusID:218551201).
2626
27+
!!! Note
28+
To use the checklist integration you should install ``allennlp`` with the
29+
"checklist" extra (e.g. ``pip install allennlp[checklist]``) or just install
30+
`checklist` after the fact.
31+
2732
Task suites are intended to be used as a form of behavioral testing
2833
for NLP models to check for robustness across several general linguistic
2934
capabilities; eg. Vocabulary, SRL, Negation, etc.

requirements.txt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
################################
2+
###### Core dependencies #######
3+
################################
4+
torch>=1.6.0,<1.11.0
5+
torchvision>=0.8.1,<0.12.0
6+
cached-path>=1.0.2,<2.0.0
7+
fairscale==0.4.5
8+
jsonnet>=0.10.0 ; sys.platform != 'win32'
9+
nltk<3.6.6
10+
spacy>=2.1.0,<3.3
11+
numpy
12+
tensorboardX>=1.2
13+
requests>=2.18
14+
tqdm>=4.62
15+
h5py
16+
scikit-learn
17+
scipy
18+
pytest
19+
transformers>=4.1,<4.17
20+
sentencepiece
21+
dataclasses;python_version<'3.7'
22+
filelock>=3.3,<3.5
23+
lmdb
24+
more-itertools
25+
termcolor==1.1.0
26+
wandb>=0.10.0,<0.13.0
27+
huggingface_hub>=0.0.16
28+
datasets>=1.2.1,<2.0
29+
dill
30+
base58
31+
sqlitedict
32+
33+
##################################################
34+
###### Extra dependencies for integrations #######
35+
##################################################
36+
# NOTE: we use a special trailing comment on each line to denote which extras
37+
# each package is needed by. For example, checklist is needed by the 'checklist' extra
38+
# that you install with 'pip install allennlp[checklist]'.
39+
checklist==0.0.11 # needed by: checklist

scripts/check_torch_version.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ def _get_latest_torch_version() -> Tuple[str, str, str]:
4545

4646

4747
def _get_torch_version_upper_limit() -> Tuple[str, str, str]:
48-
with open("setup.py") as f:
48+
with open("requirements.txt") as f:
4949
for line in f:
5050
# The torch version line should look like:
5151
# "torch>=X.Y.Z,<X.V.0",
52-
if '"torch>=' in line:
53-
version = tuple(line.split('"')[1].split("<")[1].strip().split("."))
52+
if "torch>=" in line:
53+
version = tuple(line.split("<")[1].strip().split("."))
5454
assert len(version) == 3, f"Bad parsed version '{version}'"
5555
break
5656
else:
57-
raise RuntimeError("could not find torch version spec in setup.py")
57+
raise RuntimeError("could not find torch version spec in requirements.txt")
5858
return cast(Tuple[str, str, str], version)
5959

6060

0 commit comments

Comments
 (0)