allenai / allennlp

An open-source NLP research library, built on PyTorch.
http://www.allennlp.org
Apache License 2.0
11.76k stars 2.25k forks source link

Problems installing with conda environment #377

Closed kellywzhang closed 7 years ago

kellywzhang commented 7 years ago

I created a new python 3.6.2 conda environment. I installed pytorch and then ran INSTALL_TEST_REQUIREMENTS="true" ./scripts/install_requirements.sh.

When I tested the installation with pytest -v though I got 74 errors. I'm not sure what the problem is. Please let me know if there are any fixes / things I should do differently.

Here's a subset of the errors I got:

______________________________ ERROR collecting tests/training/metrics/span_based_f1_measure_test.py _______________________________ tests/training/metrics/span_based_f1_measure_test.py:5: in <module> from allennlp.common.testing import AllenNlpTestCase allennlp/common/testing/__init__.py:5: in <module> from allennlp.common.testing.model_test_case import ModelTestCase allennlp/common/testing/model_test_case.py:6: in <module> from allennlp.commands.train import train_model_from_file allennlp/commands/__init__.py:4: in <module> from allennlp.commands.serve import add_subparser as add_serve_subparser allennlp/commands/serve.py:27: in <module> from allennlp.service import server_sanic allennlp/service/server_sanic.py:21: in <module> from allennlp.service.predictors import Predictor allennlp/service/predictors/__init__.py:9: in <module> from .predictor import Predictor allennlp/service/predictors/predictor.py:4: in <module> from allennlp.models import Model allennlp/models/__init__.py:7: in <module> from allennlp.models.decomposable_attention import DecomposableAttention allennlp/models/decomposable_attention.py:9: in <module> from allennlp.modules import FeedForward, MatrixAttention allennlp/modules/__init__.py:12: in <module> from allennlp.modules.seq2seq_encoders import Seq2SeqEncoder allennlp/modules/seq2seq_encoders/__init__.py:72: in <module> Seq2SeqEncoder.register("gru")(_Seq2SeqWrapper(torch.nn.GRU)) allennlp/common/registrable.py:47: in add_subclass_to_registry name, cls.__name__, registry[name].__name__) E AttributeError: '_Seq2SeqWrapper' object has no attribute '__name__' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 74 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

matt-gardner commented 7 years ago

Can you give the first few lines of pylint output, where it shows version information for everything?

kellywzhang commented 7 years ago

Some errors seem related to spacy installation, which is installed and doesn't have import errors when I import it outside the test (I checked which python).

============================= test session starts ==============================
platform linux -- Python 3.6.3, pytest-3.2.3, py-1.4.34, pluggy-0.4.0 -- /home/k/.conda/envs/py36/bin/python
cachedir: .cache
rootdir: /home/k/allennlp, inifile: pytest.ini
plugins: pythonpath-0.7.1, cov-2.5.1, flaky-3.4.0
collecting ... collected 1 item / 74 errors

===Flaky Test Report===

===End Flaky Test Report===
==================================== ERRORS ====================================
___________________ ERROR collecting tests/notebooks_test.py ___________________
ImportError while importing test module '/home/k/allennlp/tests/notebooks_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/notebooks_test.py:7: in <module>
    from allennlp.common.testing import AllenNlpTestCase
allennlp/common/testing/__init__.py:5: in <module>
    from allennlp.common.testing.model_test_case import ModelTestCase
allennlp/common/testing/model_test_case.py:6: in <module>
    from allennlp.commands.train import train_model_from_file
allennlp/commands/__init__.py:4: in <module>
    from allennlp.commands.serve import add_subparser as add_serve_subparser
allennlp/commands/serve.py:27: in <module>
    from allennlp.service import server_sanic
allennlp/service/server_sanic.py:20: in <module>
    from allennlp.models.archival import load_archive
allennlp/models/__init__.py:6: in <module>
    from allennlp.models.archival import archive_model, load_archive
allennlp/models/archival.py:10: in <module>
    from allennlp.models.model import Model, _DEFAULT_WEIGHTS
allennlp/models/model.py:12: in <module>
    from allennlp.data import Instance, Vocabulary
allennlp/data/__init__.py:1: in <module>
    from allennlp.data.dataset import Dataset
allennlp/data/dataset.py:13: in <module>
    from allennlp.data.instance import Instance
allennlp/data/instance.py:3: in <module>
    from allennlp.data.fields.field import DataArray, Field
allennlp/data/fields/__init__.py:13: in <module>
    from allennlp.data.fields.text_field import TextField
allennlp/data/fields/text_field.py:9: in <module>
    from spacy.tokens import Token as SpacyToken
E   ModuleNotFoundError: No module named 'spacy.tokens'
_______________ ERROR collecting tests/commands/evaluate_test.py _______________
ImportError while importing test module '/home/k/allennlp/tests/commands/evaluate_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/commands/evaluate_test.py:6: in <module>
    from allennlp.common.testing import AllenNlpTestCase
allennlp/common/testing/__init__.py:5: in <module>
    from allennlp.common.testing.model_test_case import ModelTestCase
allennlp/common/testing/model_test_case.py:6: in <module>
    from allennlp.commands.train import train_model_from_file
allennlp/commands/__init__.py:4: in <module>
    from allennlp.commands.serve import add_subparser as add_serve_subparser
allennlp/commands/serve.py:27: in <module>
    from allennlp.service import server_sanic
allennlp/service/server_sanic.py:20: in <module>
    from allennlp.models.archival import load_archive
allennlp/models/__init__.py:6: in <module>
    from allennlp.models.archival import archive_model, load_archive
allennlp/models/archival.py:10: in <module>
    from allennlp.models.model import Model, _DEFAULT_WEIGHTS
allennlp/models/model.py:12: in <module>
    from allennlp.data import Instance, Vocabulary
allennlp/data/__init__.py:2: in <module>
    from allennlp.data.dataset_readers.dataset_reader import DatasetReader
allennlp/data/dataset_readers/__init__.py:10: in <module>
    from allennlp.data.dataset_readers.language_modeling import LanguageModelingReader
allennlp/data/dataset_readers/language_modeling.py:16: in <module>
    from allennlp.data.fields import TextField
allennlp/data/fields/__init__.py:13: in <module>
    from allennlp.data.fields.text_field import TextField
allennlp/data/fields/text_field.py:9: in <module>
    from spacy.tokens import Token as SpacyToken
E   ModuleNotFoundError: No module named 'spacy.tokens'
_________________ ERROR collecting tests/commands/main_test.py _________________
ImportError while importing test module '/home/k/allennlp/tests/commands/main_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/commands/main_test.py:4: in <module>
    from allennlp.commands import main
allennlp/commands/__init__.py:4: in <module>
    from allennlp.commands.serve import add_subparser as add_serve_subparser
allennlp/commands/serve.py:27: in <module>
    from allennlp.service import server_sanic
allennlp/service/server_sanic.py:20: in <module>
    from allennlp.models.archival import load_archive
allennlp/models/__init__.py:7: in <module>
    from allennlp.models.decomposable_attention import DecomposableAttention
allennlp/models/decomposable_attention.py:9: in <module>
    from allennlp.modules import FeedForward, MatrixAttention
allennlp/modules/__init__.py:12: in <module>
    from allennlp.modules.seq2seq_encoders import Seq2SeqEncoder
allennlp/modules/seq2seq_encoders/__init__.py:78: in <module>
    from allennlp.modules.alternating_highway_lstm import AlternatingHighwayLSTM
allennlp/modules/alternating_highway_lstm.py:10: in <module>
    from allennlp.custom_extensions._ext import highway_lstm_layer
matt-gardner commented 7 years ago

You said you created a python 3.6.2 environment, but pylint says it is running python 3.6.3. Are you sure pylint is using the right python environment?

kellywzhang commented 7 years ago

Oh sorry, my python environment is 3.6.3.

matt-gardner commented 7 years ago

Not sure what to say at this point. I'm quite sure this is an environment problem (none of us have seen this issue, and everything runs on docker just fine), but I don't know how to help you fix your environment. Sorry. Maybe someone else has some better ideas.

kellywzhang commented 7 years ago

I've now switched to using the pre-built docker image. I'm using Singularity (an alternative to Docker that's available on my compute cluster). I'm now getting the following error when I try training a bidaf model.

Any advice?

Traceback (most recent call last): File "/opt/conda/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/opt/conda/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/k/allennlp/allennlp/run.py", line 10, in <module> from allennlp.commands import main # pylint: disable=wrong-import-position File "/home/k/allennlp/allennlp/commands/__init__.py", line 4, in <module> from allennlp.commands.serve import add_subparser as add_serve_subparser File "/home/k/allennlp/allennlp/commands/serve.py", line 27, in <module> from allennlp.service import server_sanic File "/home/k/allennlp/allennlp/service/server_sanic.py", line 20, in <module> from allennlp.models.archival import load_archive File "/home/k/allennlp/allennlp/models/__init__.py", line 7, in <module> from allennlp.models.decomposable_attention import DecomposableAttention File "/home/k/allennlp/allennlp/models/decomposable_attention.py", line 9, in <module> from allennlp.modules import FeedForward, MatrixAttention File "/home/k/allennlp/allennlp/modules/__init__.py", line 12, in <module> from allennlp.modules.seq2seq_encoders import Seq2SeqEncoder File "/home/k/allennlp/allennlp/modules/seq2seq_encoders/__init__.py", line 78, in <module> from allennlp.modules.alternating_highway_lstm import AlternatingHighwayLSTM File "/home/k/allennlp/allennlp/modules/alternating_highway_lstm.py", line 10, in <module> from allennlp.custom_extensions._ext import highway_lstm_layer File "/home/k/allennlp/allennlp/custom_extensions/_ext/highway_lstm_layer/__init__.py", line 3, in <module> from ._highway_lstm_layer import lib as _lib, ffi as _ffi ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

kellywzhang commented 7 years ago

Also I only get this issue when using GPUs. CPU training works fine.

matt-gardner commented 7 years ago

@DeNeutoy, @nafitzgerald, is there some CUDA code that needs to be copied to the docker image that isn't happening correctly?

DeNeutoy commented 7 years ago

No, this seems to be a lower level issue with the cffi package which is used to build the python extensions. I also can't recreate it using docker. It seems like the python-dev package is needed for cffi extensions: https://stackoverflow.com/questions/31002091/what-is-python-dev-package-used-for

can you try running sudo apt-get install python-dev and see if that fixes it?

kellywzhang commented 7 years ago

Thanks for the quick response! I don't have sudo powers in the cluster I'm using. Do I have to install python-dev within the docker environment?

matt-gardner commented 7 years ago

Yeah, install it in the container.

kellywzhang commented 7 years ago

Hmm, it seems I need sudo permissions to use sudo within the container. I will look for a work around.

matt-gardner commented 7 years ago

I don't think you should need sudo to install things with apt-get inside a container. But, I don't know how Singularity works.

kellywzhang commented 7 years ago

Finally got this to work. Had to get my cluster manager to create a public allennlp image. Thanks for all the help!