Scaling Speech, Language and Vision Models with Mixture of Experts Technique

Published Apr 29 2022 03:38 PM 2,903 Views
Microsoft

Authors: Devang Patel (@devang_patel), Wei Zuo (@weizuo), Yu Shi (@yu3shi2), Kenichi Kumatani (@kekumata), Mengchen Liu (@MengchenLiu), Robert Gmyr (@rogmyr) and Kshama Pawar (@kshama-msft)

 

Introduction

Mixture of Experts technique, frequently referred to as MoE, is gaining traction in the NLP community. It is primarily used to scale Transformer models without incurring high computational resource costs. In this post, we discuss how ORT MoE, an MoE implementation from the ONNX Runtime team, is used to scale networks and improve the quality in Speech and Vision models in addition to NLP models. Automatic Speech Recognition model is able to increase quality by 16.3% and language models are able to improve sample efficiency by 10x using this technique. We will briefly describe MoE architecture first. ORT MoE features and implementation details are discussed in the second half of this post.

 

The Mixture of Expert techniques typically use subcomponents such as Experts and, Gating Functions in a Transformer block as shown in Figure 1.

 

kshamamsft_0-1651007683838.png

 

Figure 1: MoE components

 

Experts are at the heart of the Mixture of Experts technique. Usually, a standard feedforward neural network sublayer is used as an expert but that is not necessary. Fundamentally, the Mixture of Experts technique deploys many experts to increase model parameter count to achieve better model quality. However, at runtime only a small subset of these experts is used to process the given input tokens. This allows data scientists to keep FLOP budget under control while increasing the model size. A gating function is used to select a small subset of experts at runtime. Top1 or Top2 algorithms are popular choices as gating functions. MixtureOfExperts sublayer consists of the gating function, experts and the needed communication collectives to synchronize experts across multiple shards. This sublayer is the core of an MoE implementation. Finally, a Transformer layer is constructed using MixtureOfExperts sub layer and other components such as multi-headed attention layer.

 

MoE Acceleration Scenarios

We discuss scenarios where MoE improves scalability and model quality for large scale Transformer based models within Microsoft below.


Improving quality of Automatic Speech Recognition model using MoE

We are able to increase the quality of the Automatic Speech Recognition model by 16.3% by applying the MoE technique. We have used ORT MoE implementation to introduce experts layer in transformer networks for multi-lingual speech recognition tasks. To train the multi-lingual network, we used approximately 75,000 hours of data from 10 languages. The baseline network for the model consists of a Transformer encoder with 18 blocks and a decoder with 6 blocks, where each block contains 8 heads of the attention network followed by the feed-forwarding network (FFN) with pre-normalization. MoE is applied to every 2 FFN layers; see here for details.

 

The targeted scenario was to provide a teacher model to improve the accuracy of student models through semi-supervised learning such as knowledge distillation.

 

The table below shows the word error rates (WERs) obtained with the baseline and MoE networks with 24, 72 and 120 experts. The WER is shown for each language as well as the overall language, the WER averaged weighted based on the number of words. The MoE network improves recognition accuracy, and the results indicate that the MoE network is a promising approach as the teacher model. The MoE architecture reduces the computational complexity during training and inference.

 

kshamamsft_0-1651021929491.png

 

Figure 2a: Word Error Rates for the baseline and MoE networks against #experts


We have also investigated if the MoE teacher model can be compressed without loss of recognition accuracy. For this study, we have developed Teacher-Student (TS) training with Knowledge Distillation (KD). To make the student model closer to the teacher model, we initialize the student model with teacher’s weights. For initialization of student’s FFN, we select one of the teacher’s experts based on the frequency used in inference on a validation dataset. The student model is updated with KD loss and then fine-tuned with supervised learning. The details are described here. The table shows the WERs obtained with two teacher models with 24 and 72 experts as well as the student model distilled from knowledge of each teacher model. As a baseline, the table also shows the WER of the student model trained from scratch without the teacher model. It is clear from the table that TS training can provide better accuracy than the model trained from scratch whether a teacher model is small or large. It is also clear that when the teacher model is large, the student model will require more capacity to provide accuracy comparable to the teacher model.

 

kshamamsft_1-1651022026675.png

 

Figure 2b: Word Error Rates for the MoE teacher and student dense networks

 

Improving sample efficiency by 10x for a 10B parameter Language model using MoE

We evaluated MoE technique using ORT MoE implementation to research variants of language models for machine translation. Two sets of multilingual data are used which consists of 20 and 50 languages respectively. Both models have the Transformer encoder-decoder architecture. We use a base-sized model and multi-task training for 20 languages and a large-sized model and single-task (machine translation) training for 50 languages. In MoE models, MoE layers, each containing one top-1 gate and multiple feedforward experts, are injected in every other block in the Transformer stack. All non-MoE hyperparameters in the MoE models are kept the same with the corresponding dense model.

 

The baseline dense model for 20 languages has 243M parameters. Expert scaling is investigated by adding 32, 64, 128, and 256 experts separately. The obtained model sizes are 1.6B, 2.9B, 5.6B, and 11.1B parameters. Experimental results show that the more the experts the higher the BLEU score hence the better the translation quality.

 

kshamamsft_3-1651008150556.png

 

Figure 3: BLEU scores with expert scaling for 20 languages

 

In the experiment of 50 languages, the baseline dense model has 761M parameters. A 64-expert MoE model with 10.3B parameters is trained and achieves similar BLEU score at 1/10 of training steps, indicating about 10x sample efficiency compared to the non-MoE baseline.

 

kshamamsft_4-1651008186526.png

 

Figure 4: Sample efficiency of 64 experts for 50 languages

 

Improving accuracy and efficiency of a Vision Foundation Model using MoE

A foundation model in Vision is trained from broad data at scale and is capable of being adapted (e.g. fine-tuned) to a wide range of downstream tasks. Foundation models become promising due to their impressive performance and generalization capabilities. They are quickly integrated and deployed into real-world AI systems, such as image retrieval, image classification, object detection, visual question answering and action recognition. We find that ORT MoE provides an efficient approach to scale up a vision foundation model for larger capacity to effectively digest broader data.

 

Accuracy

We evaluate the model performance via a set of zero-shot classification tasks. The model is a CLIP Vision model ([2103.00020] Learning Transferable Visual Models From Natural Language Supervision (arxiv.org) ) that learns a matching between image-text-pairs. As shown in the table, with more expert, the model has a larger capacity and achieve better performance on various tasks.

 

kshamamsft_2-1651022116957.png

 

Figure 5: Evaluation results between base model and MoE models on vision tasks.

 

Sample efficiency

We further demonstrate the sample efficiency of MoE. We compare the sample efficiency between base model, MoE model with 8 and 32 experts. We can achieve around ~2X sample efficiency using ORT MoE implementation.

 

kshamamsft_0-1651076159396.png

 

 

Figure 6: Data efficiency comparison of MoE on vision task

 

ORT MoE Deep Dive

ORT MoE implementation provides a wide variety of features to support real world workloads discussed above.

  • Precision: ORT MoE’s core component MixtureOfExperts supports FP32 as well as FP16 precision. This flexible implementation enables use of mixed precision model training through external packages such as NVIDIA Apex and PyTorch Automatic Mixed Precision (AMP) support.
  • Variable Length Inputs: The MixtureOfExperts uses pair of AllToAll in each layer. Typically, standard AllToAll implementations require input tensor size to match on all ranks. ORT MoE is used in multi-lingual models where input data size on each rank could vary for each batch and for the given batch all ranks may not have same input size. To accommodate this, ORT MoE provides modified AllToAll implementation that supports variable length input tensors.
  • DistributionGrid: ORT MoE provides DistributionGrid to create and manage process groups for various distributed training configurations considering underlying cluster topology. The DistributionGrid takes the number of ranks available for the given distribution strategy as an input and handles the complexity of creating and placing torch.distributed process groups.

 

 

#Create standard data parallel grid where each rank holds entire copy of the model.
dgrid = DistributionGrid(data_parallel_group_size = <no_of_ranks_available>)

#Create expert parallel grid where experts are evenly distributed among available ranks.
dgrid = DistributionGrid(expert_parallel_group_size = <no_of_ranks_available>)

 

 

  • Checkpointing: The DistributionGrid also provides an interface to map experts for checkpoint saving and loading. Based on this interface, utility functions are provided to query and translate model state dictionary. The utilities are robust to translate parameter mapping from one model distribution strategy to other while hiding complexity of expert parameter placement from data scientists.
  • Loss Functions: ORT MoE provides multiple loss functions for flexible MoE experimentation. The `load_balancing_loss` is the auxiliary loss defined in the Switch Transformers paper to seek uniform routing of the batch of samples across the experts. The `sparsity_l1_loss` and `mean_importance_loss` are introduced in the SpeechMoE paper. The former encourages the sparsity of router activation while the latter leads to a balanced routing strategy. The `z_loss` belongs to the spherical loss family in multi-class classification and is proposed in this paper. In ORT MoE, it is a variant of the original z-loss following Google’s TensorFlow MoE. The `ideal_load_balancing_loss` is a straight through estimator of the ideal load balance which is not differentiable.
  • Gating Utilities: ORT MoE also provides gating utilities for balancing exploration. For top-1 gating, `switch_jitter` will add multiplicative jitter noise on the incoming representations. `switch_dropout` will add input dropout on the incoming representations. For both top-1 and top-2 gating, `logits_gumbel` uses Gumbel-max trick to sample from the softmax distribution. `token_drop_type` includes 3 methods for sample dropping when the expert capacity is not enough: `cut` means cut the sequence tail, `random` means random sampling, and `routing_weight` means dropping samples according to the routing weights. For top-2 gating, a 2nd-place loss can be added by specifying the ratio using ` second_place_loss_ratio`.
  • Gate Metrics: To help interpret and visualize the gate and expert behavior, ORT MOE provides some useful gate metrics for logging. `gate_entropy` computes the average entropy of the router probability distribution. `gate_probability` computes the average probability of the selected expert over all samples. This is a good metric to monitor expert specialty. `gate_routed` computes the fraction of samples being routed. This usually indicates how difficult the expert loads can be balanced over the given samples for a proper capacity factor or whether the capacity is not big enough. Per-layer values of these metrics can be obtained by using utility function get_moe_loss() and setting layer_level=True. There are also two metrics for expert usage. `expert_fraction` indicates the fraction of samples dispatched to each expert before applying capacity constraint. `expert_routed_fraction` indicates the fraction of routed samples to each expert for computation.
  • Base Layer Routing: A new balanced routing of experts to improve quality of large MoE models as described in BASE Layers paper.

 

ORT MoE Performance Improvements

We have employed various techniques to improve computational efficiency and reduce memory consumption of MoE models. These techniques increase training throughput and batch size. We introduce three major techniques here, Sparse to dense mask in gating function, Fast Gating Indexing algorithm, and Merged Experts.

  • In MoE implementations the matrix used to store routing information has the size of O(S^2) where S is the token length. ORT MoE implements a dense matrix of size O(S) to record routing efficiency which allowed 29.49% throughput increase in Vision models.
  • ORT MoE uses a sorting-based algorithm, instead a typical cumulative sum operator, to implement fast indexing in the gating function. The new algorithm increases throughput by 42.17%.
  • In a typical expert module there are two matrix-multiplication (MM) kernels separated by an activation function. In scenarios, where multiple experts are placed on a single GPU, each expert module is instantiated sequentially in a loop. This increases kernel launch overhead and GPU utilization remains low for smaller expert sizes. Since all expert computations are independent of each other they could be executed in parallel. ORT MoE implements MergedFFNExpert which uses batched GEMM, instead of MM, to execute multiple expert computations in a single kernel launch. Merged experts improves throughput by 53.87% for Vision models.

kshamamsft_7-1651008766845.png

 

Figure 7: ORT MoE performance improvement on the CLIP Vision model (NDV4 cluster)

 

  • ORT MoE integrates with Tutel computation optimization features and provides user an option to take advantage of Tutel.

 

Distribution Strategies supported by ORT MoE

Unlike the traditional transformer structure (or neural network), the routing logic of MoE breaks the locality of input tokens: instead of being only consumed by a single or a small set of GPUs (e.g., model parallelism), the tokens on each GPU are routed globally to experts on other GPUs. This gives flexibility to how we distribute the experts and provides opportunities to explore distribution strategies with different communication patterns and the associated trade-offs. As different workloads may require different distributions for best performance, it is important to support a rich set of distribution strategies. In this section we discuss some of the distribution strategies we used with ORT MoE.

 

Expert Parallelism (EP):

In this scheme, experts are evenly divided across ranks. Alltoall collectives are inserted before and after experts to route the input and output tokens to the correct position, according to the gating function. The non-expert parameters are replicated across ranks and synchronized using AllReduction collective. This is the distribution strategy that was introduced in the GShard paper.

 

This distribution enables a simple and good load-balanced distribution of MoE and has been widely used in different models. In this distribution, the performance of Alltoall is one critical factor of the throughput.

 

kshamamsft_8-1651008821024.png

 

Figure 8: Expert Parallelism as described in Gshard paper

 

Data scientists have deployed multiple replicas of Expert Parallel distribution, known as Expert Parallel Replica, to increase training throughput when larger number of GPUs are available. Under this strategy, like traditional data parallel training, experts from each EP replica are synchronized by additional AllReduce collective.

 

Expert Slicing:

A few drawbacks of EP are: (1) to maintain the load-balance, the number of experts must be larger and dividable by the number of GPUs. (2) Padding of the tokens may needed, when the number of tokens routed to an expert is fewer than the expert capacity, which incurs waste of memory and computation. (3) Each expert has a capacity of number of tokens taking in, which results in tokens exceeding the capacity are dropped, and affects the learning efficiency.

 

To avoid these drawbacks, we provide another distribution technique, called expert slicing. Here each expert is evenly sharded across the number of GPUs. An all-gather is used to collect inputs from all ranks to each rank, and an allreduce is used after the experts to compute the output correctly. Then each rank uses a narrow-like operation to select the outputs belonging to itself. Note, since each rank has all inputs before the gating, a global loss computation and routing decision is made, which increases the learning efficiency. Since each rank computes partial results of all experts, there is no token dropping, nor padding is needed. However, there is a memory tradeoff: each rank is taking inputs from all ranks, which increases the size of activation.

 

Model scaling with ORT MoE

One essential promise of MoE is that the model size scales with the number of GPUs used, while keeping the parameter size, computation, and memory consumption per GPU constant. Ideally, we would like the model to scale as a linear function of the number of GPUs. However, due to additional communication cost (which also increases with the number of GPUs), only sublinear scaling may be feasible today.

 

To evaluate the scalability of our ORT MoE implementation, we deployed the CLIP Vision MoE model discussed above using CC2M dataset on 1 to 64 GPUs, and 128 GPUs, on Azure NDv4 cluster ( https://docs.microsoft.com/en-us/azure/virtual-machines/nda100-v4-series ), using expert parallelism. For each setting, we keep the model size per GPU constant, and scale up the number of experts along with the number of GPUs.

 

kshamamsft_9-1651008878621.png

 

Figure 9: Scaling Result

 

kshamamsft_10-1651008921528.png

 

Figure 10: Model size for each data point

 

Figure 9 records the scaling result. The x-axis is the number of nodes used; y-axis is the throughput. The orange line represents “perfect scaling”, which is computed as the product of the throughput of model on a single node and the number of nodes used. It is linear scaling. The blue line is the actual throughput. Figure 10 records the model size for each data point, where we can see we are scaling the parameter size almost linearly.

 

From the result we can see that the MoE model maintains good scalability: on 128 GPUs, it preserves 65% of the theoretical value. One reason is the Azure NDv4 cluster provides high-bandwidth cross node network (InfiniBand: Supported, GPUDirect RDMA, 8 x 200 Gigabit HDR). We do observe that an increase in the number of nodes increases the gap between the actual and theoretical throughput. This is expected, since the communication cost is bigger.

 

ZeRO integration

ZeRO technique enables data scientists to scale PyTorch models efficiently by providing memory savings. DeepSpeed ZeRO and FairScale FSDP are some of the common independent implementations of the ZeRO technique. ZeRO techniques can be applied on an MoE model that is using ORT MoE. ZeRO technique reduces memory consumption which could enable data scientists to increase batch size. We were able to increase batch size of a CLIP model by applying ZeRO using Fairscale FSDP implementation. Figure 11 shows the result. We applied FSDP on 2 replicas of CLIP Vision model running on 8 GPUs. In this configuration expert parameters are sharded in two partitions and non-expert parameters are sharded in eight partitions. When at batch 36, with FSDP, it uses 36% less peak memory. Without FSDP, the max batch size per gpu can reach 36, while with FSDP, it increases to 48.

 

kshamamsft_11-1651008974582.png

 

Figure 11 : ZeRO helps improve batch size for the CLIP Model

 

Ongoing Effort

 

Training on AMD GPUs

We are able to train same CLIP Vision MoE model configuration on NVIDIA A100 GPUs as well as AMD MI100 GPUs. We are able to improve model accuracy and efficiency using ORT MoE on both platforms.

 

ORTModule integration

We have implemented MixtureOfExperts as a standard torch.nn.module. The implementation allows seamless integration with PyTorch packages. ORTModule provides performance boost to standard PyTorch modules. ORT MoE could be simply wrapped inside ORTModule to gain the performance boost while constructing the model. A model could be entirely wrapped inside ORTModule also. See ORTModule documentation for more information.

 

 

dgrid = DistributionGrid(expert_parallel_group_size = dist.get_world_size())
encoder = TransformerMoEEncoderLayer(256, 4, nexperts=8, distribution_grid = dgrid)
encoder = ORTModule(encoder)

 

 

Looking Forward

We are able to scale various language, speech and vision models using the Mixture Of Experts technique by incorporating ORT MoE. We will continue to optimize the ORT MoE implementation to improve training throughput and explore new distribution strategies. This will enable data scientists scale models to further improve the quality of the services built upon these models. We invite data scientists to explore the MoE technique using the flexible ORT MoE implementation here.

%3CLINGO-SUB%20id%3D%22lingo-sub-3295750%22%20slang%3D%22en-US%22%3EScaling%20Speech%2C%20Language%20and%20Vision%20Models%20with%20Mixture%20of%20Experts%20Technique%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3295750%22%20slang%3D%22en-US%22%3E%3CP%3E%3CEM%3EAuthors%3A%20Devang%20Patel%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1373992%22%20target%3D%22_blank%22%3E%40devang_patel%3C%2FA%3E)%2C%20Wei%20Zuo%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1374096%22%20target%3D%22_blank%22%3E%40weizuo%3C%2FA%3E)%2C%20Yu%20Shi%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1373978%22%20target%3D%22_blank%22%3E%40yu3shi2%3C%2FA%3E)%2C%20Kenichi%20Kumatani%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1373955%22%20target%3D%22_blank%22%3E%40kekumata%3C%2FA%3E)%2C%20Mengchen%20Liu%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1374016%22%20target%3D%22_blank%22%3E%40MengchenLiu%3C%2FA%3E)%2C%20Robert%20Gmyr%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1374098%22%20target%3D%22_blank%22%3E%40rogmyr%3C%2FA%3E)%20and%20Kshama%20Pawar%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1099824%22%20target%3D%22_blank%22%3E%40kshama-msft%3C%2FA%3E)%3C%2FEM%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-395637655%22%20id%3D%22toc-hId-416785490%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1411816808%22%20id%3D%22toc-hId--1390668973%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EMixture%20of%20Experts%20technique%2C%20frequently%20referred%20to%20as%20MoE%2C%20is%20gaining%20traction%20in%20the%20NLP%20community.%20It%20is%20primarily%20used%20to%20scale%20Transformer%20models%20without%20incurring%20high%20computational%20resource%20costs.%20In%20this%20post%2C%20we%20discuss%20how%20ORT%20MoE%2C%20an%20MoE%20implementation%20from%20the%20ONNX%20Runtime%20team%2C%20is%20used%20to%20scale%20networks%20and%20improve%20the%20quality%20in%20Speech%20and%20Vision%20models%20in%20addition%20to%20NLP%20models.%20Automatic%20Speech%20Recognition%20model%20is%20able%20to%20increase%20quality%20by%2016.3%25%20and%20language%20models%20are%20able%20to%20improve%20sample%20efficiency%20by%2010x%20using%20this%20technique.%20We%20will%20briefly%20describe%20MoE%20architecture%20first.%20ORT%20MoE%20features%20and%20implementation%20details%20are%20discussed%20in%20the%20second%20half%20of%20this%20post.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Mixture%20of%20Expert%20techniques%20typically%20use%20subcomponents%20such%20as%20Experts%20and%2C%20Gating%20Functions%20in%20a%20Transformer%20block%20as%20shown%20in%20Figure%201.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_0-1651007683838.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367057i31244F8F47F5008D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_0-1651007683838.png%22%20alt%3D%22kshamamsft_0-1651007683838.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%201%3A%20MoE%20components%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExperts%20are%20at%20the%20heart%20of%20the%20Mixture%20of%20Experts%20technique.%20Usually%2C%20a%20standard%20feedforward%20neural%20network%20sublayer%20is%20used%20as%20an%20expert%20but%20that%20is%20not%20necessary.%20Fundamentally%2C%20the%20Mixture%20of%20Experts%20technique%20deploys%20many%20experts%20to%20increase%20model%20parameter%20count%20to%20achieve%20better%20model%20quality.%20However%2C%20at%20runtime%20only%20a%20small%20subset%20of%20these%20experts%20is%20used%20to%20process%20the%20given%20input%20tokens.%20This%20allows%20data%20scientists%20to%20keep%20FLOP%20budget%20under%20control%20while%20increasing%20the%20model%20size.%20A%20gating%20function%20is%20used%20to%20select%20a%20small%20subset%20of%20experts%20at%20runtime.%20Top1%20or%20Top2%20algorithms%20are%20popular%20choices%20as%20gating%20functions.%20MixtureOfExperts%20sublayer%20consists%20of%20the%20gating%20function%2C%20experts%20and%20the%20needed%20communication%20collectives%20to%20synchronize%20experts%20across%20multiple%20shards.%20This%20sublayer%20is%20the%20core%20of%20an%20MoE%20implementation.%20Finally%2C%20a%20Transformer%20layer%20is%20constructed%20using%20MixtureOfExperts%20sub%20layer%20and%20other%20components%20such%20as%20multi-headed%20attention%20layer.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1075696025%22%20id%3D%22toc-hId-1096843860%22%3EMoE%20Acceleration%20Scenarios%3C%2FH2%3E%0A%3CP%3EWe%20discuss%20scenarios%20where%20MoE%20improves%20scalability%20and%20model%20quality%20for%20large%20scale%20Transformer%20based%20models%20within%20Microsoft%20below.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1766257499%22%20id%3D%22toc-hId-1787405334%22%3E%3CBR%20%2F%3EImproving%20quality%20of%20Automatic%20Speech%20Recognition%20model%20using%20MoE%3C%2FH3%3E%0A%3CP%3EWe%20are%20able%20to%20increase%20the%20quality%20of%20the%20Automatic%20Speech%20Recognition%20model%20by%2016.3%25%20by%20applying%20the%20MoE%20technique.%20We%20have%20used%20ORT%20MoE%20implementation%20to%20introduce%20experts%20layer%20in%20transformer%20networks%20for%20multi-lingual%20speech%20recognition%20tasks.%20To%20train%20the%20multi-lingual%20network%2C%20we%20used%20approximately%2075%2C000%20hours%20of%20data%20from%2010%20languages.%20The%20baseline%20network%20for%20the%20model%20consists%20of%20a%20Transformer%20encoder%20with%2018%20blocks%20and%20a%20decoder%20with%206%20blocks%2C%20where%20each%20block%20contains%208%20heads%20of%20the%20attention%20network%20followed%20by%20the%20feed-forwarding%20network%20(FFN)%20with%20pre-normalization.%20MoE%20is%20applied%20to%20every%202%20FFN%20layers%3B%20see%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fabs%2F2112.05820%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20for%20details.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20targeted%20scenario%20was%20to%20provide%20a%20teacher%20model%20to%20improve%20the%20accuracy%20of%20student%20models%20through%20semi-supervised%20learning%20such%20as%20knowledge%20distillation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20table%20below%20shows%20the%20word%20error%20rates%20(WERs)%20obtained%20with%20the%20baseline%20and%20MoE%20networks%20with%2024%2C%2072%20and%20120%20experts.%20The%20WER%20is%20shown%20for%20each%20language%20as%20well%20as%20the%20overall%20language%2C%20the%20WER%20averaged%20weighted%20based%20on%20the%20number%20of%20words.%20The%20MoE%20network%20improves%20recognition%20accuracy%2C%20and%20the%20results%20indicate%20that%20the%20MoE%20network%20is%20a%20promising%20approach%20as%20the%20teacher%20model.%20The%20MoE%20architecture%20reduces%20the%20computational%20complexity%20during%20training%20and%20inference.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_0-1651021929491.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367103i998C274C3184360C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_0-1651021929491.png%22%20alt%3D%22kshamamsft_0-1651021929491.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%202a%3A%20Word%20Error%20Rates%20for%20the%20baseline%20and%20MoE%20networks%20against%20%23experts%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EWe%20have%20also%20investigated%20if%20the%20MoE%20teacher%20model%20can%20be%20compressed%20without%20loss%20of%20recognition%20accuracy.%20For%20this%20study%2C%20we%20have%20developed%20Teacher-Student%20(TS)%20training%20with%20Knowledge%20Distillation%20(KD).%20To%20make%20the%20student%20model%20closer%20to%20the%20teacher%20model%2C%20we%20initialize%20the%20student%20model%20with%20teacher%E2%80%99s%20weights.%20For%20initialization%20of%20student%E2%80%99s%20FFN%2C%20we%20select%20one%20of%20the%20teacher%E2%80%99s%20experts%20based%20on%20the%20frequency%20used%20in%20inference%20on%20a%20validation%20dataset.%20The%20student%20model%20is%20updated%20with%20KD%20loss%20and%20then%20fine-tuned%20with%20supervised%20learning.%20The%20details%20are%20described%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fpublication%2Fknowledge-distillation-for-mixture-of-experts-models-in-speech-recognition%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20The%20table%20shows%20the%20WERs%20obtained%20with%20two%20teacher%20models%20with%2024%20and%2072%20experts%20as%20well%20as%20the%20student%20model%20distilled%20from%20knowledge%20of%20each%20teacher%20model.%20As%20a%20baseline%2C%20the%20table%20also%20shows%20the%20WER%20of%20the%20student%20model%20trained%20from%20scratch%20without%20the%20teacher%20model.%20It%20is%20clear%20from%20the%20table%20that%20TS%20training%20can%20provide%20better%20accuracy%20than%20the%20model%20trained%20from%20scratch%20whether%20a%20teacher%20model%20is%20small%20or%20large.%20It%20is%20also%20clear%20that%20when%20the%20teacher%20model%20is%20large%2C%20the%20student%20model%20will%20require%20more%20capacity%20to%20provide%20accuracy%20comparable%20to%20the%20teacher%20model.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_1-1651022026675.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367104i2C6CB4F536B97B44%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_1-1651022026675.png%22%20alt%3D%22kshamamsft_1-1651022026675.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%202b%3A%20Word%20Error%20Rates%20for%20the%20MoE%20teacher%20and%20student%20dense%20networks%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--41196964%22%20id%3D%22toc-hId--20049129%22%3EImproving%20sample%20efficiency%20by%2010x%20for%20a%2010B%20parameter%20Language%20model%20using%20MoE%3C%2FH3%3E%0A%3CP%3EWe%20evaluated%20MoE%20technique%20using%20ORT%20MoE%20implementation%20to%20research%20variants%20of%20language%20models%20for%20machine%20translation.%20Two%20sets%20of%20multilingual%20data%20are%20used%20which%20consists%20of%2020%20and%2050%20languages%20respectively.%20Both%20models%20have%20the%20Transformer%20encoder-decoder%20architecture.%20We%20use%20a%20base-sized%20model%20and%20multi-task%20training%20for%2020%20languages%20and%20a%20large-sized%20model%20and%20single-task%20(machine%20translation)%20training%20for%2050%20languages.%20In%20MoE%20models%2C%20MoE%20layers%2C%20each%20containing%20one%20top-1%20gate%20and%20multiple%20feedforward%20experts%2C%20are%20injected%20in%20every%20other%20block%20in%20the%20Transformer%20stack.%20All%20non-MoE%20hyperparameters%20in%20the%20MoE%20models%20are%20kept%20the%20same%20with%20the%20corresponding%20dense%20model.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20baseline%20dense%20model%20for%2020%20languages%20has%20243M%20parameters.%20Expert%20scaling%20is%20investigated%20by%20adding%2032%2C%2064%2C%20128%2C%20and%20256%20experts%20separately.%20The%20obtained%20model%20sizes%20are%201.6B%2C%202.9B%2C%205.6B%2C%20and%2011.1B%20parameters.%20Experimental%20results%20show%20that%20the%20more%20the%20experts%20the%20higher%20the%20BLEU%20score%20hence%20the%20better%20the%20translation%20quality.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_3-1651008150556.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367062iBF1CCF5AC1528822%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_3-1651008150556.png%22%20alt%3D%22kshamamsft_3-1651008150556.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%20%3A%20left%3B%20%22%3EFigure%203%3A%20BLEU%20scores%20with%20expert%20scaling%20for%2020%20languages%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20experiment%20of%2050%20languages%2C%20the%20baseline%20dense%20model%20has%20761M%20parameters.%20A%2064-expert%20MoE%20model%20with%2010.3B%20parameters%20is%20trained%20and%20achieves%20similar%20BLEU%20score%20at%201%2F10%20of%20training%20steps%2C%20indicating%20about%2010x%20sample%20efficiency%20compared%20to%20the%20non-MoE%20baseline.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_4-1651008186526.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367063i6EE7BD6B8F56EBF7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_4-1651008186526.png%22%20alt%3D%22kshamamsft_4-1651008186526.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%20%3A%20left%3B%20%22%3EFigure%204%3A%26nbsp%3BSample%20efficiency%20of%2064%20experts%20for%2050%20languages%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1848651427%22%20id%3D%22toc-hId--1827503592%22%3EImproving%20accuracy%20and%20efficiency%20of%20a%20Vision%20Foundation%20Model%20using%20MoE%3C%2FH3%3E%0A%3CP%3EA%20foundation%20model%20in%20Vision%20is%20trained%20from%20broad%20data%20at%20scale%20and%20is%20capable%20of%20being%20adapted%20(e.g.%20fine-tuned)%20to%20a%20wide%20range%20of%20downstream%20tasks.%20Foundation%20models%20become%20promising%20due%20to%20their%20impressive%20performance%20and%20generalization%20capabilities.%20They%20are%20quickly%20integrated%20and%20deployed%20into%20real-world%20AI%20systems%2C%20such%20as%20image%20retrieval%2C%20image%20classification%2C%20object%20detection%2C%20visual%20question%20answering%20and%20action%20recognition.%20We%20find%20that%20ORT%20MoE%20provides%20an%20efficient%20approach%20to%20scale%20up%20a%20vision%20foundation%20model%20for%20larger%20capacity%20to%20effectively%20digest%20broader%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1158089953%22%20id%3D%22toc-hId--1136942118%22%3EAccuracy%3C%2FH4%3E%0A%3CP%3EWe%20evaluate%20the%20model%20performance%20via%20a%20set%20of%20zero-shot%20classification%20tasks.%20The%20model%20is%20a%20CLIP%20Vision%20model%20(%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fabs%2F2103.00020%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%5B2103.00020%5D%20Learning%20Transferable%20Visual%20Models%20From%20Natural%20Language%20Supervision%20(arxiv.org)%3C%2FA%3E%20)%20that%20learns%20a%20matching%20between%20image-text-pairs.%20As%20shown%20in%20the%20table%2C%20with%20more%20expert%2C%20the%20model%20has%20a%20larger%20capacity%20and%20achieve%20better%20performance%20on%20various%20tasks.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_2-1651022116957.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367105iE8BD9657A72C3A5C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_2-1651022116957.png%22%20alt%3D%22kshamamsft_2-1651022116957.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%205%3A%20Evaluation%20results%20between%20base%20model%20and%20MoE%20models%20on%20vision%20tasks.%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1329422880%22%20id%3D%22toc-hId-1350570715%22%3ESample%20efficiency%3C%2FH4%3E%0A%3CP%3EWe%20further%20demonstrate%20the%20sample%20efficiency%20of%20MoE.%20We%20compare%20the%20sample%20efficiency%20between%20base%20model%2C%20MoE%20model%20with%208%20and%2032%20experts.%20We%20can%20achieve%20around%20~2X%20sample%20efficiency%20using%20ORT%20MoE%20implementation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_0-1651076159396.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367363iD34B7775CEFDCFDB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_0-1651076159396.png%22%20alt%3D%22kshamamsft_0-1651076159396.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%206%3A%20Data%20efficiency%20comparison%20of%20MoE%20on%20vision%20task%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1179096161%22%20id%3D%22toc-hId--1157948326%22%3EORT%20MoE%20Deep%20Dive%3C%2FH2%3E%0A%3CP%3EORT%20MoE%20implementation%20provides%20a%20wide%20variety%20of%20features%20to%20support%20real%20world%20workloads%20discussed%20above.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EPrecision%3A%3C%2FSTRONG%3E%20ORT%20MoE%E2%80%99s%20core%20component%20MixtureOfExperts%20supports%20FP32%20as%20well%20as%20FP16%20precision.%20This%20flexible%20implementation%20enables%20use%20of%20mixed%20precision%20model%20training%20through%20external%20packages%20such%20as%20NVIDIA%20Apex%20and%20PyTorch%20Automatic%20Mixed%20Precision%20(AMP)%20support.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EVariable%20Length%20Inputs%3A%3C%2FSTRONG%3E%20The%20MixtureOfExperts%20uses%20pair%20of%20AllToAll%20in%20each%20layer.%20Typically%2C%20standard%20AllToAll%20implementations%20require%20input%20tensor%20size%20to%20match%20on%20all%20ranks.%20ORT%20MoE%20is%20used%20in%20multi-lingual%20models%20where%20input%20data%20size%20on%20each%20rank%20could%20vary%20for%20each%20batch%20and%20for%20the%20given%20batch%20all%20ranks%20may%20not%20have%20same%20input%20size.%20To%20accommodate%20this%2C%20ORT%20MoE%20provides%20modified%20AllToAll%20implementation%20that%20supports%20variable%20length%20input%20tensors.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EDistributionGrid%3A%3C%2FSTRONG%3E%20ORT%20MoE%20provides%20DistributionGrid%20to%20create%20and%20manage%20process%20groups%20for%20various%20distributed%20training%20configurations%20considering%20underlying%20cluster%20topology.%20The%20DistributionGrid%20takes%20the%20number%20of%20ranks%20available%20for%20the%20given%20distribution%20strategy%20as%20an%20input%20and%20handles%20the%20complexity%20of%20creating%20and%20placing%20torch.distributed%20process%20groups.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3E%23Create%20standard%20data%20parallel%20grid%20where%20each%20rank%20holds%20entire%20copy%20of%20the%20model.%0Adgrid%20%3D%20DistributionGrid(data_parallel_group_size%20%3D%20%3CNO_OF_RANKS_AVAILABLE%3E)%0A%0A%23Create%20expert%20parallel%20grid%20where%20experts%20are%20evenly%20distributed%20among%20available%20ranks.%0Adgrid%20%3D%20DistributionGrid(expert_parallel_group_size%20%3D%20%3CNO_OF_RANKS_AVAILABLE%3E)%0A%3C%2FNO_OF_RANKS_AVAILABLE%3E%3C%2FNO_OF_RANKS_AVAILABLE%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ECheckpointing%3A%3C%2FSTRONG%3E%20The%20DistributionGrid%20also%20provides%20an%20interface%20to%20map%20experts%20for%20checkpoint%20saving%20and%20loading.%20Based%20on%20this%20interface%2C%20utility%20functions%20are%20provided%20to%20query%20and%20translate%20model%20state%20dictionary.%20The%20utilities%20are%20robust%20to%20translate%20parameter%20mapping%20from%20one%20model%20distribution%20strategy%20to%20other%20while%20hiding%20complexity%20of%20expert%20parameter%20placement%20from%20data%20scientists.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ELoss%20Functions%3A%3C%2FSTRONG%3E%20ORT%20MoE%20provides%20multiple%20loss%20functions%20for%20flexible%20MoE%20experimentation.%20The%20%60load_balancing_loss%60%20is%20the%20auxiliary%20loss%20defined%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fabs%2F2101.03961%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ESwitch%20Transformers%20paper%3C%2FA%3E%20to%20seek%20uniform%20routing%20of%20the%20batch%20of%20samples%20across%20the%20experts.%20The%20%60sparsity_l1_loss%60%20and%20%60mean_importance_loss%60%20are%20introduced%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fabs%2F2105.03036%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ESpeechMoE%20paper%3C%2FA%3E.%20The%20former%20encourages%20the%20sparsity%20of%20router%20activation%20while%20the%20latter%20leads%20to%20a%20balanced%20routing%20strategy.%20The%20%60z_loss%60%20belongs%20to%20the%20spherical%20loss%20family%20in%20multi-class%20classification%20and%20is%20proposed%20in%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fabs%2F1604.08859%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ethis%3C%2FA%3E%20paper.%20In%20ORT%20MoE%2C%20it%20is%20a%20variant%20of%20the%20original%20z-loss%20following%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftensorflow%2Fmesh%2Fblob%2Fa54f5cf75ef44d8a97190b3e5aaec176c138b3c0%2Fmesh_tensorflow%2Ftransformer%2Fmoe.py%23L1258%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EGoogle%E2%80%99s%20TensorFlow%20MoE%3C%2FA%3E.%20The%20%60ideal_load_balancing_loss%60%20is%20a%20straight%20through%20estimator%20of%20the%20ideal%20load%20balance%20which%20is%20not%20differentiable.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EGating%20Utilities%3A%3C%2FSTRONG%3E%20ORT%20MoE%20also%20provides%20gating%20utilities%20for%20balancing%20exploration.%20For%20top-1%20gating%2C%20%60switch_jitter%60%20will%20add%20multiplicative%20jitter%20noise%20on%20the%20incoming%20representations.%20%60switch_dropout%60%20will%20add%20input%20dropout%20on%20the%20incoming%20representations.%20For%20both%20top-1%20and%20top-2%20gating%2C%20%60logits_gumbel%60%20uses%20Gumbel-max%20trick%20to%20sample%20from%20the%20softmax%20distribution.%20%60token_drop_type%60%20includes%203%20methods%20for%20sample%20dropping%20when%20the%20expert%20capacity%20is%20not%20enough%3A%20%60cut%60%20means%20cut%20the%20sequence%20tail%2C%20%60random%60%20means%20random%20sampling%2C%20and%20%60routing_weight%60%20means%20dropping%20samples%20according%20to%20the%20routing%20weights.%20For%20top-2%20gating%2C%20a%202nd-place%20loss%20can%20be%20added%20by%20specifying%20the%20ratio%20using%20%60%20second_place_loss_ratio%60.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EGate%20Metrics%3A%3C%2FSTRONG%3E%20To%20help%20interpret%20and%20visualize%20the%20gate%20and%20expert%20behavior%2C%20ORT%20MOE%20provides%20some%20useful%20gate%20metrics%20for%20logging.%20%60gate_entropy%60%20computes%20the%20average%20entropy%20of%20the%20router%20probability%20distribution.%20%60gate_probability%60%20computes%20the%20average%20probability%20of%20the%20selected%20expert%20over%20all%20samples.%20This%20is%20a%20good%20metric%20to%20monitor%20expert%20specialty.%20%60gate_routed%60%20computes%20the%20fraction%20of%20samples%20being%20routed.%20This%20usually%20indicates%20how%20difficult%20the%20expert%20loads%20can%20be%20balanced%20over%20the%20given%20samples%20for%20a%20proper%20capacity%20factor%20or%20whether%20the%20capacity%20is%20not%20big%20enough.%20Per-layer%20values%20of%20these%20metrics%20can%20be%20obtained%20by%20using%20utility%20function%20get_moe_loss()%20and%20setting%20layer_level%3DTrue.%20There%20are%20also%20two%20metrics%20for%20expert%20usage.%20%60expert_fraction%60%20indicates%20the%20fraction%20of%20samples%20dispatched%20to%20each%20expert%20before%20applying%20capacity%20constraint.%20%60expert_routed_fraction%60%20indicates%20the%20fraction%20of%20routed%20samples%20to%20each%20expert%20for%20computation.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EBase%20Layer%20Routing%3A%3C%2FSTRONG%3E%20A%20new%20balanced%20routing%20of%20experts%20to%20improve%20quality%20of%20large%20MoE%20models%20as%20described%20in%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fpdf%2F2103.16716.pdf%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EBASE%20Layers%20paper%3C%2FA%3E.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId--488534687%22%20id%3D%22toc-hId--467386852%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-1303814667%22%20id%3D%22toc-hId-1324962502%22%3EORT%20MoE%20Performance%20Improvements%3C%2FH3%3E%0A%3CP%3EWe%20have%20employed%20various%20techniques%20to%20improve%20computational%20efficiency%20and%20reduce%20memory%20consumption%20of%20MoE%20models.%20These%20techniques%20increase%20training%20throughput%20and%20batch%20size.%20We%20introduce%20three%20major%20techniques%20here%2C%20Sparse%20to%20dense%20mask%20in%20gating%20function%2C%20Fast%20Gating%20Indexing%20algorithm%2C%20and%20Merged%20Experts.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20MoE%20implementations%20the%20matrix%20used%20to%20store%20routing%20information%20has%20the%20size%20of%20O(S%5E2)%20where%20S%20is%20the%20token%20length.%20ORT%20MoE%20implements%20a%20dense%20matrix%20of%20size%20O(S)%20to%20record%20routing%20efficiency%20which%20allowed%2029.49%25%20throughput%20increase%20in%20Vision%20models.%3C%2FLI%3E%0A%3CLI%3EORT%20MoE%20uses%20a%20sorting-based%20algorithm%2C%20instead%20a%20typical%20cumulative%20sum%20operator%2C%20to%20implement%20fast%20indexing%20in%20the%20gating%20function.%20The%20new%20algorithm%20increases%20throughput%20by%2042.17%25.%3C%2FLI%3E%0A%3CLI%3EIn%20a%20typical%20expert%20module%20there%20are%20two%20matrix-multiplication%20(MM)%20kernels%20separated%20by%20an%20activation%20function.%20In%20scenarios%2C%20where%20multiple%20experts%20are%20placed%20on%20a%20single%20GPU%2C%20each%20expert%20module%20is%20instantiated%20sequentially%20in%20a%20loop.%20This%20increases%20kernel%20launch%20overhead%20and%20GPU%20utilization%20remains%20low%20for%20smaller%20expert%20sizes.%20Since%20all%20expert%20computations%20are%20independent%20of%20each%20other%20they%20could%20be%20executed%20in%20parallel.%20ORT%20MoE%20implements%20MergedFFNExpert%20which%20uses%20batched%20GEMM%2C%20instead%20of%20MM%2C%20to%20execute%20multiple%20expert%20computations%20in%20a%20single%20kernel%20launch.%20Merged%20experts%20improves%20throughput%20by%2053.87%25%20for%20Vision%20models.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_7-1651008766845.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367068iB750020C8CE7CEF9%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_7-1651008766845.png%22%20alt%3D%22kshamamsft_7-1651008766845.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%207%3A%20ORT%20MoE%20performance%20improvement%20on%20the%20CLIP%20Vision%20model%20(NDV4%20cluster)%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EORT%20MoE%20integrates%20with%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fblog%2Ftutel-an-efficient-mixture-of-experts-implementation-for-large-dnn-model-training%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3ETutel%3C%2FA%3E%20computation%20optimization%20features%20and%20provides%20user%20an%20option%20to%20take%20advantage%20of%20Tutel.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId--503639796%22%20id%3D%22toc-hId--482491961%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-1983873037%22%20id%3D%22toc-hId-2005020872%22%3EDistribution%20Strategies%20supported%20by%20ORT%20MoE%3C%2FH3%3E%0A%3CP%3EUnlike%20the%20traditional%20transformer%20structure%20(or%20neural%20network)%2C%20the%20routing%20logic%20of%20MoE%20breaks%20the%20locality%20of%20input%20tokens%3A%20instead%20of%20being%20only%20consumed%20by%20a%20single%20or%20a%20small%20set%20of%20GPUs%20(e.g.%2C%20model%20parallelism)%2C%20the%20tokens%20on%20each%20GPU%20are%20routed%20globally%20to%20experts%20on%20other%20GPUs.%20This%20gives%20flexibility%20to%20how%20we%20distribute%20the%20experts%20and%20provides%20opportunities%20to%20explore%20distribution%20strategies%20with%20different%20communication%20patterns%20and%20the%20associated%20trade-offs.%20As%20different%20workloads%20may%20require%20different%20distributions%20for%20best%20performance%2C%20it%20is%20important%20to%20support%20a%20rich%20set%20of%20distribution%20strategies.%20In%20this%20section%20we%20discuss%20some%20of%20the%20distribution%20strategies%20we%20used%20with%20ORT%20MoE.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EExpert%20Parallelism%20(EP)%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIn%20this%20scheme%2C%20experts%20are%20evenly%20divided%20across%20ranks.%20Alltoall%20collectives%20are%20inserted%20before%20and%20after%20experts%20to%20route%20the%20input%20and%20output%20tokens%20to%20the%20correct%20position%2C%20according%20to%20the%20gating%20function.%20The%20non-expert%20parameters%20are%20replicated%20across%20ranks%20and%20synchronized%20using%20AllReduction%20collective.%20This%20is%20the%20distribution%20strategy%20that%20was%20introduced%20in%20the%20GShard%20paper.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20distribution%20enables%20a%20simple%20and%20good%20load-balanced%20distribution%20of%20MoE%20and%20has%20been%20widely%20used%20in%20different%20models.%20In%20this%20distribution%2C%20the%20performance%20of%20Alltoall%20is%20one%20critical%20factor%20of%20the%20throughput.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_8-1651008821024.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367069i77B8F1EB7DC95837%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_8-1651008821024.png%22%20alt%3D%22kshamamsft_8-1651008821024.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%208%3A%20Expert%20Parallelism%20as%20described%20in%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fpdf%2F2006.16668.pdf%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EGshard%20paper%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EData%20scientists%20have%20deployed%20multiple%20replicas%20of%20Expert%20Parallel%20distribution%2C%20known%20as%20Expert%20Parallel%20Replica%2C%20to%20increase%20training%20throughput%20when%20larger%20number%20of%20GPUs%20are%20available.%20Under%20this%20strategy%2C%20like%20traditional%20data%20parallel%20training%2C%20experts%20from%20each%20EP%20replica%20are%20synchronized%20by%20additional%20AllReduce%20collective.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EExpert%20Slicing%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EA%20few%20drawbacks%20of%20EP%20are%3A%20(1)%20to%20maintain%20the%20load-balance%2C%20the%20number%20of%20experts%20must%20be%20larger%20and%20dividable%20by%20the%20number%20of%20GPUs.%20(2)%20Padding%20of%20the%20tokens%20may%20needed%2C%20when%20the%20number%20of%20tokens%20routed%20to%20an%20expert%20is%20fewer%20than%20the%20expert%20capacity%2C%20which%20incurs%20waste%20of%20memory%20and%20computation.%20(3)%20Each%20expert%20has%20a%20capacity%20of%20number%20of%20tokens%20taking%20in%2C%20which%20results%20in%20tokens%20exceeding%20the%20capacity%20are%20dropped%2C%20and%20affects%20the%20learning%20efficiency.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20avoid%20these%20drawbacks%2C%20we%20provide%20another%20distribution%20technique%2C%20called%20expert%20slicing.%20Here%20each%20expert%20is%20evenly%20sharded%20across%20the%20number%20of%20GPUs.%20An%20all-gather%20is%20used%20to%20collect%20inputs%20from%20all%20ranks%20to%20each%20rank%2C%20and%20an%20allreduce%20is%20used%20after%20the%20experts%20to%20compute%20the%20output%20correctly.%20Then%20each%20rank%20uses%20a%20narrow-like%20operation%20to%20select%20the%20outputs%20belonging%20to%20itself.%20Note%2C%20since%20each%20rank%20has%20all%20inputs%20before%20the%20gating%2C%20a%20global%20loss%20computation%20and%20routing%20decision%20is%20made%2C%20which%20increases%20the%20learning%20efficiency.%20Since%20each%20rank%20computes%20partial%20results%20of%20all%20experts%2C%20there%20is%20no%20token%20dropping%2C%20nor%20padding%20is%20needed.%20However%2C%20there%20is%20a%20memory%20tradeoff%3A%20each%20rank%20is%20taking%20inputs%20from%20all%20ranks%2C%20which%20increases%20the%20size%20of%20activation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-176418574%22%20id%3D%22toc-hId-197566409%22%3EModel%20scaling%20with%20ORT%20MoE%3C%2FH3%3E%0A%3CP%3EOne%20essential%20promise%20of%20MoE%20is%20that%20the%20model%20size%20scales%20with%20the%20number%20of%20GPUs%20used%2C%20while%20keeping%20the%20parameter%20size%2C%20computation%2C%20and%20memory%20consumption%20per%20GPU%20constant.%20Ideally%2C%20we%20would%20like%20the%20model%20to%20scale%20as%20a%20linear%20function%20of%20the%20number%20of%20GPUs.%20However%2C%20due%20to%20additional%20communication%20cost%20(which%20also%20increases%20with%20the%20number%20of%20GPUs)%2C%20only%20sublinear%20scaling%20may%20be%20feasible%20today.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20evaluate%20the%20scalability%20of%20our%20ORT%20MoE%20implementation%2C%20we%20deployed%20the%20CLIP%20Vision%20MoE%20model%20discussed%20above%20using%20CC2M%20dataset%20on%201%20to%2064%20GPUs%2C%20and%20128%20GPUs%2C%20on%20Azure%20NDv4%20cluster%20(%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fnda100-v4-series%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fnda100-v4-series%3C%2FA%3E%20)%2C%20using%20expert%20parallelism.%20For%20each%20setting%2C%20we%20keep%20the%20model%20size%20per%20GPU%20constant%2C%20and%20scale%20up%20the%20number%20of%20experts%20along%20with%20the%20number%20of%20GPUs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_9-1651008878621.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367070i7813166B68164030%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_9-1651008878621.png%22%20alt%3D%22kshamamsft_9-1651008878621.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%209%3A%20Scaling%20Result%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_10-1651008921528.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367071iA3308EA19E81F87D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22kshamamsft_10-1651008921528.png%22%20alt%3D%22kshamamsft_10-1651008921528.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3EFigure%2010%3A%20Model%20size%20for%20each%20data%20point%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFigure%209%20records%20the%20scaling%20result.%20The%20x-axis%20is%20the%20number%20of%20nodes%20used%3B%20y-axis%20is%20the%20throughput.%20The%20orange%20line%20represents%20%E2%80%9Cperfect%20scaling%E2%80%9D%2C%20which%20is%20computed%20as%20the%20product%20of%20the%20throughput%20of%20model%20on%20a%20single%20node%20and%20the%20number%20of%20nodes%20used.%20It%20is%20linear%20scaling.%20The%20blue%20line%20is%20the%20actual%20throughput.%20Figure%2010%20records%20the%20model%20size%20for%20each%20data%20point%2C%20where%20we%20can%20see%20we%20are%20scaling%20the%20parameter%20size%20almost%20linearly.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFrom%20the%20result%20we%20can%20see%20that%20the%20MoE%20model%20maintains%20good%20scalability%3A%20on%20128%20GPUs%2C%20it%20preserves%2065%25%20of%20the%20theoretical%20value.%20One%20reason%20is%20the%20Azure%20NDv4%20cluster%20provides%20high-bandwidth%20cross%20node%20network%20(InfiniBand%3A%20Supported%2C%20GPUDirect%20RDMA%2C%208%20x%20200%20Gigabit%20HDR).%20We%20do%20observe%20that%20an%20increase%20in%20the%20number%20of%20nodes%20increases%20the%20gap%20between%20the%20actual%20and%20theoretical%20throughput.%20This%20is%20expected%2C%20since%20the%20communication%20cost%20is%20bigger.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1631035889%22%20id%3D%22toc-hId--1609888054%22%3EZeRO%20integration%3C%2FH3%3E%0A%3CP%3EZeRO%20technique%20enables%20data%20scientists%20to%20scale%20PyTorch%20models%20efficiently%20by%20providing%20memory%20savings.%20%3CA%20href%3D%22https%3A%2F%2Fwww.deepspeed.ai%2Fdocs%2Fconfig-json%2F%23zero-optimizations-for-fp16-training%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EDeepSpeed%20ZeRO%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fengineering.fb.com%2F2021%2F07%2F15%2Fopen-source%2Ffsdp%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EFairScale%20FSDP%3C%2FA%3E%20are%20some%20of%20the%20common%20independent%20implementations%20of%20the%20ZeRO%20technique.%20ZeRO%20techniques%20can%20be%20applied%20on%20an%20MoE%20model%20that%20is%20using%20ORT%20MoE.%20ZeRO%20technique%20reduces%20memory%20consumption%20which%20could%20enable%20data%20scientists%20to%20increase%20batch%20size.%20We%20were%20able%20to%20increase%20batch%20size%20of%20a%20CLIP%20model%20by%20applying%20ZeRO%20using%20Fairscale%20FSDP%20implementation.%20Figure%2011%20shows%20the%20result.%20We%20applied%20FSDP%20on%202%20replicas%20of%20CLIP%20Vision%20model%20running%20on%208%20GPUs.%20In%20this%20configuration%20expert%20parameters%20are%20sharded%20in%20two%20partitions%20and%20non-expert%20parameters%20are%20sharded%20in%20eight%20partitions.%20When%20at%20batch%2036%2C%20with%20FSDP%2C%20it%20uses%2036%25%20less%20peak%20memory.%20Without%20FSDP%2C%20the%20max%20batch%20size%20per%20gpu%20can%20reach%2036%2C%20while%20with%20FSDP%2C%20it%20increases%20to%2048.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22kshamamsft_11-1651008974582.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F367072iF667EA42A326B371%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22kshamamsft_11-1651008974582.png%22%20alt%3D%22kshamamsft_11-1651008974582.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%3A%20center%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%20%3A%20left%3B%20%22%3EFigure%2011%20%3A%20ZeRO%20helps%20improve%20batch%20size%20for%20the%20CLIP%20Model%3C%2FP%3E%0A%3CP%20style%3D%22%20text-align%20%3A%20left%3B%20%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20style%3D%22%20text-align%20%3A%20left%3B%20%22%20id%3D%22toc-hId-748542060%22%3EOngoing%20Effort%3C%2FH2%3E%0A%3CH3%20id%3D%22toc-hId--950977519%22%20id%3D%22toc-hId--929829684%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-1536535314%22%20id%3D%22toc-hId-1557683149%22%3ETraining%20on%20AMD%20GPUs%3C%2FH3%3E%0A%3CP%3EWe%20are%20able%20to%20train%20same%20CLIP%20Vision%20MoE%20model%20configuration%20on%20NVIDIA%20A100%20GPUs%20as%20well%20as%20AMD%20MI100%20GPUs.%20We%20are%20able%20to%20improve%20model%20accuracy%20and%20efficiency%20using%20ORT%20MoE%20on%20both%20platforms.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--270919149%22%20id%3D%22toc-hId--249771314%22%3EORTModule%20integration%3C%2FH3%3E%0A%3CP%3EWe%20have%20implemented%20MixtureOfExperts%20as%20a%20standard%20torch.nn.module.%20The%20implementation%20allows%20seamless%20integration%20with%20PyTorch%20packages.%20ORTModule%20provides%20performance%20boost%20to%20standard%20PyTorch%20modules.%20ORT%20MoE%20could%20be%20simply%20wrapped%20inside%20ORTModule%20to%20gain%20the%20performance%20boost%20while%20constructing%20the%20model.%20A%20model%20could%20be%20entirely%20wrapped%20inside%20ORTModule%20also.%20See%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpytorch%2Fort%2Fblob%2Fmain%2Fdocs%2Fortmodule.rst%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EORTModule%20documentation%3C%2FA%3E%20for%20more%20information.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3Edgrid%20%3D%20DistributionGrid(expert_parallel_group_size%20%3D%20dist.get_world_size())%0Aencoder%20%3D%20TransformerMoEEncoderLayer(256%2C%204%2C%20nexperts%3D8%2C%20distribution_grid%20%3D%20dgrid)%0Aencoder%20%3D%20ORTModule(encoder)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2087510965%22%20id%3D%22toc-hId-2108658800%22%3ELooking%20Forward%3C%2FH2%3E%0A%3CP%3EWe%20are%20able%20to%20scale%20various%20language%2C%20speech%20and%20vision%20models%20using%20the%20Mixture%20Of%20Experts%20technique%20by%20incorporating%20ORT%20MoE.%20We%20will%20continue%20to%20optimize%20the%20ORT%20MoE%20implementation%20to%20improve%20training%20throughput%20and%20explore%20new%20distribution%20strategies.%20This%20will%20enable%20data%20scientists%20scale%20models%20to%20further%20improve%20the%20quality%20of%20the%20services%20built%20upon%20these%20models.%20We%20invite%20data%20scientists%20to%20explore%20the%20MoE%20technique%20using%20the%20flexible%20ORT%20MoE%20implementation%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpytorch%2Fort%2Ftree%2Fmain%2Fort_moe%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎May 02 2022 01:21 PM
Updated by: