COMPUTER READABLE RECORDING MEDIUM STORING ARITHMETIC PROGRAM, ARITHMETIC METHOD, AND ARITHMETIC DEVICE
A computer-implemented method of an arithmetic processing, the method including: identifying maximum absolute values of individual dimensions by projecting a maximum absolute value in a direction of each of the individual dimensions of a tensor represented by a multidimensional array, the tensor in which a value is set for each of elements of the array; identifying a minimum value that indicates a minimum maximum absolute value among the maximum absolute values of the individual dimensions; and setting a quantization range for the tensor on a basis of the minimum value.
Latest FUJITSU LIMITED Patents:
- RADIO ACCESS NETWORK ADJUSTMENT
- COOLING MODULE
- COMPUTER-READABLE RECORDING MEDIUM STORING INFORMATION PROCESSING PROGRAM, INFORMATION PROCESSING METHOD, AND INFORMATION PROCESSING DEVICE
- CHANGE DETECTION IN HIGH-DIMENSIONAL DATA STREAMS USING QUANTUM DEVICES
- NEUROMORPHIC COMPUTING CIRCUIT AND METHOD FOR CONTROL
This application is based upon and claims the benefit of priority of the prior Japanese Patent Application No. 2021-146728, filed on Sep. 9, 2021, the entire contents of which are incorporated herein by reference.
FIELDThe embodiments discussed herein are related to a non-transitory computer-readable storage medium storing an arithmetic program and the like.
BACKGROUNDIn deep learning, there is a method of quantizing data values to speed up a process of machine learning for a learning model. Here, an existing technique of quantizing a tensor used for the machine learning will be described.
A value of the tensor is expressed by the formula (1). Element data of the tensor is represented by an FP format (s-ebit-mbit) and an exponent part bias b. For example, in the example indicated by the formula (1), s represents a 1-bit fixed sign bit. The number of bits in the exponent part e is represented by ebit. The number of bits in the mantissa m is represented by mbit. A bias value of the exponent part is represented by b. All elements in the tensor use the same ebit, mbit, and b.
In the existing technique, there is a rounding range due to the upper and lower quantization.
According to the existing technique, the quantization target range is calculated on the basis of the maximum absolute value (max_e) of an element of a quantization target tensor T. The maximum absolute value is calculated on the basis of the formula (2).
International Publication Pamphlet No. WO 2020/065874, International Publication Pamphlet No. WO 2019/146189, and U.S. Patent Application Publication No. 2019/0340492 are disclosed as related art.
SUMMARYAccording to an aspect of the embodiments, there is provided a computer-implemented method of an arithmetic processing. In an example, the method includes: identifying maximum absolute values of individual dimensions by projecting a maximum absolute value in a direction of each of the individual dimensions of a tensor represented by a multidimensional array, the tensor in which a value is set for each of elements of the array; identifying a minimum value that indicates a minimum maximum absolute value among the maximum absolute values of the individual dimensions; and setting a quantization range for the tensor on a basis of the minimum value.
The object and advantages of the invention will be realized and attained by means of the elements and combinations particularly pointed out in the claims.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory and are not restrictive of the invention.
However, the existing technique described above has a problem that a mathematical property of the tensor changes at a time of quantizing the tensor.
In one aspect, the embodiments aim to provide an arithmetic program, an arithmetic method, and an arithmetic device capable of quantizing a tensor without changing a mathematical property of the tensor.
Hereinafter, embodiments of an arithmetic program, an arithmetic method, and an arithmetic device disclosed in the present application will be described in detail with reference to the drawings. Note that the embodiments do not limit the present disclosure.
First EmbodimentAn arithmetic device according to a first embodiment executes the following processing to set a range of quantization in order to quantize a tensor without changing a mathematical property of the tensor.
The arithmetic device projects the maximum absolute value in the direction of each of dimensions, thereby identifying the individual maximum absolute values of the dimensions. For example, the arithmetic device projects the maximum absolute value in the row direction of the elements (0, 0), (0, 1), and (0, 2), thereby identifying “16”. The arithmetic device projects the maximum absolute value in the row direction of the elements (1, 0), (1, 1), and (1, 2), thereby identifying “1,024”. The arithmetic device projects the maximum absolute value in the row direction of the elements (2, 0), (2, 1), and (2, 2), thereby identifying “128”.
The arithmetic device projects the maximum absolute value in the column direction of the elements (0, 0), (1, 0), and (2, 0), thereby identifying “128”. The arithmetic device projects the maximum absolute value in the column direction of the elements (0, 1), (1, 1), and (2, 1), thereby identifying “1,024”. The arithmetic device projects the maximum absolute value in the column direction of the elements (0, 2), (1, 2), and (2, 2), thereby identifying “128”.
The arithmetic device identifies the minimum maximum absolute value among the maximum absolute values of the individual dimensions identified by the processing described above. In the following descriptions, the minimum maximum absolute value will be referred to as a “minimum value a”. In the example illustrated in
The arithmetic device specifies “rank_e” on the basis of the minimum value a. On the basis of the formula (3), rank_e is specified. When the minimum value a=16, rank_e=4.
rank_e=[log2a] (3)
The arithmetic device sets a quantization range on the basis of rank_e. For example, it is assumed that the quantization range is [rank_e, rank_e+E]. Here, E represents a quantization exponent width, and is specified in advance. In a case where rank_e=4 and E=2, the quantization range is [4, 5].
Meanwhile, according to the existing technique, the quantization range is determined on the basis of max_e. There is a relation of max_e=log2 (a′+E), and a′ represents the maximum absolute value of each element of the tensor Ta. The quantization range based on max_e is [log2a′, log2 (a′+E)]. For example, the maximum absolute value a′ of the tensor Ta illustrated in
Meanwhile, when the quantization is carried out with max_e as in the existing technique, the quantization range is “9, 10”, and the tensor Ta is quantized into a tensor Tc. According to such quantization, only the maximum value 1,024 (=210) becomes a non-zero element, and the rank is also lowered to 1, whereby the mathematical property of the tensor is greatly impaired.
Next, an exemplary configuration of the arithmetic device according to the first embodiment will be described.
The communication unit 110 is connected to an external device or the like by wire or wirelessly, and exchanges information with the external device or the like. For example, the communication unit 110 is implemented by a network interface card (NIC) or the like. The communication unit 110 may be connected to a network (not illustrated). The communication unit 110 may receive a quantization target tensor 140a from an external device via the network.
The input unit 120 is an input device that inputs various types of information to the arithmetic device 100. The input unit 120 corresponds to a keyboard, a mouse, a touch panel, or the like.
The display unit 130 is a display device that displays information output from the control unit 150. The display unit 130 corresponds to a liquid crystal display, an organic electro luminescence (EL) display, a touch panel, or the like.
The storage unit 140 includes the quantization target tensor 140a and a quantized tensor 140b. The storage unit 140 is implemented by, for example, a semiconductor memory element such as a random access memory (RAM), a flash memory, or the like, or a storage device such as a hard disk, an optical disk, or the like.
The quantization target tensor 140a indicates a tensor to be quantized. In the first embodiment, the quantization target tensor 140a is to be the two-dimensional tensor Ta described with reference to
The quantized tensor 140b is a tensor obtained as a result of quantizing the quantization target tensor 140a. For example, the quantized tensor 140b corresponds to the tensor Tb described with reference to
The control unit 150 includes a specifying unit 151, a setting unit 152, and a quantization unit 153. The control unit 150 is implemented by, for example, a central processing unit (CPU) or a micro processing unit (MPU). Furthermore, the control unit 150 may be implemented by, for example, an integrated circuit such as an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or the like.
The specifying unit 151 projects the maximum absolute value in the direction of each dimension of the quantization target tensor 140a, thereby identifying the maximum absolute value of each dimension. The specifying unit 151 identifies the minimum value a indicating the minimum maximum absolute value among the maximum absolute values of the individual dimensions. The specifying unit 151 outputs information regarding the minimum value a to the setting unit 152.
Processing of the specifying unit 151 will be described with reference to
The specifying unit 151 projects the maximum absolute value in the column direction of the elements (0, 0), (1, 0), and (2, 0), thereby identifying “128”. The specifying unit 151 projects the maximum absolute value in the column direction of the elements (0, 1), (1, 1), and (2, 1), thereby identifying “1,024”. The specifying unit 151 projects the maximum absolute value in the column direction of the elements (0, 2), (1, 2), and (2, 2), thereby identifying “128”.
The specifying unit 151 identifies the minimum value a from the maximum absolute values of the individual dimensions identified by the process described above. In the example illustrated in
The setting unit 152 sets a quantization range for the quantization target tensor 140a on the basis of the minimum value a. The setting unit 152 outputs information regarding the quantization range to the quantization unit 153.
The setting unit 152 specifies rank_e on the basis of the minimum value a and the formula (3). The setting unit 152 sets the quantization range [rank_e, rank_e+E] on the basis of rank_e. For example, in a case where the minimum value a=16, rank_e=4 and the quantization range is [4, 5].
The quantization unit 153 quantizes the quantization target tensor 140a within the quantization range received from the setting unit 152, thereby generating a quantized tensor 140b.
Processing of the quantization unit 153 will be described with reference to
The quantization unit 153 may transmit the quantized tensor 140b to an external device serving as a transmission source of the quantization target tensor 140a. For example, such an external device executes machine learning of a learning model using the quantized tensor 140b. Note that, although illustration is omitted, the arithmetic device 100 may execute the machine learning of the learning model using the quantized tensor 140b.
Next, an exemplary processing procedure of the arithmetic device 100 according to the first embodiment will be described.
The specifying unit 151 projects the maximum absolute value of each dimension for all the elements of the quantization target tensor 140a (step S102). The specifying unit 151 identifies the minimum value a among the maximum absolute values of all dimensions (step S103).
The setting unit 152 of the arithmetic device 100 calculates rank_e on the basis of the minimum value a (step S104). The setting unit 152 sets the quantization range [rank_e, rank_e+E] on the basis of rank_e (step S105).
The quantization unit 153 of the arithmetic device 100 quantizes the quantization target tensor 140a in the quantization range (step S106). The quantization unit 153 outputs the quantized tensor 140b (step S107).
Next, effects of the arithmetic device 100 according to the first embodiment will be described. The arithmetic device 100 projects the maximum absolute value in the direction of each of dimensions of the quantization target tensor 140a to identify the maximum absolute value of each of the dimensions, and identifies the minimum value a from the maximum absolute values of the individual dimensions. The arithmetic device 100 sets the quantization range on the basis of the minimum value a to carry out quantization. This makes it possible to quantize the tensor without changing the mathematical property of the tensor.
For example, as described with reference to
Meanwhile, when the quantization is carried out with max_e as in the existing technique, the quantization range is “9, 10”, and the tensor Ta is quantized into a tensor Tc. According to such quantization, only the maximum value 1,024 (=210) becomes a non-zero element, and the rank is also lowered to 1, whereby the mathematical property of the tensor is greatly impaired.
Second Embodiment
e0=min(rank_e,max_e) (4)
The arithmetic device according to the second embodiment identifies the smaller minimum value e0 of rank_e and max_e, and sets the quantization range [e0, e0+E] using the minimum value e0, whereby it is enabled to quantize the tensor more appropriately, and to enhance learning accuracy at the time of executing machine learning.
Descriptions regarding the communication unit 210, the input unit 220, and the display unit 230 are similar to the descriptions regarding the communication unit 110, the input unit 120, and the display unit 130 described with reference to
The storage unit 240 includes a quantization target tensor 240a and a quantized tensor 240b. The storage unit 240 is implemented by, for example, a semiconductor memory element such as a RAM, a flash memory, or the like, or a storage device such as a hard disk, an optical disk, or the like.
Description regarding the quantization target tensor 240a is similar to the description regarding the quantization target tensor 140a. Description regarding the quantized tensor 240b is similar to the description regarding the quantized tensor 140b.
The control unit 250 includes a calculation unit 251, a specifying unit 252, a setting unit 253, and a quantization unit 254. The control unit 250 is implemented by, for example, a CPU or an MPU. Furthermore, the control unit 250 may be implemented by, for example, an integrated circuit such as an ASIC, an FPGA, or the like.
The calculation unit 251 calculates max_e, which is the maximum absolute value, among all the elements of the quantization target tensor 240a. For example, the calculation unit 251 calculates max_e using the formula (2) mentioned above. The calculation unit 251 outputs information regarding max_e to the setting unit 253.
The specifying unit 252 identifies the minimum value a on the basis of the quantization target tensor 240a. A process in which the specifying unit 252 identifies the minimum value a is similar to the process in which the specifying unit 151 identifies the minimum value a described in the first embodiment. The specifying unit 252 outputs information regarding the minimum value a to the setting unit 253.
The setting unit 253 specifies rank_e on the basis of the minimum value a and the formula (3). The setting unit 253 identifies the minimum value e0 on the basis of the formula (4), rank_e, and max_e. The setting unit 253 sets the quantization range [e0, e0+E] using the minimum value e0. The setting unit 253 outputs information regarding the quantization range to the quantization unit 254.
The quantization unit 254 quantizes the quantization target tensor 240a within the quantization range received from the setting unit 253, thereby generating a quantized tensor 240b. Processing of the quantization unit 254 is similar to the processing of the quantization unit 153 described in the first embodiment.
Next, an exemplary processing procedure of the arithmetic device 200 according to the second embodiment will be described.
The calculation unit 251 calculates max_e on the basis of the quantization target tensor 240a (step S202). The specifying unit 252 of the arithmetic device 200 projects the maximum absolute value of each dimension for all the elements of the quantization target tensor 240a (step S203). The specifying unit 252 identifies the minimum value a among the maximum absolute values of all dimensions (step S204).
The setting unit 253 of the arithmetic device 200 calculates rank_e on the basis of the minimum value a (step S205). The setting unit 253 identifies the minimum value e0 of rank_e and max_e (step S206). The setting unit 253 sets the quantization range [e0, e0+E] on the basis of the minimum value e0 (step S207).
The quantization unit 254 of the arithmetic device 200 quantizes the quantization target tensor 240a in the quantization range (step S208). The quantization unit 254 outputs the quantized tensor 240b (step S209).
Next, effects of the arithmetic device 200 according to the second embodiment will be described. The arithmetic device 200 identifies the minimum value e0 from max_e and rank_e obtained from the quantization target tensor 240a, and sets the quantization range on the basis of the minimum value e0 to carry out quantization. As a result, it becomes possible to quantize the tensor more appropriately, and to enhance the learning accuracy at the time of executing the machine learning.
Meanwhile, while the setting unit 253 sets the smaller one of rank_e and max_e as the minimum value e0 to set the quantization range in the second embodiment described above, it is not limited to this. The setting unit 253 may calculate a weighted sum ew of rank_e and max_e to set the quantization range on the basis of the weighted sum ew.
For example, the setting unit 253 calculates the weighted sum ew on the basis of the formula (5). In the formula (5), c represents a constant, which is set in a range of 0≤c≤1. The setting unit 253 sets the quantization range as [ew, ew+E].
ew=c*rank_e+(1−c)*max_e (5)
Here, the inventor measured learning accuracy for a learning model for a tensor (first tensor) quantized by the existing technique, a tensor (second tensor) quantized by the method of the first embodiment, and a tensor (third tensor) quantized by the method (weighted sum) of the second embodiment. As a result, the learning accuracy of the first tensor was “79.30%”, the learning accuracy of the second tensor was “79.89%”, and the learning accuracy of the third tensor was “80.27%”. For example, according to the quantization methods of the first and second embodiments, it is possible to enhance the learning accuracy at the time of executing the machine learning as compared with the existing technique.
Next, an exemplary hardware configuration of a computer that implements functions similar to those of the arithmetic device 200 (100) indicated in the embodiments described above will be described.
As illustrated in
The hard disk device 307 includes a calculation program 307a, a specifying program 307b, a setting program 307c, and a quantization program 307d. Furthermore, the CPU 301 reads each of the programs 307a to 307d, and loads it in the RAM 306.
The calculation program 307a functions as a calculation process 306a. The specifying program 307b functions as a specifying process 306b. The setting program 307c functions as a setting process 306c. The quantization program 307d functions as a quantization process 306d.
Processing of the calculation process 306a corresponds to the processing of the calculation unit 251. Processing of the specifying process 306b corresponds to the processing of the specifying units 151 and 252. Processing of the setting process 306c corresponds to the processing of the setting units 152 and 253. Processing of the quantization process 306d corresponds to the processing of the quantization units 153 and 254.
Note that each of the programs 307a to 307d may not necessarily be stored in the hard disk device 307 beforehand. For example, each of the programs is stored in a “portable physical medium” to be inserted in the computer 300, such as a flexible disk (FD), a compact disc read only memory (CD-ROM), a digital versatile disc (DVD), a magneto-optical disk, an IC card, or the like. Then, the computer 300 may read and execute each of the programs 307a to 307d.
All examples and conditional language provided herein are intended for the pedagogical purposes of aiding the reader in understanding the invention and the concepts contributed by the inventor to further the art, and are not to be construed as limitations to such specifically recited examples and conditions, nor does the organization of such examples in the specification relate to a showing of the superiority and inferiority of the invention. Although one or more embodiments of the present invention have been described in detail, it should be understood that the various changes, substitutions, and alterations could be made hereto without departing from the spirit and scope of the invention.
Claims
1. A non-transitory computer-readable recording medium storing an arithmetic program for causing a computer to execute a process comprising:
- identifying maximum absolute values of individual dimensions by projecting a maximum absolute value in a direction of each of the individual dimensions of a tensor represented by a multidimensional array, the tensor in which a value is set for each of elements of the array;
- identifying a minimum value that indicates a minimum maximum absolute value among the maximum absolute values of the individual dimensions; and
- setting a quantization range for the tensor on a basis of the minimum value.
2. The non-transitory computer-readable recording medium according to claim 1, wherein the setting the quantization range sets the quantization range on a basis of a smaller value of the minimum value and a value obtained by subtracting a value that corresponds to the quantization range from the maximum absolute value of all the elements included in the tensor.
3. The non-transitory computer-readable recording medium according to claim 1, wherein the setting the quantization range sets the quantization range on a basis of a weighted sum of the minimum value and a value obtained by subtracting a value that corresponds to the quantization range from the maximum absolute value of all the elements included in the tensor.
4. The non-transitory computer-readable recording medium according to claim 1, the processing further comprising: quantizing the tensor on a basis of the quantization range set for the tensor.
5. A computer-implemented method of an arithmetic processing, the method comprising:
- identifying maximum absolute values of individual dimensions by projecting a maximum absolute value in a direction of each of the individual dimensions of a tensor represented by a multidimensional array, the tensor in which a value is set for each of elements of the array;
- identifying a minimum value that indicates a minimum maximum absolute value among the maximum absolute values of the individual dimensions; and
- setting a quantization range for the tensor on a basis of the minimum value.
6. An arithmetic apparatus comprising:
- a memory; and
- a processor coupled to the memory, the processor being configured to perform processing including:
- identifying maximum absolute values of individual dimensions by projecting a maximum absolute value in a direction of each of the individual dimensions of a tensor represented by a multidimensional array, the tensor in which a value is set for each of elements of the array;
- identifying a minimum value that indicates a minimum maximum absolute value among the maximum absolute values of the individual dimensions; and
- setting a quantization range for the tensor on a basis of the minimum value.
Type: Application
Filed: Jun 8, 2022
Publication Date: Mar 9, 2023
Applicant: FUJITSU LIMITED (Kawasaki-shi)
Inventor: Yutaka Tamiya (Yokohama)
Application Number: 17/834,981