This invention relates generally to neural networks and, more specifically, relates to automatic scaling for fixed point implementation of deep neural networks.
This section is intended to provide a background or context to the invention disclosed below. The description herein may include concepts that could be pursued, but are not necessarily ones that have been previously conceived, implemented or described. Therefore, unless otherwise explicitly indicated herein, what is described in this section is not prior art to the description in this application and is not admitted to be prior art by inclusion in this section.
A neural network is a computing solution that is loosely modeled after structures of the brain. A neural network comprises interconnected processing elements called nodes or neurons that work together to produce an output. The neural network is effectively a parallel distributed processing network.
Deep neural networks (DNNs) are an improvement over the original neural networks. DNNs have many layers (e.g., between four and 1,000 or possibly more), and typically involve a huge number of parameters, e.g., from 100 to 1 trillion. DNNs are also quite computationally intensive.
That computational intensity provides benefits. For instance, DNNs have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular type of DNN, known as a Convolutional Neural Network (CNN), has demonstrated state-of-the-art results in object recognition and detection.
Most DNNs use floating point numbers as the neural network coefficients, and for network input and output. Some neuromorphic chips are using a fixed-point implementation, which use a limited integer range to represent numbers instead of using floating point numbers. Fixed point implementation is easier to implement on single-chip, lower-power semiconductor circuits. However, it can be difficult to convert floating point numbers to fixed point numbers, particularly when the distribution of the floating point numbers is not known in advance. Furthermore, the parameters for DNNs are typically not predictable in advance and vary widely depending on application, and this provides an additional challenge to using fixed point implementations of DNNs.
This section is intended to include examples and is not intended to be limiting.
In an exemplary embodiment, a method is disclosed for performing automatic scaling on a floating point implementation of a deep neural network to perform scaling to a fixed point implementation of the deep neural network, wherein the deep neural network comprises a plurality of layers in an order from a starting layer to an ending layer and uses floating point calculations in the plurality of layers. The automatic scaling comprises: determining a scaling factor for each of multiple ones of the layers during training of the deep neural network, wherein the scaling factor converts floating point numbers used for calculations in a corresponding layer into integer numbers to be used in the calculations, and wherein determining a scaling factor comprises determining the scaling factor for a selected layer, which is at a position in the order, based on scaling factors used in layers in the order prior to the position of the selected layer; and outputting the scaling factors for the multiple layers to be used for implementing the fixed point implementation of the deep neural network, wherein the fixed point implementation of the deep neural network uses integer calculations instead of floating point calculations.
In another example, an apparatus is disclosed that comprises one or more memories comprising a computer readable program, and one or more processors. The one or more processors are configured, in response to executing the computer readable program, to cause the apparatus to perform operations comprising: performing automatic scaling on a floating point implementation of a deep neural network to perform scaling to a fixed point implementation of the deep neural network, wherein the deep neural network comprises a plurality of layers in an order from a starting layer to an ending layer and uses floating point calculations in the plurality of layers, the automatic scaling comprising: determining a scaling factor for each of multiple ones of the layers during training of the deep neural network, wherein the scaling factor converts floating point numbers used for calculations in a corresponding layer into integer numbers to be used in the calculations, and wherein determining a scaling factor comprises determining the scaling factor for a selected layer, which is at a position in the order, based on scaling factors used in layers in the order prior to the position of the selected layer; and outputting the scaling factors for the multiple layers to be used for implementing the fixed point implementation of the deep neural network, wherein the fixed point implementation of the deep neural network uses integer calculations instead of floating point calculations.
In an additional exemplary embodiment, a deep neural network is disclosed that is formed in circuitry based on a method comprising: performing automatic scaling on a floating point implementation of a deep neural network to perform scaling to a fixed point implementation of the deep neural network, wherein the deep neural network comprises a plurality of layers in an order from a starting layer to an ending layer and uses floating point calculations in the plurality of layers, the automatic scaling comprising: determining a scaling factor for each of multiple ones of the layers during training of the deep neural network, wherein the scaling factor converts floating point numbers used for calculations in a corresponding layer into integer numbers to be used in the calculations, and wherein determining a scaling factor comprises determining the scaling factor for a selected layer, which is at a position in the order, based on scaling factors used in layers in the order prior to the position of the selected layer; and outputting the scaling factors for the multiple layers to be used for implementing the fixed point implementation of the deep neural network, wherein the fixed point implementation of the deep neural network uses integer calculations instead of floating point calculations.
In the attached Drawing Figures:
The word “exemplary” is used herein to mean “serving as an example, instance, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments. All of the embodiments described in this Detailed Description are exemplary embodiments provided to enable persons skilled in the art to make or use the invention and not to limit the scope of the invention which is defined by the claims.
State-of-the-art DNNs use float point number for all the network coefficients, input and output. In floating point implementations, each floating point variable typically uses a sign, exponent and mantissa. The value of the floating point variable is calculated using a formula involving that information. Floating point implementations of DNNs can be quite computationally intensive.
To achieve the least cost and energy, by contract some researchers are working on binarizing the input for neural networks, coefficients and activations, and these researchers have achieved initial success on datasets with, e.g., small image size. However, there is significant performance loss for larger image datasets. Hence, using a reasonable width of integers to represent the input, coefficients and activations is still valuable and necessary to reach the state-of-the-art performance as well as achieve the advantage of fixed point implementation.
Fixed point formats typically consist of a signed mantissa and a global scaling factor shared between all fixed point variables. The scaling factor can be seen as a position of a radix point. This position is usually fixed, hence the name “fixed point”. Reducing the scaling factor reduces the range and augments the precision of the format. The scaling factor is typically a power of two for computational efficiency, as the scaling multiplications are replaced with shifts. See, M. Courbariaux, et al., “Training deep neural networks with low precision multiplications”, arXiv:1412.7024, sections 3 and 4 (2015). To reach the best performance, the scaling factor can be any number and does not have to be power of two or an integer.
Scaling is used to adjust the range of a fixed point number to represent the floating point number with minimum performance loss, which is widely used in many industries, for example wireless communication. Usually the best scaling can be pre-calculated if the floating point number's distribution is known. The system's performance is very sensitive to the scaling factor.
However, when dealing with DNNs, this is quite a different story. A DNN itself can automatically match the scaling factor because of its training, which makes the scaling of a DNN more tolerable. There are, however, still limitations. For instance, if the system's behavior can be predicted, then scaling factors can be pre-calculated based on the float number's distribution. However, DNNs' parameters are highly decided by the training and not predictable, and a DNN's best scaling is highly decided by the training and is, thus, difficult to predict. Hence an automatic scheme based on real-time training is needed to improve fixed point performance.
If one wants to deploy DNNs into a FPGA (field-programmable gate array) or an ASIC (application-specific integrated circuit), or a neuromorphic chip, fixed point representation is beneficial to save cost and energy. It is necessary to have techniques for creating such a fixed point representation.
The exemplary embodiments herein provide such techniques and specifically provide systems and methods in exemplary embodiments to enable auto scaling (automatic scaling) for DNN fixed point implementations. It is possible to achieve the best performance of the trained system within the limited accuracy of a fixed point representation. In particular, exemplary methods herein have better performance on getting a smaller fix point bit width than do conventional methods.
Exemplary embodiments herein provide, e.g., a system and method to train a fixed point DNN by enabling auto scaling. With auto scaling, stable accuracy performance as well as low bit-width of fix-point can be achieved. This low bit-width fixed point DNN can be deployed into low power consumption platforms like FPGA, ASIC or some neuromorphic chips. The disclosed methods can be applied to different datasets and different neural networks following the same process.
Turning to
The flow in
In
Referring to
Furthermore, although it is expected that the DNN 190 would not be implemented as a low power DNN platform 130 until after the process 120 is performed and the trained fixed point (or fix-point) DNN 125 has been created, it is also possible to both simulate the DNN 190 and perform the corresponding process 120 in circuitry 197, such as an FPGA 197-1, an ASIC 197-2, and/or a neuromorphic chip 197-3. This may be performed as an alternative to operations performed the computer system(s) 140 or in addition to those.
Turning to
The flow for the auto scaling of DNNs process 120 starts in block 205, and in block 210, the scaling factors are initialized. The scaling factors for each neural network layer are initialized empirically. In an example, a reasonable number is used as a starting point of the scaling factor of each layer. Reasonable means the number is within the upper and lower bound and in most cases, the number will not make the network instable. In block 215, the training parameters are set. Setting the training parameters include at least deploying the initialized or updated scaling factors to be used for the subsequent training in block 220. In block 220, the DNN is trained (e.g., using samples from the dataset 110). In block 225, the scaling factors are updated, e.g., through multiple stages of auto scaling, described below. In block 230, it is determined whether the training is finished. If not (block 230=No), the process 120 proceeds to block 215. If the training is finished (block 230—Yes), the process 120 ends in 235. At this point, the output is the trained fixed point DNN 125.
Before proceeding with additional detail regarding the auto scaling enabled training used herein, it is helpful to review additional description regarding the scaling factor. Simplistically, a scaling factor, Sf, is used to convert a floating point number to a fixed point number, which is essential in fixed-point implementations, e.g., using the following:
If the bit width is W for a fixed point number, then the range of a signed fixed point number is (−2(W-1), 2(W-1)−1), and the range of unsigned fixed point number is (0,2W−1).
The fixed point number needs to be saturated within the range decided by its bit width. If one knows the range of float and fix, usually Sf, can be decided as follows:
For example, if one knows the floating point number to be express is from −1024 to 1024 and will be expressed by a 3-bit fixed point number (able to represent −4:3), then a good scaling factor could be
(as the maximum for the fixed point number is −4).
In real situations, usually one cannot determine the maximum of floating point numbers because this maximum is random. Also one does not want to lose the accuracy such that a rare big number cannot be expressed. Hence, another good way to estimate the maximum for a floating point number is to determine the statistical information of the floating point number. Usually if the data size is large enough, it can be assumed that the distribution will be Gaussian like. In DNNs, the parameters can be in the millions, which is quite large. The techniques below therefore use statistical information for the floating point numbers in order to determine the scaling factors.
The process 225 starts in block 305, and in block 310, it is determined if there are enough samples to perform updating of the scaling factors. Auto scaling will be carried out when enough training samples have been used for training. This could be every N samples, where N should be large enough, such as 0.1˜1× (from 10 percent to all) of whole training samples. Using too small N will cause scaling factor adjustment become jittering. If there are not enough samples (block 310=No), the process 225 ends in block 335. Otherwise, if there are enough samples (block 310=Yes), the process 225 continues in block 315.
In block 315, statistics for the layer n are determined. As stated above, a DNN 190 has multiple layers, and each layer has its input and output. In block 315, collection of all the output of each DNN layer is performed (e.g., by the controller 170). After training with enough samples (see block 310), the mean and standard deviation are calculated (e.g., again by the controller 170) for each layer.
This step is specially designed to get the suitable scaling factor, which is not required for traditional pure float point DNN training. These statistics are the mean, μn, and the standard deviation, δn as illustrated in block 315 and used below.
In block 320, a scaling factor, Sf, is calculated based on each layer's statistical information. The bit width of each layer's filter is predefined (e.g., a hyper parameter). Only one scaling factor is needed for each layer to decide on output. A new scaling factor, Sfn_new, is determined via the following equation, in an exemplary embodiment, which is a layer by layer adaption of the scaling factors:
where:
μn is a mean of the floating point numbers used for the layer n;
δn is a standard deviation of the floating point numbers used for the layer n;
K is used to control a range of floating point numbers (a typical value might be four);
Rn: is a range of fixed point numbers for the layer n;
old indicates a previous value; and
new indicates a current value.
The range Rn is decided by the fixed number's bit width. For instance, if we use seven digits to represent the floating point numbers for a particular layer, then the range is 64 (=2(x-1), where x in this case is the number of digits, seven). That is, seven digits can represent −64˜63 (negative 64 to positive 63, assuming signed integers). The range can be set per layer or per all layers.
It should be noted that the scaling factor for a layer such as layer 3 (=n) depends on the (old and new) scaling factors for previous layers 1 and 2. This is true because if one modifies the scaling factor in the previous layer, the following layer's data distribution is also changed. The previous equation considers the chained change. For example, if one uses a scaling factor of two instead of four for layer 1, then layer 1's output will be twice as large. Then layer 2's output will also be twice as large if one did not modify layer 2's scaling factor. This is an important point to make the scaling factor adjustment stable.
It should also be noted that using the mean and standard deviation to represent the statistical information of each layer's output is just one example, and other techniques are possible. For instance, in Matthieu Courbariaux, Jean-Pierre David, Yoshua Bengio, “Training Deep Neural Networks With Low Precision Multiplications”, arXiv:1511.00363 (2016), this reference uses overflow rate, which is another possibility. In the Courbariaux reference, they used dynamic fixed point (and an overflow rate) and updated the scaling factors once every 10000 examples. See, e.g., the Algorithm 2, Policy to update a scaling factor, in Section 5, entitled “DYNAMIC FIXED POINT”. Such an algorithm could be adapted for use here, but with the above layer by layer adaption of the scaling factors, where a scaling factor for one layer depends on the scaling factors for previous layers (e.g., determining the scaling factor for a selected layer, which is at a position in an order of layers from a starting layer to an ending layer in a DNN, is based on scaling factors used in layers in the order prior to the position of the selected layer).
Additionally, one can always find different ways to represent the statistical information. For example, one can use variance instead of standard deviation; for mean, this can be replaced by a middle value (median). Other techniques are also possible.
In block 325, the scaling factor, Sfn_new, is saturated within [lower bound, upper bound]. That is, the scaling factor will be set to the lower bound if the scaling factor is less than the lower bound, or will be set to the upper bound if the scaling factor is greater than the upper bound. The bounds are typically predefined parameters, such as in an exemplary embodiment the bound can be specified for each layer. Alternatively, the bounds could be the same for all the layers. In block 330, there is a multiple stage scaling adjustment, described below. The flow 225 ends in block 335.
The multiple stage scaling adjustment in block 330 may be performed as follows. Typically, large steps are employed at the beginning iterations of the updating of the scaling factor, and then smaller steps are performed in later iterations. Finally, scaling adjustment can be disabled to achieve a stable training performance. An implementation example is as follows:
Sf
n
_
new
=Sf
n
+a(Sfn
The variable a can be used to control the adjusting speed for different stages of iterations. In the beginning iteration(s), a could be 1, then 0.5, then 0.1 and so on. In a fixed stage, a can be 0 (zero). The fixed stage is when the adjusting speed is no longer being adjusted, which typically occurs in the later iterations.
The present invention may be a system, a method, and/or a computer program product at any possible technical detail level of integration. The computer program product may include a computer readable storage medium (or media) having computer readable program instructions thereon for causing a processor to carry out aspects of the present invention.
The computer readable storage medium can be a tangible device that can retain and store instructions for use by an instruction execution device. The computer readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer readable storage medium includes the following: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire.
Computer readable program instructions described herein can be downloaded to respective computing/processing devices from a computer readable storage medium or to an external computer or external storage device via a network, for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing/processing device.
Computer readable program instructions for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, configuration data for integrated circuitry, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++, or the like, and procedural programming languages, such as the “C” programming language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) may execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention.
Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer readable program instructions.
These computer readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the blocks may occur out of the order noted in the Figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.