hubconf.py 842 Bytes
Newer Older
1
# Copyright (c) Facebook, Inc. and its affiliates.
Nathan Ng's avatar
Nathan Ng committed
2
#
3
4
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
Nathan Ng's avatar
Nathan Ng committed
5

Myle Ott's avatar
Myle Ott committed
6
7
import functools

Myle Ott's avatar
Myle Ott committed
8
9
from fairseq.hub_utils import BPEHubInterface as bpe  # noqa
from fairseq.hub_utils import TokenizerHubInterface as tokenizer  # noqa
Myle Ott's avatar
Myle Ott committed
10
from fairseq.models import MODEL_REGISTRY
Nathan Ng's avatar
Nathan Ng committed
11
12


Myle Ott's avatar
Myle Ott committed
13
14
dependencies = [
    'regex',
Myle Ott's avatar
Myle Ott committed
15
    'requests',
Myle Ott's avatar
Myle Ott committed
16
17
18
19
20
    'sacremoses',
    'sentencepiece',
    'subword_nmt',
    'torch',
]
Nathan Ng's avatar
Nathan Ng committed
21
22


Myle Ott's avatar
Myle Ott committed
23
for _model_type, _cls in MODEL_REGISTRY.items():
Myle Ott's avatar
Myle Ott committed
24
25
26
27
28
29
    for model_name in _cls.hub_models().keys():
        globals()[model_name] = functools.partial(
            _cls.from_pretrained,
            model_name_or_path=model_name,
        )
    # to simplify the interface we only expose named models
Myle Ott's avatar
Myle Ott committed
30
    # globals()[_model_type] = _cls.from_pretrained