From 540fb42c523e98f066989c3e3b61a18caaca24f5 Mon Sep 17 00:00:00 2001 From: Myle Ott Date: Tue, 5 Jan 2021 12:13:07 -0800 Subject: [PATCH] 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 --- hubconf.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hubconf.py b/hubconf.py index 4eb6998504..5949e274ed 100644 --- a/hubconf.py +++ b/hubconf.py @@ -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 @@ 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: