Example #1
0
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import importlib
import os

from ncc import registry
from ncc.optim.ncc_optimizer import NccOptimizer
from ncc.optim.fp16_optimizer import FP16Optimizer, MemoryEfficientFP16Optimizer
from ncc.optim.bmuf import NccBMUF  # noqa

__all__ = [
    'NccOptimizer',
    'FP16Optimizer',
    'MemoryEfficientFP16Optimizer',
]

build_optimizer, register_optimizer, OPTIMIZER_REGISTRY = registry.setup_registry(
    'optimizer',
    base_class=NccOptimizer,
    default='nag',
)

# automatically import any Python files in the optim/ directory
for file in os.listdir(os.path.dirname(__file__)):
    if file.endswith('.py') and not file.startswith('_'):
        module = file[:file.find('.py')]
        importlib.import_module('ncc.optim.' + module)
Example #2
0
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import importlib
import os

from ncc import registry
from ncc.criterions.ncc_criterion import NccCriterion, LegacyNccCriterion

build_criterion, register_criterion, CRITERION_REGISTRY = registry.setup_registry(
    'criterion',
    base_class=NccCriterion,
    default='cross_entropy',
)

# # automatically import any Python files in the criterions/ directory
# for file in os.listdir(os.path.dirname(__file__)):
#     if file.endswith('.py') and not file.startswith('_'):
#         module = file[:file.find('.py')]
#         importlib.import_module('ncc.criterions.' + module)

criterions_dir = os.path.dirname(__file__)
for file in os.listdir(criterions_dir):
    path = os.path.join(criterions_dir, file)
    if (not file.startswith('_') and not file.startswith('.')
            and (file.endswith('.py') or os.path.isdir(path))):
        criterion_name = file[:file.find('.py')] if file.endswith(
            '.py') else file
        module = importlib.import_module('ncc.criterions.' + criterion_name)
Example #3
0
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import importlib
import os

from ncc import registry

build_tokenizer, register_tokenizer, TOKENIZER_REGISTRY = registry.setup_registry(
    'tokenizer',
    default=None,
)

build_bpe, register_bpe, BPE_REGISTRY = registry.setup_registry(
    'bpe',
    default=None,
)

# automatically import any Python files in the encoders/ directory
for file in os.listdir(os.path.dirname(__file__)):
    if file.endswith('.py') and not file.startswith('_'):
        module = file[:file.find('.py')]
        importlib.import_module('ncc.tokenizers.' + module)
Example #4
0
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import importlib
import os

from ncc import registry
from ncc.optimizers.lr_schedulers.ncc_lr_scheduler import NccLRScheduler

build_lr_scheduler, register_lr_scheduler, LR_SCHEDULER_REGISTRY = registry.setup_registry(
    'lr_scheduler',
    base_class=NccLRScheduler,
    default='fixed',
)

for file in os.listdir(os.path.dirname(__file__)):
    if file.endswith('.py') and not file.startswith('_'):
        module = file[:file.find('.py')]
        importlib.import_module('ncc.optimizers.lr_schedulers.' + module)