Move dep checks before fairseq imports in hubconf.py (fixes #3093) (#3104)

Summary: Pull Request resolved: https://github.com/pytorch/fairseq/pull/3104

Reviewed By: alexeib

Differential Revision: D25786013

Pulled By: myleott

fbshipit-source-id: 894b104f275573ce824d7f2318d043516f0e0c5c
This commit is contained in:
Myle Ott 2021-01-05 12:13:07 -08:00 committed by Facebook GitHub Bot
parent 7e5e45b483
commit 540fb42c52

View File

@ -2,16 +2,11 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""isort:skip_file"""
import functools
import importlib
from fairseq.hub_utils import ( # noqa; noqa
BPEHubInterface as bpe,
TokenizerHubInterface as tokenizer,
)
from fairseq.models import MODEL_REGISTRY # noqa
dependencies = [
"dataclasses",
@ -40,6 +35,14 @@ if len(missing_deps) > 0:
raise RuntimeError("Missing dependencies: {}".format(", ".join(missing_deps)))
# only do fairseq imports after checking for dependencies
from fairseq.hub_utils import ( # noqa; noqa
BPEHubInterface as bpe,
TokenizerHubInterface as tokenizer,
)
from fairseq.models import MODEL_REGISTRY # noqa
# torch.hub doesn't build Cython components, so if they are not found then try
# to build them here
try: