WO2025260957A1 - Data processing apparatus, processor, board, and data processing method - Google Patents

Data processing apparatus, processor, board, and data processing method

Info

Publication number
WO2025260957A1
WO2025260957A1 PCT/CN2025/090097 CN2025090097W WO2025260957A1 WO 2025260957 A1 WO2025260957 A1 WO 2025260957A1 CN 2025090097 W CN2025090097 W CN 2025090097W WO 2025260957 A1 WO2025260957 A1 WO 2025260957A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
quantized
circuit
scaling factor
processing apparatus
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
PCT/CN2025/090097
Other languages
French (fr)
Chinese (zh)
Inventor
刘恩赫
李震
刘少礼
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Cambricon Information Technology Co Ltd
Original Assignee
Shanghai Cambricon Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Cambricon Information Technology Co Ltd filed Critical Shanghai Cambricon Information Technology Co Ltd
Publication of WO2025260957A1 publication Critical patent/WO2025260957A1/en
Pending legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F15/00Digital computers in general; Data processing equipment in general
    • G06F15/76Architectures of general purpose stored program computers
    • G06F15/78Architectures of general purpose stored program computers comprising a single central processing unit
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/15Correlation function computation including computation of convolution operations
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/16Matrix or vector computation, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/18Complex mathematical operations for evaluating statistical data, e.g. average values, frequency distributions, probability functions, regression analysis
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/483Computations with numbers represented by a non-linear combination of denominational numbers, e.g. rational numbers, logarithmic number system or floating-point numbers
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00Computing arrangements using knowledge-based models
    • G06N5/04Inference or reasoning models

Definitions

  • This disclosure generally relates to the field of computer processors. More specifically, this disclosure relates to a data processing apparatus, a processor, a circuit board, and a data processing method implemented by the data processing apparatus.
  • the Open Compute Project introduced the MX (MicroXcaling) quantization format.
  • the MX quantization format is an interoperable quantization data format with shared, fine-grained block sizes.
  • MX-compliant data formats support AI training and inference, featuring lower bit-width arithmetic operations and smaller memory footprints, thus driving improvements in hardware performance and efficiency, thereby reducing overhead and operating costs.
  • this disclosure proposes a convolution operation scheme compatible with the MX quantization format in several aspects. Furthermore, an improved MX quantization scheme is also provided.
  • this disclosure provides a data processing apparatus, comprising: a control circuit configured to parse a convolution instruction, the convolution instruction instructing a convolution operation on an input neuron and weights to obtain an output neuron, wherein either or both of the input neuron and weights are particle-quantized; and a computation circuit configured to perform a convolution operation on data of the input neuron and data of the weights according to the convolution instruction, and to fuse scaling factors of the input neuron and/or scaling factors of the weights in the convolution operation.
  • this disclosure provides a processor that includes the data processing apparatus described in the first aspect.
  • this disclosure provides a board that includes the processor described in the second aspect above.
  • this disclosure provides a data processing method implemented by a data processing apparatus, the data processing apparatus including a control circuit and a computation circuit, the method comprising: the control circuit parsing a convolution instruction, the convolution instruction instructing a convolution operation on an input neuron and weights to obtain an output neuron, wherein either or both of the input neuron and weights are particle-quantized; and the computation circuit performing a convolution operation on the data of the input neuron and the data of the weights according to the convolution instruction, and fusing the scaling factor of the input neuron and/or the scaling factor of the weights in the convolution operation.
  • the data dequantization process can be integrated into the convolution operation without prior dequantization. This avoids separate dequantization processing and fully utilizes the advantages of low bit width and small memory footprint of the particle quantization format in the convolution operation.
  • the particle quantization format may include the MX quantization format proposed by OCP and the extended MX quantization format proposed in this disclosure embodiment.
  • the operand bit widths are asymmetrical, only the data portion of the operand can be processed, without needing to process the operand scaling factor, thereby simplifying the computation. Moreover, this processing allows for the mixed execution of operations with operands of various data types.
  • particle quantization of the results of convolution operations i.e., the output neurons
  • This particle quantization facilitates online hardware quantization and supports multiple data types of the quantized scaling factors, thereby improving algorithm accuracy.
  • the scaling factor obtained by extended MX quantization can also be compressed, thereby reducing the waste of storage space and bandwidth.
  • Figure 1 shows a structural diagram of the board card according to an embodiment of this disclosure
  • Figure 2 shows a structural diagram of the combined processing apparatus according to an embodiment of this disclosure
  • Figure 3 shows a schematic diagram of the internal structure of the processing core when the computing device is a single-core or multi-core device
  • Figure 4 shows a schematic diagram of the MX quantization data format
  • Figure 5 shows a schematic block diagram of a data quantization apparatus according to some embodiments of this disclosure
  • Figure 6 shows a schematic block diagram of the comparison circuit of some embodiments of this disclosure.
  • Figure 7 illustrates a schematic structural diagram of a data processing apparatus that can implement embodiments of the present disclosure
  • Figure 8 shows an exemplary flowchart of a data processing method implemented by a data processing circuit according to an embodiment of this disclosure.
  • sign is the sign bit, 0 for positive and 1 for negative
  • E represents the exponent (or index), which is a weighted sum of 2 raised to the power of E (possibly a negative power)
  • mantissa represents the mantissa, a binary fraction.
  • Floating-point numbers are represented in computers using three fields, each encoded separately:
  • Fixed-point numbers are a way of representing numbers in computers, characterized by a fixed decimal point. Fixed-point numbers can represent integers or decimals, depending on the implicit position of the decimal point.
  • a fixed-point number consists of three parts: a shared exponent, a sign bit, and a mantissa.
  • the shared exponent means that the exponent is shared within a set of real numbers to be quantized; the sign bit indicates whether the fixed-point number is positive or negative; and the mantissa determines the number of significant digits, i.e., the precision.
  • Bit width How many bits are used to represent data.
  • Quantization The process of converting high-precision numbers into lower-precision data that takes up less memory.
  • Dequantization The process of converting low-precision numbers into higher-precision data.
  • FP* Represents a floating-point data type, where * can be an integer such as 2, 4, 6, 8, 16, 32, 64, etc. The value of * indicates the bit width of the data represented by this data type.
  • BF16 and TF32 are data types suitable for deep learning, which improve computational performance by sacrificing precision and range.
  • int* Represents an integer data type, where * can be an integer such as 2, 4, 6, 8, 16, 32, 64, etc.
  • the value of * indicates the bit width of the data represented by this data type.
  • ExMy A data format where E represents the exponent, M represents the mantissa, x represents the exponent width, and y represents the mantissa width.
  • MX refers to the Microscaling specification (see “OCP Microscaling Formats (MX) Specification Version 1.0”).
  • Extended MX refers to a quantization scheme proposed in the embodiments disclosed herein.
  • Granular quantization This includes MX and extended MX, as well as other quantizations with similar data structures.
  • the quantization granularity is determined based on the amount of data that the arithmetic unit can process at one time.
  • the data to be quantized or dequantized can be various data in the neural network, including but not limited to input neurons, weights, output neurons, gradients, etc.
  • the neural network provided in this disclosed embodiment can be applied to various fields and can process various types of data.
  • AI applications such as game AI, virtual reality, and animation generation can include data types such as game state data and user interaction data.
  • applications such as physics simulation, chemical compound prediction, and astrophysical analysis can include data types such as experimental data, simulation results, and observational data.
  • Generative AI applications utilize complex algorithms, models, and rules to learn from large-scale datasets to create new, original content. This includes, but is not limited to, creating various types of content such as text, images, audio, video, and code.
  • the input neuron data processed can be unquantized or quantized image data, audio data, video data, speech data, text data, document data, etc.
  • the corresponding output neuron data can also be unquantized or quantized image data, audio data, video data, speech data, text data, document data, etc.
  • the output of the neural network can include a probability score of an image belonging to a specific object category, a probability score of a document relating to a specific topic, a probability score of the correct translation of a text fragment in the target language from a text fragment in the source language, or a probability score of the correct transcription of a text fragment from spoken language, etc.
  • These output data can also be quantized or unquantized.
  • the data quantization scheme of this disclosure embodiment can also be used in the inference and training of neural networks. By performing the quantization process described in this disclosure embodiment on the data of the neural network, the accuracy of the task can be guaranteed when the neural network performs one or more of the aforementioned processing tasks, while improving the speed and performance of the neural network model's inference and training.
  • FIG. 1 shows a schematic diagram of the structure of a board 10 according to an embodiment of this disclosure.
  • the board 10 includes one or more chips 101, which are system-on-chips (SoCs) that integrate one or more combined processing devices.
  • SoCs system-on-chips
  • the combined processing device is an artificial intelligence computing unit used to support various deep learning and machine learning algorithms, meeting the intelligent processing needs of complex scenarios in fields such as computer vision, speech, natural language processing, and data mining.
  • deep learning technology is widely used in the field of cloud intelligence.
  • a significant characteristic of cloud intelligence applications is the large amount of input data, which places high demands on the platform's storage and computing capabilities.
  • the board 10 of this embodiment is suitable for cloud intelligence applications, possessing massive off-chip storage, on-chip storage, and powerful computing capabilities.
  • Chip 101 is connected to external device 103 via external interface device 102.
  • External device 103 may be, for example, a server, computer, camera, monitor, mouse, keyboard, network card, or Wi-Fi interface.
  • Data to be processed can be transmitted from external device 103 to chip 101 via external interface device 102.
  • the calculation results from chip 101 can be transmitted back to external device 103 via external interface device 102.
  • external interface device 102 may have different interface forms, such as PCIe (Peripheral Component Interconnect Express) interface.
  • the board 10 also includes a storage device 104 for storing data, which includes one or more memory cells 105.
  • the storage device 104 is connected to and transmits data with the controller 106 and the chip 101 via a bus.
  • the controller 106 in the board 10 is configured to regulate the state of the chip 101. Therefore, in one application scenario, the controller 106 may include a microcontroller, also known as a microcontroller unit (MCU).
  • MCU microcontroller unit
  • FIG. 2 is a structural diagram illustrating the combined processing device in chip 101 of this embodiment.
  • the combined processing device 20 includes a computing device 201, an interface device 202, a processing device 203, and a storage device 204.
  • the computing device 201 is configured to perform user-specified operations. It is mainly implemented as a single-core intelligent processor or a multi-core intelligent processor to perform deep learning or machine learning calculations. It can interact with the processing device 203 through the interface device 202 to jointly complete the user-specified operations.
  • Interface device 202 is used to transmit data and control commands between computing device 201 and processing device 203.
  • computing device 201 can obtain input data from processing device 203 via interface device 202 and write it to on-chip storage device of computing device 201.
  • computing device 201 can obtain control commands from processing device 203 via interface device 202 and write them to on-chip control cache of computing device 201.
  • interface device 202 can also read data from storage device of computing device 201 and transmit it to processing device 203.
  • Processing device 203 performs basic control including but not limited to data transfer, and starting and/or stopping computing device 201.
  • processing device 203 may be one or more types of processors, including but not limited to digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., and their number can be determined according to actual needs.
  • DSPs digital signal processors
  • ASICs application-specific integrated circuits
  • FPGAs field-programmable gate arrays
  • computing device 201 disclosed herein can be considered as having a single-core structure or a homogeneous multi-core structure. However, when computing device 201 and processing device 203 are considered together, they are considered to form a heterogeneous multi-core structure.
  • Storage device 204 is used to store data to be processed. It may be DRAM (Dynamic Random Access Memory) or DDR (Double Data Rate) memory, typically 16G or larger, and is used to store data of computing device 201 and/or processing device 203.
  • DRAM Dynamic Random Access Memory
  • DDR Double Data Rate
  • FIG 3 shows a schematic diagram of the internal structure of the processing core when the computing device 201 in Figure 2 is a single-core or multi-core device.
  • the computing device 301 is used to process input data such as computer vision, speech, natural language, and data mining.
  • the computing device 301 includes three main modules: a control module 31 (also called a controller), an arithmetic module 32 (also called an arithmetic unit), and a storage module 33 (also called a memory).
  • the control module 31 coordinates and controls the operation of the computation module 32 and the storage module 33 to complete the deep learning task. It includes an instruction fetch unit (IFU) 311 and an instruction decode unit (IDU) 312.
  • the instruction fetch unit 311 fetches instructions from the processing device 203, and the instruction decode unit 312 decodes the fetched instructions and sends the decoding result as control information to the computation module 32 and the storage module 33.
  • the computation module 32 includes a vector operation unit 321 and a matrix operation unit 322.
  • the vector operation unit 321 is used to perform vector operations and can support complex operations such as vector multiplication, addition, and nonlinear transformations;
  • the matrix operation unit 322 is responsible for the core computations of deep learning algorithms, namely matrix multiplication and convolution.
  • NRAM Neuron RAM
  • WRAM Weight RAM
  • DMA Direct Memory Access
  • NRAM 331 stores input neurons, output neurons, and intermediate results after computation
  • WRAM 332 stores the convolution kernels of the deep learning network, i.e., the weights
  • DMA 333 is connected to DRAM 204 via bus 34 and is responsible for data transfer between computing device 301 and DRAM 204.
  • NRAM and WRAM here can be two storage areas formed by dividing the same memory in logical storage space, or they can be two independent memories; no specific limitation is made here.
  • FIG. 4 illustrates the MX quantized data format, which represents the components of MX quantized data.
  • the MX quantized data format is characterized by three parts: the scaling factor (X, shared scale), the scaling block size (K, scaling block size), and the private element data within the block (P ⁇ sub>i ⁇ /sub> ).
  • the scaling factor X relates to the data type or encoding of the scaling factor.
  • the private element (P ⁇ sub>i ⁇ /sub> ) also relates to its data type or encoding.
  • the scaling block size (K) represents the number of private elements P ⁇ sub>i ⁇ /sub> within the block. All K elements P ⁇ sub> i ⁇ /sub> within the block have the same data type and therefore the same bit width.
  • the scaling factor X is shared among these K elements.
  • the data type of the elements and the data type of the scaling factor can be chosen independently.
  • MX can be viewed as a mechanism for constructing vector data types based on scalar data types.
  • W represents the number of bits used to encode the shared scaling factor X, which is also the bit width of scaling factor X
  • d represents the number of bits used to represent each element Pi , which is also the bit width of Pi . Therefore, for an MX block containing K elements, it can be encoded using (W+Kd) bits.
  • Table 1 shows some common MX formats and related parameters. Table 1
  • ExMy represents a scalar format notation with x exponent bits and y mantissa bits.
  • FP8 E4M3
  • FP8 E4M3
  • y 0
  • E8M0 the format does not include a sign bit.
  • the scaling factor X is calculated as follows:
  • the inventors also discovered that if the data type of the scaling factor used in the quantization method is the same as the original data type, although the above-mentioned problem of decreased accuracy can be solved to some extent, this method will lead to greater resource overhead (such as storage space, area overhead required for hardware support, etc.).
  • this disclosure provides a novel data quantization scheme.
  • This scheme determines a scaling factor based on the maximum absolute value of the data to be quantized, and obtains a scaling coefficient by converting the scaling factor to a different data type. Since the converted scaling coefficient has a non-zero mantissa, the accuracy of the quantized data is improved, resulting in processing tasks performed on the quantized data according to the embodiments of this disclosure exhibiting better accuracy.
  • setting the quantization granularity based on the hardware's single-processing capacity facilitates the quantization of a block of granularity in a single hardware operation. This makes online quantization/dequantization more convenient, facilitating pipelined design and enabling neural network models using this hardware as a computing platform to perform quantization operations at various stages, including inference and training, thereby improving the computational efficiency of the neural network model.
  • the scaling factor is calculated as follows:
  • the target data type is the data type of the quantized data obtained after quantizing the data to be quantized. Before quantization, the target data type can be set as needed, and its precision is generally lower than that of the original data type of the data to be quantized.
  • the original data type of the data to be quantized may include at least one of FP16, BF16, FP32, FP64, TF32, etc.; the target data type may include at least one of FP8, FP6, FP4, FP2, int8, int4, int2, int6, FP12, etc.
  • floating-point data types such as FP8, FP6, and FP4 can support multiple data formats.
  • FP4 can be divided in several ways according to the rule of "sign bit + exponent bit + mantissa bit," with the sign bit typically occupying 1 bit.
  • Common combinations of exponent and mantissa bits include E3M0 and E2M1.
  • FP8 can support data formats such as E4M3 and E5M2
  • FP6 can support data formats such as E3M2 and E2M3.
  • each data type has a maximum representable value.
  • the maximum representable value when the target data type is FP4 is 6; the maximum representable value when the target data type is int8 is 127.
  • there is a one-to-one correspondence between the maximum value and the target data type which can be obtained through methods such as table lookup.
  • the data type of the absolute maximum value is the same as the original data type of the data to be quantized
  • the data type of the scaling factor obtained by the ratio i.e., the first data type
  • the bit width of the first data type can be greater than the bit width of the original data type
  • the first data type is the scaling factor's data type
  • the second data type is the scaling coefficient's data type.
  • Data type conversion makes the bit width of the second data type smaller than that of the first data type, thus the precision of the scaling coefficient is less than the precision of the scaling factor.
  • the conversion from scaling factor to scaling coefficient can be achieved using a conversion instruction, such as ⁇ cvt_to_scale_dtype() ⁇ .
  • the conversion supports multiple round modes, such as ⁇ rn(round to nearest, ties to even) ⁇ .
  • the second data type can be represented as ExMy, where E represents the exponent bits, M represents the mantissa bits, x represents the exponent bit width, y represents the mantissa bit width, and x + y ⁇ the bit width of the original data type.
  • E represents the exponent bits
  • M represents the mantissa bits
  • x represents the exponent bit width
  • y represents the mantissa bit width
  • x + y ⁇ the bit width of the original data type For example, assuming the original data type is FP16, then x + y ⁇ 16.
  • the specific values of x and y can be set according to needs or the hardware environment, where x is a positive integer and y ⁇ 0.
  • the second data type may include at least one of, for example, E8M0, E8M1, E8M2, E8M3, E8M4, E8M5, E8M6, E8M7, E5M0, E5M1, E5M2, E5M3, E5M4, E5M5, E5M6, E3M0, E3M1, E3M2, E3M3, E3M4, E3M5, E3M6, E3M7, E3M8, E3M9, etc.
  • y 0.
  • the second data type may be E8M2 or E8M3.
  • this scaling factor in the disclosed embodiment is beneficial for improving the precision of the quantized data; compared to the case where the data type of the scaling factor is the same as the original data type, this scaling factor in the disclosed embodiment is beneficial for reducing hardware resource overhead or storage overhead.
  • mantissa bit width affects the quantization accuracy
  • a larger mantissa bit width can provide a scaling factor with higher accuracy, thereby preserving more original data details during the quantization process. Therefore, compared with the scaling factor of E8M0 format in MX quantization, when the mantissa bit width y of the scaling factor in this disclosed embodiment is greater than 0, it is beneficial to improve the accuracy of quantized data and the accuracy of processing tasks.
  • the second data type needs to be set to 8 bits
  • the second data type can be set to E8M0
  • the absolute value range of a set of data to be quantized is between 2 ⁇ sup>-4 ⁇ /sup> and 2 ⁇ sup> 4 ⁇ /sup>
  • the second data type can be set to E3M5.
  • the bit width of the second data type is not limited to 8 bits; it can also be set to 5 bits, 4 bits, etc., as needed.
  • the scaling factor can be used to quantize the corresponding data to be quantized, or to dequantize the quantized data.
  • quantization processing may include: dividing the data to be quantized by a scaling factor to obtain an intermediate quantization result; and performing data type conversion on the intermediate quantization result to obtain quantized data with the target data type.
  • This data type conversion can also be implemented using a conversion instruction, such as ⁇ cvt_to_scale_dtype() ⁇ .
  • This conversion instruction can be a hardware or software instruction at various levels, such as processor microinstructions, ISA instructions, or function instructions implemented in high-level languages at various software levels.
  • Dequantization is generally the process of restoring low-precision data to high-precision data.
  • dequantizing quantized data using a scaling factor may include multiplying the quantized data with the scaling factor.
  • the quantized data may be converted from a target data type to a desired data type before being multiplied with the scaling factor, wherein the precision of the desired data type is higher than that of the target data type.
  • dequantization can restore the quantized data to its original state before the quantization operation.
  • these two or more scaling factors can be compressed. Then, the compressed scaling factors are used to quantize the corresponding sets of data to be quantized, respectively, to output quantized data with the target data type.
  • a compression process can be included, which specifically includes: determining the shared exponent of the Z scaling factors to be compressed, where Z ⁇ 2; determining the Z new mantissas corresponding to these Z scaling factors; and bundling the shared exponent with the Z new mantissas for output for association. That is, after compression, the exponents of the Z scaling factors are reused, and their mantissas are different, thereby saving at least Z-1 exponent bits.
  • determining the Z new mantissas corresponding to the Z scaling factors can include: setting the new mantissa of scaling factors whose exponent is less than the maximum exponent to 0; and setting the new mantissa of scaling factors whose exponent is equal to the maximum exponent to the original mantissa. It can be understood that for scaling factors whose exponent is equal to the maximum exponent, since the exponent remains unchanged, its mantissa remains unchanged; however, for scaling factors whose exponent is less than the maximum exponent, after the exponent is scaled up to the maximum exponent, to maintain equivalence, the mantissa would be proportionally reduced, exceeding the range of values that the mantissa can represent. Therefore, its new mantissa is set to 0 here. This setting will result in some precision loss, but compared to the storage and bandwidth gains, this precision loss is acceptable in some cases.
  • the shared exponent and the Z new mantissas can be bundled together in sequence for association. For example, first the shared exponent, then the new mantissa of the first scaling factor, the new mantissa of the second scaling factor, and so on up to the new mantissa of the Z scaling factor.
  • the Z scaling factors belong to Z adjacent groups of data to be quantized. This allows the data to be processed sequentially without requiring additional information to indicate the scaling factors that are compressed together.
  • the scaling factors need to be decompressed first. Specifically, during dequantization, in response to the scaling factors being in a compressed format, the compressed scaling factors are decompressed; and the decompressed scaling factors are used to dequantize the quantized data.
  • the bundled Z scaling factors can be decoded into Z independent scaling factors.
  • the shared exponent can be combined with each of the Z new mantissas to obtain the Z decompressed scaling factors.
  • the reciprocal of the scaling factor is also calculated and stored. This facilitates converting the division operation between the data to be quantized and the scaling factor into a multiplication operation between the data to be quantized and the reciprocal of the scaling factor during the quantization process.
  • the reciprocal of the scaling factor has the same data type as the scaling factor. Therefore, the compression and decompression processes described above can also be applied to the reciprocal of the scaling factor, which will not be described in detail here.
  • the scaling factor is determined based on the maximum absolute value of the data to be quantized. This ensures the accuracy of the data after quantization based on the maximum absolute value. Furthermore, since the larger the value of the data to be quantized during the quantization process, the greater the loss of accuracy and the greater the impact on the task calculation results, ensuring the accuracy of the data based on the maximum absolute value helps to reduce the loss of task accuracy. Therefore, compared to methods such as calculating the scaling factor in MX, the extended MX quantization scheme is better at ensuring task accuracy.
  • the scaling factor with a second data type obtained by the number of revolutions in this disclosed embodiment can reduce the storage space required to store the scaling factor and the hardware overhead required to execute the task while ensuring the accuracy of the task.
  • the number of data to be quantized in a set of data to be quantized can be determined based on the single processing volume and/or the number of input ports of the processing circuit performing the quantization process; or the number of data to be quantized in a set of data to be quantized can be determined based on the single operation volume and/or the number of input ports of the arithmetic unit that performs the operation using the quantized data.
  • the number of data points to be quantized in a set of data can be determined based on the processing capacity of the processing circuit (i.e., the amount of data that can be processed in a single run), or based on the processing capacity of the arithmetic unit that performs operations such as multiply-accumulate or vector inner product using quantized data (i.e., the amount of data that can be processed in a single run), and grouped according to this granularity.
  • the processing capacity of the processing circuit i.e., the amount of data that can be processed in a single run
  • the arithmetic unit that performs operations such as multiply-accumulate or vector inner product using quantized data
  • a set of data points sharing a single scaling factor can be processed in one computation cycle, without needing to span multiple computation cycles, thus improving hardware implementation and fully utilizing hardware computing power.
  • the number of data points to be quantized in a set of data can be determined based on the number of input ports of the processing circuit performing quantization or the number of input ports of the arithmetic unit that uses quantized data for calculation, and grouped accordingly.
  • a set of data to be quantized can be input at once using the number of hardware input ports, allowing a set of data sharing a single scaling factor to be processed in a single input, eliminating the need for multiple inputs. This improves hardware implementation, reduces hardware processing latency, and lowers I/O overhead.
  • the aforementioned processing circuit or arithmetic unit can process 32 data points in a single operation, and its corresponding number of input ports is also 32, then the data points to be quantized can be grouped into sets of 32. If the aforementioned processing circuit or arithmetic unit can process 64 data points in a single operation, and its corresponding number of input ports is less than 64, for example, 32, then the data points to be quantized can be grouped according to the number of input ports, ensuring that the number of data points to be quantized in each group is equal to the number of input ports.
  • 32 data points are input at once, and the two groups of data can be processed in parallel; alternatively, the 64 data points to be quantized can still be grouped together and input twice to complete the processing of one group of data points at once. If the aforementioned processing circuit or arithmetic unit can process 32 data points in a single operation, and its corresponding number of input ports is more than 32, then the 32 data points to be quantized can be grouped together to achieve one-time input and processing of one group of data points.
  • the shape of the tensor composed of each data block after grouping (i.e., the dimensions and dimensions of the tensor) can be represented as (B, S/32), that is, the dimension of the second dimension after grouping is S/32.
  • Figure 5 shows a schematic block diagram of a data quantization apparatus according to some embodiments of this disclosure.
  • the apparatus 500 may include a first processing circuit 510 and a second processing circuit 520, wherein the first processing circuit 510 is used to output a scaling factor, and the second processing circuit 520 is used to perform quantization processing.
  • the apparatus 500 may further include a compression circuit 540.
  • the compression circuit 540 is configured to compress two or more scaling factors after quantization of two or more sets of data to be quantized.
  • the second processing circuit 520 is configured to quantize the corresponding sets of data to be quantized using the compressed scaling factors, respectively, to output quantized data with the target data type.
  • device 500 when device 500 needs to dequantize extended MX quantized data using a compressed format, the scaling factors must first be decompressed.
  • device 500 may also include a decompression circuit (not shown in the figure).
  • the decompression circuit is configured to decompress the compressed scaling factors in response to the scaling factors being in a compressed format.
  • the circuit in device 500 that performs the dequantization process e.g., the second processing circuit 520 or the third processing circuit 530
  • the operations performed by the first processing circuit 510, the second processing circuit 520, the compression circuit 540, and the decompression circuit have been described in detail above in conjunction with the extended MX quantization method, and will not be repeated here.
  • the first processing circuit 510 may include: a comparison circuit 511, which can be used to determine the maximum absolute value in a set of data to be quantized; a first division circuit 512, which can be used to obtain the maximum value that the target data type after quantization of the data to be quantized can represent, and determine the scaling factor corresponding to a set of data to be quantized based on the ratio between the maximum absolute value and the maximum value; and a first rotation circuit 513, which can be used to convert the scaling factor from a first data type to a second data type to output the scaling coefficient.
  • the first division circuit 512 can obtain the maximum value by means of table lookup or other methods.
  • the second processing circuit 520 may include a second division circuit 521 and a second rotation circuit 522, wherein the second division circuit 521 can be used to perform a division operation on the data to be quantized and the scaling factor, and the second rotation circuit 522 can be used to perform a rotation operation on the result of the division operation (i.e., the intermediate quantization result) to output the result of quantization of the data to be quantized (i.e., the quantized data).
  • the second division circuit 521 can be used to perform a division operation on the data to be quantized and the scaling factor
  • the second rotation circuit 522 can be used to perform a rotation operation on the result of the division operation (i.e., the intermediate quantization result) to output the result of quantization of the data to be quantized (i.e., the quantized data).
  • the second processing circuit 520 can also be used to perform dequantization processing on the quantized data using scaling factors.
  • the second processing circuit 520 may also include a multiplication circuit for multiplying the quantized data and the scaling factors.
  • the second rotation circuit 522 can also be used to perform rotation operations on the quantized data to convert the quantized data from the target data type to the data type required for dequantization processing; the multiplication circuit is used to multiply the rotated quantized data and the scaling factors to obtain the dequantization result.
  • dequantization processing can restore the quantized data to the data to be quantized before the quantization operation.
  • the dequantization process is not limited to being performed by the second processing circuit 520 as described above, but can also be performed by other circuits.
  • the apparatus 500 may further include a third processing circuit 530 (shown in a dashed box in the figure) for dequantizing the quantized data using a scaling factor.
  • the third processing circuit 530 may receive, for example, quantized data output by the second processing circuit 520, and may also receive scaling factors output by the first processing circuit 510.
  • a storage circuit may be further included between the third processing circuit 530 and the second processing circuit 520, or the second processing circuit 520 may include a storage circuit for storing quantized data so that the third processing circuit 530 can read the quantized data from the storage circuit for dequantization processing.
  • the comparison circuit 511 when a piece of data to be quantized is input to the comparison circuit 511, the comparison circuit 511 can output the absolute value of that piece of data as the maximum absolute value. In some embodiments, when multiple pieces of data to be quantized are input to the comparison circuit 511, the comparison circuit 511 can output the maximum absolute value among the multiple pieces of data to be quantized.
  • the comparison circuit 511 can also be used to divide the multiple pieces of data to be quantized into multiple groups and output the maximum absolute value of each group of data to be quantized; the first division circuit 512 can be further used to determine a scaling factor corresponding to each group of data to be quantized; and the first revolution circuit 513 can be further used to determine a scaling coefficient corresponding to each group of data to be quantized based on each scaling factor.
  • the data to be quantized is an element of tensor data, and the comparison circuit 511 can be further used to divide the multiple pieces of data to be quantized of the tensor data into multiple groups in at least one dimension of the tensor data.
  • the first processing circuit for obtaining the scaling factor may not be limited to the comparison circuit, the first division circuit, and the first rotation circuit described above, but may also be implemented using, for example, a lookup table (circuit). Since the dividend (the maximum value that the target data type can represent) is a constant, a lookup table or similar method can be used to directly determine the value based on the input data, thereby implementing the division operation and data type conversion functions described above to obtain the scaling factor. Furthermore, to facilitate understanding of the grouping function implemented by the comparison circuit, an exemplary description will be provided below with reference to Figure 6.
  • Figure 6 shows a schematic block diagram of a comparison circuit according to some embodiments of this disclosure.
  • the comparison circuit 511 may include a comparator tree composed of multiple levels of comparators, for example, it may include layers a, b, c, ..., z, each level including one or more comparators, with the number of comparators decreasing sequentially at each level.
  • the outputs of multiple comparators in the upper level of an adjacent level can be input to the comparators in the lower level.
  • the outputs of the required levels can be selected as needed by means of software or hardware to achieve grouping of multiple data to be quantized and to obtain the maximum absolute value of each group of data to be quantized. For ease of understanding, further examples will be provided below with reference to Figure 6.
  • layer a includes comparators a1, a2, a3, ..., an, where n represents the number of comparators in layer a; layer b includes comparators b1, b2, etc.; layer c includes comparator c1, etc.; and layer z includes comparator z1.
  • the comparator tree shown in the figure is exemplary, and the number of levels in the comparator tree can be set more or less as needed, and the number of comparators included in each level can also be set as required.
  • the number of comparators *n* in layer *a* can be the same as the number of input data to be quantized, so that each data point to be quantized is input into a corresponding comparator in layer *a*.
  • the output can be gradually reduced to obtain the desired grouping result and the maximum absolute value of each group. For example, assuming the input layer receives 128 data points to be quantized, and layer *a* has 128 comparators, then each data point to be quantized is input into a corresponding comparator in layer *a*. The output of layer *a* can then divide the 128 data points to be quantized into 128 groups.
  • layer *b* includes 64 comparators
  • the output of every two comparators in layer *a* can be input into a comparator in the next layer, layer *b*.
  • the outputs of comparators *a1* and *a2* in layer *a* can be input into comparator *b1* in layer *b*.
  • Layer *b* then outputs 64 maximum absolute values, thus dividing the 128 data points to be quantized into 64 groups.
  • layer c contains 32 comparators
  • the outputs of every two comparators in layer b can be input into a comparator in the next layer c.
  • the outputs of comparators b1 and b2 in layer b can be input into comparator c1 in layer c.
  • layer c outputs 32 maximum absolute values, effectively dividing the 128 data points to be quantized into 32 groups. This process continues until the last layer z outputs a single maximum absolute value, thus dividing the 128 data points to be quantized into one group.
  • the output of layer C can be selected as the output of comparator circuit 411 through methods such as programming, logic control, or selectors.
  • This allows the first division circuit to determine the scaling factor corresponding to each of the 32 groups of data to be quantized based on the 32 outputs of layer C (i.e., the 32 maximum absolute values). Therefore, the comparator tree provides multiple granularity grouping methods, allowing users to flexibly select the output of a certain level in the comparator tree according to the required quantization granularity.
  • the comparator tree structure is not limited to the two comparators in each level shown in the diagram whose outputs correspond to one comparator in the next level. It can also be configured to have, for example, three or more comparators whose outputs correspond to one comparator in the next level. For instance, assuming level a has 128 comparators, level b can have 4 comparators. That is, the outputs of the 32 comparators in level a correspond to one comparator in level b. Therefore, the output of level b can divide the 128 data points to be quantized into 4 groups and output the maximum absolute value of the 32 data points in each group.
  • the number of comparators n in layer a can be different from the number of input data to be quantized, as illustrated below. Assuming the number of comparators in layer a is less than the number of data to be quantized, multiple data to be quantized can be input into a single comparator in layer a. This achieves the division of multiple data to be quantized into fewer groups for output in layer a.
  • the data to be quantized input to each comparator in layer a can also be controlled before layer a (e.g., in the input layer) by using methods such as address decoders, multiplexers (MUX), or other logic circuits.
  • layer 'a' has 64 comparators. Then, every two data points to be quantized are input into one of the corresponding comparators in layer 'a'. At this point, the output of layer 'a' divides the 128 data points into 64 groups. The number of comparators in subsequent layers is halved sequentially until the last layer outputs the maximum absolute value, at which point the 128 data points are divided into one group.
  • the foregoing description in conjunction with Figure 6, exemplarily illustrates the scheme for implementing grouping and outputting the maximum absolute value using a comparison circuit according to an embodiment of this disclosure.
  • the structure of the comparison circuit shown in the figure and the preceding description are exemplary and not restrictive.
  • the last level of the comparison circuit 511 may not be limited to including only one comparator as shown in the figure, but may also include multiple comparators as needed, such as using level c in the figure as the last level.
  • the comparator circuit 511 may not be limited to including only one comparator tree, but may also include multiple comparator trees as needed, thereby enabling, for example, parallel grouping.
  • the comparison circuit of this embodiment of the disclosure may not be limited to being implemented using the aforementioned comparator tree, but may also be implemented based on radix sorting or other methods.
  • particle quantization format when referring to "particle quantization format,” “particle size format,” or “particle quantization,” it refers to the three-part data format shown in Figure 4.
  • the specific element data types, scaling block sizes, scaling factor data types, etc. are not limited to those listed in Table 1, but can include many other combinations.
  • the particle quantization format can include the MX quantization format proposed by OCP, the extended MX quantization format proposed in this disclosed embodiment, or any other data format conforming to the structure of Figure 4.
  • the term "instruction” can include software instructions, hardware instructions, firmware instructions, or any combination thereof.
  • Software instructions typically refer to statements or commands in a programming language; they are high-level, abstract instructions, such as function calls, machine code, and bytecode.
  • Hardware instructions also known as machine instructions or instruction set architecture (ISA) instructions, are low-level commands that computer hardware can directly recognize and execute, such as processor instructions and CPU instructions.
  • Firmware instructions include, for example, opcodes and microcode.
  • different CPU architectures and different instruction sets can have different hardware instruction sets. Based on the complexity of the computer instruction set, hardware design, execution speed, compiler complexity, and instruction format, they can be further classified as: CISC (Complex Instruction Set Computer), RISC (Reduced Instruction Set Computer), and VLIW (Very Long Instruction Word).
  • Convolutional layers in neural network models perform convolution operations, extracting features by applying convolution kernels (also called weights, filters, etc.) to the input neurons (also called input data or input feature maps).
  • a convolutional layer can contain multiple convolution kernels, with each element of the kernel corresponding to a weight coefficient and a bias.
  • the tensor shape of the input neurons or input feature maps in a convolutional layer is represented as X[N Hi Wi Ci], indicating N sets of input feature maps, each containing Hi ⁇ Wi ⁇ Ci pieces of information, where Hi and Wi are the height and width of the input feature map, respectively, and Ci is the number of input feature maps, also known as the number of input channels.
  • the tensor shape of the convolutional kernel is represented as K[Co Kh Kw Ci], meaning the convolutional layer has Ci ⁇ Co kernels of size Kh ⁇ Kw, where Ci is the number of input channels, Co is the number of output feature maps (or output channels), and Kh and Kw are the height and width of the convolutional kernel, respectively.
  • sh and sw are the convolution stride in the height and width directions, respectively.
  • the size of the convolution stride affects the size of the output feature map.
  • the formula ignores the bias, padding, and dilation, and assumes that the input data X has already been padded and the convolution kernel has already been dilated.
  • the formula also ignores the N-dimensional dimension; the forward computation of the neural network model is independent in the N-dimensional dimension.
  • each convolution output point has a corresponding convolution window, the shape of which is equal to the shape of the convolution kernel. The value of each convolution output point corresponds to the positional multiplication and accumulation result of the input feature map and weights within its convolution window.
  • This disclosure presents a convolution operation scheme compatible with MX quantization format.
  • any one or more of the input neurons, weights, and output neurons can be in a particle-quantized data format.
  • the data dequantization process can be integrated into the convolution operation without prior dequantization. This avoids separate dequantization processing and fully utilizes the advantages of low bit width and small memory footprint of the particle-quantized format in the convolution operation.
  • the output neurons or input neurons and weights that are not in a particle-quantized format be converted to a particle-quantized format, they can be quantized online via hardware circuitry.
  • Figure 7 illustrates a schematic structural diagram of a data processing apparatus that can implement embodiments of the present disclosure. It can be understood that this structure can be viewed as a refinement of the internal structure of a single processing core in Figure 3, or as a functional partitioning diagram based on multiple processing cores shown in Figure 3.
  • the data processing apparatus 700 may include a control circuit 710, a storage circuit 720, and an arithmetic circuit 730, which are interconnected to transmit various data and instructions.
  • the control circuit 710 is responsible for handling various functions on the data processing device 700, including but not limited to control, instruction fetching, decoding, and calculation.
  • the control circuit 710 may include, for example, the control module 31 shown in FIG3.
  • the storage circuit 720 can be used to store information, including at least pre-processing and/or post-processing information, and may also include intermediate information that needs to be cached during processing, such as various RAMs shown in FIG3, or on-chip caches.
  • the storage circuit 720 can be configured to store input neurons, weights, convolution operation results (output neurons), and/or cache intermediate results.
  • the arithmetic circuit 730 can be configured to perform various arithmetic operations according to relevant instructions.
  • the arithmetic circuit 730 can be configured to perform convolution operations on the input neurons and weights under the control of the control circuit 710.
  • the arithmetic circuit 730 may include a convolution circuit 731.
  • control circuit 710 may be configured to parse convolution instructions and control the storage circuit 720 and the arithmetic circuit 730 to perform convolution operations on the input neurons and weights.
  • the convolution instruction directs the convolution operation on the input neuron and weights to obtain the output neuron.
  • the convolution instruction may support the granular quantization of any one or more of the input neuron, weights, and output neuron.
  • the data formats of the input neuron, weights, and output neuron may differ in different application scenarios.
  • the input neuron may be unquantized, while the weights may have been quantized, for example, offline, and the output neuron requires quantization before being transmitted to the next convolutional layer.
  • the output neuron received from the previous layer is now quantized as the input neuron, the weights are also quantized, and the output neuron obtained from the convolution operation also requires quantization before being input to the next convolutional layer.
  • the above scenario is merely exemplary, and various other application scenarios may exist where any one or more of the input neuron, weights, and output neuron are granularly quantized.
  • a granular quantization format includes three parts: a scaling factor (X, scale), a granular block size (K, scaling block size), and the private element data within the block (P ⁇ sub>i ⁇ /sub> , data).
  • the granular block size is pre-defined, for example, 32. Therefore, the convolution operation requires two parts for the granular quantization parameters: the scaling factor X and the element data P ⁇ sub> i ⁇ /sub> . Compared to convolution operations performed on non-quantized data, this adds the memory access requirement for the scaling factor X.
  • the computation circuit 730 is configured to perform a convolution operation on the data of the input neuron and the data of the weights according to the convolution instructions described above, and to fuse the scaling factors of the input neuron and/or the scaling factors of the weights in the convolution operation. More specifically, the scaling factors can be fused in the convolution operation in units of particle-level granular block size.
  • the convolution circuit 731 can be configured to perform the convolution operation as follows: iteratively calculate the partial sum of each granular block in units of granularity block size T (quantified by particle size); and iteratively accumulate the partial sums of each granular block within a single convolution window to obtain the output neuron value of the corresponding convolution window.
  • T granularity block size
  • the computational data involved in a convolution window usually includes multiple granular blocks. Therefore, partial sums can be calculated in units of granularity blocks, and then the partial sums can be accumulated.
  • the convolution circuit 731 can be configured to calculate the partial sum of each granularity block as follows: within each granularity block, the sum of the product of the data of the input neuron and the data of the weights is calculated; the product of this sum of products with the scaling factor of the input neuron and/or the scaling factor of the weights is calculated to obtain the partial sum of the granularity block. Since the element data shares the same scaling factor within the same granularity block, the sum of the element-wise products can be calculated first, and then multiplied by the common scaling factor, thereby incorporating dequantization into the convolution operation.
  • Equation (1) gives the convolution operation for non-quantized data.
  • the order of the convolution operation can be adjusted depending on which dimension(s) of the tensor data the granularity blocks are divided on.
  • Equation (1) can be adjusted to Equation (2) as follows:
  • Y is the output neuron with dimensions Ho, Wo, and Co;
  • A is the input neuron with dimensions Ci, Hi, and Wi;
  • W is the weight with dimensions Ci, Kh, Kw, and Co, where Kh and Kw are the sizes of the Kh and Kw dimensions, respectively.
  • the input neuron and/or weights have been quantized in the Ci dimension, and the quantized granularity block size is T.
  • T are the scaling factors for the nth granularity block of the input neuron A and the weight W, respectively, and
  • s ⁇ sub>h ⁇ /sub> and s ⁇ sub> w ⁇ /sub> are the convolution strides of the weights in the dimensions K ⁇ sub>h ⁇ /sub> and K ⁇ sub>w ⁇ /sub>, respectively.
  • particle quantization is the quantization of shared scaling factors on the Ci dimension according to T data.
  • the number of data on the Ci dimension is not sufficient to align to T, when it is split into less than T data, the remaining data share the same scaling factor.
  • the computation circuit 730 may further include a first rotation circuit 732, which can be configured to rotate the data of the input neuron and/or the data of the weights in response to a convolution instruction indicating that the data bit width of the input neuron and the weights are different, so that the data bit width of the input neuron and the weights are the same.
  • the convolution circuit 731 can perform the aforementioned convolution operation based on the data of the input neuron and the data of the weights having the same data bit width, as well as the scaling factor of the input neuron and/or the scaling factor of the weights.
  • Non-quantized weights and non-quantized input neurons have different bit widths.
  • the first rotation circuit 732 can rotate the weights and/or input neurons to make the data bit widths of the weights and input neurons the same.
  • data with shorter bit widths in the weights and input neurons can be converted to data with longer bit widths to unify the bit widths.
  • both the weights and input neurons can also be converted to data with bit widths longer than their original widths, thereby improving accuracy.
  • the particle quantization weights and input neurons have the same bit width. At this time, no revolutions are needed.
  • the convolution circuit 731 performs inverse quantization by fusing the scaling factor during the convolution operation, for example, according to the operation method described above in conjunction with formula (2).
  • the weights and input neurons are quantized into particles with different bit widths.
  • the first rotation circuit 732 can rotate the weights and/or input neurons to make their data bit widths the same. For example, data with shorter bit widths in the weights and input neurons can be converted to data with longer bit widths, thus unifying the bit width.
  • the scaling factor of the particle quantization is then processed by the convolution circuit during the convolution operation. Similarly, both the weights and input neurons can be converted to data with a bit width longer than their original values.
  • both data types can be converted to FP16, and convolution operations can be performed based on the FP16 data type. Note that the converted FP16 is still particle quantization data with scaling factors.
  • the advantage of using the scaling factor of particle quantization (i.e., convolution fused dequantization) in the convolution operation of this disclosed embodiment is that it can improve the performance speedup.
  • the input neurons and weights are both particle quantized data, such as neuron data and weights being FP8
  • the computation bandwidth is N bytes, and the number of data that can be processed in one cycle is N/2.
  • the quantized data format of FP8 is directly input into the computation circuit, and dequantization is performed using the scaling factor X during the operation, the computation bandwidth N can be fully utilized, and the computing power is twice that of the previous approach.
  • the convolution instructions suitable for particle quantization in this disclosure embodiment add memory access requirements for the scaling factor X.
  • the scaling factor X can be stored contiguously with its associated k element data P ⁇ sub>i ⁇ /sub>.
  • the scaling factor X and the element data P ⁇ sub> i ⁇ /sub> can be accessed together, for example, through a single memory address.
  • the convolution instruction can provide only one memory address for a single parameter.
  • the scaling factor X can be stored independently of its associated k element data P ⁇ sub>i ⁇ /sub>.
  • the scaling factor X and the element data P ⁇ sub> i ⁇ /sub> can be accessed independently, for example, through different addresses.
  • the convolution instruction requires two memory addresses for a single parameter.
  • a selector can be added to the existing neuron read port to select whether to read neuron data or neuron scaling factors; a selector can be added to the existing weight read port to select whether to read weight data or weight scaling factors. Similarly, a selector can be added to the existing output neuron (result) write-back port to select whether to write back result data or result scaling factors.
  • scaling factors are shared within granular blocks can be utilized to fully utilize the bandwidth when reading scaling factors in each cycle, and buffer them for use in subsequent cycles.
  • the convolution instruction also instructs the scaling factor and its corresponding data to reuse the same read port, and for each frame of scaling factor read, multiple frames of corresponding data are read proportionally. It can be understood that even without port reuse, the scaling factor read port and the data read port can still be controlled to perform read operations proportionally. For example, for each frame of scaling factor read by the scaling factor read port, the data read port reads the corresponding data for n frames. In this way, the scaling factor read port will be idle for n-1 frames, which can then be used to read other data.
  • the data processing apparatus 700 further includes a first buffer 741 configured to buffer scaling factors read from off-chip to be supplied in proportion to the corresponding data to the convolution circuit 731 in the arithmetic circuit 730 for performing convolution operations.
  • the scaling factor is in E8M3 format with a bit width of 2 bytes
  • the element data is in FP8 format with a bit width of 1 byte
  • T 32
  • the read scaling factor is buffered in the first buffer.
  • the above ratio can be adjusted accordingly based on the compression ratio.
  • the scaling factor format is E8M3
  • the decompression circuit 734 can decompress the scaling factors cached in the first buffer 741 and provide them to the convolution circuit 731.
  • separate cache spaces can be set up for the scaling coefficients of the input neurons and the scaling coefficients of the weights.
  • two first caches can be set up, one for caching the scaling coefficients of the input neurons and the other for caching the scaling coefficients of the weights, and the data can be shifted and retrieved in each first cache according to the usage in each operation cycle.
  • they can also be set up in the same cache, and the embodiments disclosed herein are not limited in this respect.
  • the write-back storage circuit will also include the result data and the result scaling factor.
  • K e.g. 32
  • a second buffer (second buffer 742 in Figure 7) can be set up to temporarily store the result scaling factors.
  • the output order can be controlled to output n cycles of result data first, followed by one cycle of result scaling factors.
  • n is determined based on the granularity block size T, the bit width of the result data, and the bit width of the result scaling factor.
  • the scaling factor output of the arithmetic circuit is written back to the storage circuit in the order of Co-Wo-Ho, and the granular quantization is split and quantized in the Co dimension, there may be discontinuities and jumps in the Co dimension. Therefore, when caching the scaling factor in the second buffer, it is cached in stride order according to the continuous Co. For output points with discontinuous Co, a certain stride is skipped.
  • a masked write-back When writing the result scaling factor from the second buffer back to the storage circuit, a masked write-back can be used.
  • the mask indicates the valid data that needs to be written to the storage circuit in the current write-back cycle. Since the result scaling factor is cached by stride, there will be empty portions. By using the mask, only the necessary data (i.e., valid data) can be written back to the storage circuit.
  • the quantization circuit 733 may further include a compression circuit (not shown), configured to: compress two or more scaling factors after quantization of two or more sets of data to be quantized, in response to a convolution instruction indicating that the scaling factors are in a compressed format.
  • the quantization circuit uses the compressed scaling factors to quantize the corresponding sets of data to be quantized, respectively, to output quantized data with the target data type.
  • the quantization circuit 733 can be implemented in various ways. In some embodiments, the specific implementation of the quantization circuit 733 can be referred to the previous description of extended MX quantization, which will not be repeated here.
  • FIG. 8 illustrates an exemplary flowchart of a data processing method implemented by a data processing circuit according to an embodiment of this disclosure.
  • a control circuit controls a computation circuit to perform a convolution operation on the input neurons and weights.
  • step 820 under the control of the control circuit, the computation circuit performs convolution operation on the data of the input neuron and the data of the weights according to the convolution instruction, and incorporates the scaling factor of the input neuron and/or the scaling factor of the weights into the convolution operation.
  • step 820 may further include: sub-step 821, in response to a convolution instruction indicating that the data bit width of the input neuron and the weights are different, performing a rotation on the data of the input neuron and/or the data of the weights to make the data bit width of the input neuron and the weights the same; and sub-step 822, performing a convolution operation based on the data of the input neuron and the data of the weights having the same data bit width, and the scaling factor of the input neuron and/or the scaling factor of the weights.
  • Sub-step 821 may be executed by a first rotation circuit
  • sub-step 822 may be executed by a convolution circuit.
  • substep 822 may be performed as follows: cyclically calculating the partial sum of each granularity block in units of granularity block size T measured by microparticles; and cyclically accumulating the partial sum of each granularity block within a single convolution window to obtain the output neuron value of the corresponding convolution window.
  • step 820 may further include: sub-step 823, which involves quantizing the result of the convolution operation according to the convolution instruction to generate result data and result scaling factors.
  • Sub-step 823 may be performed by a quantization circuit. Specific quantization methods can be found in the preceding description.
  • the method may further include a preprocessing step, such as quantizing the input neurons and weights that are not quantized by a quantization circuit according to convolution instructions.
  • Quantization can convert computation of high-bit-width data into computation of low-bit-width data, reducing computational power consumption.
  • This disclosure also provides a processor, including the aforementioned data processing apparatus.
  • This disclosure further provides a chip, which may include the processor of any of the embodiments described above in conjunction with the accompanying drawings. Furthermore, this disclosure also provides a board that may include the aforementioned chip.
  • the electronic devices or apparatus disclosed herein may include servers, cloud servers, server clusters, data processing devices, robots, computers, printers, scanners, tablets, smart terminals, PC devices, IoT terminals, mobile terminals, mobile phones, dashcams, navigators, sensors, cameras, video cameras, projectors, watches, headphones, mobile storage, wearable devices, visual terminals, autonomous driving terminals, vehicles, home appliances, and/or medical devices.
  • the vehicles include airplanes, ships, and/or vehicles;
  • the home appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, lights, gas stoves, and range hoods;
  • the medical devices include MRI scanners, ultrasound machines, and/or electrocardiographs.
  • the electronic devices or apparatus disclosed herein can also be applied in fields such as the Internet, IoT, data centers, energy, transportation, public management, manufacturing, education, power grids, telecommunications, finance, retail, construction sites, and healthcare. Furthermore, the electronic devices or apparatus disclosed herein can also be used in application scenarios related to artificial intelligence, big data, and/or cloud computing, such as cloud computing, edge computing, and terminal applications.
  • the high-computing-power electronic devices or apparatuses according to the present disclosure can be applied to cloud devices (e.g., cloud servers), while the low-power electronic devices or apparatuses can be applied to terminal devices and/or edge devices (e.g., smartphones or cameras).
  • the hardware information of the cloud devices and the hardware information of the terminal devices and/or edge devices are compatible with each other, so that suitable hardware resources can be matched from the hardware resources of the cloud devices to simulate the hardware resources of the terminal devices and/or edge devices based on the hardware information of the terminal devices and/or edge devices, so as to complete the unified management, scheduling and collaborative work of end-to-cloud or cloud-edge-end integration.
  • the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units.
  • the aforementioned components or units may be located in the same location or distributed across multiple network units.
  • some or all of the units can be selected to achieve the purpose of the solution described in the embodiments of this disclosure.
  • multiple units in the embodiments of this disclosure may be integrated into one unit or each unit may exist physically independently.
  • the quantization circuit, as a post-processing circuit may be integrated into the convolution circuit or independent of the convolution circuit.
  • the quantization circuit, as a pre-processing circuit may be integrated into the revolutions circuit or independent of the revolutions circuit.
  • the embodiments of this disclosure are not limited in this respect.
  • the integrated units described above can also be implemented in hardware, i.e., as specific hardware circuits, which may include digital circuits and/or analog circuits.
  • the physical implementation of the circuit's hardware structure may include, but is not limited to, physical devices, which may include, but are not limited to, transistors or memristors. Therefore, the various devices described herein (e.g., computing devices or other processing devices) can be implemented using appropriate hardware processors, such as central processing units, GPUs, FPGAs, DSPs, and ASICs.
  • the aforementioned storage unit or storage device can be any suitable storage medium (including magnetic storage medium or magneto-optical storage medium, etc.), such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), ROM (read-only memory), and RAM (random access memory), etc.
  • RRAM resistive random access memory
  • DRAM dynamic random access memory
  • SRAM static random access memory
  • EDRAM enhanced dynamic random access memory
  • HBM high-bandwidth memory
  • HMC hybrid memory cube
  • ROM read-only memory
  • RAM random access memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Mathematical Physics (AREA)
  • General Engineering & Computer Science (AREA)
  • Pure & Applied Mathematics (AREA)
  • Mathematical Optimization (AREA)
  • Mathematical Analysis (AREA)
  • Computational Mathematics (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Artificial Intelligence (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Evolutionary Computation (AREA)
  • Algebra (AREA)
  • Databases & Information Systems (AREA)
  • Computer Hardware Design (AREA)
  • Biophysics (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Nonlinear Science (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Evolutionary Biology (AREA)
  • Operations Research (AREA)
  • Probability & Statistics with Applications (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Image Processing (AREA)

Abstract

The present application discloses a data processing apparatus, a processor, a board, and a data processing method. The data processing apparatus can be comprised in a computing apparatus of a combined processing apparatus, and the combined processing apparatus can further comprise an interface apparatus and another processing apparatus. The data processing apparatus interacts with the other processing apparatus to jointly complete a computing operation specified by a user. The combined processing apparatus can also comprise a storage apparatus. The storage apparatus is separately connected to the computing apparatus and the other processing apparatus, and is used for storing data of the computing apparatus and the other processing apparatus. The present application provides a convolution operation scheme compatible with various fine-grained quantization formats, which can simplify processing and make full use of the advantages of low bit width operation and small memory occupation of the fine-grained quantization formats.

Description

数据处理装置、处理器、板卡及数据处理方法Data processing device, processor, circuit board and data processing method

相关申请的交叉引用Cross-reference to related applications

本申请要求于2024年06月21日申请的,申请号为202410813862.X,名称为“数据处理装置、处理器、板卡及数据处理方法”以及于2024年09月25日申请的,申请号为202411347002.8,名称为“数据处理装置、处理器、板卡及数据处理方法”的中国专利申请的优先权。This application claims priority to Chinese patent applications filed on June 21, 2024, with application number 202410813862.X, entitled "Data Processing Apparatus, Processor, Board and Data Processing Method" and filed on September 25, 2024, with application number 202411347002.8, entitled "Data Processing Apparatus, Processor, Board and Data Processing Method".

技术领域Technical Field

本披露一般涉及计算机处理器领域。更具体地,本披露涉及一种数据处理装置、处理器、板卡及由数据处理装置实施的数据处理方法。This disclosure generally relates to the field of computer processors. More specifically, this disclosure relates to a data processing apparatus, a processor, a circuit board, and a data processing method implemented by the data processing apparatus.

背景技术Background Technology

随着人工智能的飞速发展,神经网络模型的计算量和参数量都在持续增加。研究表明,在训练和推理过程中,可以通过降低浮点运算的精度来有效的提升运行速度,降低功耗和芯片面积。With the rapid development of artificial intelligence, the computational load and number of parameters in neural network models are continuously increasing. Research shows that during training and inference, reducing the precision of floating-point operations can effectively improve operating speed, reduce power consumption, and decrease chip area.

为此,AI厂商设计了各种浮点格式,例如BF16、TF32等,以取得AI系统性能和精度的平衡。这些浮点格式都有着各自的应用场景和优势,但是类型多样或特殊的浮点格式也面临着迁移的问题,例如A厂商用FP6训练的模型,没办法在B厂商的推理硬件上运行。To address this, AI vendors have designed various floating-point formats, such as BF16 and TF32, to achieve a balance between AI system performance and accuracy. These floating-point formats each have their own application scenarios and advantages; however, the diverse or specialized nature of these formats also presents migration challenges. For example, a model trained by vendor A using FP6 cannot run on vendor B's inference hardware.

为了形成统一的行业标准,OCP(开放计算项目)推出了一种MX(MicroXcaling)量化格式。MX量化格式是一种具有共享、细粒度块规模的可互操作的量化数据格式。符合MX的数据格式支持AI训练和推理,具有更低的位宽算术运算和更小的内存占用,因此推动了硬件性能和效率的提高,从而可以减少开销和运营成本。To establish a unified industry standard, the Open Compute Project (OCP) introduced the MX (MicroXcaling) quantization format. The MX quantization format is an interoperable quantization data format with shared, fine-grained block sizes. MX-compliant data formats support AI training and inference, featuring lower bit-width arithmetic operations and smaller memory footprints, thus driving improvements in hardware performance and efficiency, thereby reducing overhead and operating costs.

有鉴于此,需要针对MX量化格式,开发能够兼容MX量化格式的运算模式和相应硬件,尤其是神经网络运算中占有大比例的卷积运算,从而充分发挥MX量化格式的优势。Therefore, it is necessary to develop an operation mode and corresponding hardware that are compatible with the MX quantization format, especially for convolution operations, which account for a large proportion of neural network operations, so as to give full play to the advantages of the MX quantization format.

发明内容Summary of the Invention

为了至少解决如上所提到的一个或多个技术问题,本披露在多个方面中提出了一种兼容MX量化格式的卷积运算方案。进一步地,还提供了一种改进的MX量化方案。To address at least one or more of the technical problems mentioned above, this disclosure proposes a convolution operation scheme compatible with the MX quantization format in several aspects. Furthermore, an improved MX quantization scheme is also provided.

在第一方面中,本披露提供一种数据处理装置,包括:控制电路,配置用于解析卷积指令,所述卷积指令指示对输入神经元和权值进行卷积运算以获得输出神经元,其中所述输入神经元和权值中任一或二者是微粒度量化的;以及运算电路,配置用于根据所述卷积指令,对所述输入神经元的数据和所述权值的数据执行卷积运算,并且将所述输入神经元的缩放系数和/或所述权值的缩放系数融合在所述卷积运算中。In a first aspect, this disclosure provides a data processing apparatus, comprising: a control circuit configured to parse a convolution instruction, the convolution instruction instructing a convolution operation on an input neuron and weights to obtain an output neuron, wherein either or both of the input neuron and weights are particle-quantized; and a computation circuit configured to perform a convolution operation on data of the input neuron and data of the weights according to the convolution instruction, and to fuse scaling factors of the input neuron and/or scaling factors of the weights in the convolution operation.

在第二方面中,本披露提供一种处理器,包括前述第一方面所述的数据处理装置。In a second aspect, this disclosure provides a processor that includes the data processing apparatus described in the first aspect.

在第三方面中,本披露提供一种板卡,包括前述第二方面所述的处理器。In a third aspect, this disclosure provides a board that includes the processor described in the second aspect above.

在第四方面中,本披露提供一种由数据处理装置实施的数据处理方法,所述数据处理装置包括控制电路和运算电路,所述方法包括:所述控制电路对卷积指令进行解析,所述卷积指令指示对输入神经元和权值进行卷积运算以获得输出神经元,其中所述输入神经元和权值中任一或二者是微粒度量化的;以及所述运算电路根据所述卷积指令,对所述输入神经元的数据和所述权值的数据执行卷积运算,并且将所述输入神经元的缩放系数和/或所述权值的缩放系数融合在所述卷积运算中。In a fourth aspect, this disclosure provides a data processing method implemented by a data processing apparatus, the data processing apparatus including a control circuit and a computation circuit, the method comprising: the control circuit parsing a convolution instruction, the convolution instruction instructing a convolution operation on an input neuron and weights to obtain an output neuron, wherein either or both of the input neuron and weights are particle-quantized; and the computation circuit performing a convolution operation on the data of the input neuron and the data of the weights according to the convolution instruction, and fusing the scaling factor of the input neuron and/or the scaling factor of the weights in the convolution operation.

在本披露实施例所提供的卷积运算方案中,当输入神经元和权值中任一或二者为微粒度量化格式时,可以将数据的反量化过程融合在卷积运算中,而无需事先专门对数据进行反量化,由此既避免了单独的反量化处理,又可以在卷积运算中充分利用微粒度量化格式的低位宽运算和小内存占用的优势。此处,微粒度量化格式可以包括OCP提出的MX量化格式和本披露实施例提出的扩展MX量化格式。In the convolution operation scheme provided in this disclosure embodiment, when either or both of the input neurons and weights are in a particle quantization format, the data dequantization process can be integrated into the convolution operation without prior dequantization. This avoids separate dequantization processing and fully utilizes the advantages of low bit width and small memory footprint of the particle quantization format in the convolution operation. Here, the particle quantization format may include the MX quantization format proposed by OCP and the extended MX quantization format proposed in this disclosure embodiment.

进一步地,在一些实施例中,当运算的操作数位宽不对称时,可以仅对操作数的数据部分进行转数处理,而无需对操作数的缩放系数进行处理,由此简化了运算。而且,这种转数处理使得可以支持多种不同数据类型的操作数混合执行运算。Furthermore, in some embodiments, when the operand bit widths are asymmetrical, only the data portion of the operand can be processed, without needing to process the operand scaling factor, thereby simplifying the computation. Moreover, this processing allows for the mixed execution of operations with operands of various data types.

可选地或附加地,在一些实施例中,还支持对卷积运算的结果,也即对输出神经元进行微粒度量化处理。这种微粒度量化处理一方面便于进行硬件在线量化,另一方面还支持量化后的缩放系数的多种数据类型,由此可以提升算法精度。Optionally or additionally, in some embodiments, particle quantization of the results of convolution operations, i.e., the output neurons, is also supported. This particle quantization facilitates online hardware quantization and supports multiple data types of the quantized scaling factors, thereby improving algorithm accuracy.

可选地或附加地,在一些实施例中,还可以对扩展MX量化得到的缩放系数进行压缩,从而减少存储空间和带宽的浪费。Optionally or additionally, in some embodiments, the scaling factor obtained by extended MX quantization can also be compressed, thereby reducing the waste of storage space and bandwidth.

附图说明Attached Figure Description

通过参考附图阅读下文的详细描述,本披露示例性实施方式的上述以及其他目的、特征和优点将变得易于理解。在附图中,以示例性而非限制性的方式示出了本披露的若干实施方式,并且相同或对应的标号表示相同或对应的部分,其中:The above and other objects, features, and advantages of exemplary embodiments of this disclosure will become readily apparent upon reading the following detailed description with reference to the accompanying drawings. In the drawings, several embodiments of this disclosure are illustrated by way of example and not limitation, and like or corresponding reference numerals denote like or corresponding parts, wherein:

图1示出本披露实施例的板卡的结构图;Figure 1 shows a structural diagram of the board card according to an embodiment of this disclosure;

图2示出本披露实施例的组合处理装置的结构图;Figure 2 shows a structural diagram of the combined processing apparatus according to an embodiment of this disclosure;

图3示出计算装置为单核或多核装置时处理核的内部结构示意图;Figure 3 shows a schematic diagram of the internal structure of the processing core when the computing device is a single-core or multi-core device;

图4示出了MX量化数据格式的示意图;Figure 4 shows a schematic diagram of the MX quantization data format;

图5示出了本披露一些实施例的数据量化的装置的示意性框图;Figure 5 shows a schematic block diagram of a data quantization apparatus according to some embodiments of this disclosure;

图6示出了本披露一些实施例的比较电路的示意性结构框图;Figure 6 shows a schematic block diagram of the comparison circuit of some embodiments of this disclosure;

图7示例性示出了可以实施本披露实施例的数据处理装置的示意性结构图;Figure 7 illustrates a schematic structural diagram of a data processing apparatus that can implement embodiments of the present disclosure;

图8示出了根据本披露实施例的由数据处理电路实施的数据处理方法的示例性流程图。Figure 8 shows an exemplary flowchart of a data processing method implemented by a data processing circuit according to an embodiment of this disclosure.

具体实施方式Detailed Implementation

下面将结合本披露实施例中的附图,对本披露实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本披露一部分实施例,而不是全部的实施例。基于本披露中的实施例,本领域技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本披露保护的范围。The technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, not all of them. Based on the embodiments in this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

应当理解,本披露的权利要求、说明书及附图中可能出现的术语“第一”、“第二”、“第三”和“第四”等是用于区别不同对象,而不是用于描述特定顺序。本披露的说明书和权利要求书中使用的术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。It should be understood that the terms "first," "second," "third," and "fourth," etc., that may appear in the claims, specification, and drawings of this disclosure are used to distinguish different objects, rather than to describe a specific order. The terms "comprising" and "including" as used in the specification and claims of this disclosure indicate the presence of the described features, integrals, steps, operations, elements, and/or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and/or collections thereof.

还应当理解,在此本披露说明书中所使用的术语仅仅是出于描述特定实施例的目的,而并不意在限定本披露。如在本披露说明书和权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。还应当进一步理解,在本披露说明书和权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。It should also be understood that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this disclosure. As used in this disclosure and claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and/or” as used in this disclosure and claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations.

下面结合附图来详细描述本披露的具体实施方式。The specific embodiments disclosed herein will now be described in detail with reference to the accompanying drawings.

首先给出本披露中可能用到的技术术语的解释。First, we provide explanations of the technical terms that may be used in this disclosure.

浮点数:IEEE浮点标准用V=(-1)sign*mantissa*2E的形式表示一个数。其中,sign为符号位,0表示正数,1代表负数;E表示阶码(或指数),对浮点数进行加权,权值是2的E次幂(可能是负数次幂);mantissa表示尾数,mantissa是一个二进制小数。浮点数在计算机中的表示分为三个字段,分别对这些字段进行编码:Floating-point numbers: The IEEE floating-point standard represents a number in the form V = (-1) sign * mantissa * 2 E. Here, sign is the sign bit, 0 for positive and 1 for negative; E represents the exponent (or index), which is a weighted sum of 2 raised to the power of E (possibly a negative power); mantissa represents the mantissa, a binary fraction. Floating-point numbers are represented in computers using three fields, each encoded separately:

(1)一个单独的符号位sign直接编码符号s;(1) A single sign bit directly encodes the symbol s;

(2)k位的阶码字段编码阶码,exp=e(k-1)......e(1)e(0);(2) The exponent field of the k-bit is encoded as exp=e(k-1)......e(1)e(0);

(3)n位的小数字段mantissa,编码尾数。但编码结果依赖阶码字段是否全为0。(3) The n-digit mantissa is used to encode the mantissa. However, the encoding result depends on whether the exponent field is all 0.

定点数:是一种计算机中表示数字的方式,其特点是小数点的位置固定不变。定点数可以表示整数或小数,具体取决于小数点的隐含位置。定点数可以由共享指数(exponent)、符号位(sign)、尾数(mantissa)三部分构成。其中,共享指数是说指数在需要量化的一个实数集合内共享;符号位标志了定点数的正负。尾数决定了定点数的有效数字位数,即精度。Fixed-point numbers are a way of representing numbers in computers, characterized by a fixed decimal point. Fixed-point numbers can represent integers or decimals, depending on the implicit position of the decimal point. A fixed-point number consists of three parts: a shared exponent, a sign bit, and a mantissa. The shared exponent means that the exponent is shared within a set of real numbers to be quantized; the sign bit indicates whether the fixed-point number is positive or negative; and the mantissa determines the number of significant digits, i.e., the precision.

位宽:数据用多少个比特位来表示。Bit width: How many bits are used to represent data.

量化:将高精度数转换成占用较少内存空间的、一般为较低精度的数据的过程。Quantization: The process of converting high-precision numbers into lower-precision data that takes up less memory.

反量化:将低精度数转换成一般为较高精度的数据的过程。Dequantization: The process of converting low-precision numbers into higher-precision data.

FP*:表示一种浮点型数据类型,其中,*可以为2、4、6、8、16、32、64等整数,*的数值表示该数据类型表示的数据的位宽。FP*: Represents a floating-point data type, where * can be an integer such as 2, 4, 6, 8, 16, 32, 64, etc. The value of * indicates the bit width of the data represented by this data type.

BF16、TF32:适用于深度学习的数据类型,通过牺牲精度与范围来提升计算性能。BF16 and TF32 are data types suitable for deep learning, which improve computational performance by sacrificing precision and range.

int*:表示一种整数型数据类型,其中,*可以为2、4、6、8、16、32、64等整数,*的数值表示该数据类型表示的数据的位宽。int*: Represents an integer data type, where * can be an integer such as 2, 4, 6, 8, 16, 32, 64, etc. The value of * indicates the bit width of the data represented by this data type.

ExMy:一种数据格式,其中,E表示指数位,M表示尾数位,x表示指数位位宽,y表示尾数位位宽。ExMy: A data format where E represents the exponent, M represents the mantissa, x represents the exponent width, and y represents the mantissa width.

MX:是指Microscaling规范(可参见“OCP Microscaling Formats(MX)Specification Version 1.0”)。MX: refers to the Microscaling specification (see “OCP Microscaling Formats (MX) Specification Version 1.0”).

扩展MX:是指本披露实施例提出的一种量化方案。Extended MX: refers to a quantization scheme proposed in the embodiments disclosed herein.

微粒度量化:包括MX和扩展MX,以及其他具有类似数据结构的量化,量化粒度根据运算器一次可处理的数据量确定。Granular quantization: This includes MX and extended MX, as well as other quantizations with similar data structures. The quantization granularity is determined based on the amount of data that the arithmetic unit can process at one time.

需要注意,在本披露实施例中,需要进行或已经量化或反量化的数据可以是神经网络中的各种数据,包括但不限于输入神经元、权值、输出神经元、梯度等。本披露实施例提供的神经网络可以应用于各种领域,并且能够处理各种类型的数据。例如,图像识别和处理中的面部识别、物体检测、图像分类、医学图像分析等,数据类型可以包括像素数据、图像特征等;自然语言处理(NLP)中的语言翻译、情感分析、文本摘要、语音识别等,数据类型可以包括文本数据、词汇嵌入、句子结构等;语音识别和处理中的智能助手、自动字幕生成、语音到文本转换等,数据类型可以包括音频信号、声谱图等;推荐系统中的个性化内容推荐、产品推荐、广告投放等,数据类型可以包括用户行为数据、物品特征、评分数据等;医疗健康中的疾病诊断、药物发现、基因序列分析等,数据类型可以包括医疗记录、生物标志物数据、基因组数据等;金融领域中的风险评估、欺诈检测、股市预测等,数据类型可以包括交易数据、用户信用评分、市场数据等;自动驾驶中的车辆感知、决策制定、路径规划等,数据类型可以包括传感器数据、环境特征、交通信号等。游戏和娱乐中的游戏AI、虚拟现实、动画生成等,数据类型可以包括游戏状态数据、用户交互数据等;科学研究中的物理模拟、化学化合物预测、天体物理分析等,数据类型可以包括实验数据、模拟结果、观测数据等;生成式AI应用等。生成式AI是指利用复杂的算法、模型和规则,从大规模数据集中学习,以创造新的原创内容的人工智能技术,例如但不限于能够创造文本、图片、声音、视频和代码等多种类型的内容。相应地,所处理的输入神经元数据可以是未量化或已经量化的图像数据、音频数据、视频数据、语音数据、文本数据、文档数据等,对应的输出神经元也可以是未量化或已经量化的图像数据、音频数据、视频数据、语音数据、文本数据、文档数据等。神经网络的输出可以包括图像属于特定对象类别的可能性得分、文档关于特定主题的可能性得分、目标语言的文本片段是源语言的文本片段的正确翻译的可能性得分、或者文本片段是口语话语的正确转录的可能性得分等。这些输出数据也可以是已经量化或未量化的。通过对数据的量化/反量化处理,可以在保证这些处理任务的处理效果的同时,降低运算量和节省计算资源。本披露实施例的数据量化方案同样可以用于神经网络的推理和训练中,通过对神经网络的数据进行如本披露实施例中所描述的量化处理过程,可以在神经网络执行前述一种或多种处理任务时保证任务精度,同时提高神经网络模型的推理、训练的速度及性能。It should be noted that in this disclosed embodiment, the data to be quantized or dequantized can be various data in the neural network, including but not limited to input neurons, weights, output neurons, gradients, etc. The neural network provided in this disclosed embodiment can be applied to various fields and can process various types of data. For example, in image recognition and processing, facial recognition, object detection, image classification, and medical image analysis can include data types such as pixel data and image features; in natural language processing (NLP), language translation, sentiment analysis, text summarization, and speech recognition can include data types such as text data, word embeddings, and sentence structure; in speech recognition and processing, intelligent assistants, automatic caption generation, and speech-to-text conversion can include data types such as audio signals and spectrograms; in recommendation systems, personalized content recommendation, product recommendation, and advertising can include data types such as user behavior data, item features, and rating data; in healthcare, disease diagnosis, drug discovery, and gene sequence analysis can include data types such as medical records, biomarker data, and genomic data; in the financial field, risk assessment, fraud detection, and stock market prediction can include data types such as transaction data, user credit scores, and market data; and in autonomous driving, vehicle perception, decision-making, and path planning can include data types such as sensor data, environmental features, and traffic signals. In gaming and entertainment, AI applications such as game AI, virtual reality, and animation generation can include data types such as game state data and user interaction data. In scientific research, applications such as physics simulation, chemical compound prediction, and astrophysical analysis can include data types such as experimental data, simulation results, and observational data. Generative AI applications, on the other hand, utilize complex algorithms, models, and rules to learn from large-scale datasets to create new, original content. This includes, but is not limited to, creating various types of content such as text, images, audio, video, and code. Correspondingly, the input neuron data processed can be unquantized or quantized image data, audio data, video data, speech data, text data, document data, etc., and the corresponding output neuron data can also be unquantized or quantized image data, audio data, video data, speech data, text data, document data, etc. The output of the neural network can include a probability score of an image belonging to a specific object category, a probability score of a document relating to a specific topic, a probability score of the correct translation of a text fragment in the target language from a text fragment in the source language, or a probability score of the correct transcription of a text fragment from spoken language, etc. These output data can also be quantized or unquantized. By quantizing/dequantizing the data, the computational load and resources can be reduced while ensuring the processing effectiveness of these tasks. The data quantization scheme of this disclosure embodiment can also be used in the inference and training of neural networks. By performing the quantization process described in this disclosure embodiment on the data of the neural network, the accuracy of the task can be guaranteed when the neural network performs one or more of the aforementioned processing tasks, while improving the speed and performance of the neural network model's inference and training.

示例性硬件架构Exemplary hardware architecture

图1示出本披露实施例的一种板卡10的结构示意图。如图1所示,板卡10包括一个或多个芯片101,其是一种系统级芯片,或称片上系统(System on Chip,SoC),集成有一个或多个组合处理装置。组合处理装置是一种人工智能运算单元,用以支持各类深度学习和机器学习算法,满足计算机视觉、语音、自然语言处理、数据挖掘等领域复杂场景下的智能处理需求。特别是深度学习技术大量应用在云端智能领域,云端智能应用的一个显著特点是输入数据量大,对平台的存储能力和计算能力有很高的要求,此实施例的板卡10适用在云端智能应用,具有庞大的片外存储、片上存储和强大的计算能力。Figure 1 shows a schematic diagram of the structure of a board 10 according to an embodiment of this disclosure. As shown in Figure 1, the board 10 includes one or more chips 101, which are system-on-chips (SoCs) that integrate one or more combined processing devices. The combined processing device is an artificial intelligence computing unit used to support various deep learning and machine learning algorithms, meeting the intelligent processing needs of complex scenarios in fields such as computer vision, speech, natural language processing, and data mining. In particular, deep learning technology is widely used in the field of cloud intelligence. A significant characteristic of cloud intelligence applications is the large amount of input data, which places high demands on the platform's storage and computing capabilities. The board 10 of this embodiment is suitable for cloud intelligence applications, possessing massive off-chip storage, on-chip storage, and powerful computing capabilities.

芯片101通过对外接口装置102与外部设备103相连接。外部设备103例如是服务器、计算机、摄像头、显示器、鼠标、键盘、网卡或wifi接口等。待处理的数据可以由外部设备103通过对外接口装置102传递至芯片101。芯片101的计算结果可以经由对外接口装置102传送回外部设备103。根据不同的应用场景,对外接口装置102可以具有不同的接口形式,例如PCIe(Peripheral Component Interconnect express,高速外围组件互连)接口等。Chip 101 is connected to external device 103 via external interface device 102. External device 103 may be, for example, a server, computer, camera, monitor, mouse, keyboard, network card, or Wi-Fi interface. Data to be processed can be transmitted from external device 103 to chip 101 via external interface device 102. The calculation results from chip 101 can be transmitted back to external device 103 via external interface device 102. Depending on the application scenario, external interface device 102 may have different interface forms, such as PCIe (Peripheral Component Interconnect Express) interface.

板卡10还包括用于存储数据的存储器件104,其包括一个或多个存储单元105。存储器件104通过总线与控制器件106和芯片101进行连接和数据传输。板卡10中的控制器件106配置用于对芯片101的状态进行调控。为此,在一个应用场景中,控制器件106可以包括单片机,又称微控制单元(Micro Controller Unit,MCU)。The board 10 also includes a storage device 104 for storing data, which includes one or more memory cells 105. The storage device 104 is connected to and transmits data with the controller 106 and the chip 101 via a bus. The controller 106 in the board 10 is configured to regulate the state of the chip 101. Therefore, in one application scenario, the controller 106 may include a microcontroller, also known as a microcontroller unit (MCU).

图2是示出此实施例的芯片101中的组合处理装置的结构图。如图2中所示,组合处理装置20包括计算装置201、接口装置202、处理装置203和存储装置204。Figure 2 is a structural diagram illustrating the combined processing device in chip 101 of this embodiment. As shown in Figure 2, the combined processing device 20 includes a computing device 201, an interface device 202, a processing device 203, and a storage device 204.

计算装置201配置成执行用户指定的操作,主要实现为单核智能处理器或者多核智能处理器,用以执行深度学习或机器学习的计算,其可以通过接口装置202与处理装置203进行交互,以共同完成用户指定的操作。The computing device 201 is configured to perform user-specified operations. It is mainly implemented as a single-core intelligent processor or a multi-core intelligent processor to perform deep learning or machine learning calculations. It can interact with the processing device 203 through the interface device 202 to jointly complete the user-specified operations.

接口装置202用于在计算装置201与处理装置203间传输数据和控制指令。例如,计算装置201可以经由接口装置202从处理装置203中获取输入数据,写入计算装置201片上的存储装置。进一步,计算装置201可以经由接口装置202从处理装置203中获取控制指令,写入计算装置201片上的控制缓存中。替代地或可选地,接口装置202也可以读取计算装置201的存储装置中的数据并传输给处理装置203。Interface device 202 is used to transmit data and control commands between computing device 201 and processing device 203. For example, computing device 201 can obtain input data from processing device 203 via interface device 202 and write it to on-chip storage device of computing device 201. Further, computing device 201 can obtain control commands from processing device 203 via interface device 202 and write them to on-chip control cache of computing device 201. Alternatively or optionally, interface device 202 can also read data from storage device of computing device 201 and transmit it to processing device 203.

处理装置203作为通用的处理装置,执行包括但不限于数据搬运、对计算装置201的开启和/或停止等基本控制。根据实现方式的不同,处理装置203可以是中央处理器(Central Processing Unit,CPU)、图形处理器(Graphics Processing Unit,GPU)或其他通用和/或专用处理器中的一种或多种类型的处理器,这些处理器包括但不限于数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等,并且其数目可以根据实际需要来确定。如前所述,仅就本披露的计算装置201而言,其可以视为具有单核结构或者同构多核结构。然而,当将计算装置201和处理装置203整合共同考虑时,二者视为形成异构多核结构。Processing device 203, as a general-purpose processing device, performs basic control including but not limited to data transfer, and starting and/or stopping computing device 201. Depending on the implementation, processing device 203 may be one or more types of processors, including but not limited to digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., and their number can be determined according to actual needs. As mentioned above, computing device 201 disclosed herein can be considered as having a single-core structure or a homogeneous multi-core structure. However, when computing device 201 and processing device 203 are considered together, they are considered to form a heterogeneous multi-core structure.

存储装置204用以存储待处理的数据,其可以是DRAM(Dynamic Random Access Memory,动态随机存取存储器),为DDR(Double Data Rate,双倍速率)内存,大小通常为16G或更大,用于保存计算装置201和/或处理装置203的数据。Storage device 204 is used to store data to be processed. It may be DRAM (Dynamic Random Access Memory) or DDR (Double Data Rate) memory, typically 16G or larger, and is used to store data of computing device 201 and/or processing device 203.

图3示出了图2中的计算装置201为单核或多核装置时处理核的内部结构示意图。计算装置301用以处理计算机视觉、语音、自然语言、数据挖掘等输入数据,计算装置301包括三大模块:控制模块31(也称为控制器)、运算模块32(也称为运算器)及存储模块33(也称为存储器)。Figure 3 shows a schematic diagram of the internal structure of the processing core when the computing device 201 in Figure 2 is a single-core or multi-core device. The computing device 301 is used to process input data such as computer vision, speech, natural language, and data mining. The computing device 301 includes three main modules: a control module 31 (also called a controller), an arithmetic module 32 (also called an arithmetic unit), and a storage module 33 (also called a memory).

控制模块31用以协调并控制运算模块32和存储模块33的工作,以完成深度学习的任务,其包括取指单元(Instruction Fetch Unit,IFU)311及指令译码单元(Instruction Decode Unit,IDU)312。取指单元311用以获取来自处理装置203的指令,指令译码单元312则将获取的指令进行译码,并将译码结果作为控制信息发送给运算模块32和存储模块33。The control module 31 coordinates and controls the operation of the computation module 32 and the storage module 33 to complete the deep learning task. It includes an instruction fetch unit (IFU) 311 and an instruction decode unit (IDU) 312. The instruction fetch unit 311 fetches instructions from the processing device 203, and the instruction decode unit 312 decodes the fetched instructions and sends the decoding result as control information to the computation module 32 and the storage module 33.

运算模块32包括向量运算单元321及矩阵运算单元322。向量运算单元321用以执行向量运算,可支持向量乘、加、非线性变换等复杂运算;矩阵运算单元322负责深度学习算法的核心计算,即矩阵乘及卷积。The computation module 32 includes a vector operation unit 321 and a matrix operation unit 322. The vector operation unit 321 is used to perform vector operations and can support complex operations such as vector multiplication, addition, and nonlinear transformations; the matrix operation unit 322 is responsible for the core computations of deep learning algorithms, namely matrix multiplication and convolution.

存储模块33用来存储或搬运相关数据,包括神经元存储单元(Neuron RAM,NRAM)331、权值存储单元(Weight RAM,WRAM)332、直接内存访问模块(Direct Memory Access,DMA)333。NRAM 331用以存储输入神经元、输出神经元和计算后的中间结果;WRAM 332则用以存储深度学习网络的卷积核,即权值;DMA 333通过总线34连接DRAM 204,负责计算装置301与DRAM 204间的数据搬运。应当注意,此处的NRAM和WRAM可以是同一存储器在逻辑存储空间上划分形成的两个存储区域,也可以是两个独立的存储器,此处不做具体限定。Storage module 33 is used to store or move relevant data, including Neuron RAM (NRAM) 331, Weight RAM (WRAM) 332, and Direct Memory Access (DMA) 333. NRAM 331 stores input neurons, output neurons, and intermediate results after computation; WRAM 332 stores the convolution kernels of the deep learning network, i.e., the weights; DMA 333 is connected to DRAM 204 via bus 34 and is responsible for data transfer between computing device 301 and DRAM 204. It should be noted that NRAM and WRAM here can be two storage areas formed by dividing the same memory in logical storage space, or they can be two independent memories; no specific limitation is made here.

示例性MX量化数据Exemplary MX quantization data

图4示出了MX量化数据格式的示意图,也即MX量化数据的组成部分。如图所示,MX量化数据格式通过三部分来表征,分别是缩放系数(X,shared scale),缩放块大小(K,Scaling Block size),以及块内的私有元素数据(Pi)。Figure 4 illustrates the MX quantized data format, which represents the components of MX quantized data. As shown, the MX quantized data format is characterized by three parts: the scaling factor (X, shared scale), the scaling block size (K, scaling block size), and the private element data within the block (P <sub>i</sub> ).

缩放系数X涉及缩放系数的数据类型或编码方式。私有元素(Pi)也涉及其数据类型或编码方式。缩放块大小(K)表示块内私有元素Pi的个数。块内的所有K个元素Pi都具有相同的数据类型,因而也拥有相同的位宽。缩放系数X在这K个元素间共享。元素的数据类型和缩放系数的数据类型可以独立选择。从某种意义上说,MX可以视为一种根据标量数据类型构建向量数据类型的机制。一个MX块中所表示的值V1,…,Vk可以按如下确定:Vi=XPiThe scaling factor X relates to the data type or encoding of the scaling factor. The private element (P <sub>i</sub> ) also relates to its data type or encoding. The scaling block size (K) represents the number of private elements P <sub>i </sub> within the block. All K elements P<sub>i</sub> within the block have the same data type and therefore the same bit width. The scaling factor X is shared among these K elements. The data type of the elements and the data type of the scaling factor can be chosen independently. In a sense, MX can be viewed as a mechanism for constructing vector data types based on scalar data types. The values V <sub>1</sub> , ..., V<sub>k</sub> represented in an MX block can be determined as follows: Vi = XP<sub>i</sub> .

如图所示,W表示用于编码共享缩放系数X的比特数,也即缩放系数X的位宽;d表示用于代表每个元素Pi的比特数,也即Pi的位宽。因此,对于一个包含K个元素的MX块而言,可以通过(W+Kd)比特进行编码。As shown in the figure, W represents the number of bits used to encode the shared scaling factor X, which is also the bit width of scaling factor X; d represents the number of bits used to represent each element Pi , which is also the bit width of Pi . Therefore, for an MX block containing K elements, it can be encoded using (W+Kd) bits.

表1中给出了MX的一些常见格式及相关参数。

表1
Table 1 shows some common MX formats and related parameters.

Table 1

在上述表1中,ExMy表示具有x个指数位和y个尾数位的标量格式记法。例如FP8(E4M3)表示具有1个符号位、4个指示位和3个尾数位的FP8格式。在y为0的情况下(例如E8M0),该格式不包括符号位。In Table 1 above, ExMy represents a scalar format notation with x exponent bits and y mantissa bits. For example, FP8 (E4M3) represents an FP8 format with 1 sign bit, 4 indicator bits, and 3 mantissa bits. When y is 0 (e.g., E8M0), the format does not include a sign bit.

进一步地,在MX量化中,缩放系数X的计算方法为:Furthermore, in MX quantization, the scaling factor X is calculated as follows:

(1)确定小于或等于K个元素Pi中的绝对值最大值的最大2次幂;(1) Determine the largest power of the absolute value of the K elements Pi that are less than or equal to the K elements Pi ;

(2)将该最大2次幂除以元素Pi的数据类型可表示的最大数值的2次幂,得到的计算结果设置为缩放系数Scale X。(2) Divide the maximum power of 2 by the power of the maximum value that the data type of element P i can represent, and set the result as the scaling factor Scale X.

本发明人发现,对于MX量化方式,在将原始数据处理为F4(表示数据位宽为4比特位的数据格式)等超低精度数据类型时,会导致大模型的任务精度急剧下降,也就是说,会对任务的计算结果的准确性产生较大影响。以图像识别任务为例,任务精度或者任务的处理效果可以体现为图像识别结果的准确性,也即图像识别的计算结果是否准确。前述量化方式量化后得到的图像量化数据会影响图像识别结果的准确性。The inventors have discovered that, for MX quantization, processing the original data into ultra-low precision data types such as F4 (representing a 4-bit data format) leads to a sharp decrease in the accuracy of large models, significantly impacting the accuracy of the computational results. Taking image recognition tasks as an example, task accuracy or processing performance is reflected in the accuracy of the image recognition results, i.e., whether the image recognition computation is accurate. The quantized image data obtained after quantization using the aforementioned quantization method affects the accuracy of the image recognition results.

本发明人还发现,假如量化方式中使用的缩放系数的数据类型与原始数据类型相同,虽然可以在一定程度上解决上述精度下降的问题,但是这样的方式将导致资源开销(例如存储空间、硬件支持所需要的面积开销等)更大。The inventors also discovered that if the data type of the scaling factor used in the quantization method is the same as the original data type, although the above-mentioned problem of decreased accuracy can be solved to some extent, this method will lead to greater resource overhead (such as storage space, area overhead required for hardware support, etc.).

示例性的扩展MX量化方法Exemplary Extended MX Quantization Method

基于以上发现,本披露提供了一种全新的数据量化的方案,其中基于待量化数据的绝对值最大值来确定缩放因子,以及通过对缩放因子进行数据类型转换来得到缩放系数。由于转换后的缩放系数具有非零的尾数,由此改善了量化后数据的精度,使得基于本披露实施例量化后的量化数据执行的处理任务具有较好的精度。此外,基于硬件的单次处理量来设置量化的粒度,便于通过硬件的单次处理完成一个粒度块的量化,从而更方便硬件在线实现量化/反量化,便于流水化设计,并使得以此硬件作为计算载体的神经网络模型可以在推理及训练等各阶段实现量化运算,提高神经网络模型的运算效率。Based on the above findings, this disclosure provides a novel data quantization scheme. This scheme determines a scaling factor based on the maximum absolute value of the data to be quantized, and obtains a scaling coefficient by converting the scaling factor to a different data type. Since the converted scaling coefficient has a non-zero mantissa, the accuracy of the quantized data is improved, resulting in processing tasks performed on the quantized data according to the embodiments of this disclosure exhibiting better accuracy. Furthermore, setting the quantization granularity based on the hardware's single-processing capacity facilitates the quantization of a block of granularity in a single hardware operation. This makes online quantization/dequantization more convenient, facilitating pipelined design and enabling neural network models using this hardware as a computing platform to perform quantization operations at various stages, including inference and training, thereby improving the computational efficiency of the neural network model.

在扩展MX量化方案中,缩放系数的计算方法为:In the extended MX quantization scheme, the scaling factor is calculated as follows:

(1)确定一组待量化数据中的绝对值最大值;(1) Determine the maximum absolute value in a set of data to be quantified;

(2)获取待量化数据量化后的目标数据类型能够表示的最大数值;(2) Obtain the maximum value that the target data type can represent after the data to be quantized is quantized;

(3)基于绝对值最大值与最大数值之间的比值,确定这一组待量化数据对应的缩放因子;(3) Determine the scaling factor corresponding to this set of data to be quantized based on the ratio between the maximum absolute value and the maximum value;

(4)将缩放因子由第一数据类型转换为第二数据类型,以得到缩放系数,其中第二数据类型的位宽可以小于第一数据类型的位宽。(4) Convert the scaling factor from the first data type to the second data type to obtain the scaling coefficient, wherein the bit width of the second data type can be smaller than the bit width of the first data type.

目标数据类型是待量化数据量化后得到的量化数据的数据类型。在量化处理之前,目标数据类型可以根据需要进行设定,其精度一般低于待量化数据的原始数据类型的精度。在一些实施例中,待量化数据的原始数据类型可以包括例如FP16、BF16、FP32、FP64、TF32等中的至少一种;目标数据类型可以包括例如FP8、FP6、FP4、FP2、int8、int4、int2、int6、FP12等中的至少一种。其中,FP8、FP6、FP4等浮点型数据类型可以支持多种数据格式。以FP4为例,按照“符号位+指数位+尾数位”的规则可以有多种划分,通常符号位占1位,指数位和尾数位的组合常见形式有E3M0和E2M1。类似地,FP8可以支持E4M3、E5M2等数据格式,FP6可以支持E3M2、E2M3等数据格式。The target data type is the data type of the quantized data obtained after quantizing the data to be quantized. Before quantization, the target data type can be set as needed, and its precision is generally lower than that of the original data type of the data to be quantized. In some embodiments, the original data type of the data to be quantized may include at least one of FP16, BF16, FP32, FP64, TF32, etc.; the target data type may include at least one of FP8, FP6, FP4, FP2, int8, int4, int2, int6, FP12, etc. Among these, floating-point data types such as FP8, FP6, and FP4 can support multiple data formats. Taking FP4 as an example, it can be divided in several ways according to the rule of "sign bit + exponent bit + mantissa bit," with the sign bit typically occupying 1 bit. Common combinations of exponent and mantissa bits include E3M0 and E2M1. Similarly, FP8 can support data formats such as E4M3 and E5M2, and FP6 can support data formats such as E3M2 and E2M3.

由于每一种数据类型的位宽限制,使得每一种数据类型均具有其能够表示的最大数值。例如,目标数据类型为FP4时能够表示的最大数值为6;目标数据类型为int8时能够表示的最大数值为127。通常,最大数值与目标数据类型具有一一对应关系,可以通过例如查表等方式来获得。Due to the bit width limitations of each data type, each data type has a maximum representable value. For example, the maximum representable value when the target data type is FP4 is 6; the maximum representable value when the target data type is int8 is 127. Typically, there is a one-to-one correspondence between the maximum value and the target data type, which can be obtained through methods such as table lookup.

由于绝对值最大值的数据类型与待量化数据的原始数据类型相同,因此通过比值得到的缩放因子的数据类型(即第一数据类型)与其对应的待量化数据的原始数据类型相同,或者第一数据类型的位宽可以大于原始数据类型的位宽。Since the data type of the absolute maximum value is the same as the original data type of the data to be quantized, the data type of the scaling factor obtained by the ratio (i.e., the first data type) is the same as the original data type of the corresponding data to be quantized, or the bit width of the first data type can be greater than the bit width of the original data type.

第一数据类型是缩放因子的数据类型,第二数据类型是缩放系数的数据类型。通过数据类型转换使得第二数据类型的位宽小于第一数据类型的位宽,从而缩放系数的精度小于缩放因子的精度。在一些实施例中,将缩放因子转换为缩放系数,可以通过转数指令来实现,例如cvt_to_scale_dtype()。在另一些实施例中,将缩放因子转换为缩放系数,支持多种round模式,例如rn(round to nearest,ties to even)。The first data type is the scaling factor's data type, and the second data type is the scaling coefficient's data type. Data type conversion makes the bit width of the second data type smaller than that of the first data type, thus the precision of the scaling coefficient is less than the precision of the scaling factor. In some embodiments, the conversion from scaling factor to scaling coefficient can be achieved using a conversion instruction, such as `cvt_to_scale_dtype()`. In other embodiments, the conversion supports multiple round modes, such as `rn(round to nearest, ties to even)`.

在另一些实施例中,第二数据类型可以表示为ExMy,其中,E表示指数位,M表示尾数位,x表示指数位位宽,y表示尾数位位宽,x+y<原始数据类型的位宽。例如,假设原始数据类型为FP16,则x+y<16。x、y的具体数值可以根据需要或者硬件环境进行设置,x为正整数,y≥0。在又一些实施例中,3≤x+y<原始数据类型的位宽。在一些实施例中,8≤x+y<原始数据类型的位宽。在一些实施例中,第二数据类型可以包括例如E8M0、E8M1、E8M2、E8M3、E8M4、E8M5、E8M6、E8M7、E5M0、E5M1、E5M2、E5M3、E5M4、E5M5、E5M6、E3M0、E3M1、E3M2、E3M3、E3M4、E3M5、E3M6、E3M7、E3M8、E3M9等中的至少一种。在一些优选实施例中,y>0。在进一步优选实施例中,第二数据类型可以为E8M2或E8M3。In other embodiments, the second data type can be represented as ExMy, where E represents the exponent bits, M represents the mantissa bits, x represents the exponent bit width, y represents the mantissa bit width, and x + y < the bit width of the original data type. For example, assuming the original data type is FP16, then x + y < 16. The specific values of x and y can be set according to needs or the hardware environment, where x is a positive integer and y ≥ 0. In still other embodiments, 3 ≤ x + y < the bit width of the original data type. In some embodiments, 8 ≤ x + y < the bit width of the original data type. In some embodiments, the second data type may include at least one of, for example, E8M0, E8M1, E8M2, E8M3, E8M4, E8M5, E8M6, E8M7, E5M0, E5M1, E5M2, E5M3, E5M4, E5M5, E5M6, E3M0, E3M1, E3M2, E3M3, E3M4, E3M5, E3M6, E3M7, E3M8, E3M9, etc. In some preferred embodiments, y > 0. In a further preferred embodiment, the second data type may be E8M2 or E8M3.

为了便于理解,仍以原始数据类型为FP16为例,当8<x+y<原始数据类型的位宽时,缩放系数的第二数据类型ExMy表示的位宽(即x+y)可以介于8位到16位之间。使用这样的缩放系数对神经网络的运算数据进行量化处理,并使用量化后得到的量化数据进行神经网络的推理和训练等,得到的神经网络的精度介于8位表示(例如MX中表示的E8M0)与原始16位表示(例如E5M10、E8M7,即FP16、BF16)之间。相比于MX格式,本披露实施例这样的缩放系数有利于提高量化数据的精度;相比于缩放系数的数据类型与原始数据类型相同的情况,本披露实施例这样的缩放系数有利于降低硬件资源开销或存储开销等。For ease of understanding, taking the original data type FP16 as an example, when 8 < x + y < the bit width of the original data type, the bit width (i.e., x + y) represented by the second data type ExMy of the scaling factor can be between 8 bits and 16 bits. Using such a scaling factor to quantize the computational data of the neural network, and then using the quantized data for neural network inference and training, the resulting neural network precision is between that of an 8-bit representation (e.g., E8M0 in MX) and the original 16-bit representation (e.g., E5M10, E8M7, i.e., FP16, BF16). Compared to the MX format, this scaling factor in the disclosed embodiment is beneficial for improving the precision of the quantized data; compared to the case where the data type of the scaling factor is the same as the original data type, this scaling factor in the disclosed embodiment is beneficial for reducing hardware resource overhead or storage overhead.

进一步地,由于尾数位位宽影响量化的精度,较大的尾数位位宽可以提供精度更高的缩放系数,从而在量化过程中保留更多的原始数据细节,因此相比于MX量化中E8M0格式的缩放系数,当本披露实施例中缩放系数的尾数位位宽y>0时,有利于提升量化数据的精度以及处理任务的精度。Furthermore, since the mantissa bit width affects the quantization accuracy, a larger mantissa bit width can provide a scaling factor with higher accuracy, thereby preserving more original data details during the quantization process. Therefore, compared with the scaling factor of E8M0 format in MX quantization, when the mantissa bit width y of the scaling factor in this disclosed embodiment is greater than 0, it is beneficial to improve the accuracy of quantized data and the accuracy of processing tasks.

此外,本披露实施例通过对缩放因子进行数据类型转换,使得缩放系数支持多种数据类型,从而可以更灵活地适应不同数据特性和精度要求。关于缩放系数的指数位位宽和尾数位位宽的选择,可以考虑待量化数据的分布特点。缩放系数的指数位位宽越大,能表示的数值越多。如果一组待量化数据的数值范围变化较大,则可以将缩放系数的指数位位宽设置的大一些;如果一组待量化数据的数值范围变化较小,则可以将缩放系数的指数位位宽设置的小一些,尾数位位宽设置的大一些。Furthermore, this disclosed embodiment enables the scaling factor to support multiple data types by performing data type conversion, thereby allowing for more flexible adaptation to different data characteristics and precision requirements. Regarding the selection of the exponent and mantissa bit widths of the scaling factor, the distribution characteristics of the data to be quantized can be considered. A larger exponent bit width allows for the representation of more values. If the range of values in a set of data to be quantized varies significantly, the exponent bit width of the scaling factor can be set larger; conversely, if the range of values in a set of data to be quantized varies only slightly, the exponent bit width of the scaling factor can be set smaller, while the mantissa bit width can be set larger.

举例来说,假设第二数据类型需要设置为8bit,如果一组待量化数据的绝对值数值范围涉及到2-127~2127,则第二数据类型可以设置为E8M0;如果一组待量化数据的绝对值数值范围涉及到2-4~24,则第二数据类型可以设置为E3M5。当然,可以理解的是,第二数据类型的位宽可以不限于8bit,也可以根据需要设置为5bit、或者4bit等。For example, assuming the second data type needs to be set to 8 bits, if the absolute value range of a set of data to be quantized is between 2 <sup>-127 </sup> and 2 <sup>127</sup> , then the second data type can be set to E8M0; if the absolute value range of a set of data to be quantized is between 2 <sup>-4 </sup> and 2<sup>4</sup> , then the second data type can be set to E3M5. Of course, it's understandable that the bit width of the second data type is not limited to 8 bits; it can also be set to 5 bits, 4 bits, etc., as needed.

在通过上述方式确定了缩放系数之后,该缩放系数可以用于对与其对应的待量化数据进行量化处理,也可以用于对量化数据进行反量化处理。After determining the scaling factor in the above manner, the scaling factor can be used to quantize the corresponding data to be quantized, or to dequantize the quantized data.

在一些实施例中,量化处理可以包括:将待量化数据除以缩放系数,得到量化中间结果;对该量化中间结果进行数据类型转换,以得到具有目标数据类型的量化数据。这里的数据类型转换也可以通过转数指令来实现,例如cvt_to_scale_dtype()。这里的转数指令可以是各层级的软硬件指令,例如是处理器内部微指令、或ISA指令、或软件侧各层级的高级语言实现的函数指令等。In some embodiments, quantization processing may include: dividing the data to be quantized by a scaling factor to obtain an intermediate quantization result; and performing data type conversion on the intermediate quantization result to obtain quantized data with the target data type. This data type conversion can also be implemented using a conversion instruction, such as `cvt_to_scale_dtype()`. This conversion instruction can be a hardware or software instruction at various levels, such as processor microinstructions, ISA instructions, or function instructions implemented in high-level languages at various software levels.

反量化处理一般是将低精度的数据还原为高精度的数据的过程。在一些实施例中,利用缩放系数对量化数据进行反量化处理可以包括:将量化数据与缩放系数进行乘法操作。在另一些实施例中,可以将量化数据由目标数据类型转换为所需数据类型后,再与缩放系数进行乘法操作,其中所需数据类型的精度高于目标数据类型的精度。在又一些实施例中,反量化处理可以将量化数据还原为量化操作前的待量化数据。Dequantization is generally the process of restoring low-precision data to high-precision data. In some embodiments, dequantizing quantized data using a scaling factor may include multiplying the quantized data with the scaling factor. In other embodiments, the quantized data may be converted from a target data type to a desired data type before being multiplied with the scaling factor, wherein the precision of the desired data type is higher than that of the target data type. In still other embodiments, dequantization can restore the quantized data to its original state before the quantization operation.

从前面转换得到的缩放系数的第二数据类型可以看出,单个缩放系数的位宽为3~15比特,例如E8M4需要12比特,通常需要分配2字节(2B)的存储空间,因此肯定占不满。这样难免带来存储空间和传输带宽的浪费。为了解决这一问题,在一些实施例中,可以对两个或更多个缩放系数进行压缩,从而节省存储空间和带宽。As can be seen from the second data type of the scaling factor obtained from the previous conversion, the bit width of a single scaling factor is 3 to 15 bits. For example, E8M4 requires 12 bits, which typically requires 2 bytes (2B) of storage space, so it will definitely not be fully utilized. This inevitably leads to a waste of storage space and transmission bandwidth. To solve this problem, in some embodiments, two or more scaling factors can be compressed, thereby saving storage space and bandwidth.

在一些实施例中,在利用前述方法对两组或更多组待量化数据量化以得到两个或更多个缩放系数后,可以对这两个或更多个缩放系数进行压缩处理。继而,使用压缩后的缩放系数分别对对应组待量化数据进行量化处理,以输出具有目标数据类型的量化数据。In some embodiments, after quantizing two or more sets of data to be quantized using the aforementioned method to obtain two or more scaling factors, these two or more scaling factors can be compressed. Then, the compressed scaling factors are used to quantize the corresponding sets of data to be quantized, respectively, to output quantized data with the target data type.

具体地,可以在按前述方法得到缩放系数之后包括压缩处理步骤,具体包括:确定待压缩的Z个缩放系数的共享指数,Z≥2;确定这Z个缩放系数对应的Z个新尾数;以及将共享指数与Z个新尾数捆绑输出以供关联使用。也即,经过压缩后,Z个缩放系数的指数复用,各自的尾数不同,由此至少可以节省Z-1个指数位宽。Specifically, after obtaining the scaling factors as described above, a compression process can be included, which specifically includes: determining the shared exponent of the Z scaling factors to be compressed, where Z ≥ 2; determining the Z new mantissas corresponding to these Z scaling factors; and bundling the shared exponent with the Z new mantissas for output for association. That is, after compression, the exponents of the Z scaling factors are reused, and their mantissas are different, thereby saving at least Z-1 exponent bits.

在一些实现中,确定待压缩的Z个缩放系数的共享指数可以包括:将这Z个缩放系数中的最大指数设置为共享指数。选择最大指数作为共享指数,可以尽可能确保数值更大的数的精度,因为通常数值更大的数对计算结果的影响更大。In some implementations, determining the shared exponent for the Z scaling factors to be compressed may involve setting the largest exponent among these Z scaling factors as the shared exponent. Choosing the largest exponent as the shared exponent ensures the precision of larger numbers as much as possible, since larger numbers typically have a greater impact on the calculation results.

在一些实现中,确定Z个缩放系数对应的Z个新尾数可以包括:将指数小于最大指数的缩放系数的新尾数设置为0;以及将指数等于最大指数的缩放系数的新尾数设置为原尾数。可以理解,对于指数等于最大指数的缩放系数而言,由于指数不变,因此其尾数部分不变;而对于指数小于最大指数的缩放系数,其指数放大成最大指数后,若要保持等价,则尾数会成比例缩小,超出了尾数部分能表示的数值范围。因此,此处将其新尾数设置为0。这种设置会存在一定的精度损失,但是相对于存储和带宽收益而言,这种精度损失在一些情况下是可接受的。In some implementations, determining the Z new mantissas corresponding to the Z scaling factors can include: setting the new mantissa of scaling factors whose exponent is less than the maximum exponent to 0; and setting the new mantissa of scaling factors whose exponent is equal to the maximum exponent to the original mantissa. It can be understood that for scaling factors whose exponent is equal to the maximum exponent, since the exponent remains unchanged, its mantissa remains unchanged; however, for scaling factors whose exponent is less than the maximum exponent, after the exponent is scaled up to the maximum exponent, to maintain equivalence, the mantissa would be proportionally reduced, exceeding the range of values that the mantissa can represent. Therefore, its new mantissa is set to 0 here. This setting will result in some precision loss, but compared to the storage and bandwidth gains, this precision loss is acceptable in some cases.

在一些实现中,共享指数与Z个新尾数可以按顺序排列捆绑输出以供关联使用。例如,先是共享指数,接着是第一个缩放系数的新尾数,第二个缩放系数的新尾数,直至第Z个缩放系数的新尾数。In some implementations, the shared exponent and the Z new mantissas can be bundled together in sequence for association. For example, first the shared exponent, then the new mantissa of the first scaling factor, the new mantissa of the second scaling factor, and so on up to the new mantissa of the Z scaling factor.

接着,使用压缩后的缩放系数分别对对应组待量化数据进行量化处理,以输出具有目标数据类型的量化数据。由于压缩后,指数小于最大指数的缩放系数的指数和尾数部分都会发生变化,因此为了保持量化与反量化的一致性,使用压缩后的缩放系数分别对对应组待量化数据进行量化处理。Next, the compressed scaling factors are used to quantize the corresponding groups of data to be quantized, so as to output quantized data with the target data type. Since the exponent and mantissa of the scaling factors with an exponent smaller than the maximum exponent will change after compression, the compressed scaling factors are used to quantize the corresponding groups of data to be quantized separately in order to maintain the consistency of quantization and dequantization.

在一些实现中,待压缩的Z个缩放系数的第二数据类型相同。例如,Z个缩放系数都是E8M4类型。这样,压缩后复用的共享指数位宽为8比特,Z个新尾数为4Z比特。In some implementations, the second data type of the Z scaling factors to be compressed is the same. For example, all Z scaling factors are of type E8M4. In this way, the shared exponent bit width after compression is 8 bits, and the Z new mantissas are 4Z bits.

在一些实现中,Z个缩放系数属于相邻的Z组待量化数据。这样,可以对数据顺序地进行处理,而不需要额外的信息来指示压缩在一起的缩放系数。In some implementations, the Z scaling factors belong to Z adjacent groups of data to be quantized. This allows the data to be processed sequentially without requiring additional information to indicate the scaling factors that are compressed together.

在一些实现中,Z可以为2或4或8或其他。本领域技术人员可以根据一组待量化数据中待量化数据的数量K来选择合适的Z值。例如,当K较小时,Z的取值可以大些;当K较大时,Z的取值则需小点,由此确保采用压缩方案后的收益大于将K放大Z倍的收益。In some implementations, Z can be 2, 4, 8, or other values. Those skilled in the art can choose an appropriate Z value based on the number K of data to be quantized in a set of data. For example, when K is small, the value of Z can be larger; when K is large, the value of Z needs to be smaller, thereby ensuring that the benefit of using the compression scheme is greater than the benefit of amplifying K by Z times.

类似地,当对使用了压缩格式的扩展MX量化数据进行反量化时,需要先对缩放系数进行解压缩。具体地,在反量化处理时,响应于缩放系数为压缩格式,对压缩后的缩放系数进行解压缩;以及利用解压缩后的缩放系数对量化数据进行反量化处理。Similarly, when dequantizing extended MX quantized data using a compressed format, the scaling factors need to be decompressed first. Specifically, during dequantization, in response to the scaling factors being in a compressed format, the compressed scaling factors are decompressed; and the decompressed scaling factors are used to dequantize the quantized data.

根据前面描述的压缩方法及捆绑方式,可以将捆绑的Z个缩放系数解码成Z个独立的缩放系数。具体地,可以将共享指数分别与Z个新尾数进行组合,即可得到Z个解压缩后的缩放系数。Based on the compression method and bundling approach described above, the bundled Z scaling factors can be decoded into Z independent scaling factors. Specifically, the shared exponent can be combined with each of the Z new mantissas to obtain the Z decompressed scaling factors.

可以理解,在一些实施例中,除了计算和保存缩放系数之外,也会计算和保存缩放系数的倒数,以方便在量化过程中,将待量化数据与缩放系数之间的除法运算转换为待量化数据与缩放系数的倒数之间的乘法运算。缩放系数的倒数与缩放系数具有相同的数据类型。因此,上面的压缩和解压缩处理同样可以应用于缩放系数的倒数,此处不再展开描述。It is understood that in some embodiments, in addition to calculating and storing the scaling factor, the reciprocal of the scaling factor is also calculated and stored. This facilitates converting the division operation between the data to be quantized and the scaling factor into a multiplication operation between the data to be quantized and the reciprocal of the scaling factor during the quantization process. The reciprocal of the scaling factor has the same data type as the scaling factor. Therefore, the compression and decompression processes described above can also be applied to the reciprocal of the scaling factor, which will not be described in detail here.

在上述扩展MX量化方案中,通过基于待量化数据的绝对值最大值来确定缩放系数,能够保证绝对值最大值量化后的数据精度,并且由于在量化过程中,待量化数据的数值越大,其精度损失越大将对任务计算结果的影响越大,因此通过保证绝对值最大值的数据精度,可以有助于减小任务精度的损失,从而相比于例如MX中计算缩放系数的方式,扩展MX量化方案能够有利于保证任务精度。In the extended MX quantization scheme described above, the scaling factor is determined based on the maximum absolute value of the data to be quantized. This ensures the accuracy of the data after quantization based on the maximum absolute value. Furthermore, since the larger the value of the data to be quantized during the quantization process, the greater the loss of accuracy and the greater the impact on the task calculation results, ensuring the accuracy of the data based on the maximum absolute value helps to reduce the loss of task accuracy. Therefore, compared to methods such as calculating the scaling factor in MX, the extended MX quantization scheme is better at ensuring task accuracy.

此外,相比于缩放系数的数据类型与原始数据类型相同的量化方式,本披露实施例中通过转数得到具有第二数据类型的缩放系数,能够在保证任务精度的同时,还能够有利于降低存储缩放系数所需的存储空间以及执行任务所需的硬件开销等。Furthermore, compared to the quantization method where the data type of the scaling factor is the same as the original data type, the scaling factor with a second data type obtained by the number of revolutions in this disclosed embodiment can reduce the storage space required to store the scaling factor and the hardware overhead required to execute the task while ensuring the accuracy of the task.

在一些实施例中,可以根据执行量化处理的处理电路的单次处理量和/或输入端口数量,确定一组待量化数据中待量化数据的数量;或者根据使用量化数据进行运算的运算器的单次运算量和/或输入端口数量,确定所述一组待量化数据中待量化数据的数量。In some embodiments, the number of data to be quantized in a set of data to be quantized can be determined based on the single processing volume and/or the number of input ports of the processing circuit performing the quantization process; or the number of data to be quantized in a set of data to be quantized can be determined based on the single operation volume and/or the number of input ports of the arithmetic unit that performs the operation using the quantized data.

例如,可以根据处理电路进行量化处理的单次处理量(即单次运行可处理的数据量),或者根据使用量化数据进行例如乘累加运算、或向量内积运算等的运算器的单次运算量(即单次运行可运算的数据量),确定一组待量化数据中待量化数据的数量,并依此粒度来进行分组。根据这样的设置,可以将共用一个缩放系数的一组待量化数据在一个运算周期内一次性处理完,而无需跨越多个运算周期才能将共用一个缩放系数的待量化数据处理完,从而更利于硬件实现以及充分利用硬件算力。For example, the number of data points to be quantized in a set of data can be determined based on the processing capacity of the processing circuit (i.e., the amount of data that can be processed in a single run), or based on the processing capacity of the arithmetic unit that performs operations such as multiply-accumulate or vector inner product using quantized data (i.e., the amount of data that can be processed in a single run), and grouped according to this granularity. With this setup, a set of data points sharing a single scaling factor can be processed in one computation cycle, without needing to span multiple computation cycles, thus improving hardware implementation and fully utilizing hardware computing power.

还例如,可以根据执行量化处理的处理电路的输入端口数量或者使用量化数据进行运算的运算器的输入端口数量,确定一组待量化数据中待量化数据的数量,并依此粒度来进行分组。根据这样的设置,可以利用硬件的输入端口数量一次性输入一组待量化数据,使得共用一个缩放系数的一组待量化数据能够在一次输入中一次性处理完,而无需输入多次才能处理完一组待量化数据,从而有利于硬件实现、降低硬件处理等待时间以及降低IO调用开销。For example, the number of data points to be quantized in a set of data can be determined based on the number of input ports of the processing circuit performing quantization or the number of input ports of the arithmetic unit that uses quantized data for calculation, and grouped accordingly. With this setup, a set of data to be quantized can be input at once using the number of hardware input ports, allowing a set of data sharing a single scaling factor to be processed in a single input, eliminating the need for multiple inputs. This improves hardware implementation, reduces hardware processing latency, and lowers I/O overhead.

举例来说,假设上述处理电路或者运算器的单次运算可以处理32个数据,其相应的输入端口数量也可以是32个,则可以将每32个待量化数据划分为一组。假设上述处理电路或者运算器的单次运算可以处理64个数据,其相应的输入端口数量少于64个,例如输入端口数量为32个,则可以根据输入端口数量对待量化数据进行分组,使得每组中待量化数据的数量与输入端口数量相等,此时以32个数据为一组进行一次性输入,两组数据可以并行运算;或者也可以仍将64个待量化数据划分为一组,并进行两次输入实现一组待量化数据一次性运算完。假设上述处理电路或者运算器的单次运算可以处理32个数据,其相应的输入端口数量多于32个,则可以选择将32个待量化数据划分为一组,以实现一次性输入一组待量化数据并且一次性处理完。For example, assuming the aforementioned processing circuit or arithmetic unit can process 32 data points in a single operation, and its corresponding number of input ports is also 32, then the data points to be quantized can be grouped into sets of 32. If the aforementioned processing circuit or arithmetic unit can process 64 data points in a single operation, and its corresponding number of input ports is less than 64, for example, 32, then the data points to be quantized can be grouped according to the number of input ports, ensuring that the number of data points to be quantized in each group is equal to the number of input ports. In this case, 32 data points are input at once, and the two groups of data can be processed in parallel; alternatively, the 64 data points to be quantized can still be grouped together and input twice to complete the processing of one group of data points at once. If the aforementioned processing circuit or arithmetic unit can process 32 data points in a single operation, and its corresponding number of input ports is more than 32, then the 32 data points to be quantized can be grouped together to achieve one-time input and processing of one group of data points.

在一些实施例中,待量化数据可以为张量数据的元素,将多个待量化数据划分为多组可以包括:在张量数据的至少一个维度上,将张量数据的多个待量化数据划分为多组。例如,假设张量数据A(B,S),B和S分别表示第一维度和第二维度的尺寸,如果在第二维度上进行划分,以分组粒度为32为例(即每组包含32个待量化数据),将S维度上连续32个待量化数据划分为一组,得到(B×S/32)个组,以每个组作为一个数据块,则分组后由各数据块组成的张量的形状(也即,张量的维度和尺寸)可以表示为(B,S/32),也即分组后第二维度的尺寸为S/32。In some embodiments, the data to be quantized can be elements of tensor data. Dividing multiple data to be quantized into multiple groups can include: dividing the multiple data to be quantized into multiple groups along at least one dimension of the tensor data. For example, suppose tensor data A(B, S), where B and S represent the dimensions of the first and second dimensions, respectively. If the division is performed along the second dimension, taking a grouping granularity of 32 as an example (i.e., each group contains 32 data to be quantized), dividing 32 consecutive data to be quantized along dimension S into a group results in (B×S/32) groups. Taking each group as a data block, the shape of the tensor composed of each data block after grouping (i.e., the dimensions and dimensions of the tensor) can be represented as (B, S/32), that is, the dimension of the second dimension after grouping is S/32.

还例如,假设张量数据A’(B,S,D),B、S、D分别表示第一维度、第二维度和第三维度的尺寸,如果在第三维度上进行划分,以分组粒度为64为例,将第三维度上连续64个待量化数据划分为一组,得到(B×S×D/64)个组,以每个组作为一个数据块,则分组后由各数据块组成的张量的形状可以表示为(B,S,D/64),也即分组后第三维度的尺寸为D/64。For example, suppose tensor data A’(B, S, D), where B, S, and D represent the dimensions of the first, second, and third dimensions, respectively. If we divide the data along the third dimension, taking a grouping granularity of 64 as an example, we can divide 64 consecutive data points to be quantized along the third dimension into a group, resulting in (B×S×D/64) groups. Each group can be considered as a data block. The shape of the tensor composed of these data blocks after grouping can be represented as (B, S, D/64), which means the size of the third dimension after grouping is D/64.

可以理解的是,将多个待量化数据划分为多组可以不限于仅在张量数据的一个维度上进行划分,也可以根据需要在多个维度上进行划分。分组粒度可以不限于前述的32或者64,可以根据需要进行设置,例如可以为16、128等。分组粒度与前文所述的处理电路/运算器的运算能力或输入端口限制相关,此处不再赘述。It is understandable that dividing multiple data sets to be quantized into multiple groups is not limited to dividing them only along one dimension of the tensor data; it can also be done along multiple dimensions as needed. The grouping granularity is not limited to the aforementioned 32 or 64; it can be set as needed, for example, 16, 128, etc. The grouping granularity is related to the computing power or input port limitations of the processing circuit/arithmetic unit mentioned earlier, and will not be elaborated upon here.

需要进一步说明的是,随着分组的组数(即数据块的数量)的增多,缩放系数的数量也相应增多,缩放系数所能表示的数据的个数更多,有利于进一步提高数据量化精度。特别是,随着缩放系数的数量增多,其指数位位宽和尾数位位宽的总位宽之和增加,从而可以比MX量化中E8M0数据格式表示的数据的个数更多,进而相比于MX量化,本披露实施例的扩展MX量化中缩放系数所能表示的数据精度会更高。It should be further explained that as the number of groups (i.e., the number of data blocks) increases, the number of scaling factors also increases accordingly. The scaling factors can represent a larger number of data points, which is beneficial for further improving data quantization accuracy. In particular, as the number of scaling factors increases, the sum of the exponent bit width and mantissa bit width increases, thus allowing for the representation of more data points than the E8M0 data format in MX quantization. Consequently, compared to MX quantization, the data accuracy represented by the scaling factors in the extended MX quantization of this disclosed embodiment is higher.

由此,在基于绝对值最大值以及通过数据类型转换得到缩放系数的技术方案基础上,通过分组量化来增加量化粒度,针对每组待量化数据提供相应的缩放系数,有利于进一步提高量化后的数据精度和执行的任务精度。Therefore, based on the technical solution of obtaining scaling factors through data type conversion and the maximum absolute value, group quantization is used to increase the quantization granularity. A corresponding scaling factor is provided for each group of data to be quantized, which is conducive to further improving the accuracy of the quantized data and the accuracy of the executed task.

示例性扩展MX量化的装置Exemplary device for extended MX quantization

图5示出了本披露一些实施例的数据量化的装置的示意性框图。如图中所示,装置500可以包括第一处理电路510和第二处理电路520,其中第一处理电路510可以用于输出缩放系数,第二处理电路520可以用于执行量化处理。具体地,第一处理电路510可以用于:确定一组待量化数据中的绝对值最大值;获取待量化数据量化后的目标数据类型能够表示的最大数值;基于绝对值最大值与最大数值之间的比值,确定一组待量化数据对应的缩放因子;将缩放因子由第一数据类型转换为第二数据类型,以输出缩放系数,其中第二数据类型的位宽小于第一数据类型的位宽。第二处理电路520可以用于利用缩放系数对一组待量化数据进行量化处理,以输出具有目标数据类型的量化数据。Figure 5 shows a schematic block diagram of a data quantization apparatus according to some embodiments of this disclosure. As shown, the apparatus 500 may include a first processing circuit 510 and a second processing circuit 520, wherein the first processing circuit 510 is used to output a scaling factor, and the second processing circuit 520 is used to perform quantization processing. Specifically, the first processing circuit 510 may be used to: determine the maximum absolute value in a set of data to be quantized; obtain the maximum value that the target data type can represent after quantization of the data to be quantized; determine a scaling factor corresponding to a set of data to be quantized based on the ratio between the maximum absolute value and the maximum value; convert the scaling factor from a first data type to a second data type to output a scaling factor, wherein the bit width of the second data type is smaller than the bit width of the first data type. The second processing circuit 520 may be used to quantize a set of data to be quantized using the scaling factor to output quantized data with the target data type.

在一些实施例中,第一处理电路510可以进一步用于:根据第二处理电路520的单次处理量和/或输入端口数量,确定一组待量化数据中待量化数据的数量;或者根据使用量化数据进行运算的运算器的单次运算量和/或输入端口数量,确定一组待量化数据中待量化数据的数量。In some embodiments, the first processing circuit 510 may be further configured to: determine the number of data to be quantized in a set of data to be quantized based on the single processing volume and/or the number of input ports of the second processing circuit 520; or determine the number of data to be quantized in a set of data to be quantized based on the single operation volume and/or the number of input ports of the arithmetic unit that performs operations using quantized data.

在一些实施例中,装置500还可以包括压缩电路540。压缩电路540配置用于对两组或更多组待量化数据量化后的两个或更多个缩放系数进行压缩。此时,第二处理电路520配置用于利用压缩后的缩放系数分别对对应组待量化数据进行量化处理,以输出具有目标数据类型的量化数据。In some embodiments, the apparatus 500 may further include a compression circuit 540. The compression circuit 540 is configured to compress two or more scaling factors after quantization of two or more sets of data to be quantized. In this case, the second processing circuit 520 is configured to quantize the corresponding sets of data to be quantized using the compressed scaling factors, respectively, to output quantized data with the target data type.

对应地,当装置500需要对使用了压缩格式的扩展MX量化数据进行反量化时,需先对缩放系数进行解压缩。在这些实施例中,装置500还可以包括解压缩电路(图中未示出)。解压缩电路配置用于响应于缩放系数为压缩格式,对压缩后的缩放系数进行解压缩。此时,装置500中的执行反量化处理的电路(例如第二处理电路520或者第三处理电路530)可以配置用于利用解压缩后的缩放系数对量化数据进行反量化处理。Correspondingly, when device 500 needs to dequantize extended MX quantized data using a compressed format, the scaling factors must first be decompressed. In these embodiments, device 500 may also include a decompression circuit (not shown in the figure). The decompression circuit is configured to decompress the compressed scaling factors in response to the scaling factors being in a compressed format. At this time, the circuit in device 500 that performs the dequantization process (e.g., the second processing circuit 520 or the third processing circuit 530) can be configured to perform dequantization processing on the quantized data using the decompressed scaling factors.

以上第一处理电路510、第二处理电路520、压缩电路540和解压缩电路执行的操作已经在前文中结合扩展MX量化方法进行了详细的描述,此处不再赘述。The operations performed by the first processing circuit 510, the second processing circuit 520, the compression circuit 540, and the decompression circuit have been described in detail above in conjunction with the extended MX quantization method, and will not be repeated here.

在一些实施例中,第一处理电路510可以包括:比较电路511,可以用于确定一组待量化数据中的绝对值最大值;第一除法电路512,可以用于获取待量化数据量化后的目标数据类型能够表示的最大数值,并且基于绝对值最大值与最大数值之间的比值,确定一组待量化数据对应的缩放因子;以及第一转数电路513,可以用于将缩放因子由第一数据类型转换为第二数据类型,以输出缩放系数。在一些实施例中,第一除法电路512获取最大数值可以通过查表等方式来实现。In some embodiments, the first processing circuit 510 may include: a comparison circuit 511, which can be used to determine the maximum absolute value in a set of data to be quantized; a first division circuit 512, which can be used to obtain the maximum value that the target data type after quantization of the data to be quantized can represent, and determine the scaling factor corresponding to a set of data to be quantized based on the ratio between the maximum absolute value and the maximum value; and a first rotation circuit 513, which can be used to convert the scaling factor from a first data type to a second data type to output the scaling coefficient. In some embodiments, the first division circuit 512 can obtain the maximum value by means of table lookup or other methods.

在一些实施例中,第二处理电路520可以包括第二除法电路521和第二转数电路522,其中第二除法电路521可以用于对待量化数据与缩放系数进行除法运算,第二转数电路522可以用于对该除法运算的运算结果(即中间量化结果)进行转数操作,以输出对待量化数据量化后的结果(即,量化数据)。In some embodiments, the second processing circuit 520 may include a second division circuit 521 and a second rotation circuit 522, wherein the second division circuit 521 can be used to perform a division operation on the data to be quantized and the scaling factor, and the second rotation circuit 522 can be used to perform a rotation operation on the result of the division operation (i.e., the intermediate quantization result) to output the result of quantization of the data to be quantized (i.e., the quantized data).

在另一些实施例中,第二处理电路520还可以用于利用缩放系数对量化数据进行反量化处理。例如,第二处理电路520还可以包括乘法电路,用于对量化数据和缩放系数进行乘法运算。在又一些实施例中,第二转数电路522还可以用于对量化数据进行转数操作,以便将量化数据由目标数据类型转换为反量化处理的所需数据类型;乘法电路用于对转数后的量化数据和缩放系数进行乘法运算,以得到反量化结果。在所需数据类型为前述待量化数据的原始数据类型的情况下,反量化处理可以将量化数据还原为量化操作前的待量化数据。In other embodiments, the second processing circuit 520 can also be used to perform dequantization processing on the quantized data using scaling factors. For example, the second processing circuit 520 may also include a multiplication circuit for multiplying the quantized data and the scaling factors. In still other embodiments, the second rotation circuit 522 can also be used to perform rotation operations on the quantized data to convert the quantized data from the target data type to the data type required for dequantization processing; the multiplication circuit is used to multiply the rotated quantized data and the scaling factors to obtain the dequantization result. When the required data type is the original data type of the aforementioned data to be quantized, dequantization processing can restore the quantized data to the data to be quantized before the quantization operation.

可以理解的是,反量化处理可以不限于前述的由第二处理电路520来执行,也可以由其他电路来执行,例如,在又一些实施例中,装置500还可以包括第三处理电路530(图中以虚线框示出),用于利用缩放系数对量化数据进行反量化处理。第三处理电路530可以接收例如由第二处理电路520输出的量化数据,以及可以接收来自第一处理电路510输出的缩放系数。在一些实施例中,第三处理电路530与第二处理电路520之间还可以包括存储电路、或者第二处理电路520包括存储电路,用以存储量化数据,以便第三处理电路530可以从存储电路中读取量化数据用以反量化处理。It is understood that the dequantization process is not limited to being performed by the second processing circuit 520 as described above, but can also be performed by other circuits. For example, in some embodiments, the apparatus 500 may further include a third processing circuit 530 (shown in a dashed box in the figure) for dequantizing the quantized data using a scaling factor. The third processing circuit 530 may receive, for example, quantized data output by the second processing circuit 520, and may also receive scaling factors output by the first processing circuit 510. In some embodiments, a storage circuit may be further included between the third processing circuit 530 and the second processing circuit 520, or the second processing circuit 520 may include a storage circuit for storing quantized data so that the third processing circuit 530 can read the quantized data from the storage circuit for dequantization processing.

在另一些实施例中,当一个待量化数据输入至比较电路511时,比较电路511可以输出该一个待量化数据的绝对值作为绝对值最大值。在另一些实施例中,当多个待量化数据输入至比较电路511时,比较电路511可以输出该多个待量化数据中的绝对值最大值。在又一些实施例中,比较电路511还可以用于将多个待量化数据划分为多组,并输出每组待量化数据的绝对值最大值;第一除法电路512可以进一步用于确定每组待量化数据对应的一个缩放因子;以及第一转数电路513可以进一步用于基于每个缩放因子,确定每组待量化数据对应的缩放系数。在一些实施例中,待量化数据为张量数据的元素,比较电路511可以进一步用于:在张量数据的至少一个维度上,将张量数据的多个待量化数据划分为多组。In some embodiments, when a piece of data to be quantized is input to the comparison circuit 511, the comparison circuit 511 can output the absolute value of that piece of data as the maximum absolute value. In some embodiments, when multiple pieces of data to be quantized are input to the comparison circuit 511, the comparison circuit 511 can output the maximum absolute value among the multiple pieces of data to be quantized. In still some embodiments, the comparison circuit 511 can also be used to divide the multiple pieces of data to be quantized into multiple groups and output the maximum absolute value of each group of data to be quantized; the first division circuit 512 can be further used to determine a scaling factor corresponding to each group of data to be quantized; and the first revolution circuit 513 can be further used to determine a scaling coefficient corresponding to each group of data to be quantized based on each scaling factor. In some embodiments, the data to be quantized is an element of tensor data, and the comparison circuit 511 can be further used to divide the multiple pieces of data to be quantized of the tensor data into multiple groups in at least one dimension of the tensor data.

可以理解的是,以上描述是示例性的而非限制性的。例如,用于获得缩放系数的第一处理电路可以不限于通过上述的比较电路、第一除法电路和第一转数电路来实现,也可以通过例如查找表(电路)等方式来实现。由于被除数(目标数据类型能够表示的最大数值)是常量,因此可以利用查找表等方式直接根据输入数据来进行判断,实现上述除法运算和数据类型转换的功能,以得到缩放系数。此外,为了便于理解比较电路实现的分组功能,下面将结合图6进行示例性的说明。It is understood that the above description is exemplary and not restrictive. For example, the first processing circuit for obtaining the scaling factor may not be limited to the comparison circuit, the first division circuit, and the first rotation circuit described above, but may also be implemented using, for example, a lookup table (circuit). Since the dividend (the maximum value that the target data type can represent) is a constant, a lookup table or similar method can be used to directly determine the value based on the input data, thereby implementing the division operation and data type conversion functions described above to obtain the scaling factor. Furthermore, to facilitate understanding of the grouping function implemented by the comparison circuit, an exemplary description will be provided below with reference to Figure 6.

图6示出了本披露一些实施例的比较电路的示意性结构框图。如图中所示,比较电路511可以包括由多层级比较器组成的比较器树,例如,可以包括a层、b层、c层、…、z层,每层级包括一个或多个比较器,各层级的比较器数量依次减少,其中相邻层级的上一层级的多个比较器的输出可以输入至下一层级的比较器中。在实际应用中,可以通过软件或者硬件的方式根据需要选择所需层级的输出,以实现对多个待量化数据的分组以及得到每组待量化数据的绝对值最大值。为了便于理解,下面将结合图6中进行进一步的举例说明。Figure 6 shows a schematic block diagram of a comparison circuit according to some embodiments of this disclosure. As shown, the comparison circuit 511 may include a comparator tree composed of multiple levels of comparators, for example, it may include layers a, b, c, ..., z, each level including one or more comparators, with the number of comparators decreasing sequentially at each level. The outputs of multiple comparators in the upper level of an adjacent level can be input to the comparators in the lower level. In practical applications, the outputs of the required levels can be selected as needed by means of software or hardware to achieve grouping of multiple data to be quantized and to obtain the maximum absolute value of each group of data to be quantized. For ease of understanding, further examples will be provided below with reference to Figure 6.

如图6中进一步示出的,a层包括比较器a1、比较器a2、比较器a3、…、比较器an,其中n表示a层比较器的数量;b层包括比较器b1、比较器b2等;c层包括比较器c1等;z层包括比较器z1。可以理解的是,图示中所示的比较器树是示例性的,比较器树的层级数可以根据需要设置的更多或者更少,每个层级中包括的比较器的数量也可以根据需要进行设置。As further illustrated in Figure 6, layer a includes comparators a1, a2, a3, ..., an, where n represents the number of comparators in layer a; layer b includes comparators b1, b2, etc.; layer c includes comparator c1, etc.; and layer z includes comparator z1. It is understood that the comparator tree shown in the figure is exemplary, and the number of levels in the comparator tree can be set more or less as needed, and the number of comparators included in each level can also be set as required.

在一些实施例中,a层的比较器数量n可以与输入的待量化数据的数量相同,使得每个待量化数据输入a层中相应的一个比较器中,随着后续层级中的比较器数量的依次减少,可以逐渐减少输出,以得到所需的分组结果和每组的绝对值最大值。举例来说,假设输入层接收到128个待量化数据,a层设置有128个比较器,则每个待量化数据输入a层相应的一个比较器中。此时a层的输出可以实现将128个待量化数据划分为128组。假设b层包括64个比较器,则a层中每两个比较器的输出可以输入至下一层级b层的一个比较器中,例如图示中的a层的比较器a1和比较器a2的输出可以输入至b层的比较器b1中。此时b层输出64个绝对值最大值,同时实现将128个待量化数据分为64组。假设c层包括32个比较器,则b层中每两个比较器的输出可以输入至下一层级c层的一个比较器中,例如图示中的b层的比较器b1和比较器b2的输出可以输入至c层的比较器c1中。此时c层输出32个绝对值最大值,同时实现将128个待量化数据分为32组。依次类推,直至最后一个层级z层输出一个绝对值最大值,此时实现将128个待量化数据分为1组。In some embodiments, the number of comparators *n* in layer *a* can be the same as the number of input data to be quantized, so that each data point to be quantized is input into a corresponding comparator in layer *a*. As the number of comparators in subsequent layers decreases sequentially, the output can be gradually reduced to obtain the desired grouping result and the maximum absolute value of each group. For example, assuming the input layer receives 128 data points to be quantized, and layer *a* has 128 comparators, then each data point to be quantized is input into a corresponding comparator in layer *a*. The output of layer *a* can then divide the 128 data points to be quantized into 128 groups. Assuming layer *b* includes 64 comparators, then the output of every two comparators in layer *a* can be input into a comparator in the next layer, layer *b*. For example, the outputs of comparators *a1* and *a2* in layer *a* can be input into comparator *b1* in layer *b*. Layer *b* then outputs 64 maximum absolute values, thus dividing the 128 data points to be quantized into 64 groups. Assuming layer c contains 32 comparators, the outputs of every two comparators in layer b can be input into a comparator in the next layer c. For example, the outputs of comparators b1 and b2 in layer b can be input into comparator c1 in layer c. At this point, layer c outputs 32 maximum absolute values, effectively dividing the 128 data points to be quantized into 32 groups. This process continues until the last layer z outputs a single maximum absolute value, thus dividing the 128 data points to be quantized into one group.

仍以该实施例为例,在实际应用中,假设需要将128个待量化数据中每4个数据划分为一组,共划分为32组,则可以通过例如程序设计、逻辑控制或者选择器等方式选择c层的输出作为比较电路411的输出,使得第一除法电路可以基于c层的32个输出(即,32个绝对值最大值),确定该32组待量化数据中每组待量化数据对应的缩放因子。因此,比较器树的设置提供了多种粒度的分组方式,使用者可以根据所需量化粒度,灵活选择比较器树中的某一层级的输出。Taking this embodiment as an example, in practical applications, assuming that 128 data points to be quantized need to be divided into groups of four, resulting in 32 groups, the output of layer C can be selected as the output of comparator circuit 411 through methods such as programming, logic control, or selectors. This allows the first division circuit to determine the scaling factor corresponding to each of the 32 groups of data to be quantized based on the 32 outputs of layer C (i.e., the 32 maximum absolute values). Therefore, the comparator tree provides multiple granularity grouping methods, allowing users to flexibly select the output of a certain level in the comparator tree according to the required quantization granularity.

此外,需要说明的是,比较器树的结构可以不限于图示中的每个层级中的两个比较器的输出对应输入下一层级中的一个比较器中,也可以根据需要设置例如三个比较器、或者更多数量的比较器的输出输入至下一层级中的一个比较器中。例如,假设a层设置128个比较器,b层可以设置4个比较器,即a层的32个比较器的输出对应输入至b层的一个比较器中,则b层的输出可以实现将128个待量化数据划分为4组,以及输出每组的32个待量化数据中的绝对值最大值。Furthermore, it should be noted that the comparator tree structure is not limited to the two comparators in each level shown in the diagram whose outputs correspond to one comparator in the next level. It can also be configured to have, for example, three or more comparators whose outputs correspond to one comparator in the next level. For instance, assuming level a has 128 comparators, level b can have 4 comparators. That is, the outputs of the 32 comparators in level a correspond to one comparator in level b. Therefore, the output of level b can divide the 128 data points to be quantized into 4 groups and output the maximum absolute value of the 32 data points in each group.

在另一些实施例中,a层的比较器数量n可以与输入的待量化数据的数量不同,下面举例说明。假设a层比较器的数量少于待量化数据的数量,可以在a层中设置多个待量化数据输入一个比较器中,则在a层即实现了将多个待量化数据划分为少于待量化数据数量的分组输出。在该实施例中,还可以在a层之前(例如输入层),通过设置例如地址解码器、多路选择器(MUX)或其他逻辑电路等方式,控制输入至a层中每个比较器的待量化数据。In other embodiments, the number of comparators n in layer a can be different from the number of input data to be quantized, as illustrated below. Assuming the number of comparators in layer a is less than the number of data to be quantized, multiple data to be quantized can be input into a single comparator in layer a. This achieves the division of multiple data to be quantized into fewer groups for output in layer a. In this embodiment, the data to be quantized input to each comparator in layer a can also be controlled before layer a (e.g., in the input layer) by using methods such as address decoders, multiplexers (MUX), or other logic circuits.

举例来说,假设输入层接收到128个待量化数据,a层设置有64个比较器,则每两个待量化数据输入a层相应的一个比较器中。此时a层的输出可以实现将128个待量化数据划分为64组。之后层级设置的比较器数量依次减半,直至最后一个层级输出一个绝对值最大值,此时实现将128个待量化数据分为1组。For example, suppose the input layer receives 128 data points to be quantized, and layer 'a' has 64 comparators. Then, every two data points to be quantized are input into one of the corresponding comparators in layer 'a'. At this point, the output of layer 'a' divides the 128 data points into 64 groups. The number of comparators in subsequent layers is halved sequentially until the last layer outputs the maximum absolute value, at which point the 128 data points are divided into one group.

以上结合图6对根据本披露实施例的比较电路实现分组以及输出绝对值最大值的方案进行了示例性的描述。可以理解的是,图中所示的比较电路的结构以及前面的描述均是示例性的而非限制性的,例如比较电路511的最后一个层级可以不限于图示中的仅包括一个比较器,也可以根据需要包括多个比较器,例如将图示中的c层作为最后一个层级。还例如,比较器电路511可以不限于仅包括一个比较器树,还可以根据需要设置多个比较器树,从而可以实现例如并行分组等。本披露实施例的比较电路可以不限于通过前述比较器树来实现,还可以基于基数排序等方式来实现。The foregoing description, in conjunction with Figure 6, exemplarily illustrates the scheme for implementing grouping and outputting the maximum absolute value using a comparison circuit according to an embodiment of this disclosure. It is understood that the structure of the comparison circuit shown in the figure and the preceding description are exemplary and not restrictive. For example, the last level of the comparison circuit 511 may not be limited to including only one comparator as shown in the figure, but may also include multiple comparators as needed, such as using level c in the figure as the last level. Furthermore, the comparator circuit 511 may not be limited to including only one comparator tree, but may also include multiple comparator trees as needed, thereby enabling, for example, parallel grouping. The comparison circuit of this embodiment of the disclosure may not be limited to being implemented using the aforementioned comparator tree, but may also be implemented based on radix sorting or other methods.

还可以理解的是,本披露实施例中实现分组的方式可以不限于比较电路,还可以通过结合软件的方式实现。例如,通过软件设定分组参数(包括每组的待量化数据的数量K等信息),比较电路可以按照这个分组参数,读取连续K个待量化数据为一组,直接输出每组待量化数据中的绝对值最大值。It is also understood that the grouping method in this disclosed embodiment is not limited to the comparison circuit, but can also be implemented by combining software. For example, by setting grouping parameters (including information such as the number of data to be quantized in each group K) through software, the comparison circuit can read K consecutive data to be quantized as a group according to these grouping parameters, and directly output the maximum absolute value in each group of data to be quantized.

在本披露实施例中,当提及“微粒度量化格式”、“微粒度格式”、“微粒度量化”时,是指图4所示这种包括三部分的数据格式,但是具体的元素数据类型、缩放块大小、缩放系数数据类型等不限于表1所列出的那些,而是可以有更多类型的组合。换言之,微粒度量化格式可以包括OCP提出的MX量化格式,也可以包括本披露实施例提出的扩展MX量化格式,还可以包括其他任何符合图4这种结构的数据格式。In this disclosed embodiment, when referring to "particle quantization format," "particle size format," or "particle quantization," it refers to the three-part data format shown in Figure 4. However, the specific element data types, scaling block sizes, scaling factor data types, etc., are not limited to those listed in Table 1, but can include many other combinations. In other words, the particle quantization format can include the MX quantization format proposed by OCP, the extended MX quantization format proposed in this disclosed embodiment, or any other data format conforming to the structure of Figure 4.

在本披露实施例中,当提及“指令”时,可以包括软件指令、硬件指令、固件指令或其任意组合。软件指令通常指的是编程语言中的语句或命令,是高级、抽象的指令,例如包括函数调用、机器代码、字节代码等。硬件指令也称为机器指令或指令集架构(ISA)指令,是计算机硬件能够直接识别和执行的低级命令,例如包括处理器指令、CPU指令等。固件指令例如包括操作码、微代码等。进一步地,不同的CPU架构和不同的指令集可以有不同的硬件指令集,按照计算机指令集的复杂性、硬件设计、执行速度、编译器复杂性和指令格式等,又可以划分为:CISC(复杂指令集计算机)、RISC(精简指令集计算机)和VLIW(超长指令字)。In this disclosed embodiment, the term "instruction" can include software instructions, hardware instructions, firmware instructions, or any combination thereof. Software instructions typically refer to statements or commands in a programming language; they are high-level, abstract instructions, such as function calls, machine code, and bytecode. Hardware instructions, also known as machine instructions or instruction set architecture (ISA) instructions, are low-level commands that computer hardware can directly recognize and execute, such as processor instructions and CPU instructions. Firmware instructions include, for example, opcodes and microcode. Furthermore, different CPU architectures and different instruction sets can have different hardware instruction sets. Based on the complexity of the computer instruction set, hardware design, execution speed, compiler complexity, and instruction format, they can be further classified as: CISC (Complex Instruction Set Computer), RISC (Reduced Instruction Set Computer), and VLIW (Very Long Instruction Word).

示例性卷积运算原理Exemplary Convolution Operation Principle

神经网络模型中的卷积层可以执行卷积运算,通过对输入神经元(也称为输入数据、输入特征图)应用卷积核(也称为权值、过滤器等)做卷积处理,从而进行特征提取。卷积层内部可以包含多个卷积核,组成卷积核的每个元素对应一个权值系数和一个偏差量bias。Convolutional layers in neural network models perform convolution operations, extracting features by applying convolution kernels (also called weights, filters, etc.) to the input neurons (also called input data or input feature maps). A convolutional layer can contain multiple convolution kernels, with each element of the kernel corresponding to a weight coefficient and a bias.

在常规3D卷积运算中,假设卷积层中输入神经元或输入特征图(Feature map)张量形状表示为X[N Hi Wi Ci],表示有N组输入特征图,每组包含Hi×Wi×Ci个信息,其中Hi和Wi分别是输入特征图的高度和宽度,Ci是输入特征图的个数,也称为输入通道数。卷积核(kernel)的张量形状表示为K[Co Kh Kw Ci],也即卷积层有Ci×Co个Kh×Kw大小的卷积核,其中Ci是输入通道数,Co是输出特征图的个数(或输出通道数),Kh和Kw分别是卷积核的高度和宽度。输出的结果为Y[N Ho Wo Co],也即有N组输出特征图,每组输出特征图包含Ho×Wo×Co个信息,其中Ho和Wo分别是输出特征图的高度和宽度,Co是输出通道数。那么,简化的卷积运算的数学计算公式可以表示如下:
Yin,jc,jh,jw=∑0≤ic≤ci,0≤ih≤kh,0≤iw≤kwXin,ic,jh×sh+ih,jw×sw+iw×Kjc,ic,ih,iw   (1)
In conventional 3D convolution operations, assuming the tensor shape of the input neurons or input feature maps in a convolutional layer is represented as X[N Hi Wi Ci], indicating N sets of input feature maps, each containing Hi×Wi×Ci pieces of information, where Hi and Wi are the height and width of the input feature map, respectively, and Ci is the number of input feature maps, also known as the number of input channels. The tensor shape of the convolutional kernel is represented as K[Co Kh Kw Ci], meaning the convolutional layer has Ci×Co kernels of size Kh×Kw, where Ci is the number of input channels, Co is the number of output feature maps (or output channels), and Kh and Kw are the height and width of the convolutional kernel, respectively. The output result is Y[N Ho Wo Co], meaning there are N sets of output feature maps, each containing Ho×Wo×Co pieces of information, where Ho and Wo are the height and width of the output feature map, respectively, and Co is the number of output channels. Therefore, the simplified mathematical formula for convolution operations can be expressed as follows:
Y in,jc,jh,jw =∑ 0≤ic≤ci,0≤ih≤kh,0≤iw≤kw X in,ic,jh×sh+ih,jw×sw+iw ×K jc,ic,ih,iw (1)

上式中,sh和sw是在高度和宽度方向上的卷积步长(stride),卷积步长的大小会影响输出特征图的尺寸。公式中忽略了偏差量bias,填充pad和膨胀dilation,并且假设输入数据X已经做了填充,卷积核已经做了膨胀。公式还忽略了N维度,神经网络模型的正向计算在N维度上的计算都是独立的。卷积核在工作时,会按照一定的步长扫过输入特征,在卷积窗口内对输入特征做矩阵元素乘法求和并叠加偏差量。In the above formula, sh and sw are the convolution stride in the height and width directions, respectively. The size of the convolution stride affects the size of the output feature map. The formula ignores the bias, padding, and dilation, and assumes that the input data X has already been padded and the convolution kernel has already been dilated. The formula also ignores the N-dimensional dimension; the forward computation of the neural network model is independent in the N-dimensional dimension. When the convolution kernel is working, it scans the input features with a certain stride, performs element-wise matrix multiplication and summation on the input features within the convolution window, and adds the bias.

注意,在本文中,输入特征图(Feature map)、输入数据、神经元或输入神经元可互换使用;卷积核、过滤器或权值可互换使用。此外,H(高度)和Y维度可互换使用,W(宽度)和X维度可互换使用。相应地,输入特征图的H维度可以表示为Hi或Yi,输出特征图的H维度可以表示为Ho或Yo,W维度类似表示。在本披露实施例中,每个卷积输出点具有对应的卷积窗口,卷积窗口的形状等于卷积核的形状。每个卷积输出点的值对应于其卷积窗口内的输入特征图与权值的对位乘累加结果。Note that in this paper, the terms input feature map, input data, neuron, or input neuron are used interchangeably; convolution kernel, filter, or weights are used interchangeably. Furthermore, the H (height) and Y dimensions are used interchangeably, as are the W (width) and X dimensions. Accordingly, the H dimension of the input feature map can be represented as Hi or Yi, the H dimension of the output feature map can be represented as Ho or Yo, and the W dimension is represented similarly. In this disclosed embodiment, each convolution output point has a corresponding convolution window, the shape of which is equal to the shape of the convolution kernel. The value of each convolution output point corresponds to the positional multiplication and accumulation result of the input feature map and weights within its convolution window.

示例性数据处理装置Exemplary data processing device

在本披露实施例中,提出了一种兼容MX量化格式的卷积运算方案。在此卷积运算中,输入神经元、权值和输出神经元中任一或多个可以是微粒度量化的数据格式。当输入神经元和权值中任一或二者为微粒度量化格式时,可以将数据的反量化过程融合在卷积运算中,而无需事先专门对数据进行反量化,由此既避免了单独的反量化处理,又可以在卷积运算中充分利用微粒度量化格式的低位宽运算和小内存占用的优势。进一步地,当要求输出神经元或输入神经元和权值中未微粒度量化的变为微粒度量化格式时,可以通过硬件电路对其在线进行量化。This disclosure presents a convolution operation scheme compatible with MX quantization format. In this convolution operation, any one or more of the input neurons, weights, and output neurons can be in a particle-quantized data format. When any one or both of the input neurons and weights are in a particle-quantized format, the data dequantization process can be integrated into the convolution operation without prior dequantization. This avoids separate dequantization processing and fully utilizes the advantages of low bit width and small memory footprint of the particle-quantized format in the convolution operation. Furthermore, when it is required that the output neurons or input neurons and weights that are not in a particle-quantized format be converted to a particle-quantized format, they can be quantized online via hardware circuitry.

图7示例性示出了可以实施本披露实施例的数据处理装置的示意性结构图。可以理解,该结构可以视为图3中单个处理核的内部结构细化,也可以视为在多个图3所示处理核基础上联合的功能划分框图。如图7所示,数据处理装置700可以包括控制电路710、存储电路720和运算电路730,三者之间相互连接以传输各种数据和指令。Figure 7 illustrates a schematic structural diagram of a data processing apparatus that can implement embodiments of the present disclosure. It can be understood that this structure can be viewed as a refinement of the internal structure of a single processing core in Figure 3, or as a functional partitioning diagram based on multiple processing cores shown in Figure 3. As shown in Figure 7, the data processing apparatus 700 may include a control circuit 710, a storage circuit 720, and an arithmetic circuit 730, which are interconnected to transmit various data and instructions.

控制电路710负责处理数据处理装置700上的各种功能,包括但不限于控制、取指、译码、计算等。控制电路710例如可以包括图3中的控制模块31。The control circuit 710 is responsible for handling various functions on the data processing device 700, including but not limited to control, instruction fetching, decoding, and calculation. The control circuit 710 may include, for example, the control module 31 shown in FIG3.

存储电路720可以用于存储信息,这些信息至少包括处理前和/或处理后的信息,也可以包括处理期间需要缓存的中间信息,其例如可以是图3所示的各种RAM,或称片上缓存。在一些实施例中,存储电路720可以配置用于存储输入神经元、权值、卷积运算结果(输出神经元)和/或缓存中间结果。The storage circuit 720 can be used to store information, including at least pre-processing and/or post-processing information, and may also include intermediate information that needs to be cached during processing, such as various RAMs shown in FIG3, or on-chip caches. In some embodiments, the storage circuit 720 can be configured to store input neurons, weights, convolution operation results (output neurons), and/or cache intermediate results.

运算电路730可以配置用于根据相关指令执行各种运算操作。例如,运算电路730可以配置用于在控制电路710的控制下,对输入神经元与权值执行卷积运算。此时,运算电路730可以包括卷积电路731。The arithmetic circuit 730 can be configured to perform various arithmetic operations according to relevant instructions. For example, the arithmetic circuit 730 can be configured to perform convolution operations on the input neurons and weights under the control of the control circuit 710. In this case, the arithmetic circuit 730 may include a convolution circuit 731.

在一些实施例中,控制电路710可以配置用于解析卷积指令,控制存储电路720和运算电路730对输入神经元和权值执行卷积运算处理。In some embodiments, the control circuit 710 may be configured to parse convolution instructions and control the storage circuit 720 and the arithmetic circuit 730 to perform convolution operations on the input neurons and weights.

卷积指令指示对输入神经元和权值进行卷积运算以获得输出神经元。在一些实施例中,该卷积指令可以支持输入神经元、权值和输出神经元中的任一或多个是微粒度量化的。例如,在不同的应用场景下,输入神经元、权值和输出神经元的数据格式可能各有不同。在神经网络的首个卷积层中,输入神经元可能是未量化的,而权值可能是已经例如离线量化的,输出神经元则是要求量化后传输到下一个卷积层。此时,在下一个卷积层的卷积运算中,从上一层接收的输出神经元在此作为输入神经元是已量化的,权值也是已量化,卷积运算得到的输出神经元也要求经量化后输入到再下一个卷积层。本领域技术人员可以理解,以上场景仅是示例性的,还可能存在各种其他应用场合,使得输入神经元、权值和输出神经元中的任一或多个是微粒度量化的。The convolution instruction directs the convolution operation on the input neuron and weights to obtain the output neuron. In some embodiments, the convolution instruction may support the granular quantization of any one or more of the input neuron, weights, and output neuron. For example, the data formats of the input neuron, weights, and output neuron may differ in different application scenarios. In the first convolutional layer of a neural network, the input neuron may be unquantized, while the weights may have been quantized, for example, offline, and the output neuron requires quantization before being transmitted to the next convolutional layer. In this case, in the convolution operation of the next convolutional layer, the output neuron received from the previous layer is now quantized as the input neuron, the weights are also quantized, and the output neuron obtained from the convolution operation also requires quantization before being input to the next convolutional layer. Those skilled in the art will understand that the above scenario is merely exemplary, and various other application scenarios may exist where any one or more of the input neuron, weights, and output neuron are granularly quantized.

从前面的微粒度量化格式的描述可知,微粒度量化格式下会包括缩放系数(X,scale),粒度块大小(K,Scaling Block size),以及块内的私有元素数据(Pi,data)这三部分。通常,粒度块大小是预先设定的,例如32。因此,卷积运算中需要为微粒度量化的参数提供两部分内容:缩放系数X和元素数据Pi。相比于针对非量化格式数据执行的卷积运算,增加了对缩放系数X的访存要求。As described above, a granular quantization format includes three parts: a scaling factor (X, scale), a granular block size (K, scaling block size), and the private element data within the block (P <sub>i</sub> , data). Typically, the granular block size is pre-defined, for example, 32. Therefore, the convolution operation requires two parts for the granular quantization parameters: the scaling factor X and the element data P<sub>i</sub> . Compared to convolution operations performed on non-quantized data, this adds the memory access requirement for the scaling factor X.

在一些实施例中,运算电路730配置用于根据上述卷积指令,对输入神经元的数据和权值的数据执行卷积运算,将输入神经元的缩放系数和/或权值的缩放系数融合在该卷积运算中。更具体地,可以以微粒度量化的粒度块大小为单位,将缩放系数融合在卷积运算中。In some embodiments, the computation circuit 730 is configured to perform a convolution operation on the data of the input neuron and the data of the weights according to the convolution instructions described above, and to fuse the scaling factors of the input neuron and/or the scaling factors of the weights in the convolution operation. More specifically, the scaling factors can be fused in the convolution operation in units of particle-level granular block size.

在一些实施例中,卷积电路731可以配置用于按如下执行上述卷积运算:以微粒度量化的粒度块大小T为单位,循环计算各个粒度块的部分和;以及,循环累加单个卷积窗口内的各个粒度块的部分和,得到对应卷积窗口的输出神经元数值。可以理解,粒度块大小T通常不超过硬件单次运算量,一个卷积窗口内所涉及的运算数据通常会包括多个粒度块,因此可以以粒度块为单位进行部分和的计算,再对部分和进行累加。In some embodiments, the convolution circuit 731 can be configured to perform the convolution operation as follows: iteratively calculate the partial sum of each granular block in units of granularity block size T (quantified by particle size); and iteratively accumulate the partial sums of each granular block within a single convolution window to obtain the output neuron value of the corresponding convolution window. It is understood that the granularity block size T typically does not exceed the amount of hardware computation per operation, and the computational data involved in a convolution window usually includes multiple granular blocks. Therefore, partial sums can be calculated in units of granularity blocks, and then the partial sums can be accumulated.

进一步地,在一些实施例中,卷积电路731可以配置用于按如下计算各个粒度块的部分和:在每个粒度块内,计算输入神经元的数据和权值的数据的乘积和;计算该乘积和与输入神经元的缩放系数和/或权值的缩放系数的乘积,得到该粒度块的部分和。由于在同一粒度块内,元数数据共享同一缩放系数,因此,可以先计算元素的乘积和,再乘以公共的缩放系数,从而将反量化融合在卷积运算中。Furthermore, in some embodiments, the convolution circuit 731 can be configured to calculate the partial sum of each granularity block as follows: within each granularity block, the sum of the product of the data of the input neuron and the data of the weights is calculated; the product of this sum of products with the scaling factor of the input neuron and/or the scaling factor of the weights is calculated to obtain the partial sum of the granularity block. Since the element data shares the same scaling factor within the same granularity block, the sum of the element-wise products can be calculated first, and then multiplied by the common scaling factor, thereby incorporating dequantization into the convolution operation.

前面的公式(1)给出了非量化格式数据的卷积运算。取决于粒度块在张量数据的哪个或哪些维度上的划分,卷积运算的顺序也可以相应调整。在一些实施例中,当输入神经元和权值是微粒度量化格式,并且在输入通道Ci维度上已按照粒度块大小T进行微粒度量化时,公式(1)可以调整为如下公式(2):
Equation (1) above gives the convolution operation for non-quantized data. The order of the convolution operation can be adjusted depending on which dimension(s) of the tensor data the granularity blocks are divided on. In some embodiments, when the input neurons and weights are in a granular quantization format and have been quantized according to the granularity block size T in the input channel Ci dimension, Equation (1) can be adjusted to Equation (2) as follows:

在公式(2)中,Y为输出神经元,具有Ho,Wo,Co维度;A为输入神经元,具有Ci,Hi,Wi维度;W为权值,具有Ci,Kh,Kw,Co维度,Kh、Kw分别为Kh和Kw维度的大小,输入神经元和/或权值在Ci维度上已进行微粒度量化,量化的粒度块大小为T,分别为输入神经元A和权值W的第n个粒度块的缩放系数,sh、sw分别为权值在Kh和Kw维度的卷积步长。In formula (2), Y is the output neuron with dimensions Ho, Wo, and Co; A is the input neuron with dimensions Ci, Hi, and Wi; W is the weight with dimensions Ci, Kh, Kw, and Co, where Kh and Kw are the sizes of the Kh and Kw dimensions, respectively. The input neuron and/or weights have been quantized in the Ci dimension, and the quantized granularity block size is T. are the scaling factors for the nth granularity block of the input neuron A and the weight W, respectively, and s <sub>h </sub> and s<sub>w</sub> are the convolution strides of the weights in the dimensions K<sub>h</sub> and K<sub>w</sub>, respectively.

从公式(2)可以看出,在上述实施例中,由于输入神经元和权值在Ci维度上每T个数据共享一个缩放系数进行量化,而卷积运算在Ci维度上是累加的,因此可以以粒度块大小T为单位,先对输入神经元数据与权值数据执行乘累加得到部分和,再乘以各自对应的缩放系数,从而实现反量化,得到反量化后的部分和。反量化后的部分和可以与同一卷积窗口内的其他粒度块的反量化的部分和继续累加,从而得到该卷积窗口对应的输出点,也即输出神经元的数值。As can be seen from formula (2), in the above embodiment, since the input neurons and weights share a scaling factor for quantization every T data points in the Ci dimension, and the convolution operation is cumulative in the Ci dimension, the input neuron data and weight data can be multiplied and accumulated to obtain a partial sum in units of granularity block size T. Then, multiply by their respective scaling factors to achieve dequantization and obtain the dequantized partial sum. The dequantized partial sum can be accumulated with the dequantized partial sums of other granularity blocks within the same convolution window to obtain the output point corresponding to that convolution window, i.e., the value of the output neuron.

具体地,在一些实施例中,卷积电路731可以配置用于按如下执行上述卷积运算:在输入通道Ci维度上,以粒度块的大小T为单位,循环计算各个粒度块的部分和;在输入通道Ci维度上,累加各个粒度块分块的部分和,得到第一累加结果;以及在高度H和宽度W维度上,循环累加单个卷积窗口内的各个第一累加结果,得到对应卷积窗口的输出神经元数值。Specifically, in some embodiments, the convolution circuit 731 may be configured to perform the above convolution operation as follows: in the input channel Ci dimension, the partial sum of each granularity block is calculated iteratively in units of granularity block size T; in the input channel Ci dimension, the partial sum of each granularity block is accumulated to obtain a first accumulation result; and in the height H and width W dimensions, the first accumulation results within a single convolution window are accumulated iteratively to obtain the output neuron value of the corresponding convolution window.

在上述实施例中,微粒度量化是在Ci维度上按照T个数据进行共享缩放系数的量化,当Ci维度上的数据个数不满足对齐到T时,拆分至不足T个数据时,剩余的这些数据共享相同的缩放系数。In the above embodiment, particle quantization is the quantization of shared scaling factors on the Ci dimension according to T data. When the number of data on the Ci dimension is not sufficient to align to T, when it is split into less than T data, the remaining data share the same scaling factor.

可以理解,尽管上面的公式(2)按照输入神经元与权值均具有缩放系数给出,但其也适合于输入神经元与权值中任一或二者均为非量化数据的情况。例如,当输入神经元为非量化数据,权值为量化数据时,不存在输入神经元的缩放系数,只需将乘积和与权值的缩放系数相乘即可得到粒度块的部分和。换言之,此时的输入神经元的缩放系数是1,反之亦然。可以理解,公式(2)也兼容输入神经元与权值均为非量化数据的情形,此时输入神经元和权值的缩放系数均为1。It is understandable that although formula (2) above assumes that both the input neuron and the weights have scaling factors, it is also suitable for cases where either or both of the input neuron and the weights are non-quantized data. For example, when the input neuron is non-quantized data and the weights are quantized data, there is no scaling factor for the input neuron; the partial sum of the granularity blocks can be obtained by multiplying the sum of the products by the scaling factor of the weights. In other words, the scaling factor of the input neuron is 1 in this case, and vice versa. It is understandable that formula (2) is also compatible with the case where both the input neuron and the weights are non-quantized data, in which case the scaling factors of both the input neuron and the weights are 1.

在一些应用场景中,还可能出现输入神经元数据与权值数据的位宽不相同的情况。通常运算硬件支持操作数的位宽相同,也即对称输入的情况。为了更好地适应硬件,可以在运算电路730中增加预处理电路。In some applications, the bit widths of the input neuron data and the weight data may differ. Typically, computing hardware supports operands with the same bit width, i.e., symmetrical input. To better adapt to the hardware, a preprocessing circuit can be added to the computing circuit 730.

如图7所示,在一些实施例中,运算电路730还可以包括第一转数电路732,其可以配置用于响应于卷积指令指示输入神经元与权值的数据位宽不同,对输入神经元的数据和/或权值的数据进行转数,以使输入神经元和权值的数据位宽相同。继而,卷积电路731可以基于具有相同数据位宽的输入神经元的数据和权值的数据、以及输入神经元的缩放系数和/或权值的缩放系数来执行前述卷积运算。As shown in Figure 7, in some embodiments, the computation circuit 730 may further include a first rotation circuit 732, which can be configured to rotate the data of the input neuron and/or the data of the weights in response to a convolution instruction indicating that the data bit width of the input neuron and the weights are different, so that the data bit width of the input neuron and the weights are the same. Then, the convolution circuit 731 can perform the aforementioned convolution operation based on the data of the input neuron and the data of the weights having the same data bit width, as well as the scaling factor of the input neuron and/or the scaling factor of the weights.

本披露实施例的卷积指令可以兼容各种输入情况。以下针对各种情况描述可以采取的处理方案。The convolution instructions disclosed in this embodiment are compatible with various input conditions. The following describes possible processing solutions for each condition.

(1)非量化权值和非量化输入神经元,位宽相同。此时无需转数。(1) Non-quantized weights and non-quantized input neurons have the same bit width. No revolutions are required in this case.

(2)非量化权值和非量化输入神经元,位宽不同。此时第一转数电路732可以对权值和/或输入神经元进行转数,以使权值和输入神经元的数据位宽相同。例如,可以将权值和输入神经元中具有较短位宽的数据转为较长位宽数据,从而统一位宽。当然,也可以将权值和输入神经元均转为比原二者的位宽更长位宽的数据,由此提高精度。(2) Non-quantized weights and non-quantized input neurons have different bit widths. In this case, the first rotation circuit 732 can rotate the weights and/or input neurons to make the data bit widths of the weights and input neurons the same. For example, data with shorter bit widths in the weights and input neurons can be converted to data with longer bit widths to unify the bit widths. Of course, both the weights and input neurons can also be converted to data with bit widths longer than their original widths, thereby improving accuracy.

(3)微粒度量化权值或输入神经元,与非量化输入神经元或权值,位宽相同。此时可以有两种处理方案。一种是不进行转数,由卷积电路731在执行卷积运算的过程中进行反量化,例如按照前面结合公式(2)描述的运算方式。另一种是对微粒度量化的权值或输入神经元在第一转数电路732中执行反量化,从而后续可以按照常规卷积运算方式(例如公式(1)),与非量化输入神经元或权值一起执行卷积运算。(3) The particle-quantized weights or input neurons have the same bit width as the non-quantized input neurons or weights. There are two processing schemes at this time. One is to not perform a number of revolutions, and to dequantize the convolution circuit 731 during the convolution operation, for example, according to the operation method described above in conjunction with formula (2). The other is to perform dequantization on the particle-quantized weights or input neurons in the first number of revolutions circuit 732, so that the subsequent convolution operation can be performed together with the non-quantized input neurons or weights according to the conventional convolution operation method (for example, formula (1)).

(4)微粒度量化权值或输入神经元,与非量化输入神经元或权值,位宽不同。此时需要执行转数,但是与(3)类似地也可以有两种处理方案。一种是第一转数电路732对权值和/或输入神经元进行转数,以使权值和输入神经元的数据位宽相同。通常微粒度量化的数据位宽较短,因此可以将微粒度量化权值或输入神经元转为与非量化输入神经元或权值相同的位宽(较长位宽数据)。微粒度量化的缩放系数则由卷积电路融合在执行卷积运算的过程中处理。同样地,也可以将权值和输入神经元均转为比原二者的位宽更长位宽的数据。另一种是由第一转数电路在对微粒度量化的权值或输入神经元进行转数的同时执行反量化,从而后续可以按照常规卷积运算方式,与非量化输入神经元或权值一起执行卷积运算。(4) The bit width of the quantized weights or input neurons differs from that of the unquantized input neurons or weights. In this case, a rotation is required, but similar to (3), there are two possible solutions. One is that the first rotation circuit 732 rotates the weights and/or input neurons to make their data bit widths the same. Typically, the bit width of the quantized data is shorter, so the quantized weights or input neurons can be converted to the same bit width as the unquantized input neurons or weights (longer bit width data). The scaling factor of the quantization is then processed by the convolution circuit during the convolution operation. Similarly, both the weights and input neurons can be converted to data with a longer bit width than their original values. Another solution is that the first rotation circuit performs dequantization while rotating the quantized weights or input neurons, allowing subsequent convolution operations to be performed together with the unquantized input neurons or weights using the conventional convolution operation method.

(5)微粒度量化权值和输入神经元,位宽相同。此时无需转数,由卷积电路731在执行卷积运算的过程中融合缩放系数进行反量化,例如按照前面结合公式(2)描述的运算方式。(5) The particle quantization weights and input neurons have the same bit width. At this time, no revolutions are needed. The convolution circuit 731 performs inverse quantization by fusing the scaling factor during the convolution operation, for example, according to the operation method described above in conjunction with formula (2).

(6)微粒度量化权值和输入神经元,位宽不同。此时第一转数电路732可以对权值和/或输入神经元进行转数,以使权值和输入神经元的数据位宽相同。例如,可以将权值和输入神经元中具有较短位宽的数据转为较长位宽数据,从而统一位宽。微粒度量化的缩放系数则由卷积电路融合在执行卷积运算的过程中处理。同样的,也可以将权值和输入神经元均转为比原二者的位宽更长位宽的数据。例如,将输入神经元微粒度量化后的数据类型为FP8,权值微粒度量化后的数据类型为FP4,可以将二者的数据类型均转换为FP16,基于FP16的数据类型进行卷积运算。注意,此处转换后的FP16仍然是带有缩放系数的微粒度量化数据。(6) The weights and input neurons are quantized into particles with different bit widths. At this point, the first rotation circuit 732 can rotate the weights and/or input neurons to make their data bit widths the same. For example, data with shorter bit widths in the weights and input neurons can be converted to data with longer bit widths, thus unifying the bit width. The scaling factor of the particle quantization is then processed by the convolution circuit during the convolution operation. Similarly, both the weights and input neurons can be converted to data with a bit width longer than their original values. For example, if the data type of the input neuron after particle quantization is FP8 and the data type of the weight after particle quantization is FP4, both data types can be converted to FP16, and convolution operations can be performed based on the FP16 data type. Note that the converted FP16 is still particle quantization data with scaling factors.

在上述各种方案中,相比于先做反量化再做卷积的方案,采用本披露实施例的在卷积运算过程中融合微粒度量化的缩放系数(也即卷积融合反量化)的优势在于可以提高性能加速比。例如,在输入神经元和权值都是微粒度量化数据的情况下,比如神经元数据和权值都是FP8,如果先做反量化,都转成量化后的FP16,运算带宽是N Byte,则一拍能够处理的数据个数是N/2。然而,如果直接以FP8的量化数据格式输入运算电路,在运算过程中使用缩放系数X进行反量化,则运算带宽N可以用满,此时的算力是之前的2倍。Among the various solutions described above, compared to the approach of performing dequantization before convolution, the advantage of using the scaling factor of particle quantization (i.e., convolution fused dequantization) in the convolution operation of this disclosed embodiment is that it can improve the performance speedup. For example, when the input neurons and weights are both particle quantized data, such as neuron data and weights being FP8, if dequantization is performed first, converting them to quantized FP16, the computation bandwidth is N bytes, and the number of data that can be processed in one cycle is N/2. However, if the quantized data format of FP8 is directly input into the computation circuit, and dequantization is performed using the scaling factor X during the operation, the computation bandwidth N can be fully utilized, and the computing power is twice that of the previous approach.

可以理解,在需要执行转数的情况下,转数通道上的真实访存需要按照通道带宽/转数比例的规模来访问存储电路(例如存储电路720),以避免转数后的数据量超过通道带宽。例如,如果转数前为FP4,转数后为FP8,带宽为128B,则单次访问的数据量为128B/(8/4)=64B。It is understandable that when revolutions count is required, the actual memory access on the revolutions channel needs to be based on the channel bandwidth/revolutions ratio to access the memory circuit (e.g., memory circuit 720) to avoid the amount of data after revolutions exceeding the channel bandwidth. For example, if the bandwidth is 128B before revolutions and FP4 after revolutions, then the amount of data accessed in a single instance is 128B/(8/4) = 64B.

如前面所提到的,相比于针对非量化格式数据执行的卷积运算,本披露实施例中适合微粒度量化的卷积指令中增加了对缩放系数X的访存要求。As mentioned earlier, compared to convolution operations performed on non-quantized data, the convolution instructions suitable for particle quantization in this disclosure embodiment add memory access requirements for the scaling factor X.

在一些实现中,缩放系数X可以与其关联的k个元素数据Pi连续地存储,此时缩放系数X与元素数据Pi可以一起访存,例如通过一个地址进行访存。此时,卷积指令针对单个参数可以只提供一个访存地址。In some implementations, the scaling factor X can be stored contiguously with its associated k element data P <sub>i </sub>. In this case, the scaling factor X and the element data P<sub> i </sub> can be accessed together, for example, through a single memory address. In this scenario, the convolution instruction can provide only one memory address for a single parameter.

在另一些实现中,缩放系数X可以与其关联的k个元素数据Pi独立地存储,此时缩放系数X与元素数据Pi可以独立访存,例如分别通过不同的地址进行访存。此时,卷积指令针对单个参数需要提供两个访存地址。In other implementations, the scaling factor X can be stored independently of its associated k element data P <sub>i </sub>. In this case, the scaling factor X and the element data P<sub> i </sub> can be accessed independently, for example, through different addresses. In this scenario, the convolution instruction requires two memory addresses for a single parameter.

在一些实施例中,缩放系数X可以采取前述压缩格式,以节省存储空间和传输带宽。在这种情况下,卷积指令可以增加相应的指示信息,用以指示缩放系数X的这种压缩格式。此时,运算电路730还可以包括解压缩电路734,配置用于响应于卷积指令指示其中的缩放系数是压缩格式,对压缩格式的缩放系数进行解压缩,以获得解压缩后的缩放系数。在一些实现中,压缩格式包括已压缩的Z个缩放系数的共享指数以及对应的Z个新尾数,其中Z≥2。此时,解压缩电路734进一步配置用于:将共享指数与Z个新尾数分别进行组合,以得到Z个解压缩后的缩放系数,以供卷积电路731使用。In some embodiments, the scaling factor X can adopt the aforementioned compressed format to save storage space and transmission bandwidth. In this case, the convolution instruction can add corresponding indication information to indicate this compressed format of the scaling factor X. The computation circuit 730 may further include a decompression circuit 734 configured to decompress the compressed scaling factor in response to the convolution instruction indicating that the scaling factor is in a compressed format, to obtain the decompressed scaling factor. In some implementations, the compressed format includes a shared exponent of Z compressed scaling factors and corresponding Z new mantissas, where Z ≥ 2. In this case, the decompression circuit 734 is further configured to combine the shared exponent with the Z new mantissas respectively to obtain Z decompressed scaling factors for use by the convolution circuit 731.

目前的AI芯片中,通常对片上RAM的访存是瓶颈,现有的数据已经把片上访存带宽占据得差不多了。针对新增加的缩放系数的访存需求,可以通过两种方案来实现。一种方案是增加访存带宽,例如为片上RAM新增加几个端口,用于这些新增加的缩放系数的访存。另一种方案是复用原有的端口进行缩放系数的访存。例如在原有的神经元读取端口上增加一个选择器,选择读取神经元数据或神经元缩放系数;在原有的权值读取端口上增加一个选择器,选择读取权值数据或权值缩放系数。类似地,在原有的输出神经元(结果)写回端口增加一个选择器,选择写回结果数据或结果缩放系数。In current AI chips, access to on-chip RAM is typically a bottleneck, as existing data already consumes a significant portion of the on-chip memory bandwidth. To address the memory access requirements of newly added scaling factors, two approaches can be taken. One approach is to increase the memory access bandwidth, for example, by adding several new ports to the on-chip RAM for accessing these new scaling factors. The other approach is to reuse existing ports for scaling factor access. For example, a selector can be added to the existing neuron read port to select whether to read neuron data or neuron scaling factors; a selector can be added to the existing weight read port to select whether to read weight data or weight scaling factors. Similarly, a selector can be added to the existing output neuron (result) write-back port to select whether to write back result data or result scaling factors.

在复用端口的情况下,由于需要分出时间读取缩放系数,数据不能连续供数,势必会导致一些性能的下降。因此,在一些实施例中,可以利用缩放系数在粒度块内共享的性质,在每拍读取缩放系数时,打满带宽,缓存以供后续的多个周期使用。When multiplexing ports, data cannot be continuously supplied because time needs to be allocated for reading scaling factors, which inevitably leads to some performance degradation. Therefore, in some embodiments, the property that scaling factors are shared within granular blocks can be utilized to fully utilize the bandwidth when reading scaling factors in each cycle, and buffer them for use in subsequent cycles.

具体地,在一些实施例中,卷积指令还指示缩放系数与其对应的数据复用相同的读取端口,并且每读一拍缩放系数,按比例读取多拍对应的数据。可以理解,在不复用端口的情况下,同样可以控制缩放系数读端口和数据读端口之间按比例执行读取动作,例如缩放系数读端口每读一拍缩放系数,数据读端口读n拍对应的数据,这样缩放系数读端口会空闲n-1拍,可以用于读其他数据。Specifically, in some embodiments, the convolution instruction also instructs the scaling factor and its corresponding data to reuse the same read port, and for each frame of scaling factor read, multiple frames of corresponding data are read proportionally. It can be understood that even without port reuse, the scaling factor read port and the data read port can still be controlled to perform read operations proportionally. For example, for each frame of scaling factor read by the scaling factor read port, the data read port reads the corresponding data for n frames. In this way, the scaling factor read port will be idle for n-1 frames, which can then be used to read other data.

在这些实施例中,如图7所示,数据处理装置700还包括第一缓存器741,配置用于缓存从片外读取的缩放系数,以与对应的数据成比例地供应给运算电路730中的卷积电路731执行卷积运算。In these embodiments, as shown in FIG7, the data processing apparatus 700 further includes a first buffer 741 configured to buffer scaling factors read from off-chip to be supplied in proportion to the corresponding data to the convolution circuit 731 in the arithmetic circuit 730 for performing convolution operations.

上述比例至少基于粒度块大小T、缩放系数的数据位宽、对应数据的数据位宽来确定。由于一个缩放系数在K个(也即T=K,例如32个)元素数据间共享,因此二者的使用比例是1个缩放系数对T个对应数据。根据缩放系数的数据位宽Xbw和对应数据的数据位宽Pbw,可以确定二者的使用比例(按Byte计算)是:1×Xbw:T×PbwThe above ratio is determined at least based on the granularity block size T, the data bit width of the scaling factor, and the data bit width of the corresponding data. Since a scaling factor is shared among K (i.e., T = K, for example, 32) data elements, the usage ratio is 1 scaling factor to T corresponding data elements. Based on the data bit width Xbw of the scaling factor and the data bit width Pbw of the corresponding data, the usage ratio (in bytes) can be determined as: 1 × Xbw : T × Pbw .

例如,当缩放系数的格式为E8M3,位宽占据2Byte,元素数据为FP8格式,位宽占据1Byte,T=32时,上述比例为2:32=1:16。在每拍进行读数时,无论是读取缩放系数,还是读取对应的数据,尽可能按照打满传输带宽的数据量去读取,从而充分利用传输性能。例如,假设读数/传输带宽是128B,则每读一拍缩放系数(128B/2B=64个缩放系数),对应读取16拍的元素数据(128B×16/1B=64×32)。读取的缩放系数缓存在第一缓存器中。当运算电路执行卷积运算时,每供应128B(例如打满运算带宽)的元素数据,相应地从第一缓存器供应128B/16=8B的缩放系数。由此,一拍读取的缩放系数可以在第一缓存器中停留多拍,从而缓解带宽紧张问题。For example, when the scaling factor is in E8M3 format with a bit width of 2 bytes, and the element data is in FP8 format with a bit width of 1 byte, and T = 32, the ratio is 2:32 = 1:16. When reading data in each frame, whether reading the scaling factor or the corresponding data, the data volume should be read to fully utilize the transmission bandwidth, thus making full use of transmission performance. For example, assuming the reading/transmission bandwidth is 128 bytes, then reading one frame of scaling factor (128 bytes/2 bytes = 64 scaling factors) corresponds to reading 16 frames of element data (128 bytes × 16 / 1 byte = 64 × 32). The read scaling factor is buffered in the first buffer. When the arithmetic circuit performs convolution operations, for every 128 bytes of element data supplied (e.g., to fully utilize the arithmetic bandwidth), 128 bytes/16 = 8 bytes of scaling factor are supplied from the first buffer. Therefore, the scaling factor read in one frame can remain in the first buffer for multiple frames, thus alleviating bandwidth constraints.

可以理解,当缩放系数采用压缩格式时,可以根据压缩比来相应地调整上述比例。例如,当缩放系数的格式为E8M3,每相邻的2个缩放系数进行压缩,压缩后占据2Byte,元素数据为FP8格式,位宽占据1Byte,T=32时,上述比例为2:2×32=1:32。可以看出,每读取2B的缩放系数,可以对应64个元素数据,需要读取64B的元素数据。解压缩电路734可以将第一缓存器741中缓存的缩放系数,解压缩后提供给卷积电路731。It is understandable that when the scaling factor adopts a compressed format, the above ratio can be adjusted accordingly based on the compression ratio. For example, when the scaling factor format is E8M3, every two adjacent scaling factors are compressed, occupying 2 bytes after compression, and the element data is in FP8 format with a bit width occupying 1 byte, and T=32, the above ratio is 2:2×32=1:32. It can be seen that reading 2 bytes of scaling factor corresponds to 64 elements of data, requiring the reading of 64 bytes of element data. The decompression circuit 734 can decompress the scaling factors cached in the first buffer 741 and provide them to the convolution circuit 731.

还可以理解,可以为输入神经元的缩放系数和权值的缩放系数分别设置缓存空间。例如可以设置两个第一缓存器,分别用于输入神经元的缩放系数和权值的缩放系数的缓存,在各个第一缓存器中按照每个运算周期的使用量移位取数。当然也可以设置在同一缓存器中,本披露实施例在此方面没有限制。It can also be understood that separate cache spaces can be set up for the scaling coefficients of the input neurons and the scaling coefficients of the weights. For example, two first caches can be set up, one for caching the scaling coefficients of the input neurons and the other for caching the scaling coefficients of the weights, and the data can be shifted and retrieved in each first cache according to the usage in each operation cycle. Of course, they can also be set up in the same cache, and the embodiments disclosed herein are not limited in this respect.

还可以理解,当数据存在转数时,按照转数后的数据位宽计算上述比例。It can also be understood that when the data has a number of revolutions, the above ratio is calculated based on the data bit width after the number of revolutions.

类似地,在输出神经元(卷积运算结果)需要进行微粒度量化的情况下,写回存储电路的内容也会包括结果数据和结果缩放系数。同样地,由于一个结果缩放系数在K个(例如32个)结果数据间共享,当结果数据能够打满写回的传输带宽时,对应的结果缩放系数还不够多。为了控制写回通路的传输带宽的有效利用,尽量避免写端口瓶颈,也可以设置一个第二缓存器(图7中的第二缓存器742),用于临时存储结果缩放系数。当结果缩放系数积累到一定量时,例如能够打满传输带宽时,再执行写回任务,将这些结果缩放系数通过一拍写回到存储电路。因此,输出顺序可以控制为先输出n拍结果数据,再输出1拍结果缩放系数。类似地,n根据粒度块大小T、结果数据的位宽、结果缩放系数的位宽来确定。Similarly, when the output neuron (the result of the convolution operation) needs to be granularized, the write-back storage circuit will also include the result data and the result scaling factor. Likewise, since a result scaling factor is shared among K (e.g., 32) result data, there may not be enough result scaling factors when the result data can fill the write-back transmission bandwidth. To control the efficient use of the write-back path's transmission bandwidth and avoid write port bottlenecks, a second buffer (second buffer 742 in Figure 7) can be set up to temporarily store the result scaling factors. When the result scaling factors accumulate to a certain amount, for example, when the transmission bandwidth is full, the write-back task is executed, writing these result scaling factors back to the storage circuit in one cycle. Therefore, the output order can be controlled to output n cycles of result data first, followed by one cycle of result scaling factors. Similarly, n is determined based on the granularity block size T, the bit width of the result data, and the bit width of the result scaling factor.

由于运算电路每拍的输出结果缩放系数的写回按照Co-Wo-Ho顺序存储到存储电路上,而微粒度量化会在Co维度上进行拆分量化,因此Co维度上可能会不连续,存在跳跃。此时,在第二缓存器中缓存结果缩放系数时,按照Co连续的方式按步长(stride)进行缓存。对于Co不连续的输出点,则跳过一定的stride。stride跟指令Co相关,其计算方式可以为:stride=Co/T*Xbw,其中Co为总的Co,T为粒度块大小,Xbw为缩放系数的位宽。例如,假设每拍计算64个Co,下一拍计算下一个Wo的64个Co,量化的粒度块大小T=32,则每拍会量化出2个缩放系数X,若总的Co为256,那么连续2拍的缩放系数存储步长stride=256/32*Xbw,也即按照两个缩放系数的起始存储位置的差值计算步长stride。Because the scaling factor output of the arithmetic circuit is written back to the storage circuit in the order of Co-Wo-Ho, and the granular quantization is split and quantized in the Co dimension, there may be discontinuities and jumps in the Co dimension. Therefore, when caching the scaling factor in the second buffer, it is cached in stride order according to the continuous Co. For output points with discontinuous Co, a certain stride is skipped. The stride is related to the instruction Co, and its calculation method is: stride = Co/T*X bw , where Co is the total Co, T is the granularity block size, and X bw is the bit width of the scaling factor. For example, assuming 64 Co are calculated per cycle, and the next cycle calculates 64 Co for the next Wo, with a quantization granularity block size T = 32, then 2 scaling factors X will be quantized per cycle. If the total Co is 256, then the storage stride for the scaling factor in two consecutive cycles is stride = 256/32*X bw , which is calculated based on the difference between the starting storage positions of the two scaling factors.

当将第二缓存器中的结果缩放系数写回存储电路时,可以使用带掩码(mask)的写回,其中掩码mask指示当前写回周期的数据中需要写入到存储电路上的有效数据。这样,由于结果缩放系数是按stride进行缓存,会存在空的部分,通过mask指示,可以仅将需要的数据(也即有效数据)写回到存储电路上。When writing the result scaling factor from the second buffer back to the storage circuit, a masked write-back can be used. The mask indicates the valid data that needs to be written to the storage circuit in the current write-back cycle. Since the result scaling factor is cached by stride, there will be empty portions. By using the mask, only the necessary data (i.e., valid data) can be written back to the storage circuit.

输出神经元的微粒度量化可以在图7中的量化电路733中执行。在一些实施例中,量化电路733可以配置用于根据卷积指令,将卷积运算的结果进行微粒度量化,以生成结果数据和结果缩放系数。可选地或附加地,在一些实施例中,量化电路733也可以配置用于根据卷积指令,将输入神经元和权值中未微粒度量化的进行微粒度量化。通过微粒度量化,可以将高位宽数据的计算转换为低位宽数据的计算,降低计算功耗。The particle quantization of the output neuron can be performed in the quantization circuit 733 in Figure 7. In some embodiments, the quantization circuit 733 can be configured to particle quantize the result of the convolution operation according to the convolution instruction to generate result data and result scaling factors. Optionally or additionally, in some embodiments, the quantization circuit 733 can also be configured to particle quantize the input neurons and weights that have not been particle quantized according to the convolution instruction. Through particle quantization, the computation of high-bit-width data can be converted into the computation of low-bit-width data, reducing computational power consumption.

在一些实施例中,量化电路733还可以包括压缩电路(未示出),其配置用于:响应于卷积指令指示缩放系数为压缩格式,对两组或更多组待量化数据量化后的两个或更多个缩放系数进行压缩。此时,量化电路利用压缩后的缩放系数分别对对应组待量化数据进行量化处理,以输出具有目标数据类型的量化数据。In some embodiments, the quantization circuit 733 may further include a compression circuit (not shown), configured to: compress two or more scaling factors after quantization of two or more sets of data to be quantized, in response to a convolution instruction indicating that the scaling factors are in a compressed format. In this case, the quantization circuit uses the compressed scaling factors to quantize the corresponding sets of data to be quantized, respectively, to output quantized data with the target data type.

量化电路733可以采取多种实现方式。在一些实施例中,量化电路733的具体实现可以参照前面针对扩展MX量化的描述,此处不再重复。The quantization circuit 733 can be implemented in various ways. In some embodiments, the specific implementation of the quantization circuit 733 can be referred to the previous description of extended MX quantization, which will not be repeated here.

以上结合图7描述了兼容微粒度量化格式的卷积运算方案。本领域技术人员可以理解,虽然在图7中将各个缓存器与运算电路示出为分立的模块,但是根据不同的配置,缓存器与运算电路也可以合并成一个模块。例如,第一缓存器可以与卷积电路合并在一起,第二缓存器则可以与量化电路合并在一起。本披露实施例在此方面没有限制。The convolution operation scheme compatible with particle quantization format has been described above with reference to Figure 7. Those skilled in the art will understand that although the various buffers and operation circuits are shown as discrete modules in Figure 7, depending on the configuration, the buffers and operation circuits can also be combined into a single module. For example, the first buffer can be combined with the convolution circuit, and the second buffer can be combined with the quantization circuit. The embodiments disclosed herein are not limited in this respect.

图8示出了根据本披露实施例的由数据处理电路实施的数据处理方法的示例性流程图。在此数据处理方法中,控制电路控制运算电路以对输入神经元和权值执行卷积运算。Figure 8 illustrates an exemplary flowchart of a data processing method implemented by a data processing circuit according to an embodiment of this disclosure. In this data processing method, a control circuit controls a computation circuit to perform a convolution operation on the input neurons and weights.

更具体地,在步骤810中,控制电路对卷积指令进行解析,其中卷积指令指示对输入神经元和权值进行卷积运算以获得输出神经元,并且输入神经元和权值中任一或二者是微粒度量化的。More specifically, in step 810, the control circuit parses the convolution instruction, which instructs to perform a convolution operation on the input neuron and weights to obtain the output neuron, and either or both of the input neuron and weights are quantized.

接着,在步骤820中,运算电路在控制电路的控制下,根据卷积指令,对输入神经元的数据和权值的数据执行卷积运算,并且将输入神经元的缩放系数和/或权值的缩放系数融合在卷积运算中。Next, in step 820, under the control of the control circuit, the computation circuit performs convolution operation on the data of the input neuron and the data of the weights according to the convolution instruction, and incorporates the scaling factor of the input neuron and/or the scaling factor of the weights into the convolution operation.

在一些实施例中,步骤820可以进一步包括:子步骤821,响应于卷积指令指示输入神经元与权值的数据位宽不同,对输入神经元的数据和/或权值的数据进行转数,以使输入神经元和权值的数据位宽相同;以及子步骤822,基于具有相同数据位宽的输入神经元的数据和权值的数据、以及输入神经元的缩放系数和/或权值的缩放系数执行卷积运算。子步骤821可以由第一转数电路执行,子步骤822可以由卷积电路执行。In some embodiments, step 820 may further include: sub-step 821, in response to a convolution instruction indicating that the data bit width of the input neuron and the weights are different, performing a rotation on the data of the input neuron and/or the data of the weights to make the data bit width of the input neuron and the weights the same; and sub-step 822, performing a convolution operation based on the data of the input neuron and the data of the weights having the same data bit width, and the scaling factor of the input neuron and/or the scaling factor of the weights. Sub-step 821 may be executed by a first rotation circuit, and sub-step 822 may be executed by a convolution circuit.

在一些实施例中,子步骤821中的转数,可以是将输入神经元与权值中的较短位宽数据转为较长位宽数据。In some embodiments, the number of revolutions in sub-step 821 may be to convert the shorter bit-width data in the input neuron and weights into longer bit-width data.

在一些实施例中,子步骤822可以按如下执行:以微粒度量化的粒度块大小T为单位,循环计算各个粒度块的部分和;以及循环累加单个卷积窗口内的各个粒度块的部分和,得到对应卷积窗口的输出神经元数值。In some embodiments, substep 822 may be performed as follows: cyclically calculating the partial sum of each granularity block in units of granularity block size T measured by microparticles; and cyclically accumulating the partial sum of each granularity block within a single convolution window to obtain the output neuron value of the corresponding convolution window.

具体地,计算各个粒度块的部分和可以包括:在每个粒度块内,计算输入神经元的数据和权值的数据的乘积和;计算该乘积和与输入神经元的缩放系数和/或权值的缩放系数的乘积,得到该粒度块的部分和。Specifically, calculating the partial sum of each granularity block may include: within each granularity block, calculating the sum of the product of the data of the input neuron and the data of the weights; calculating the product of this sum of products with the scaling factor of the input neuron and/or the scaling factor of the weights to obtain the partial sum of that granularity block.

在一些实施例中,步骤820可以进一步包括:子步骤823,根据卷积指令将卷积运算的结果进行微粒度量化,以生成结果数据和结果缩放系数。子步骤823可以由量化电路执行。具体的量化方法可以参考前文描述。In some embodiments, step 820 may further include: sub-step 823, which involves quantizing the result of the convolution operation according to the convolution instruction to generate result data and result scaling factors. Sub-step 823 may be performed by a quantization circuit. Specific quantization methods can be found in the preceding description.

可选地或附加地,在一些实施例中,方法还可以包括预处理步骤,例如由量化电路根据卷积指令,将输入神经元和权值中未微粒度量化的进行微粒度量化。通过微粒度量化,可以将高位宽数据的计算转换为低位宽数据的计算,降低计算功耗。Optionally or additionally, in some embodiments, the method may further include a preprocessing step, such as quantizing the input neurons and weights that are not quantized by a quantization circuit according to convolution instructions. Quantization can convert computation of high-bit-width data into computation of low-bit-width data, reducing computational power consumption.

本领域技术人员可以理解,方法流程图中描述的步骤与前面结合图7描述的数据处理装置的各个电路相对应,因此前面描述的特征同样适用于方法步骤,此处不再重复。Those skilled in the art will understand that the steps described in the method flowchart correspond to the various circuits of the data processing device described above in conjunction with Figure 7, and therefore the features described above also apply to the method steps, and will not be repeated here.

本披露实施例还提供了一种处理器,包括前述数据处理装置。本披露实施例还提供一种芯片,其可以包括前面结合附图描述的任一实施例的处理器。进一步地,本披露还提供了一种板卡,该板卡可以包括前述芯片。This disclosure also provides a processor, including the aforementioned data processing apparatus. This disclosure further provides a chip, which may include the processor of any of the embodiments described above in conjunction with the accompanying drawings. Furthermore, this disclosure also provides a board that may include the aforementioned chip.

根据不同的应用场景,本披露的电子设备或装置可以包括服务器、云端服务器、服务器集群、数据处理装置、机器人、电脑、打印机、扫描仪、平板电脑、智能终端、PC设备、物联网终端、移动终端、手机、行车记录仪、导航仪、传感器、摄像头、相机、摄像机、投影仪、手表、耳机、移动存储、可穿戴设备、视觉终端、自动驾驶终端、交通工具、家用电器、和/或医疗设备。所述交通工具包括飞机、轮船和/或车辆;所述家用电器包括电视、空调、微波炉、冰箱、电饭煲、加湿器、洗衣机、电灯、燃气灶、油烟机;所述医疗设备包括核磁共振仪、B超仪和/或心电图仪。本披露的电子设备或装置还可以被应用于互联网、物联网、数据中心、能源、交通、公共管理、制造、教育、电网、电信、金融、零售、工地、医疗等领域。进一步,本披露的电子设备或装置还可以用于云端、边缘端、终端等与人工智能、大数据和/或云计算相关的应用场景中。在一个或多个实施例中,根据本披露方案的算力高的电子设备或装置可以应用于云端设备(例如云端服务器),而功耗小的电子设备或装置可以应用于终端设备和/或边缘端设备(例如智能手机或摄像头)。在一个或多个实施例中,云端设备的硬件信息和终端设备和/或边缘端设备的硬件信息相互兼容,从而可以根据终端设备和/或边缘端设备的硬件信息,从云端设备的硬件资源中匹配出合适的硬件资源来模拟终端设备和/或边缘端设备的硬件资源,以便完成端云一体或云边端一体的统一管理、调度和协同工作。Depending on the application scenario, the electronic devices or apparatus disclosed herein may include servers, cloud servers, server clusters, data processing devices, robots, computers, printers, scanners, tablets, smart terminals, PC devices, IoT terminals, mobile terminals, mobile phones, dashcams, navigators, sensors, cameras, video cameras, projectors, watches, headphones, mobile storage, wearable devices, visual terminals, autonomous driving terminals, vehicles, home appliances, and/or medical devices. The vehicles include airplanes, ships, and/or vehicles; the home appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, lights, gas stoves, and range hoods; the medical devices include MRI scanners, ultrasound machines, and/or electrocardiographs. The electronic devices or apparatus disclosed herein can also be applied in fields such as the Internet, IoT, data centers, energy, transportation, public management, manufacturing, education, power grids, telecommunications, finance, retail, construction sites, and healthcare. Furthermore, the electronic devices or apparatus disclosed herein can also be used in application scenarios related to artificial intelligence, big data, and/or cloud computing, such as cloud computing, edge computing, and terminal applications. In one or more embodiments, the high-computing-power electronic devices or apparatuses according to the present disclosure can be applied to cloud devices (e.g., cloud servers), while the low-power electronic devices or apparatuses can be applied to terminal devices and/or edge devices (e.g., smartphones or cameras). In one or more embodiments, the hardware information of the cloud devices and the hardware information of the terminal devices and/or edge devices are compatible with each other, so that suitable hardware resources can be matched from the hardware resources of the cloud devices to simulate the hardware resources of the terminal devices and/or edge devices based on the hardware information of the terminal devices and/or edge devices, so as to complete the unified management, scheduling and collaborative work of end-to-cloud or cloud-edge-end integration.

需要说明的是,为了简明的目的,本披露将一些方法及其实施例表述为一系列的动作及其组合,但是本领域技术人员可以理解本披露的方案并不受所描述的动作的顺序限制。因此,依据本披露的公开或教导,本领域技术人员可以理解其中的某些步骤可以采用其他顺序来执行或者同时执行。进一步,本领域技术人员可以理解本披露所描述的实施例可以视为可选实施例,即其中所涉及的动作或模块对于本披露某个或某些方案的实现并不一定是必需的。另外,根据方案的不同,本披露对一些实施例的描述也各有侧重。鉴于此,本领域技术人员可以理解本披露某个实施例中没有详述的部分,也可以参见其他实施例的相关描述。It should be noted that, for the sake of brevity, this disclosure describes some methods and their embodiments as a series of actions and combinations thereof. However, those skilled in the art will understand that the solutions disclosed herein are not limited by the order of the described actions. Therefore, based on the disclosure or teachings of this document, those skilled in the art will understand that some steps can be performed in a different order or simultaneously. Furthermore, those skilled in the art will understand that the embodiments described in this disclosure can be considered optional embodiments, that is, the actions or modules involved are not necessarily essential for the implementation of one or more solutions disclosed herein. In addition, depending on the solution, the description of some embodiments in this disclosure may have different emphases. In view of this, those skilled in the art will understand that parts not described in detail in a certain embodiment of this disclosure can also be referred to the relevant descriptions of other embodiments.

在具体实现方面,基于本披露的公开和教导,本领域技术人员可以理解本披露所公开的若干实施例也可以通过本文未公开的其他方式来实现。例如,就前文所述的电子设备或装置实施例中的各个单元来说,本文在考虑了逻辑功能的基础上对其进行拆分,而实际实现时也可以有另外的拆分方式。又例如,可以将多个单元或组件结合或者集成到另一个系统,或者对单元或组件中的一些特征或功能进行选择性地禁用。就不同单元或组件之间的连接关系而言,前文结合附图所讨论的连接可以是单元或组件之间的直接或间接耦合。在一些场景中,前述的直接或间接耦合涉及利用接口的通信连接,其中通信接口可以支持电性、光学、声学、磁性或其它形式的信号传输。In terms of specific implementation, based on the disclosure and teachings of this document, those skilled in the art will understand that several embodiments disclosed herein can also be implemented in other ways not disclosed herein. For example, regarding the various units in the electronic device or apparatus embodiments described above, this document has divided them based on logical functions, but in actual implementation, there may be other ways of division. As another example, multiple units or components can be combined or integrated into another system, or some features or functions in a unit or component can be selectively disabled. Regarding the connection relationships between different units or components, the connections discussed above in conjunction with the accompanying drawings can be direct or indirect couplings between units or components. In some scenarios, the aforementioned direct or indirect couplings involve communication connections utilizing interfaces, where the communication interface can support electrical, optical, acoustic, magnetic, or other forms of signal transmission.

在本披露中,作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元示出的部件可以是或者也可以不是物理单元。前述部件或单元可以位于同一位置或者分布到多个网络单元上。另外,根据实际的需要,可以选择其中的部分或者全部单元来实现本披露实施例所述方案的目的。另外,在一些场景中,本披露实施例中的多个单元可以集成于一个单元中或者各个单元物理上单独存在。例如,在一些实施例中,量化电路作为后处理电路,可以融合在卷积电路中,也可以独立于卷积电路。在另一些实施例中,量化电路作为预处理电路,可以融合在转数电路中,也可以独立于转数电路。本披露实施例在此方面没有限制。In this disclosure, the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units. The aforementioned components or units may be located in the same location or distributed across multiple network units. Furthermore, depending on actual needs, some or all of the units can be selected to achieve the purpose of the solution described in the embodiments of this disclosure. Additionally, in some scenarios, multiple units in the embodiments of this disclosure may be integrated into one unit or each unit may exist physically independently. For example, in some embodiments, the quantization circuit, as a post-processing circuit, may be integrated into the convolution circuit or independent of the convolution circuit. In other embodiments, the quantization circuit, as a pre-processing circuit, may be integrated into the revolutions circuit or independent of the revolutions circuit. The embodiments of this disclosure are not limited in this respect.

在另外一些实现场景中,上述集成的单元也可以采用硬件的形式实现,即为具体的硬件电路,其可以包括数字电路和/或模拟电路等。电路的硬件结构的物理实现可以包括但不限于物理器件,而物理器件可以包括但不限于晶体管或忆阻器等器件。鉴于此,本文所述的各类装置(例如计算装置或其他处理装置)可以通过适当的硬件处理器来实现,例如中央处理器、GPU、FPGA、DSP和ASIC等。进一步,前述的所述存储单元或存储装置可以是任意适当的存储介质(包括磁存储介质或磁光存储介质等),其例如可以是可变电阻式存储器(Resistive Random Access Memory,RRAM)、动态随机存取存储器(Dynamic Random Access Memory,DRAM)、静态随机存取存储器(Static Random Access Memory,SRAM)、增强动态随机存取存储器(Enhanced Dynamic Random Access Memory,EDRAM)、高带宽存储器(High Bandwidth Memory,HBM)、混合存储器立方体(Hybrid Memory Cube,HMC)、ROM(Read Only Memory,只读存储器)和RAM(Random Access Memory,随机存取存储器)等。In other implementation scenarios, the integrated units described above can also be implemented in hardware, i.e., as specific hardware circuits, which may include digital circuits and/or analog circuits. The physical implementation of the circuit's hardware structure may include, but is not limited to, physical devices, which may include, but are not limited to, transistors or memristors. Therefore, the various devices described herein (e.g., computing devices or other processing devices) can be implemented using appropriate hardware processors, such as central processing units, GPUs, FPGAs, DSPs, and ASICs. Furthermore, the aforementioned storage unit or storage device can be any suitable storage medium (including magnetic storage medium or magneto-optical storage medium, etc.), such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), ROM (read-only memory), and RAM (random access memory), etc.

以上对本披露实施例进行了详细介绍,本文中应用了具体个例对本披露的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本披露的方法及其核心思想;同时,对于本领域的一般技术人员,依据本披露的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本披露的限制。The embodiments of this disclosure have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this disclosure. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this disclosure. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this disclosure. Therefore, the content of this specification should not be construed as a limitation of this disclosure.

Claims (30)

一种数据处理装置,包括:A data processing apparatus, comprising: 控制电路,配置用于解析卷积指令,所述卷积指令指示对输入神经元和权值进行卷积运算以获得输出神经元,其中所述输入神经元和权值中任一或二者是微粒度量化的;以及Control circuitry configured to parse convolution instructions, the convolution instructions directing a convolution operation on an input neuron and weights to obtain an output neuron, wherein either or both of the input neuron and weights are particle-quantized; and 运算电路,配置用于根据所述卷积指令,对所述输入神经元的数据和所述权值的数据执行卷积运算,将所述输入神经元的缩放系数和/或所述权值的缩放系数融合在所述卷积运算中。The computation circuit is configured to perform a convolution operation on the data of the input neuron and the data of the weights according to the convolution instruction, and to fuse the scaling factor of the input neuron and/or the scaling factor of the weights in the convolution operation. 根据权利要求1所述的数据处理装置,其中,所述运算电路包括:According to claim 1, the data processing apparatus, wherein the arithmetic circuit comprises: 转数电路,配置用于响应于所述卷积指令指示所述输入神经元与所述权值的数据位宽不同,对所述输入神经元的数据和/或所述权值的数据进行转数,以使所述输入神经元和所述权值的数据位宽相同;以及A rotation circuit is configured to rotate the data of the input neuron and/or the data of the weights in response to a convolution instruction indicating that the data bit widths of the input neuron and the weights are different, so that the data bit widths of the input neuron and the weights are the same; and 卷积电路,配置用于基于具有相同数据位宽的输入神经元的数据和权值的数据、以及所述输入神经元的缩放系数和/或所述权值的缩放系数执行卷积运算。A convolution circuit configured to perform a convolution operation based on data and weights of input neurons having the same data bit width, and the scaling factor of the input neurons and/or the scaling factor of the weights. 根据权利要求2所述的数据处理装置,其中,所述运算电路还包括:According to claim 2, the data processing apparatus further includes: 解压缩电路,配置用于响应于所述卷积指令指示其中的缩放系数是压缩格式,对压缩格式的缩放系数进行解压缩,以获得解压缩后的缩放系数。The decompression circuit is configured to decompress the scaling factor in the compressed format in response to the convolution instruction indicating that the scaling factor is in a compressed format, so as to obtain the decompressed scaling factor. 根据权利要求3所述的数据处理装置,其中,所述压缩格式包括已压缩的Z个缩放系数的共享指数以及对应的Z个新尾数,其中Z≥2,所述解压缩电路进一步配置用于:According to the data processing apparatus of claim 3, the compression format includes a shared exponent of Z compressed scaling factors and corresponding Z new mantissas, where Z ≥ 2, and the decompression circuit is further configured to: 将所述共享指数与所述Z个新尾数分别进行组合,以得到Z个解压缩后的缩放系数,以供所述卷积电路使用。The shared index is combined with the Z new mantissas to obtain Z decompressed scaling factors for use by the convolution circuit. 根据权利要求2-4任一所述的数据处理装置,其中,所述转数电路进一步配置用于,基于所述卷积指令,将所述输入神经元与所述权值中的较短位宽数据转为较长位宽数据。The data processing apparatus according to any one of claims 2-4, wherein the convolution circuit is further configured to convert the shorter bit-width data in the input neuron and the weights into longer bit-width data based on the convolution instruction. 根据权利要求1-5任一所述的数据处理装置,其中,所述运算电路配置用于按如下执行卷积运算:The data processing apparatus according to any one of claims 1-5, wherein the arithmetic circuit is configured to perform convolution operations as follows: 以所述微粒度量化的粒度块大小T为单位,循环计算各个粒度块的部分和;以及Using the particle size T as the unit, the partial sum of each particle size block is calculated iteratively; and 循环累加单个卷积窗口内的各个粒度块的部分和,得到对应卷积窗口的输出神经元数值。By iteratively summing the partial sums of each granularity block within a single convolution window, the output neuron value of the corresponding convolution window is obtained. 根据权利要求6所述的数据处理装置,其中所述运算电路配置用于按如下计算各个粒度块的部分和:The data processing apparatus according to claim 6, wherein the arithmetic circuitry is configured to calculate the partial sum of each granularity block as follows: 在每个粒度块内,计算输入神经元的数据和权值的数据的乘积和;以及Within each granularity block, calculate the sum of the product of the input neuron's data and the weight data; and 计算所述乘积和与所述输入神经元的缩放系数和/或所述权值的缩放系数的乘积,得到所述粒度块的部分和。The product of the sum and the scaling factor of the input neuron and/or the scaling factor of the weights is calculated to obtain a partial sum of the granularity block. 根据权利要求1-7任一所述的数据处理装置,其中所述运算电路配置用于按如下公式(1)执行卷积运算:
The data processing apparatus according to any one of claims 1-7, wherein the arithmetic circuit is configured to perform a convolution operation according to the following formula (1):
其中Y为输出神经元,具有Ho,Wo,Co维度;A为输入神经元,具有Ci,Hi,Wi维度;W为权值,具有Ci,Kh,Kw,Co维度,Kh、Kw分别为Kh和Kw维度的大小,所述输入神经元和/或所述权值在Ci维度上已进行所述微粒度量化,块大小为T,分别为输入神经元A和权值W的第n个粒度块的缩放系数,sh、sw分别为权值在Kh和Kw维度的卷积步长。Where Y is the output neuron with dimensions Ho, Wo, and Co; A is the input neuron with dimensions Ci, Hi, and Wi; W is the weight with dimensions Ci, Kh, Kw, and Co, where Kh and Kw are the sizes of the Kh and Kw dimensions, respectively. The input neuron and/or the weight have been quantized in the Ci dimension, and the block size is T. are the scaling factors for the nth granularity block of the input neuron A and the weight W, respectively, and s <sub>h </sub> and s<sub>w</sub> are the convolution strides of the weights in the dimensions K<sub>h</sub> and K<sub>w</sub>, respectively.
根据权利要求6-8任一所述的数据处理装置,其中所述卷积指令还指示每读一拍缩放系数,按比例读取多拍对应的数据,所述数据处理装置还包括:The data processing apparatus according to any one of claims 6-8, wherein the convolution instruction further indicates a scaling factor for each read frame, and reads data corresponding to multiple frames proportionally, the data processing apparatus further includes: 第一缓存器,配置用于缓存从片外读取的缩放系数,以与对应的数据成比例地供应给所述运算电路执行所述卷积运算,其中所述比例至少基于所述粒度块大小、所述缩放系数的数据位宽、对应数据的数据位宽确定。A first buffer is configured to cache scaling factors read from off-chip to be supplied to the computing circuitry in proportion to the corresponding data for performing the convolution operation, wherein the proportion is determined at least based on the granularity block size, the data bit width of the scaling factor, and the data bit width of the corresponding data. 根据权利要求9所述的数据处理装置,其中,每拍读取的数据量打满传输带宽。According to the data processing apparatus of claim 9, the amount of data read in each frame fully utilizes the transmission bandwidth. 根据权利要求1-10任一所述的数据处理装置,其中,所述运算电路还包括:The data processing apparatus according to any one of claims 1-10, wherein the arithmetic circuit further comprises: 量化电路,配置用于根据所述卷积指令,将所述卷积运算的结果进行微粒度量化,以生成结果数据和结果缩放系数;和/或配置用于根据所述卷积指令,将所述输入神经元和权值中未微粒度量化的进行微粒度量化。A quantization circuit is configured to perform particle quantization on the result of the convolution operation according to the convolution instruction to generate result data and result scaling factor; and/or is configured to perform particle quantization on the input neurons and weights that have not been particle quantized according to the convolution instruction. 根据权利要求11所述的数据处理装置,其中,所述量化电路包括:The data processing apparatus according to claim 11, wherein the quantization circuit comprises: 第一处理电路,配置用于确定所述卷积运算的结果中的一组待量化数据中的绝对值最大值;获取所述待量化数据量化后的目标数据类型能够表示的最大数值;基于所述绝对值最大值与所述最大数值之间的比值,确定所述一组待量化数据对应的缩放因子;将所述缩放因子由第一数据类型转换为第二数据类型,以输出缩放系数,其中所述第二数据类型的位宽小于所述第一数据类型的位宽;以及A first processing circuit is configured to: determine the maximum absolute value of a set of data to be quantized in the result of the convolution operation; obtain the maximum value that the target data type after quantization can represent; determine a scaling factor corresponding to the set of data to be quantized based on the ratio between the maximum absolute value and the maximum value; convert the scaling factor from a first data type to a second data type to output a scaling coefficient, wherein the bit width of the second data type is smaller than the bit width of the first data type; and 第二处理电路,配置用于利用所述缩放系数对所述一组待量化数据进行量化处理,以输出具有所述目标数据类型的量化数据。The second processing circuit is configured to quantize the set of data to be quantized using the scaling factor to output quantized data having the target data type. 根据权利要求12所述的数据处理装置,其中,所述第一处理电路包括:The data processing apparatus according to claim 12, wherein the first processing circuit comprises: 比较电路,用于确定一组待量化数据中的绝对值最大值;A comparator circuit is used to determine the maximum absolute value in a set of data to be quantized; 第一除法电路,用于获取所述待量化数据量化后的目标数据类型能够表示的最大数值,并且基于所述绝对值最大值与所述最大数值之间的比值,确定所述一组待量化数据对应的缩放因子;以及The first division circuit is used to obtain the maximum value that the target data type after quantization of the data to be quantized can represent, and to determine the scaling factor corresponding to the set of data to be quantized based on the ratio between the maximum absolute value and the maximum value; and 第一转数电路,用于将所述缩放因子由第一数据类型转换为第二数据类型,以输出缩放系数。The first rotation circuit is used to convert the scaling factor from a first data type to a second data type to output the scaling coefficient. 根据权利要求13所述的数据处理装置,其中,所述第一处理电路进一步配置用于:根据所述第二处理电路的单次处理量和/或输入端口数量,确定所述一组待量化数据中待量化数据的数量;或者According to the data processing apparatus of claim 13, wherein the first processing circuit is further configured to: determine the number of data to be quantized in the set of data to be quantized based on the single processing volume and/or the number of input ports of the second processing circuit; or 根据使用所述量化数据进行运算的运算器的单次运算量和/或输入端口数量,确定所述一组待量化数据中待量化数据的数量。The number of data points to be quantized in the set of data points is determined based on the single operation quantity and/or the number of input ports of the arithmetic unit that performs the operation using the quantized data. 根据权利要求12-14任一所述的数据处理装置,其中,所述卷积运算的结果至少在Co维度上划分为多组进行所述微粒度量化。The data processing apparatus according to any one of claims 12-14, wherein the result of the convolution operation is divided into multiple groups at least in the Co dimension for particle quantization. 根据权利要求12-15任一所述的数据处理装置,其中The data processing apparatus according to any one of claims 12-15, wherein 所述第一数据类型与所述待量化数据的原始数据类型相同,或者所述第一数据类型的位宽大于所述原始数据类型的位宽;并且The first data type is the same as the original data type of the data to be quantized, or the bit width of the first data type is greater than the bit width of the original data type; and 所述第二数据类型表示为ExMy,x+y<原始数据类型的位宽,其中,E表示指数位,M表示尾数位,x表示指数位位宽,y表示尾数位位宽。The second data type is represented as ExMy, where x + y < bit width of the original data type, where E represents the exponent bits, M represents the mantissa bits, x represents the exponent bit width, and y represents the mantissa bit width. 根据权利要求16所述的数据处理装置,其中y>0。The data processing apparatus according to claim 16, wherein y > 0. 根据权利要求12-17任一所述的数据处理装置,其中The data processing apparatus according to any one of claims 12-17, wherein 所述待量化数据的原始数据类型包括FP16、BF16、FP32、TF32、FP64中的至少一种;所述第二数据类型包括E8M0、E8M1、E8M2、E8M3、E8M4、E8M5、E8M6、E8M7、E5M0、E5M1、E5M2、E5M3、E5M4、E5M5、E5M6、E3M0、E3M1、E3M2、E3M3、E3M4、E3M5、E3M6、E3M7、E3M8、E3M9中的至少一种;和/或The original data type of the data to be quantized includes at least one of FP16, BF16, FP32, TF32, and FP64; the second data type includes at least one of E8M0, E8M1, E8M2, E8M3, E8M4, E8M5, E8M6, E8M7, E5M0, E5M1, E5M2, E5M3, E5M4, E5M5, E5M6, E3M0, E3M1, E3M2, E3M3, E3M4, E3M5, E3M6, E3M7, E3M8, and E3M9; and/or 所述目标数据类型包括FP12、FP8、FP6、FP4、FP2、int8、int4、int2、int6中的至少一种,并且FP12、FP8、FP6和FP4支持多种数据格式。The target data type includes at least one of FP12, FP8, FP6, FP4, FP2, int8, int4, int2, and int6, and FP12, FP8, FP6, and FP4 support multiple data formats. 根据权利要求12-18任一所述的数据处理装置,其中所述量化电路还包括压缩电路,配置用于:The data processing apparatus according to any one of claims 12-18, wherein the quantization circuit further comprises a compression circuit configured for: 响应于所述卷积指令指示缩放系数为压缩格式,对两组或更多组待量化数据量化后的两个或更多个缩放系数进行压缩;并且In response to the convolution instruction indicating that the scaling factors are in a compressed format, two or more scaling factors after quantization of two or more sets of data to be quantized are compressed; and 所述第二处理电路配置用于利用压缩后的缩放系数分别对对应组待量化数据进行量化处理,以输出具有所述目标数据类型的量化数据。The second processing circuit is configured to quantize the corresponding group of data to be quantized using the compressed scaling factor, so as to output quantized data with the target data type. 根据权利要求19所述的数据处理装置,其中所述压缩电路进一步配置用于:The data processing apparatus of claim 19, wherein the compression circuit is further configured to: 确定待压缩的Z个缩放系数的共享指数,Z≥2;Determine the shared exponent of the Z scaling factors to be compressed, Z≥2; 确定所述Z个缩放系数对应的Z个新尾数;以及Determine the Z new mantissas corresponding to the Z scaling factors; and 将所述共享指数与所述Z个新尾数捆绑输出以供关联使用。The shared index is bundled with the Z new tail numbers and output for association. 根据权利要求20所述的数据处理装置,其中所述压缩电路进一步配置用于:The data processing apparatus of claim 20, wherein the compression circuit is further configured to: 将所述Z个缩放系数中的最大指数设置为所述共享指数。Set the largest index among the Z scaling factors as the shared index. 根据权利要求21所述的数据处理装置,其中所述压缩电路进一步配置用于:The data processing apparatus of claim 21, wherein the compression circuit is further configured to: 将指数小于所述最大指数的缩放系数的新尾数设置为0;以及Set the new mantissa of the scaling factor whose exponent is less than the maximum exponent to 0; and 将指数等于所述最大指数的缩放系数的新尾数设置为原尾数。Set the new mantissa, whose exponent is equal to the scaling factor of the maximum exponent, as the original mantissa. 根据权利要求20-22任一所述的数据处理装置,还包括以下一项或多项:The data processing apparatus according to any one of claims 20-22 further comprises one or more of the following: 待压缩的所述Z个缩放系数的所述第二数据类型相同;The second data type of the Z scaling factors to be compressed is the same; 所述Z个缩放系数属于相邻的Z组待量化数据;The Z scaling factors belong to Z adjacent groups of data to be quantized; Z为2或4或8。Z can be 2, 4, or 8. 根据权利要求11-23任一所述的数据处理装置,还包括:The data processing apparatus according to any one of claims 11-23 further includes: 第二缓存器,配置用于缓存所述结果缩放系数,以与对应的结果数据成比例地写回到存储电路上。The second buffer is configured to cache the scaling factor of the result so that it is written back to the storage circuit in proportion to the corresponding result data. 根据权利要求24所述的数据处理装置,其中,所述结果缩放系数按照Co维度连续的方式按步长缓存在所述第二缓存器中,并且将所述结果缩放系数写回到存储电路上时为带掩码写,所述掩码指示当前写回周期的内容中需要写入到存储电路上的有效数据。According to the data processing apparatus of claim 24, the result scaling factor is cached in the second cache in a step-wise manner according to the Co dimension, and the result scaling factor is written back to the storage circuit as a masked write, wherein the mask indicates the valid data that needs to be written to the storage circuit in the content of the current write-back cycle. 根据权利要求1-25任一所述的数据处理装置,其中所述输入神经元、所述权值和/或所述输出神经元各自经量化的数据和缩放系数支持独立访存或一起访存。The data processing apparatus according to any one of claims 1-25, wherein the quantized data and scaling factor of each of the input neuron, the weights and/or the output neuron support independent or joint memory access. 根据权利要求1-26任一所述的数据处理装置,其中,当所述输入神经元和所述权值中之一为非量化数据时,所述运算电路将对应的缩放系数设置为1。The data processing apparatus according to any one of claims 1-26, wherein when one of the input neuron and the weight is non-quantized data, the computation circuit sets the corresponding scaling factor to 1. 一种处理器,包括如权利要求1-27任一所述的数据处理装置。A processor comprising the data processing apparatus as described in any one of claims 1-27. 一种板卡,包括根据权利要求28所述的处理器。A board comprising the processor according to claim 28. 一种由数据处理装置实施的数据处理方法,所述数据处理装置包括控制电路和运算电路,所述方法包括:A data processing method implemented by a data processing device, the data processing device including a control circuit and a calculation circuit, the method comprising: 所述控制电路对卷积指令进行解析,所述卷积指令指示对输入神经元和权值进行卷积运算以获得输出神经元,其中所述输入神经元和权值中任一或二者是微粒度量化的;以及The control circuit parses convolution instructions, which instruct the convolution operation to be performed on the input neuron and weights to obtain the output neuron, wherein either or both of the input neuron and weights are particle-quantized; and 所述运算电路根据所述卷积指令,对所述输入神经元的数据和所述权值的数据执行卷积运算,并且将所述输入神经元的缩放系数和/或所述权值的缩放系数融合在所述卷积运算中。The computational circuit performs a convolution operation on the data of the input neuron and the data of the weights according to the convolution instruction, and integrates the scaling factor of the input neuron and/or the scaling factor of the weights into the convolution operation.
PCT/CN2025/090097 2024-06-21 2025-04-21 Data processing apparatus, processor, board, and data processing method Pending WO2025260957A1 (en)

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN202410813862.X 2024-06-21
CN202410813862 2024-06-21
CN202411347002.8 2024-09-25
CN202411347002 2024-09-25

Publications (1)

Publication Number Publication Date
WO2025260957A1 true WO2025260957A1 (en) 2025-12-26

Family

ID=98092509

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2025/090097 Pending WO2025260957A1 (en) 2024-06-21 2025-04-21 Data processing apparatus, processor, board, and data processing method

Country Status (2)

Country Link
CN (1) CN121187535A (en)
WO (1) WO2025260957A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180314940A1 (en) * 2017-04-28 2018-11-01 Intel Corporation Incremental precision networks using residual inference and fine-grain quantization
CN110991623A (en) * 2019-12-20 2020-04-10 中国科学院自动化研究所 Neural network computing system based on digital-analog hybrid neurons
CN111930670A (en) * 2020-08-10 2020-11-13 中国科学院计算技术研究所 Heterogeneous intelligent processing quantization device, quantization method, electronic device and storage medium
US20240144439A1 (en) * 2021-09-28 2024-05-02 Tencent Technology (Shenzhen) Company Limited Filtering method and apparatus, computer-readable medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180314940A1 (en) * 2017-04-28 2018-11-01 Intel Corporation Incremental precision networks using residual inference and fine-grain quantization
CN110991623A (en) * 2019-12-20 2020-04-10 中国科学院自动化研究所 Neural network computing system based on digital-analog hybrid neurons
CN111930670A (en) * 2020-08-10 2020-11-13 中国科学院计算技术研究所 Heterogeneous intelligent processing quantization device, quantization method, electronic device and storage medium
US20240144439A1 (en) * 2021-09-28 2024-05-02 Tencent Technology (Shenzhen) Company Limited Filtering method and apparatus, computer-readable medium

Also Published As

Publication number Publication date
CN121187535A (en) 2025-12-23

Similar Documents

Publication Publication Date Title
CN106951962B (en) Complex arithmetic unit, method and electronic device for neural network
CN108628807B (en) Processing method, device and equipment of floating-point number matrix and computer readable storage medium
US20200250539A1 (en) Processing method and device
CN114118347A (en) Fine-grained per-vector scaling for neural network quantization
US20240134930A1 (en) Method and apparatus for neural network weight block compression in a compute accelerator
WO2022111002A1 (en) Method and apparatus for training neural network, and computer readable storage medium
CN118170347A (en) Precision conversion method and device, data processing method, processor, and electronic device
CN116795324A (en) Mixed-precision floating-point multiplication device and mixed-precision floating-point number processing method
WO2020256836A1 (en) Sparse convolutional neural network
WO2021040832A1 (en) Neural network training with decreased memory consumption and processor utilization
US20250307347A1 (en) Structured Sparse Matrix Acceleration In Systolic Arrays
WO2022263385A1 (en) Recurrent neural network cell activation to perform a plurality of operations in a single invocation
CN119376686A (en) A data processing method and related equipment
CN113570034A (en) Processing device, processing method of neural network and device thereof
WO2025260957A1 (en) Data processing apparatus, processor, board, and data processing method
CN118312130A (en) Data processing method and device, processor, electronic equipment and storage medium
WO2025260956A1 (en) Data processing apparatus, processor, board card, and data processing method
CN117348931A (en) Command devices, integrated circuit devices and boards
WO2023279946A1 (en) Processing apparatus, device, method, and related product
WO2025260934A1 (en) Data quantification method and apparatus, and related product
WO2025260952A1 (en) Apparatus and method for dequantizing data
CN121412507B (en) Matrix multiplication apparatus, method, electronic device, storage medium
US20250190523A1 (en) Lut-free hardware based softmax accelerator
An et al. Fast and Efficient Yolov3-Tiny Accelerator Design for Fpga Edge Computing
CN121187542A (en) Methods, apparatus and related products for quantifying revolutions

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 25829440

Country of ref document: EP

Kind code of ref document: A1