Transformer-based neural network model training methods and systems

WO2026044531A9PCT designated stage Publication Date: 2026-08-06HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2024-08-28
Publication Date
2026-08-06

Smart Images

  • Figure CN2024115037_06082026_PF_FP_ABST
    Figure CN2024115037_06082026_PF_FP_ABST
Patent Text Reader

Abstract

Devices and methods for modifying a transformed-based neural network model based on a determination of layer criticality. Layer significance is determined by measuring a change at each layer in the model in a classification token associated with an input record. The change is measured using Earth Mover's Distance (EMD). Layers may be ranked based on their average EMD measurements based on changes to classification tokens for a plurality of input records. One or more lowest ranked layers may be pruned or may have their parameters frozen during further rounds of a training process.
Need to check novelty before this filing date? Find Prior Art

Description

TRANSFORMER-BASED NEURAL NETWORK MODEL TRAINING METHODS AND SYSTEMSTECHNICAL FIELD

[0001] The present application relates to transform-based neural network models and, in particular, to methods and systems for training or refining the model that are faster and more efficient.BACKGROUND

[0002] The rapid adoption of machine learning for a range of applications has led to a significant increase in resources consumed in training and operating neural networks.

[0003] Many neural networks involve multiple cascaded layers. Each layer is a set of interconnected nodes that perform a particular computation on the input data. Some neural networks are transformer-based neural networks, such as those used to implement large language models and other generative artificial intelligence models. These transformer-based neural networks can involve a large number of layers. The training of these models involves passing training data through the model in order to tune the parameters of the layers. In some cases, this can involve thousands, millions, or even billions, of training records. The computational cost of calculating and recalculating all the parameters for all the layers is significant.

[0004] Moreover, once the model is trained and deployed, the use of the model to process input data is partly a factor of the number of layers and their complexity.SUMMARY

[0005] In accordance with one aspect of the present application method of modifying a transformer-based neural network model, wherein the model includes a plurality of layers. The method may include, for an input record, determining a classification (CLS) token representation of the input record, wherein the CLS token includes a n-dimensional tensor; for each of the layers, calculating an Earth Mover’s Distance (EMD) between the CLS token prior to the one of the layers and the CLS token after the one of the layers, wherein the EMD associated with the one of the layers represents a significance of the one of the layers to determination of the n-dimensional tensor of the CLS token; ranking each of the layers based on their associated EMDs, wherein a lower EMD represents a lower significance; and excluding at least one layer of the transformer-based neural network model based on it being a lowest ranked layer.

[0006] In some implementations, the determining and calculating are carried out during a training process for the transformer-based neural network model, and the input record is a training record.

[0007] In some implementations, excluding includes freezing weights of the at least one layer to avoid calculation of updated weights in further iterations of the training process.

[0008] In some implementations, determining the CLS token and calculating the EMD is repeated for a plurality of input training records, and the method further includes determining an average EMD for each layer across the input training records. The ranking may include ranking each of the layers based on their associated average EMDs. In some cases, at least some of the input training records are used in multiple epochs, and determining the average EMD includes determining the average EMD for each layer across the input training records and across epochs. In some cases, ranking includes ranking each of the layers based on their associated median EMDs.

[0009] In some implementations, the transformer-based neural network model is a trained model, the determining and calculating are carried out during an inference process using the trained model, and the excluding at least one layer of the transformer-based neural network model includes removing the at least one layer from the trained model to realize a modified model for use in subsequent inferences.

[0010] In some implementations, excluding includes pruning the at least one layer from the transformer-based neural network model.

[0011] In some implementations, calculating the EMD includes determining a first histogram of the n-dimensional tensor of the CLS token prior to the one of the layers and a second histogram of the n-dimensional tensor of the CLS token after the one of the  layers, and determining a Wasserstein distance between the first histogram and the second histogram. In some cases, determining the first histogram includes allocating elements of the n-dimensional tensor of the CLS token prior to the one of the layers into a plurality of bins.

[0012] In some implementations, the n-dimensional tensor includes a plurality of vector components, and calculating the EMD includes determining a first probability distribution of the vector components of the CLS token prior to the one of the layers and a second probability distribution of the vector components of the CLS token after the one of the layers, and determining a Wasserstein distance between the first probability distribution and the second probability distribution.

[0013] In another aspect, the present application describes a processor and a memory coupled to the processor. The memory may store computer-executable instructions for modifying a transformer-based neural network model. The model includes a plurality of layers. The instructions, when executed by the processor, are to configure the processor to carry out one or more of the methods described herein.

[0014] In one example, the instructions, when executed by the processor, are to configure the processor to, for an input record, determine a classification (CLS) token representation of the input record, wherein the CLS token includes a n-dimensional tensor; for each of the layers, calculate an Earth Mover’s Distance (EMD) between the CLS token prior to the one of the layers and the CLS token after the one of the layers, wherein the EMD associated with the one of the layers represents a significance of the one of the layers to determination of the n-dimensional tensor of the CLS token; rank each of the layers based on their associated EMDs, wherein a lower EMD represents a lower significance; and exclude at least one layer of the transformer-based neural network model based on it being a lowest ranked layer.

[0015] In yet a further aspect, the present application describes a computer-readable medium storing computer-executable instructions that, when executed by one or more processors, are to cause the one or more processors to carry out any one or more of the methods described herein.

[0016] In another aspect, the present application describes a computer program comprising instructions which, when executed by a computing device, are to cause the computing device to carry out any one or more of methods described herein.

[0017] In a further aspect, the present application describes a computing device having means to perform any one or more of the methods described herein.

[0018] Other aspects and features of the present application will be understood by those of ordinary skill in the art from a review of the following description of examples in conjunction with the accompanying figures.BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Reference will now be made, by way of example, to the accompanying drawings in which:

[0020] FIG. 1 shows a simplified diagram of an example of a transformer-based neural network;

[0021] FIG. 2 shows a partial architecture of a multilayered neural network;

[0022] FIG. 3 illustrates a classification (CLS) token altered by successive layers of a neural network;

[0023] FIG. 4 shows, in flowchart form, one example method for modifying a transformer-based model;

[0024] FIG. 5 shows, in flowchart form, one example method for modifying a transformer-based neural network model based on a measurement of layer criticality;

[0025] FIG. 6A shows a line graph illustrating example results for ranking of layers in a transform-based neural network based on a measurement of layer significance;

[0026] FIG. 6B shows a bar chart illustrating the example results;

[0027] FIG. 7 shows a high-level diagram of an example computing device; and

[0028] FIG. 8 shows a simplified example of software components within the computing device.

[0029] Like reference numerals are used in the drawings to denote like elements and features.DETAILED DESCRIPTION

[0030] In the present disclosure, the terms “a” , “an” and “one” are defined to mean “at least one” , that is, these terms do not exclude a plural number of items, unless stated otherwise.

[0031] In the present disclosure, terms such as “substantially” , “generally” and “about” , which modify a value, condition or characteristic of a feature of an embodiment, should be understood to mean that the value, condition or characteristic is defined within tolerances that are acceptable for the proper operation of this embodiment for its intended application.

[0032] In the present disclosure, unless stated otherwise, the terms “connected” and “coupled” , and derivatives and variants thereof, refer herein to any structural or functional connection or coupling, either direct or indirect, between two or more elements. For example, the connection or coupling between the elements can be acoustical, mechanical, optical, electrical, thermal, logical, or any combinations thereof.

[0033] In the present disclosure, expressions such as “match” , “matching” and “matched” , including variants and derivatives thereof, are intended to refer herein to a condition in which two or more elements are either the same or within some predetermined tolerance of each other. That is, these terms are meant to encompass not only “exactly” or “identically” matching the two elements but also “substantially” , “approximately” or “subjectively” matching the two or more elements, as well as providing a higher or best match among a plurality of matching possibilities.

[0034] In the present disclosure, the expression “based on” is intended to mean “based at least partly on” , that is, this expression can mean “based solely on” or “based partially on” , and so should not be interpreted in a limited manner. More particularly, the expression “based on” could also be understood as meaning “depending on” , “representative of” , “indicative of” , “associated with” or similar expressions.

[0035] In the present disclosure, the terms "system" and "network" may be used interchangeably in embodiments of this application. "At least one" means one or more, and "a plurality of" means two or more. The term "and / or" describes an association relationship of associated objects and indicates that three relationships may exist. For example, A and / or B may indicate the following three cases: Only A exists, both A and B exist, and only B exists, where A and B may be singular or plural. The character " / " usually indicates an "or" relationship between associated objects. "At least one of the following items (pieces) " or a similar expression thereof indicates any combination of these items, including a single item (piece) or any combination of a plurality of items (pieces) . For example, "at least one of A, B, or C" includes A, B, C, A and B, A and C, B and C, or A, B, and C, and "at least one of A, B, and C" may also be understood as including A, B, C, A and B, A and C, B and C, or A, B, and C. In addition, unless otherwise specified, ordinal numbers such as "first" and "second" in embodiments of this application are used to distinguish between a plurality of objects, and are not used to limit a sequence, a time sequence, priorities, or importance of the plurality of objects.

[0036] In the present application, the phrase “at least one of…or…” is intended to cover any one or more of the listed elements, including any one of the listed elements alone, any sub-combination, or all of the elements, without necessarily excluding any additional elements, and without necessarily requiring all of the elements. The term “and / or” is intended to indicate that either of the two elements may be included or both of the elements may be included.

[0037] A person skilled in the art will understand that embodiments of this application may be provided as a method, an apparatus (or system) , a computer-readable storage medium, or a computer program product. Therefore, this application may use a form of a hardware-only embodiment, a software-only embodiment, or an embodiment with a combination of software and hardware. Moreover, this application may use a form of a computer program product that is implemented on one or more computer-usable storage media (including but not limited to a disk memory, an optical memory, and the like) that include computer-usable program code.

[0038] This application is described with reference to the flowcharts and / or block diagrams of the method, the device (system) , and the computer program product according to this application. It should be understood that computer program instructions may be used to implement each process and / or each block in the flowcharts and / or the block diagrams and a combination of a process  and / or a block in the flowcharts and / or the block diagrams. The computer program instructions may be provided for a general-purpose computer, a dedicated computer, an embedded processor, or a processor of another programmable data processing device to generate a machine, so that the instructions executed by the computer or the processor of the another programmable data processing device generate an apparatus for implementing a specific function in one or more procedures in the flowcharts and / or in one or more blocks in the block diagrams.

[0039] The computer program instructions may alternatively be stored in a computer-readable memory that can indicate a computer or another programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate an artifact that includes an instruction apparatus. The instruction apparatus implements a specific function in one or more procedures in the flowcharts and / or in one or more blocks in the block diagrams.

[0040] The computer program instructions may alternatively be loaded onto a computer or another programmable data processing device, so that a series of operations and steps are performed on the computer or the another programmable device, so that computer-implemented processing is generated. Therefore, the instructions executed on the computer or the another programmable device provide steps for implementing a specific function in one or more procedures in the flowcharts and / or in one or more blocks in the block diagrams.

[0041] It will be understood that a person skilled in the art may make various modifications and variations to this application without departing from the scope of this application. This application is intended to cover these modifications and variations of this application provided that they fall within the scope of protection defined by the following claims and their equivalent technologies.

[0042] Throughout the present disclosure, a processor, a processor system, an application processor, a baseband processor, a processor circuit, or a processor core may be collectively referred to as a processor. A processor may include one or more of a central processing unit (CPU) , a digital signal processor (DSP) , a microprocessor unit (MPU) , a microcontroller unit, (MCU) , a graphics processing unit (GPU) , a field programmable gate array (FPGA) , an artificial intelligence (AI) processor, or a neural network processing unit (NPU) , or a combination of at least two of these integrated circuit forms.

[0043] Throughout the present disclosure, a memory may include one or more of the following storage media: a RAM, a static random access memory (SRAM) , a dynamic random access memory (DRAM) , a phase-change memory (PCM) , a resistive random access memory (ReRAM) , a magnetoresistive random access memory (MRAM) , a ferroelectric random access memory (FRAM) , a cache, a register, a read-only memory (ROM) , a flash memory, an erasable programmable read-only memory (EPROM) , a hard disk, and / or the like. In an example, the computer program instructions used to execute embodiments contained herein may be stored in a non-volatile memory. When a terminal runs, part or all of corresponding computer program instructions may be loaded into a memory that has a higher transmission speed with a corresponding processor, for example, the instructions may be loaded into at least a part of a memory such that the processor executes the computer program instructions to perform the steps in of embodiments described herein.

[0044] Neural networks typically involve multiple cascaded layers. In many implementations, a network may include 32, 48, or even more layers. The training of these layers involves feeding training data through the layers with feedback that includes calculating an adjustment to the parameters (e.g. weights) of each layer. Over the course of training, the weights of each layer may stabilize. However, it is suspected that not all of the layers have the same significance in terms of influencing output of the neural network. It may be advantageous to reduce the size and complexity of the model by removing the least significant layers. It may also be advantageous to remove or freeze insignificant layers during the training process so as to make the training more computationally efficient and faster.

[0045] As an example, a transformer-based neural network may be used in implementing a large language model (LLM) . Example LLMs include Llama2 7B or Mistral 7B, which have about 32 layers and can require as much as 56 GB of data in weights, optimizer and activation parameters.

[0046] One option is to simply start with an untrained model that has fewer layers. It may be difficult to anticipate in advance how many layers will be needed to achieve satisfactory results. Layers may be removed during or after training, but it may be difficult to identify which layers are significant. Some attempts have been made to determine the significance of layers of a trained model.  In one example, the magnitude of gradients flowing through a layer may be used as a proxy for significance. Layers with consistently small gradients may have a lower impact on the final result. In another example, the magnitude of a layer’s weights may be indicative of its significance. Layers will very small weights may be less influential on the output. Both gradient and weight-based approaches have drawbacks, particularly in the case of complex networks where neural network layers within a block may interact with each other in complex ways. These approaches tend to treat each layer in isolation and have not proven that effective as a proxy for significance of a layer within a multilayered neural network. A third option is a test-and-evaluate approach in which a layer may be removed and the resulting performance evaluated to determined to what degree the layer was significant, but this can be a slow and computationally costly process.

[0047] Those skilled in the art of neural networks will appreciate that the term “block” in transformer architectures typically refers to multiple layers, such as self-attention and feed-forward layers. In some cases, the term “layer” may be used to refer to an entire block. For example, in ViT (Vision Transformer) , there are 12 blocks but it is common to refer to ViT as having 12 layers. The present application uses the term “layer” , but that term should be construed as potentially applying to “blocks” in some circumstances. For example, in some cases the described methods and systems may measure the significance of “blocks” instead of layers within the blocks and may result in pruning or freezing of parameters within an entire “block” instead of a layer within the block.

[0048] FIG. 1 shows a simplified diagram of an example of a transformer-based neural network 100. The neural network 100 includes a plurality of encoder layers 102 (shown individually as 102-0, 102-1, 102-2, …, 102-n) and a plurality of decoder layers 104 (shown individually as 104-0, 104-1, 104-2, …, 104-m) . Transformer-based neural networks may be used for a variety of purposes. An input sequence 106 may be injected into the neural network 100 and an output result 108 may be produced. The encoder layers 102 may process the input sequence 106 through breaking it down and creating a multidimensional representation of the input sequence. The decoder layers 104 then use the multidimensional representation to generate the output result 108.

[0049] The architecture shown in FIG. 1 is for illustrative purposes only. The present application is not limited to this architecture and is applicable to any multilayer transformer-based neural network.

[0050] FIG. 2 shows a partial architecture of a multilayered neural network 200. An input sequence, or a portion of the input sequence, may be represented by a classification token, sometimes termed a CLS token 202. The CLS token 202 is an n-dimensional tensor that is intended to be representative of the input sequence or the portion of the input sequence. The CLS token 202 may be modified to some degree by each successive layer 204. That is the CLS token 202 prior to a layer 204 may have different values than the CLS token 202 after that layer 204. Different layers 204 may have different impacts on the CLS token 202. In accordance with one aspect of the present application, the changes in the CLS token 202 caused by one of the layers 204 serve as a proxy for the significance or importance of the layer 204.

[0051] FIG. 3 illustrates a CLS token 300 being altered by successive layers. In this simplified illustration, the CLS token 300 is depicted as a one-dimensional vector. In many implementations, the CLS token 300 may be a more complex n-dimensional tensor. The example CLS token 300 in this case includes values a0, a1, a2, …, ax prior to layer n. After layer n, the CLS token 300 has values a′0, a′1, a′2, …, a′x. After layer n+1, the CLS token 300 has values a″0, a″1, a″2, …, a″x.

[0052] In order to determine the significance of the change in the CLS token 300 attributable to a particular layer, in one aspect, the present application proposes use of Earth Mover’s Distance (EMD) to measure the significance of the shift in distribution of values within the CLS token 300. EMD has the ability to sensitively and robustly capture the significance of distributional changes of data. EMD assesses the total transformation effort required by each layer, making it particularly effective in high-dimensional spaces common in neural networks, where traditional measures of distance, like Euclidean distance, can be misleading.

[0053] The technique described herein is to generate histograms from the CLS token 300 before and after a layer, and to then use EMD to assess the relative significance of the change to the CLS token 300 by that layer versus other layers. The EMD measurement may generally be expressed as:

[0054] In the above expression, P and Q are the two histograms. The indices i and j sum from 1 to the respective number of bins of each histogram, n and m. In some cases, n is the same as m. Within the sum, fij represents the flow, or the amount of “mass” , transferred from bin i of histogram P to bin j of histogram Q, and dij represent the distance between bins i and j, which may be the absolute difference between the bin indices or the actual values they represent.

[0055] The minimization is carried out over all possible fij that meet the constraints of a valid mass transport.

[0056] Reference will now be made to FIG. 4, which shows, in flowchart form, one example method 400 for modifying a transformer-based model. The method 400 may be implemented by way of processor-readable and executable instructions stored in a memory.

[0057] In this example, the method 400 may be carried out during a training process for training the transform-based model. The method 400 includes receiving input of a training record in operation 402. The training record may be a portion of text, image (s) , audio, or any other such record suitable to the model and the purpose for which it is being trained. As a training record, the record may be tagged / labelled in a supervised training process.

[0058] As the record is forward passed through the transformed-based model, a CLS token representing the record is generated and modified at each layer of the model. As indicated by operation 404, the CLS token is determined after each layer of the model. In operation 406, EMD is calculated for each modified CLS token vis-à-vis the CLS token prior to the most-recent layer. That is, for each layer, the system calculates the EMD between the CLS token before that layer and the CLS token after that layer to measure the significance of the change to the CLS token caused by that layer. In this sense, each layer has an associated EMD measurement representing its impact on the CLS token.

[0059] Once the record has passed through the model, the layers may be ranked based on their associated EMD measurements, as indicated by operation 408. The larger the EMD measurement, the more significant a layer is and the more critical it is to the successful processing of the record. In operation 410, the model may therefore be simplified by excluding at least one of the lowest-ranked layers, i.e. at least one of the layers with the lowest EMD measurements. Excluding a layer may mean removing that layer from the model in some cases, thereby resulting a model having fewer layers, which may realize lower computational costs both for remaining training operations and in use after training. In another implementation, excluding a layer may mean freezing the weights of that layer during the training process so as to save the cost of re-calculating and updating the layer’s weights with each training record. That is, the significant computational cost of training may be reduced by freezing the weights of layers that are determined to be non-critical to the output of the model. Thus, the output model may have the same number of layers, but the cost of training that model may be reduced.

[0060] It will be understood that the above simplified method refers to one training record. In many implementations, the method 400 is carried out using a plurality of training records, and the EMD measurements determined for each training record in operation 406 are combined to find an average or a median measurement for each layer. The ranking carried out in operation 408 is then based on the average or median EMD measurement associated with each layer.

[0061] While the method 400 outlined above is described as being applied during a training process, it will be appreciated that a substantially similar method may be implemented after training to a trained model during an inference process. Application of the method during the inference process using one or more input records may result in determining that one or more layers of the trained model may be removed, resulting in a modified model having fewer layers for subsequent inference operations.

[0062] Reference is now made to FIG. 5, which shows, in flowchart form, one example method 500 for modifying a transformer-based neural network model based on a measurement of layer criticality. The model includes multiple cascaded transformer-based layers. The method 500 may be carried out during a training phase in which a plurality of training records are input to the model to refine the weights of the various layers as part of the training process. The method 500 may be implemented by way of software, including computer-executable instructions stored in memory and executed by one or more processors in a computing device.

[0063] The training phase in which the method 500 is carried out may include serially passing training records through the model. The training may include multiple epochs, wherein each epoch may include the input of the plurality of training records, such that  some or all of the training records are passed through the model multiple times.

[0064] The method 500 may not be carried out for each epoch and each training record. That is, the method 500 may be applied to a subset of the training records and / or epochs, such as a predetermined percentage of them, i.e. with a predetermined frequency.

[0065] In operation 502, a training record is input to the model. As indicated by operation 504, the record is passed forward through the model. A CLS token is determined after each layer as a result of the model processing the record, as indicate by operation 506. As described above, the CLS token may be an n-dimensional tensor that is representative of the record. Other tokens may also be generated as a result of the model.

[0066] In operation 508, after each layer, a histogram is determined for the CLS token that resulted from application of that layer. That is, a probability distribution may be determined from the values of the resultant CLS token. In operation 510, for each layer, an EMD measurement is calculated as between the CLS histogram prior to that layer and the CLS histogram after that layer. This may include determining a Wasserstein distance between the CLS histogram prior to that layer and the CLS histogram after that layer. The determined EMD measurement is then added to a cumulative EMD measurement for each layer, as indicated by operation 512.

[0067] In operation 514, the computing device carrying out the training process determines if there are further training records to be processed. If so, it returns to operation 502 to input the next training record. If not, then in operation 516 it assesses whether there is a further epoch to run. If so, then it returns to operation 502 to re-input one of the training records.

[0068] If all training records and epochs are complete, then in operation 518 the device determines an average EMD measurement for each layer based on the cumulative EMD measurement for that layer and a count of the number of times it determined an EMD measurement for that layer. Those average EMD measurements may then be used in operation 520 to rank the layers from most critical, i.e. highest average EMD measurement, to least critical, i.e. lowest average EMD measurement. The computing device may output the ranking of layers.

[0069] In another implementation, instead of building a cumulative EMD measurement and then calculating an average based on a count of the number of EMD measurements that were determined, the device may build a record containing each of the EMD measurements. The record may, for instance, be a table or matrix with each column associated with a layer and each row corresponding to an EMD measurement / training record. In some cases, a separate record may be maintained for each layer and the measurements may be ordered within the record by magnitude of the EMD measurement. With a record of all of the EMD measurements, the device may determine the average EMD measurement or may identify the median EMD measurement. The average or median value may be used in ranking of layers.

[0070] The ranked criticality of layers based on their associated average EMD measurements may be used in operation 522 to prune one or more of the least critical layers from the model, i.e. to remove or exclude one or more of the layers having the lowest associated average EMD measurements. This results in a model with fewer layers. In some cases, a model with 32 layers may be reduced to a model with 8-12 layers without losing significant accuracy.

[0071] It will be appreciated that in the above example, the average EMD measurement is only calculated at the end of the method 500 after the training has been completed. In some other implementations, the average EMD measurement may be calculated more frequently, such as after each training record is processed, thereby determining an evolving set of EMD measurements for the layers. If so, then this may be used to determine, from a ranking of layers, whether to freeze weights of one or more of the layers during training so as to save on the computational expense of recalculating weights for layers that are non-critical.

[0072] The running calculation of average EMD measurements may also or alternatively be used to determine the frequency of operation of the method 500 or whether to cease operation of the method 500. For instance, the method 500 may be initially applied with high frequency, e.g. for every record, but it may be found that the EMD measurements become consistent such that the calculated EMD measurements do not vary much from the average EMD measurements, meaning that further iterations of the method are not changing the average EMD measurements. In such a case, the method 500 may be applied less frequently, or may be terminated altogether.

[0073] In some implementations, the method 500 may be used during training to determine when to cease training. For example, by determining the average EMD measurement of each of the layers and detecting when the EMD measurements for N training records result in no or less than a threshold change to the average EMD measurements of the layers, it may be determined that the model has stabilized sufficiently to cease training.

[0074] In some cases, the method 500 may be applied after training using a pre-trained model during inference with live records. In this case, the model may be simplified after implementation in real-world use by pruning one or more layers of the model based on those one or more layers being determined to be the least critical based on their associated EMD measurements.

[0075] In one illustrative example, the building of a cumulative EMD measurement may be implemented using code, such as:

[0076] #Creating histograms and calculating EMD hist1, _= np. histogram (tensor1, bins=bins, range=range_hist, density=True) hist2, _= np. histogram (tensor2, bins=bins, range=range_hist, density=True) emd = wasserstein_distance (hist1, hist2) em_distances. append (emd)

[0077] FIG. 6A shows a line graph 600, and FIG. 6B shows a bar graph 602, illustrating one example application of EMD-based ranking of layers. In this example, the neural network includes 12 layers (labelled L0, L1, L2, …, L11) . The above-described method is applied with 100 training records.

[0078] The y-axis of the line graph 600 is the measure of EMD (Wasserstein distance, in this example) . The x-axis of the line graph 600 indicates the training steps or records, spanning from training record 0 to training record 100. Each line on the graph traces the EMD measurement associated with one of the layers L0…L11. As can be seen in the line graph 600, the first layer L0, indicated by reference numeral 604, is consistently has the highest EMD measurement and is the most significant layer.

[0079] The bar graph 602 shows the normalized average EMD measurements for the twelve layers of the model. Again, it will be noted the first layer, L0, is the most significant with a normalized average EMD of 1.0. The two least significant layers, with the lowest average normalized average EMD, are layers L8 and L9.

[0080] In some implementations, having determined the ranking of layers indicated by the bar graph 602, the computing device may exclude layers starting from the right side of the graph, e.g. starting with layer L9, on the basis that is has the lowest average EMD. In other words, it has the least impact on changing CLS tokens as compared to the other layers. Excluding may include freezing the weights of layer L9 during subsequent training or pruning (e.g. removing) layer L9 from the model.

[0081] In one example implementation, instead of excluding a layer, the computing device outputs the ranking of layers, for example via a display screen or via transmitted message.

[0082] Reference will now be made to FIG. 7, which shows a high-level diagram of an example computing device 700. The example computing device 700 includes a variety of modules. For example, the example computing device 700 may include a processor 710, a memory 720, an I / O module 740, and a communications module 750. As illustrated, the foregoing example modules of the example computing device 700 are in communication over a bus 760.

[0083] The processor 710 in this example is a hardware processor. The processor 710 may, for example, be one or more ARM, Intel x86, PowerPC processors, or the like.

[0084] The memory 720 allows data to be stored and retrieved. The memory 720 may include, for example, random access memory, read-only memory, and persistent storage. Persistent storage may be, for example, flash memory, a solid-state drive or the like. Read-only memory and persistent storage are a computer-readable medium. A computer-readable medium may be organized using a file system such as may be administered by an operating system governing overall operation of the example computing device 700.

[0085] The I / O module 740 allows the example computing device 700 to receive input signals and to transmit output signal. Input  signals may, for example, correspond to input received from a user. Some output signals may, for example, allow provision of output to a user. The I / O module 740 may serve to interconnect the example computing device 700 with one or more input devices. Input devices may, for example, include one or more of a touchscreen input, keyboard, trackball or the like. The I / O module 740 may serve to interconnect the example computing device 700 with one or more output devices. Output devices may include, for example, one or more display screens such as, for example, a liquid crystal display (LCD) , a touchscreen display. Additionally, or alternatively, output devices may include devices other than screens such as, for example, a speaker, indicator lamps (such as, for example, light-emitting diodes (LEDs) ) , and printers.

[0086] The communications module 750 allows the example computing device 700 to communicate with other electronic devices and / or various communications networks. For example, the communications module 750 may allow the example computing device 700 to send or receive communications signals. As an example, the communication module 750 may include a network connection, data port, or the like. Communications signals may be sent or received according to one or more protocols or according to one or more standards. For example, the communications module 750 may allow the example computing device 700 to communicate via a cellular data network, such as for example, according to one or more standards such as, for example, Global System for Mobile Communications (GSM) , Code Division Multiple Access (CDMA) , Evolution Data Optimized (EVDO) , Long-term Evolution (LTE) , 5G, 6G, or the like. Additionally, or alternatively, the communications module 650 may allow the example computing device 700 to communicate using near-field communication (NFC) , via Wi-Fi (TM) , via the Ethernet family of network protocols, using Bluetooth (TM) or via some combination of one or more networks or protocols. In some embodiments, all or a portion of the communications module 750 may be integrated into a component of the example computing device 700. In some examples, the communications module may be integrated into a communications chipset.

[0087] Software instructions are executed by the processor 710 from a computer-readable medium. For example, software may be loaded into random-access memory from persistent storage within memory 720. Additionally, or alternatively, instructions may be executed by the processor 710 directly from read-only memory of the memory 720.

[0088] FIG. 8 depicts a simplified organization of software components stored in memory 720 of the example computing device 700. As illustrated, these software components include, at least, application software 810 and an operating system 800.

[0089] The application software 810 adapts the example computing device 700, in combination with the operating system 800, to operate as a device performing a particular function. While a single application software 810 is illustrated in FIG. 8, in operation, the memory 720 may include more than one application software and different application software may perform different operations.

[0090] The operating system 800 is software. The operating system 800 allows the application software 810 to access the processor 710, the memory 720, the I / O module 740, and the communications module 750. The operating system 800 may, for example, be iOSTM, AndroidTM, LinuxTM, Microsoft WindowsTM, or the like.

[0091] The application software 810 and / or operating system 800 may, when executed, cause the processor 710 to carry out operations to implement at least some portion of one or more of the methods described herein.

[0092] The various embodiments presented above are merely examples and are in no way meant to limit the scope of this application. Variations of the innovations described herein will be apparent to persons of ordinary skill in the art, such variations being within the intended scope of the present application. In particular, features from one or more of the above-described example embodiments may be selected to create alternative example embodiments including a sub-combination of features which may not be explicitly described above. In addition, features from one or more of the above-described example embodiments may be selected and combined to create alternative example embodiments including a combination of features which may not be explicitly described above. Features suitable for such combinations and sub-combinations would be readily apparent to persons skilled in the art upon review of the present application as a whole. The subject matter described herein and in the recited claims intends to cover and embrace all suitable changes in technology.

Claims

1.A method of modifying a transformer-based neural network model, wherein the model includes a plurality of layers, the method comprising:for an input record, determining a classification (CLS) token representation of the input record, wherein the CLS token includes a n-dimensional tensor;for each of the layers, calculating an Earth Mover’s Distance (EMD) between the CLS token prior to the one of the layers and the CLS token after the one of the layers, wherein the EMD associated with the one of the layers represents a significance of the one of the layers to determination of the n-dimensional tensor of the CLS token;ranking each of the layers based on their associated EMDs, wherein a lower EMD represents a lower significance; andexcluding at least one layer of the transformer-based neural network model based on it being a lowest ranked layer.2.The method of claim 1, wherein the determining and calculating are carried out during a training process for the transformer-based neural network model, and wherein the input record is a training record.3.The method of claim 2, wherein excluding includes freezing weights of the at least one layer to avoid calculation of updated weights in further iterations of the training process.4.The method of claim 2, wherein the determining the CLS token and the calculating the EMD is repeated for a plurality of input training records, and further comprising determining an average EMD for each layer across the input training records.5.The method of claim 4, wherein the ranking includes ranking each of the layers based on their associated average EMDs.6.The method of claim 5, wherein at least some of the input training records are used in multiple epochs, and wherein determining the average EMD includes determining the average EMD for each layer across the input training records and across epochs.7.The method of claim 4, wherein the ranking includes ranking each of the layers based on their associated median EMDs.8.The method of claim 1, wherein the transformer-based neural network model is a trained model, wherein the determining and calculating are carried out during an inference process using the trained model, and wherein the excluding at least one layer of the transformer-based neural network model includes removing the at least one layer from the trained model to realize a modified model for use in subsequent inferences.9.The method of claim 1, wherein excluding includes pruning the at least one layer from the transformer-based neural network model.10.The method of claim 1, wherein calculating the EMD includes determining a first histogram of the n-dimensional tensor of the CLS token prior to the one of the layers and a second histogram of the n-dimensional tensor of the CLS token after the one of the layers, and determining a Wasserstein distance between the first histogram and the second histogram.11.The method of claim 10, wherein determining the first histogram includes allocating elements of the n-dimensional tensor of the CLS token prior to the one of the layers into a plurality of bins.12.The method of claim 1, wherein the n-dimensional tensor includes a plurality of vector components, and wherein calculating the EMD includes determining a first probability distribution of the vector components of the CLS token prior to the one of the layers and a second probability distribution of the vector components of the CLS token after the one of the layers, and determining a Wasserstein distance between the first probability distribution and the second probability distribution.13.A computing device, comprising:a processor; anda memory coupled to the processor, the memory storing computer-executable instructions for modifying a transformer-based neural network model, wherein the model includes a plurality of layers, wherein the instructions, when executed by the processor, are to configure the processor to:for an input record, determine a classification (CLS) token representation of the input record, wherein the CLS token includes a n-dimensional tensor;for each of the layers, calculate an Earth Mover’s Distance (EMD) between the CLS token prior to the one of the layers and the CLS token after the one of the layers, wherein the EMD associated with the one of the layers represents a significance of the one of the layers to determination of the n-dimensional tensor of the CLS token;rank each of the layers based on their associated EMDs, wherein a lower EMD represents a lower significance; andexclude at least one layer of the transformer-based neural network model based on it being a lowest ranked layer.14.The computing device of claim 13, wherein the input record is a training record, and wherein the instructions, when executed, are to configure the processor to determine the CLS token and calculate the EMD as part of a training process for the transformer-based neural network model.15.The computing device of claim 14, wherein the instructions, when executed, are to configure the processor to exclude the at least one layer by freezing weights of the at least one layer to avoid calculation of updated weights in further iterations of the training process.16.The computing device of claim 14, wherein the instructions, when executed, are to configure the processor to determine the CLS token and calculate the EMD for a plurality of input training records, and to further determine an average EMD for each layer across the input training records.17.The computing device of claim 16, wherein the instructions, when executed, are to configure the processor to rank by ranking each of the layers based on their associated average EMDs.18.The computing device of claim 13, wherein the transformer-based neural network model is a trained model, wherein the instructions, when executed, are to configure the processor to carry out the determining and calculating during an inference process using the trained model, and wherein the instructions, when executed, are to configure the processor to exclude at least one layer of the transformer-based neural network model by removing the at least one layer from the trained model to realize a modified model for use in subsequent inferences.19.The computing device of claim 13, wherein the instructions, when executed, are to configure the processor to exclude the at least one layer by pruning the at least one layer from the transformer-based neural network model.20.The computing device of claim 13, wherein the instructions, when executed, are to configure the processor to calculate the EMD by determining a first histogram of the n-dimensional tensor of the CLS token prior to the one of the layers and a second histogram of the n-dimensional tensor of the CLS token after the one of the layers, and by determining a Wasserstein distance between the first histogram and the second histogram.21.The computing device of claim 20, wherein the instructions, when executed, are to configure the processor to determine the first histogram by allocating elements of the n-dimensional tensor of the CLS token prior to the one of the layers into a plurality of bins.22.A non-transitory computer-readable medium containing instructions for modifying a transformer-based neural network model, wherein the model includes a plurality of layers, wherein the instructions, when executed by a processor, are to cause the processor to:for an input record, determine a classification (CLS) token representation of the input record, wherein the CLS token includes a n-dimensional tensor;for each of the layers, calculate an Earth Mover’s Distance (EMD) between the CLS token prior to the one of the layers and the CLS token after the one of the layers, wherein the EMD associated with the one of the layers represents a significance of the one of the layers to determination of the n-dimensional tensor of the CLS token;rank each of the layers based on their associated EMDs, wherein a lower EMD represents a lower significance; andexclude at least one layer of the transformer-based neural network model based on it being a lowest ranked layer.23.A computer-readable medium storing computer-executable instructions that, when executed by one or more processors, are to cause the one or more processors to carry out the method of any one of claims 1 to 12.24.A computer program comprising instructions which, when executed by a computing device, are to cause the computing device to carry out the method of any one of claims 1 to 12.25.A computing device comprising means to perform the method of any one of claims 1 to 12.26.A computing device comprising at least one processor and a memory coupled to the at least one processor, wherein the memory stores instructions that, when executed by the at least one processor, are to cause the at least one processor to perform the method of any one of claims 1 to 12.