Component-level Modularity

Building a scalable modular Neural Machine Translation (mNMT) system involves considering various features to ensure flexibility, efficiency, and ease of expansion.

It implements efficient GPU allocation strategies to make the most of available hardware resources. This involves optimizing the distribution of model components across GPUs, minimizing data transfer between GPUs, and leveraging parallel processing capabilities for training.

MAMMOTH offers component-level modularity for machine translation and flexibility in designing different sharing schemes for its modules. The toolkit focuses on architectures where modular components can be defined a priori and operate as separable units to enable flexible modular configuration. Each task definition must explicitly state the sequence of modules to be used for the encoders and decoders (or “sharing groups”).

Anatomy of Parameter Sharing

The trichotomy of parameter sharing is (1) full sharing, (2) no sharing, and (3) partial sharing (or everything in between). Partial sharing includes:

The training process is organized into a series of smaller “tasks,” each of which is characterized by distinct attributes to enhance modularity and efficiency. We break down mNMT training into a series of smaller “tasks”

  • A task requires specific modules (encoder and decoder layers)

  • A task is done on a specific device or across multiple devices

  • A task corresponds to a specific (parallel) corpus

In short, a task corresponds to a specific model behavior. In translation settings, a task will therefore correspond to a specific translation direction (say translating from Swahili to Catalan): All training datapoints for this task (i) must involve the same modules (pertaining to Swahili encoding and Catalan decoding); (ii) must be preprocessed with the same tokenizers; and (iii) can be grouped into a single bitext. A centralized manager handles tasks synchronization. This manager oversees the parallel execution of tasks, coordinating the flow of information between different modules, devices, and corpora to ensure a cohesive and synchronized training process.

Flexible Modularity

Let’s break down the key aspects of modularity by design:

  1. Layerwise Parameter Sharing Schemes:

    • Fully Shared Encoder and Fully Shared Decoder: Both the encoder and decoder have shared parameters, meaning they are common across all languages or translation pairs.

    • Partially Shared Encoder / Decoder: Within each encoder or decoder, individual layers can be selectively shared or made language-specific. For example, the bottom encoder layers can be shared across languages while the top layers are language-specific, or the encoder can be fully shared while each target language gets its own decoder. Same applies to the decoders.

  2. Groupwise Sharing Schemes: MAMMOTH supports grouping languages into clusters, where languages in the same cluster share parameters: give every task in a cluster the same enc_sharing_group / dec_sharing_group id for that layer stack. You choose the clusters, using any criterion, for example:

    • Phylogenetic: Distance based on language family trees (languages sharing a common ancestry are closer).

    • Typological: Distance based on linguistic features from typological databases (e.g., word order, morphology).

    • Language Embeddings: Distance based on language representations in a shared vector space.

    See Sharing Schemes for example configurations.

Custom Model Parallelism

MAMMOTH enables scaling-up a mNMT to a (very) large number of languages. It deals with the task2gpu allocation problem as illustrated below.

task2gpu-allocation

It allows for custom model parallelism across nodes and GPUs to ensure optimal utilization of resources. Each GPU holds only the components its tasks use, and a component used on several GPUs is kept identical on all of them by summing its gradients across those GPUs after every step. The figure below illustrates the distribution of modules across multiple nodes:

multi-model-parallelism

Custom model parallelism increases parameter sharing versatility: a component can be placed on any subset of GPUs. For example:

  • Language-specific components on the GPUs whose tasks use them (e.g., EN-decoder in all GPUs)

  • Language group-specific components on the GPUs of that group (e.g., GER in GPUs 1,2&3)

Custom model parallelism increases param. sharing versatility

Custom model parallelism increases inference efficiency:

  • All modules are saved independently, allowing for streamlined loading during inference.

  • Lightweight inference is achieved by loading only the modules relevant to the translation task at hand (e.g., DE->FR).

Custom model parallelism increases inference efficiency

At training time, all gradients are exchanged in one all-reduce over all GPUs per step: each GPU packs the gradients of its components into a shared buffer (zeros for components it does not hold). A single collective avoids the hundreds of overlapping communication groups that per-component synchronization would need at scale.

In conclusion, the custom model parallelism in MAMMOTH is implemented to overcome the task-to-GPU allocation challenge, enhance parameter sharing versatility, and optimize both training and inference efficiency.