Precision compensation circuit for sparse neural network computation
The tensor processing circuit with precision compensation module addresses precision loss in sparsified neural networks by adjusting intermediate tensors, ensuring high efficiency and accuracy without additional cost or speed reduction.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- MOFFETT TECH CO LTD
- Filing Date
- 2024-11-29
- Publication Date
- 2026-06-04
AI Technical Summary
Sparsification techniques in neural networks lead to a loss of precision, which degrades the performance of neural networks without adding computational overhead or slowing down processing speeds.
A tensor processing circuit with a precision compensation module that includes a tensor cache, a tensor mask cache, a computation circuit, and a precision compensation circuit to adjust intermediate tensors, using ternary gates and channel-specific adjustment parameters to restore lost precision.
Maintains high computational efficiency and accuracy of neural network outputs by compensating for precision loss without additional computational cost or processing speed reduction.
Smart Images

Figure CN2024135801_04062026_PF_FP_ABST
Abstract
Description
PRECISION COMPENSATION CIRCUIT FOR SPARSE NEURAL NETWORK COMPUTATIONTECHNICAL FIELD
[0001] The present invention relates to the field of computer processors and machine learning, specifically to compensate the data precision loss caused by tensor sparsification in neural network computation.BACKGROUND
[0002] Neural networks have become integral to various advanced computational tasks, including image recognition, natural language processing, and autonomous systems. As these networks grow in complexity, the computational cost and processing time required for neural network computations have increased significantly. To mitigate these challenges, sparsification techniques are employed to reduce the number of computations by eliminating or simplifying less significant weights within the neural network.
[0003] Sparsification methods, such as pruning and quantization, reduce computational load and enhance processing speed by representing weights with fewer bits or by removing low-magnitude weights altogether. However, these techniques inevitably lead to a loss of precision. The reduced bit representation and elimination of certain weights can degrade the performance of the neural network, potentially impacting the accuracy of results in critical applications.
[0004] While the benefits of sparsification often outweigh the drawbacks of reduced precision, there remains a need to compensate for this precision loss without introducing additional computational overhead or slowing down processing speeds.
[0005] The present disclosure addresses this gap by introducing a tensor processing circuit designed for sparsified neural network computations, incorporating a data precision compensation circuit that effectively restores lost precision without adding extra computational cost or affecting the processing speed. This design allows for the maintenance of high computational efficiency and speed while ensuring the accuracy and reliability of neural network outputs are preserved.SUMMARY
[0006] Various embodiments of the present specification may include a sparse neural network computation circuit with a precision compensation module. A system composed of one or more computers can be configured to perform specific operations or actions by installing software, firmware, hardware, or a combination of these elements. This configuration enables the system to carry out the designated actions. Similarly, computer programs can be designed to perform particular operations by including instructions that, when executed by data processing apparatus, prompt the apparatus to execute these actions.
[0007] In one general aspect, a tensor processing circuit may include a tensor cache configured to cache the weight tensor for neural network computation. The tensor processing circuit may also include a tensor mask cache configured to cache a tensor mask corresponding to the activation tensor. The activation tensor is sparse and the tensor mask is a part of a sparse representation of the activation tensor. The sparse representation of the activation tensor cause loss of computation precision in in exchange for a reduced memory footprint. The tensor mask comprises (1) information of high-magnitude features in the activation tensor and (2) information of low-magnitude features in the activation tensor, wherein the information of low-magnitude features comprises encodings of the low-magnitude features configured to compensate the loss of computation precision.
[0008] The circuit may furthermore include a computation circuit configured to perform the neural network computation based on the weight tensor, the tensor mask, and the activation tensor to generate an intermediate tensor. Additionally, the circuit may include a precision compensation circuit configured to compensate for the loss of precision of the low-magnitude features by adjusting the intermediate tensor based on the weight tensor and the tensor mask. Moreover, the circuit may include an accumulation circuit configured to perform summation operations based on the adjusted intermediate tensor and a previously cached tensor from an accumulate cache, thereby generating an output tensor of the neural network computation. Other embodiments of this aspect include corresponding computer systems, apparatus, and computer programs recorded on one or more computer storage devices, each configured to perform the actions of the methods.
[0009] Implementations may include one or more of the following features. The tensor processing circuit may include a computation circuit comprising a gather circuit coupled to both the tensor cache and the tensor mask cache. The gather circuit is configured to gather weights in the weight tensor corresponding to the high-magnitude features in the activation tensor, consolidating these weights into a condensed tensor. Additionally, a multiplier array may be configured to receive the activation tensor and the condensed tensor from the gather circuit and output the intermediate tensor.
[0010] The tensor mask cache may include a first tensor mask cache and a second tensor mask cache. The first tensor mask cache is configured to cache position information of high-magnitude features in the activation tensor, while the second tensor mask cache is configured to cache the encodings of low-magnitude features in the activation tensor. The separation of the first tensor mask cache and the second tensor mask cache allows the computation circuit and the precision compensation circuit to execute in parallel.
[0011] Furthermore, the computation circuit is coupled to both the tensor cache and the tensor mask cache and performs the neural network computation based on the high-magnitude features in the activation tensor. Simultaneously, the precision compensation circuit is coupled to the tensor cache and the tensor mask cache and performs precision compensation based on the low-magnitude features in the activation tensor. The encodings of the low-magnitude features in the activation tensor may be 2-bit or 3-bit encodings.
[0012] The precision compensation circuit may include a plurality of ternary blocks, each having an adder tree configured to sum outputs from a plurality of ternary gates. In response to the encodings of the low-magnitude features being 2-bit encodings, each ternary block is configured to generate a channel-specific adjustment parameter based on the 2-bit encoding and corresponding weight from the weight tensor. The channel-specific adjustment parameter is used to adjust the corresponding tensor element in the intermediate tensor. If the encodings are 3-bit encodings, the precision compensation circuit may further include a mask split circuit to split each 3-bit encoding into a pair of 2-bit encodings. A pair of ternary blocks are then configured to collectively generate a channel-specific adjustment parameter based on the pair of 2-bit encodings and corresponding weights from the weight tensor to adjust the corresponding tensor elements in the intermediate tensor.
[0013] Additionally, the precision compensation circuit may include a plurality of ternary gates instead of binary multiplier gates to perform multiplications between weights in the weight tensor and corresponding encodings in the tensor mask. The use of ternary gates results in a smaller chip size compared to using binary multiplier gates. Implementations of the described techniques may include hardware, a method or process, or a computer tangible medium.
[0014] In one general aspect, a method may include generating a tensor mask for the activation tensor. The activation tensor is sparse and the tensor mask is a part of a sparse representation of the activation tensor. The sparse representation of the activation tensor cause loss of computation precision in in exchange for a reduced memory footprint. The tensor mask comprises (1) information of high-magnitude features in the activation tensor and (2) information of low-magnitude features in the activation tensor, wherein the information of low-magnitude features comprises encodings of the low-magnitude features configured to compensate the loss of computation precision. The method may also include performing a neural network computation based on the weight tensor, the tensor mask, and the activation tensor to generate an intermediate tensor. Furthermore, the method may include adjusting the intermediate tensor to compensate for the loss of precision of the low-magnitude features based on the weight tensor and the tensor mask. Additionally, the method may include performing summation operations based on the adjusted intermediate tensor and a previously cached tensor from an accumulate cache, thereby generating an output tensor of the neural network computation. Other embodiments of this aspect include corresponding computer systems, apparatus, and computer programs recorded on one or more computer storage devices, each configured to perform the actions of the methods.
[0015] Implementations may include one or more of the following features. The method of performing the neural network computation may include transforming the weight tensor into a condensed tensor using a gather circuit based on the tensor mask. The condensed tensor contains weights in the weight tensor that correspond to the high-magnitude features in the activation tensor, and the neural network computation is performed based on the condensed tensor and the activation tensor.
[0016] Generating the tensor mask for the weight tensor may include generating a first tensor mask to cache position information of high-magnitude features in the activation tensor and generating a second tensor mask to cache the encodings of low-magnitude features in the activation tensor. The encodings of the low-magnitude features in the activation tensor may be 2-bit or 3-bit encodings. Adjusting the intermediate tensor to compensate for the loss of precision may include, in response to the encodings of the low-magnitude features being 2-bit encodings, generating channel-specific adjusting parameters based on the 2-bit encodings and corresponding weights from the weight tensor. The channel-specific adjusting parameters are used to adjust the corresponding tensor elements in the intermediate tensor.
[0017] If the encodings of the low-magnitude features are 3-bit encodings, the method may include splitting each 3-bit encoding into a pair of 2-bit encodings, generating a channel-specific adjusting parameter based on the pair of 2-bit encodings and corresponding weights from the weight tensor, and using the channel-specific adjusting parameter to adjust the corresponding tensor element in the intermediate tensor. Each 3-bit encoding may include a sign bit, a first bit, and a second bit. Splitting the 3-bit encoding into the pair of 2-bit encodings may include forming a first 2-bit encoding using the sign bit and the first bit and forming a second 2-bit encoding using the sign bit and the second bit. Additionally, the encodings of the low-magnitude features in the activation tensor may be K-bit encodings, where K is an integer greater than 3.
[0018] Implementations of the described techniques may include hardware, a method or process, or a computer tangible medium.
[0019] These and other features of the systems, methods, and non-transitory computer-readable media disclosed herein, as well as the methods of operation and functions of the related elements of structure and the combination of parts and economies of manufacture, will become more apparent upon consideration of the following description and the appended claims with reference to the accompanying drawings, all of which form a part of this specification, wherein like reference numerals designate corresponding parts in the various figures. It is to be expressly understood, however, that the drawings are for purposes of illustration and description only and are not intended as a definition of the limits of the invention.BRIEF DESCRIPTION OF THE DRAWINGS
[0020] FIG. 1A illustrates an exemplary system diagram of a neural network processing unit.
[0021] FIG. 1B illustrates an example Processing Entity (PE) in the neural network processing unit.
[0022] FIG. 2 illustrates an example sparse codec supporting both sparse encoding and sparse decoding, in accordance with various embodiments.
[0023] FIG. 3 illustrates a sparse encoding process using the PE with the sparse codec, in accordance with various embodiments.
[0024] FIG. 4 illustrates an exemplary architecture diagram of a sparse tensor computation processor with a precision compensation circuit, in accordance with various embodiments.
[0025] FIG. 5 illustrates an exemplary architecture diagram of the precision compensation circuit, in accordance with various embodiments.
[0026] FIG. 6 illustrate an example method of sparse encoding that enables precision compensation, in accordance with various embodiments.
[0027] FIG. 7 illustrate an example method of precision compensation for sparse neural network computation, in accordance with various embodiments. DETAIL DESCRIPTION OF THE EMBODIMENTS
[0028] Embodiments described herein provide methods, systems, apparatus for precision compensation during neural network computations involving sparsification.
[0029] A neural network computation involves the interaction between activation tensors and weight tensors to process and transform data through the network’s layers. Activation tensors represent the input data or the outputs from preceding layers, encapsulating multi-dimensional arrays of numerical values that carry essential information for tasks such as classification or prediction. Weight tensors contain the network’s learnable parameters, determining the strength and direction of connections between neurons. During computation, the weight tensor is applied to the activation tensor through operations like matrix multiplication or convolution, effectively aggregating and transforming the input data based on the learned weights. This process is typically followed by adding a bias tensor and applying an activation function, which introduces non-linearity and enables the network to model complex patterns. The continuous interplay between activation and weight tensors allows the neural network to learn from data, adjust its parameters during training, and make accurate predictions during inference.
[0030] As mentioned in the background section, sparsification in neural networks involves reducing the number of elements in weight tensors or activation tensors, thereby lowering the computational burden and memory requirements. The sparsity of neural networks can be achieved through methods such as pruning, quantization, and regularization. For example, sparsification eliminates low-magnitude elements while retaining high-magnitude elements. These methods reduce the density of neural network tensors, leading to more efficient model execution.
[0031] The sparsity of neural networks can be achieved through sparsification techniques such as pruning, quantization, and regularization. These approaches reduce the density of neural network tensors, enabling more efficient model execution. However, they also inevitably lead to a loss of precision in the tensor data. Ideally, a neural network computation circuit should harness the benefits of sparsification while being able to provide precision compensation to mitigate the precision loss caused by these techniques.
[0032] This disclosure uses distinct types of tensors to help describe the invention, such as dense tensors, sparse tensors, condensed tensors, and sparse uncondensed tensors.
[0033] A dense tensor refers to a tensor in its original size, characterized by the number of elements and the bit-depth (precision) of these elements as received from upstream or downstream processing engines. The dense tensor may include high-magnitude data and low-magnitude data. When a dense tensor contains a large number of zero-valued data, it is called a sparse tensor.
[0034] The sparse tensor may be represented and stored in different data formats using a combination of a condensed tensor, a bitmask, and optional quantization information. A condensed tensor represents a compressed version of a given tensor, the bitmask maps the data in the condensed tensor with the original tensor, and the quantization information includes quantization parameters used when generating the condensed tensor from the original tensor.
[0035] In a narrow-sense sparse representation, the sparse representation of a sparse tensor may include a condensed tensor and a bitmask. The condensed tensor only stores non-zero elements from a sparse tensor, and the bitmask uses binary values to indicate the original positions of the non-zero elements in the given tensor. The condensed tensor in combination of the bitmask can be used to restore the given tensor. The restoration may be necessary for certain tensor operations (e.g., max or average pooling) or hardware processing units.
[0036] In a more general-sense sparse representation, the sparse representation of a sparse tensor may include a condensed tensor and a bitmask. The condensed tensor stores high-magnitude elements in the original tensor (e.g., a dense tensor) . The bitmask uses multi-bits values to indicate not only the original positions of the high-magnitude elements in the original tensor, but also encoded value information of the low-magnitude elements in the original tensor. The “high-magnitude elements” refer to elements that exceed a value threshold, indicating significance of these elements for the tensor computation. The condensed tensor in combination of the multi-bit bitmask can be used to restore the given tensor.
[0037] In some embodiments, if quantization is performed when converting the given tensor into the corresponding condensed tensor, the quantization parameters (e.g., scale and bias) may be stored as part of the sparse representation in addition to the condensed tensor and the bitmask. While quantization reduces the data precision, the quantization parameters may be used to reverse (to some extent) the data precision when converting the condensed tensor back to its dense format.
[0038] The sparse uncondensed tensor is an expanded version of the condensed tensor. Elements from the condensed tensor are scattered and distributed into this larger tensor, which contains more positions or “spots” than the condensed tensor. Since the elements from the condensed tensor occupy only a subset of these spots, the remaining positions are filled with zero-valued elements, rendering the uncondensed tensor sparse.
[0039] In some scenarios, the dense tensor and the sparse uncondensed tensor share the same size and dimensions, while the condensed tensor has a smaller size. The bit-depth of the dense tensor is higher than that of the condensed tensor. The bit-depth of the sparse uncondensed tensor may remain the same as that of the dense tensor.
[0040] Additionally, the term “sparse representation” of a dense tensor used in this disclosure refers to a group of data generated through the sparsification of the dense tensor.
[0041] In neural networks sparsification, sparse encoding is a process to convert a dense tensor (either a weight tensor or an activation tensor) into a sparse representation. The sparse representation of the dense tensor may include a condensed tensor, a low-bit bitmask, and optional quantization parameters. This condensed tensor captures only the non-zero elements, significantly reducing the amount of data that needs to be processed or transmitted. The low-bit bitmask uses low bit-depth to represent the low magnitude elements. The optional quantization parameters include the parameters used during the quantization (if any) of the dense tensor, and will be used to restore the sparse representation back to the dense format (i.e., as a result of the sparse decoding) . Sparse encoding is particularly beneficial for improving computational efficiency and reducing memory usage in scenarios where the majority of the tensor elements are zeros.
[0042] However, the sparsification process introduces new challenges that must be addressed to fully exploit the benefits of sparse computing. Not all neural network operations or upstream hardware / accelerators are designed to handle sparse data natively. Many standard operations, such as max pooling and average pooling, as well as interactions with dense layers, require tensors in their original dense format. To address this need, sparse decoding is required. Sparse decoding is the reverse of sparse encoding; it reconstructs the dense tensor from its sparse representation by reintroducing the low-magnitude elements (e.g., zeros) at their appropriate positions. This step is crucial for ensuring compatibility with operations that expect dense input tensors and for maintaining the integrity of the computational process within the network.
[0043] Moreover, many existing hardware accelerators and software frameworks may lack native support for sparse operations, necessitating the use of sparse decoding to convert sparse tensors back to their dense forms. This ensures that the neural network can function correctly on a wide range of computing platforms. Additionally, the ability to restore the original dense structure of tensors is important for tasks such as model inspection, analysis, and further processing.
[0044] In the sparse encoding process, it is common practice to prune low-magnitude tensor data by marking those below a certain threshold as zeros. Traditional sparse encoders typically retain only the positions of the non-zero tensor data after pruning, completely discarding the information related to the pruned low-magnitude values in order to save spaces. However, this approach is insufficient when sparse decoding is required later in the pipeline. The goal of sparse decoding is to reconstruct the dense tensor as accurately as possible to its original form, making it crucial that the sparse encoding process does not simply abandon the pruned values. Instead, the sparse encoding process needs to not only retain a minimal memory footprint for these pruned values but also store enough information to allow the sparse decoding process to approximate the original dense tensor without significant loss of accuracy. This balance between reducing memory usage and preserving data integrity is essential for ensuring that the sparsification and subsequent de-sparsification processes do not degrade the performance of the neural network.
[0045] FIG. 1A illustrates an exemplary system diagram of a neural network (NN) processing unit 100. The neural network processing unit 100 in FIG. 1A may refer to a neural network accelerator or an NPU, e.g., a specialized microprocessor designed to accelerate machine learning and artificial intelligence (AI) tasks. Unlike traditional CPUs (Central Processing Units) and GPUs (Graphics Processing Units) , accelerators or NPUs are optimized specifically for the neural network operations such as convolution computations and vector operations..
[0046] The NN processing unit 100 illustrated in FIG. 1A includes a plurality of Processing Entities (PEs) that are designed to provide maximum parallelism to accelerate neural network operations. These PEs are organized in a 2D mesh network and interconnected via a network of routers (denoted as “R” in FIG. 1A) . Additionally, the NN processing unit 100 incorporates double data rate (DDR) memory modules and caches, such as the last-level cache (LLC) , to support efficient data storage and retrieval. The NN processing unit 100 in FIG. 1A is merely illustrative, and may comprise more, fewer, or alternative components. The accelerator 100 may be designed as a reconfigurable device such as a field-programmable gate array (FPGA) , or an application-specific integrated circuit (ASIC) . The sparse codec introduced in this disclosure may be implemented in a PE.
[0047] In some embodiments, to optimize resource utilization and enhance the parallel processing capabilities of the NN processing unit 100, the PEs within the 2D mesh network may be divided into multiple sections, with each section referred to as a core. As illustrated in FIG. 1, every group of 16 PEs (arranged in a 4x4 grid) constitutes a core, resulting in a total of four cores across the 64 PEs in the NN processing unit 100. Each core is equipped with dedicated DDR memory, LLC, and control circuits, including a RISC-V Vector Unit (RVV) , responsible for vector processing, Core-Level Scheduler (CoLS) , which manages the execution and synchronization of multiple PEs, and an Instruction Dispatch Unit (IDU) , which allocates instructions to various execution units within the accelerator. This architecture enables all four cores 110 (i.e., the four PE groups) to operate concurrently, ensuring efficient parallel processing.
[0048] In some embodiments, these cores 110 are further organized into a Network-on-Chip (NoC) for inter-core communication. For instance, in FIG. 1A, the four groups of PEs are arranged as a ring NoC, facilitating seamless communication between cores and enhancing overall computational throughput. The ring NoC architecture includes a circular arrangement of cores 110, where data packets travel along a unidirectional or bidirectional ring, passing through each core 110 until they reach their destination. The ring NoC may be used for data communication between DDRs and PCIe or for PEs to read data from DDR belonging to other cores. In addition to the ring NoC, the PEs may be arranged as a 2D mesh NoC, managing the data communication between PEs.
[0049] Furthermore, the ring NoC architecture in FIG. 1A is scalable, allowing additional cores or PEs to be easily added to the ring without significantly increasing the complexity of the network. This flexibility supports the expansion of the NN processing unit to accommodate larger neural network models or additional computational tasks as needed.
[0050] The NN processing unit 100 illustrated in FIG. 1A may interact with an external (host) CPU through a peripheral component interconnect express (PCIe) . The NN processing unit 100 illustrated in FIG. 1A may further include an internal CPU to orchestra the cores with instructions, and a chip-level scheduler (ChLS) .
[0051] FIG. 1B illustrates an example Processing Entity (PE) 140 in the neural network processing unit. The PE 140 is an example of a PE within core 110 from FIG. 1A. The internal components of PE 140 depicted in FIG. 1B are for illustrative purposes, and the actual implementation may include additional, fewer, or alternative components depending on the specific design requirements.
[0052] In some embodiments, the PE 140 includes two NoC switches: a Data NoC Switch and a Cfg NoC Switch, both used to facilitate communication with other cores on the NoC. The Data NoC Switch is responsible for transmitting high-bandwidth data and instructions, ensuring efficient communication of tensor data and processing commands across the network. The Cfg NoC Switch is dedicated to handling configuration data, including parameters and setup information for the core and its functional modules. The wired connections to the Data NoC Switch are typically of higher bandwidth compared to those of the Cfg NoC Switch, reflecting the heavier data traffic load on the data path.
[0053] Additionally, PE 140 may include a scheduler that manages instruction issuance through an instruction interface, triggering various functional modules. These modules include the DMA (Direct Memory Access) module, which facilitates high-speed data transfer between memory and processing units without burdening the central processing core. The Sparse Processing Unit (SPU) performs tensor multiplication. The Vector Processing Unit (VPU) handles vectorized operations. The Activation Engine (AE) applies activation functions, including ReLU, sigmoid, or softmax, introducing non-linearity into the neural networks. The Transpose Engine (TE) performs tensor transposition, often required in matrix multiplications and other tasks that involve reordering data dimensions. Finally, the Sorting Engine (SE) is responsible for sorting tensor elements, particularly useful in identifying and isolating high-magnitude values for optimization and pruning in sparse computations. These functional modules efficiently access shared memory, allowing seamless data transfer and interaction between them to ensure smooth operation.
[0054] Furthermore, PE 140 incorporates a local RISC-V Vector (RVV) processing unit, such as a single-core RVV, which is optimized for executing vectorized instructions for neural network tasks. The RVV is coupled with TCM (Tightly Coupled Memory) , a high-speed, low-latency memory directly connected to the PE. This TCM allows the PE to store critical data and intermediate results for rapid access, minimizing latency and ensuring efficient execution of compute-intensive tasks such as matrix operations, convolutions, and tensor manipulations.
[0055] In some embodiments, the sparse tensor computation processor with precision compensation circuit described below may be implemented as (or as a part of) the SPU in the PE as illustrated in FIG. 1B.
[0056] To clarify the need for precision compensation, it is important to first provide some context. FIG. 2 illustrates a sparse codec used in tensor sparsification, which supports both (1) sparse encoding, which transforms dense tensors into a sparse representation for computation and data transmission with a reduced memory footprint, and (2) sparse decoding, which reverses the sparse encoding process, restoring the tensor to its original form for use by other engines in a neural network processing pipeline that only accept dense tensors. Through FIG. 2, those skilled in the art can understand how precision loss occurs during this sparsification process (e.g., encoding and decoding) . FIG. 3 then presents a specific example of how sparse encoding functions, pinpointing where precision loss arises and explaining why precision compensation is necessary.
[0057] FIG. 2 illustrates an example sparse codec 140 supporting both sparse encoding and sparse decoding, in accordance with various embodiments. The sparse codec 140 may be implemented as hardware or software, depending on the use case and preferences.
[0058] In some embodiments, the sparse codec 140 may be implemented inside the PE 140 illustrated in FIGs. 1A and 1B. More particularly, the sparse codec 140 may be implemented in the Sorting Engine (SE) in the PE 140 in FIG. 1B.
[0059] The sparse codec 140 may support both sparse encoding and sparse decoding, which are both essential in practice because they work together to optimize the efficiency of data storage, transmission, and processing, especially in large-scale applications like neural networks. Sparse encoding reduces the memory footprint and computational load by representing only the most significant data elements with high-precision, while compressing less critical data into a more efficient, low-precision format. This not only saves storage space but also speeds up data processing and reduces transmission latency. In practice, the sparsified tensor often needs to be restored to its dense format for several reasons. First, many neural network operations and algorithms are designed to work on dense tensors, requiring the full data structure to be present for correct functioning. Second, many hardware processing units or accelerators require the input tensor to be dense, thus the sparse representation needs to be restored (sparse decoded) to its original dense form to be compatible with these hardware apparatuses. Lastly, certain downstream tasks, such as visualization, analysis, or further processing, may require the dense format to ensure the full integrity and interpretability of the data.
[0060] In some embodiments, during the sparse encoding process 150 (denoted as Sparse Encode in FIG. 2) , dense data 152, such as a dense weight tensor or an activation tensor (where “dense” refers to a tensor containing a mix of both high-magnitude values with greater absolute values and low-magnitude values with smaller absolute values) , is input into the sparse codec 140. The sparse codec 140 then generates a sparse representation 151 of the dense data 152. The sparse encoding process 150 prioritizes the retention of high-magnitude values due to their greater contribution to the computation accuracy of the neural network, while pruning less critical low-magnitude values to reduce memory footprint and computational cost.
[0061] In some embodiments, the sparse representation 151 of the dense data 152 may include condensed data 154 (e.g., a condensed sub-tensor) that gathers (aggregates) and compresses (e.g., through quantization) the high-magnitude values into a condensed tensor form. Quantizing the high-magnitude values in the condensed data 154 offers technical benefits by reducing the memory footprint and accelerating computation, as fewer bits are used to represent each value. The number of bits used to represent one tensor data is called bit-depth. For instance, each piece of tensor data in the original dense data 152 may use 32 bits, whereas each quantized tensor data in the condensed data 154 may use 8 bits. This way, the gathering operation may compress an original data of 64 bytes (assuming the dimension size of the tensor is 16, i.e., 16*32 bits is 64 bytes) to 16 bytes (16*8bits=16 bytes) , saving the memory footprint by 4 times. This leads to faster processing and lower power consumption, which are particularly advantageous in energy-constrained environments like mobile devices or embedded systems. Additionally, quantization decreases the bandwidth needed for data transfer, improving the efficiency of hardware utilization, especially in systems optimized for lower-precision operations.
[0062] In some embodiments, the sparse representation 151 of the dense data 152 may further include a sparse bitmask 155 that represents the positions of the high-magnitude tensor data within the original dense data 152, as well as quantized low-magnitude tensor data from the original dense data 152. This sparse bitmask 155 is necessary for restoring the sparse representation 151 of the original tensor 152 to its original dense format, as it specifies where to place the high-magnitude tensor data from the condensed data 154 and what the low-precision values should be reintroduced.
[0063] Traditional bitmasks typically use a single bit per entry to indicate a binary choice: whether a position contains a pruned or non-pruned value. However, to facilitate the subsequent sparse decoding process, the bitmask needs to convey more than just the binary information. In some embodiments, each entry in the sparse bitmask 155 may utilize two or more bits, with the first bit serving as a sign bit. This design allows each entry in the sparse bitmask 155 to not only differentiate between pruned and non-pruned values but also to specify a range of quantized tensor data. For example, using two bits per entry in the sparse bitmask 155 provides four possible states, with one state representing the presence of a high-magnitude tensor data, and each of the other three states representing a different value range for a low-magnitude tensor data. This design allows to use the same data format, i.e., the sparse bitmask 155, to assist in reconstructing a more accurate dense tensor.
[0064] Furthermore, the sparse representation 151 of the dense data 152 may include quantization parameters 156 (denoted as Quant Params in FIG. 2) . These quantization parameters 156 are determined during the sparse encoding process 150 to quantize both the high-magnitude and low-magnitude tensor data in the dense data 152. Since the value ranges of high-magnitude and low-magnitude tensor data differ, two distinct sets of quantization parameters 156 may be generated respectively for each category. If the tensor data in the dense data 152 have been quantized (resulting in the condensed data 154 and the sparse bitmask 155) , these quantization parameters 156 may be included as part of the sparse representation 151 of the dense data 152 and subsequently utilized during the sparse decoding process. For instance, the quantization parameters 156 may be applied to a quantized high-magnitude value in the condensed data 154 to generate a dequantized value close to its original high-magnitude value in the dense data 152. As another example, the quantization parameters 156 may be applied to a multi-bit entry in the sparse bitmask 155 (representing a quantized low-magnitude value) to dequantize the value into a corresponding low-magnitude value range. The dequantized values may be scattered into a dense tensor according to the sparse bitmask 155 to conclude the sparse decoding process.
[0065] In summary, the sparse encoding process 150 transforms the dense data 152 into a sparse representation 151, including one or more of the condensed data 154 representing the high-magnitude tensor data in the dense data 152, the sparse bitmask 155 representing the low-magnitude tensor data in the dense data 152, and quant params 156 preparing for sparse decoding process. This sparse representation 151 significantly reduces the memory footprint required for storage and minimizes the latency associated with transmitting the data from one PE to another, compared to handling the dense data 152 directly.
[0066] The sparse decoding process serves as the reverse operation of the sparse encoding process 150. During sparse decoding, the inputs may include one or more of the condensed data 154, the sparse bitmask 155, and the optional quantization parameters 156 if quantization occurred (or collectively, the sparse representation 151) . At a high level, the sparse bitmask 155 is utilized to map the quantized high-magnitude values from the condensed data 154 back to their original positions within the dense data 152.
[0067] If the sparse encoding process involves data quantization, the quantization parameters 156 play a crucial role in this decoding process by being used to dequantize the high-magnitude values in the condensed data 154 and the low-magnitude values in the sparse bitmask 155, thereby restoring these values as closely as possible to their original forms (e.g., precision and value) in the dense tensor. For instance, the multi-bit entries within the sparse bitmask 155, which represent the quantized low-precision values, are decoded back into their corresponding original high-precision values (with precision loss) . Although the quantization process inherently reduces the precision of the original tensor data, the use of quantization parameters 156 allows the tensor data in the sparse representation 151 of the dense data 152 to be restored with an acceptable level of precision loss compared to the original values. This bidirectional sparsification process supported by the sparse codec 140 ensures that the sparse representation 151, while more efficient, still maintains a high degree of accuracy relative to the original dense data. The number of bits in the sparse bitmask 155 is inversely related to the loss of precision of the sparse encoding and decoding process, i.e., a higher bit-depth in the sparse bitmask 155 reduces the precision loss of the sparse encoding and decoding process.
[0068] During the sparse encoding process 150, the high-magnitude tensor data from the dense data 152 may be gathered into a condensed tensor. This gathering process may be implemented as a gather circuit, which is configured to transform a tensor (either sparse or dense) into a condensed tensor based on the given tensor mask (e.g., by gathering the high-magnitude tensor data into the condensed tensor) . During the sparse decoding process, the high-magnitude tensor data in the condensed tensor need to be scatter back to their original positions in the dense data. This scattering process may be implemented as a scatter circuit, which is configured to transform the condensed tensor into a sparse uncondensed tensor based on a given bitmask by redistributing the high-magnitude tensor data to their original positions as indicated by the given bitmask, and filling the remaining positions with zero-valued elements. To complete the sparse decoding, the data in sparse uncondensed tensor may go through dequantization to restore the bit-depth of the dense tensor. The resultant tensor may be referred to as a restored dense tensor.
[0069] The presence of the gather circuit and the scatter circuit allows the sparse codec to perform sparse gather 160 and sparse scatter 170. During sparse gather 160, the uncondensed data 162 (e.g., a tensor with high-magnitude tensor data scattered at different positions) and a bitmask 163 (indicating the positions of the high-magnitude tensor data) may be received as input. The gather circuit in the sparse codec 140 may gather the high-magnitude tensor data in the uncondensed data 162 based on the bitmask 163 to generate the condensed data 164, which only contains the high-magnitude tensor data stored sequentially. In some embodiments, the bitmask 163 may be carried over as part of the output of the sparse gather 160, denoted as the bit mask 165.
[0070] During the sparse scatter 170 process, condensed data 164 and a bitmask 165 are received as inputs. The condensed data 164 contains only the high-magnitude tensor data that were retained after pruning the original dense tensor, while the bitmask 165 indicates the original positions of these high-magnitude values within the original dense tensor. The scatter circuit within the sparse codec 140 then redistributes the high-magnitude tensor data from the condensed data 164 back to their original positions in the tensor, guided by the bitmask 165. As a result, the scatter circuit generates an uncondensed data 162, which includes the high-magnitude tensor data restored to their original positions, with all other positions filled with zero tensor data.
[0071] FIG. 3 illustrates a sparse encoding process using the PE with the sparse codec, in accordance with various embodiments. The sparse encoding process illustrated in FIG. 3 may be implemented using the sparse codec module 140 in FIG. 2.
[0072] The sparse encoding process may start with receiving an input dense data 300, which includes a plurality of tensor data with different magnitudes. For example, the input dense data 300 may refer to the weight tensor at a given layer in a neural network. The input dense data 300 may go through a sorting circuit, such as an odd-even merge sort 310 circuit, to obtain sorted data 340. In some embodiments, the odd-even merge sort 310 is preferred in this context is because it works particularly well in parallel computing environments. Since the odd-even merge sort circuit may include a plurality of nodes to perform the sorting in parallel, the odd-even merge sort 310 circuit is structured to efficiently handle the sorting task by dividing the data into smaller subproblems, which can be solved simultaneously by the plurality of nodes.
[0073] As illustrated in FIG. 3, the sorted data 340 splits the high-magnitude tensor data and the low-magnitude tensor data. Note that the tensor data are sorted by their absolute magnitudes, as these magnitudes play a crucial role in neural network computations. The purposes of the sorting step include identifying the high-magnitude tensor data that are greater than a threshold value, and determining the parameters for the subsequent quantization.
[0074] For instance, the sorted data 340 may be used to generate a temporary bitmask 330 to indicate the original positions of the high-magnitude tensor data in the input dense data 300. Traditional bitmask usually uses 1s to indicate the positions of the high-magnitude tensor data and 0s to indicate the low-magnitude tensor data (those to be pruned out) . In contrast, the bitmask 330 in FIG. 3 uses 0s to indicate the high-magnitude tensor data and 1s to indicate the low-magnitude tensor data. This reverse marking design is to facilitate the subsequent bitmask merging operations, which saves one round of bit-flipping when merging the temporary bitmask 330 with the quantized LP (low-precision) bitmask 354 to generate the sparse bitmask 360 (corresponding to the low-magnitude tensor data) as a part of the sparse encoding output.
[0075] Based on the temporary bitmask 330, the gather circuit 320 may gather the high-magnitude tensor data into the HP part 352, which will be used to generate the condense data 370 as a second part of the sparse encoding output.
[0076] Using the sorted data 340, the max high-magnitude tensor data and the min high-magnitude tensor data may be determined as the range for quantizing the high-magnitude tensor data, and the max low-magnitude tensor data and the min low-magnitude tensor data may be determined as the range for quantizing the low-magnitude tensor data. Based on the max high-magnitude tensor data and the min high-magnitude tensor data, a scale and bias for the high-magnitude tensor data may be determined. Based on the max low-magnitude tensor data and the min low-magnitude tensor data, a scale and bias for the low-magnitude tensor data may be determined. These scale and bias factors may be used to quantize the high-magnitude tensor data in the HP part 352 and the LP part 350 (denoted as Low Precision Part in FIG. 3) , to generate the condensed data 370 and the quantized LP bitmask 354, respectively.
[0077] In addition to the reverse marking design of the temporary bitmask 330, several additional implementation details contribute to improved encoding efficiency of the sparse codec. For example, the sparse bitmask 360 has the same number of entries as the input dense data, encompassing bits corresponding to both the low-magnitude and high-magnitude tensor data. This design allows the same bitmask to retain both (1) the position information of the quantized high-magnitude values and (2) the encodings of the quantized low-magnitude values. These information are all encoded using two or more bits in the sparse bitmask 360.
[0078] In summary, before a dense tensor (e.g., an activation tensor) is involved in computation with another tensor (e.g., a weight tensor) , it may undergo a sparse encoding process as shown in FIG. 3. This process generates a sparse representation of the dense tensor. The sparse representation includes at least the condensed data 370 (e.g., the high-magnitude features) that will be used in the computation with the activation tensor to generate output values, and the sparse bitmask 360, which will be used to scatter these output values to the corresponding positions in an output tensor.
[0079] In this disclosure, the specific encoding used in the sparse bitmask 360 not only allows for the scattering of output values to their correct positions in the output tensor but also enables precision compensation for the low-magnitude data (e.g., the low-magnitude weights in the weight tensor) that are lost during the sparse encoding process.
[0080] FIG. 4 illustrates an exemplary architecture diagram of a sparse tensor computation processor with a precision compensation circuit, in accordance with various embodiments. The diagram in FIG. 4 is for illustrative purposes with example components. Depending on the implementation, the sparse tensor processing circuit may have additional, fewer, or alternative components. The term “single axis” here refers to the one dimension of the input tensors on which a tensor sparsification is performed.
[0081] Referring to the diagram in FIG. 4, the sparse tensor processing circuit may include a control circuit 400 and a computation module 450. The control circuit 400 receives neural network computation instructions from high level in the system, such as a host device, and dispatches the instructions to the components in the computation module to carry out the neural network computation.
[0082] In some embodiments, the control circuit 400 includes various components designed to manage and direct neural network computations. These components may include an instruction buffer configured to receive computation instructions, such as memory addresses for input tensors, the type of computation to be performed, and the destination memory address for storing the output tensor. The control circuit 400 also comprises local (engine) registers, which serve as the interface for configuring and instructing the computation module 450. The control circuit 400 may further include an instruction parser for interpreting the instructions within the instruction queue. Additionally, the control circuit 400 includes a register read / write controller that is used to get necessary data flow read / write control information from control / status registers (CSR) or instructions, a pipeline instruction buffer that acts as a staging area for buffering instructions, local registers that materialize the configurations specified by the engine registers, and pipeline controller responsible for executing the instructions fetched from the pipeline instruction buffer.
[0083] In some embodiments, the computation module 450 implements a pipeline for executing the neural network computations with precision compensation, specifically to compensate the precision loss of the low-magnitude tensor data caused by sparsification.
[0084] As shown, the computation module 450 may include a data distribute interface accepting input data as well as other parameters from the control circuit 400, a first tensor L1 cache 451, a second tensor L1 cache 453, a tensor mask L1 Cache 455, a tensor compensation L1 cache 456, a precision compensation module 457, a reconfigurable gather circuit 460, a plurality of cast circuits 461A-461C (denoted as Cast 461A, Cast 461B and Cast 461C in FIG. 4) , a multiplier array 470, an adder tree module 480, a first scaling multiplier module 484, a second scaling multiplier module 485, a compensation adder circuit 487, a scale parameter cache 486, an accumulation circuit 490 (denoted as ACC Circuit 490 in FIG. 4) , an accumulate cache 488 (denoted as ACC Cache 488 in FIG. 4) , and a shared memory 494.
[0085] A basic neural network computation involves two tensors, such as an activation tensor and a weight tensor. In the context of a convolutional neural network (CNN) , the activation tensor typically represents the input data or the outputs (activations or features) from a previous layer, such as an image or feature maps derived from earlier layers. This tensor holds the features that will be processed and analyzed in the current layer. The weight tensor, on the other hand, contains the filter or kernel weights unique to the layer, which are learned during training. These weights determine how features such as edges, textures, or patterns are detected by applying convolutions across the spatial dimensions of the activation tensor. The convolution operation combines these two tensors, producing an output tensor that reflects the presence and strength of specific features in the input. This process enables the CNN to learn hierarchical representations, with each layer progressively capturing more complex patterns in the data.
[0086] In FIG. 4, the first tensor L1 cache 451 and the second tensor L1 cache 453 are configured to cache the input tensors, including a first tensor (e.g., the activation tensor) and a second tensor (e.g., the weight tensor) . As a part of sparsification, a tensor mask of the first tensor is needed. In some embodiments, the tensor mask is a bitmask received from the control circuit or computed by the computation module 450. The tensor mask includes (1) position information of the high-magnitude tensor data (e.g., non-zero data or data exceeding a specific threshold) of the second tensor, called high-precision mask, as well as (2) multi-bits encodings of the low-magnitude tensor data of the second tensor, called low-precision mask.
[0087] In a specific example, the first tensor L1 cache 451 is configured to store the activation tensor, while the second tensor L1 cache 453 is configured to store the weight tensor. The activation tensor is represented as a sparse tensor, comprising a condensed activation tensor and a tensor mask. The condensed activation tensor includes the high-magnitude features of the sparse activation tensor, referred to as the “effective tensor data” for computation, while low-magnitude features are excluded. The tensor mask provides (1) positional information for the high-magnitude activation features and (2) multi-bit encodings for the low-magnitude activation features.
[0088] To facilitate computation between the high-magnitude activation features in the condensed activation tensor and their corresponding weights in the weight tensor, the tensor mask of the activation tensor may be utilized to gather the “effective” weights from the weight tensor that correspond to the high-magnitude activation features. These gathered weights can be compressed into a condensed weight tensor. The computation is performed based on the condensed weight tensor, the condensed activation tensor, and the tensor mask.
[0089] In some embodiments, the roles of the weight tensor and the activation tensor described in the previous sections may be interchanged. For clarity and as an illustrative example, the following description assumes that the first tensor, stored in the src tensor 0 L1 cache 451, represents the activation tensor, while the second tensor, stored in the src tensor 1 L1 cache 453, represents the weight tensor. Additionally, the tensor mask, stored in the src mask L1 cache 455, represents the bitmask associated with the activation tensor. This bitmask can be used to selectively gather the “effective” weights from the weight tensor, enabling computation with the “effective” high-magnitude activation features in the condensed format of the activation tensor.
[0090] Referring back to FIG. 4, the split circuit 454 may receive the tensor mask, and split into two parts: the first part including the high-precision mask and being stored in the src mask L1 cache 455, the second part including the low-precision mask and being stored in the src comp L1 cache.
[0091] The high-precision mask in src mask L1 cache 455 and low-precision mask in the src comp L1 cache 456 may serve different purposes in the computation process. For example, the high-precision mask (e.g., the position information of the high-magnitude tensor data) in src mask L1 cache 455 may be used as an input to the reconfigurable gather circuit 460 (along with second tensor itself from the other input from the src tensor 1 L1 cache 453) , which will gather the weights from the weight tensor that correspond to the high-magnitude activation features. The gathering may be based on the position information and the gathered weights may form a condensed weight tensor. This condensed weight tensor will be used for computation with the activation tensor in the subsequent modules such as the multiplier array 470, etc.
[0092] In comparison, the low-precision mask (e.g., the multi-bits encodings of the low-magnitude tensor data) in the src comp L1 cache 456 will be used to compensate the loss of precision, which is caused by the low-magnitude activation features being pruned out (or zero-ed out) from the activation tensor. In particular, both the weight tensor from the src tensor 1 L1 cache 453 and the multi-bits encodings of the activation tensor mask from the src comp L1 cache 456 are used as inputs to the precision compensation module 457. The precision compensation module 457 may generate the precision compensate values based on the inputs, which will be then used to generate the scaling multipliers (stored in scaling multiplier module 485) for the low-magnitude activation features. Detailed description of an example precision compensation module 457 are provided in FIG. 5.
[0093] In some embodiments, the reconfigurable gather circuit 460 is configured to receive data from the second tensor L1 cache 453 and the tensor mask L1 cache 455, and execute the sparsification of the second tensor based on the tensor mask. The sparsification transforms the second tensor from a dense format into a condensed format based on the tensor mask.
[0094] In some embodiments, sparsification of the second tensor may alter its data type, for example, converting it from a high-precision format (e.g., 32-bit in the dense format) to a low-precision format (e.g., 8-bit in the condensed format) , while the first tensor in the first tensor L1 cache 451 remains in its original format (e.g., either a dense format or a condensed format from anther engine) . To continue tensor operations, these two tensors are passed through cast circuits for data type conversion, ensuring they are converted to the same data type. The output from the cast circuits is then fed into the multiplier array 470 to proceed with the computation. As illustrated in FIG. 4, a first cast circuit 461A is connected to the first tensor L1 cache 451 for casting the first tensor, and a second cast circuit 461B is connected to the reconfigurable gather circuit 460 to cast the condensed format of the second tensor.
[0095] In some embodiments, the multiplier array 470 performs the tensor computation based on the first tensor and the condensed format of the second tensor, and generate an intermediate tensor. The intermedia tensor may be fed into the adder tree 480 for accumulation, thereby completing one cycle of MAC (Multiplication-and-Accumulation) operations on the input tensors.
[0096] Subsequently, the output of the adder tree 480 may go through the first scaling multiplier module 484 based on a scale parameter stored in the scale param cache 486, targeting the high-precision (HP) output tensor data generated based on the high-magnitude activations. The scaling process on the tensor may include adjusting the magnitude or range of tensor values before the subsequent accumulation with another intermediate tensor. This scaling process may be needed to support mixed-precision techniques, where different parts of the computation in the sparse tensor processing circuit use varying levels of numerical precision to balance performance and accuracy.
[0097] While the first scaling multiplier module 484 targets the HP part of the output of the adder tree 480, the second scaling multiplier module 485 targets the LP part of the output of the adder tree 480. The scaling factor in the second scaling multiplier module 485 is generated based on a corresponding parameter from the scale L1 cache 486 (the parameter was generated during the symmetric quantization of the high-magnitude and low-magnitude tensor data at the sort engine, e.g., the sort engine in the PE 140 in FIG. 1B) and the precision compensate values generated from the precision compensation module 457. The two scaling multipliers may be applied to the output of the adder tree 480 in the compensation adder module 487 to generate an adjusted intermediate tensor (e.g., the scaling multiplier 484 may be first applied to the intermediate tensor from the adder tree 480, targeting the high-magnitude tensor data, and the resulting tensor is stored in the comp adder 487. Then the scaling multiplier 485 may be applied to the tensor in the compensation adder 487, targeting the low-magnitude tensor data, to generate the adjusted intermediate tensor) . The separation of the first tensor mask cache and the second tensor mask cache allows the computation circuit and the precision compensation circuit to execute in parallel.
[0098] The accumulation circuit 490 may be configured to perform summation on the adjusted intermediate tensor output from the compensation adder 487 and another tensor read from the accumulate cache 488 (e.g., another intermedia tensor from a previous computation cycle) . In some cases, the output of the accumulation circuit 490 may be stored in the accumulate cache 488 for the next round of computation. In other cases, the output of the accumulation circuit 490 may go through another cast circuit 461C before being stored into the shared memory 494 as the output tensor of the neural network computation.
[0099] FIG. 5 illustrates an exemplary architecture diagram of the precision compensation circuit 457, in accordance with various embodiments. The precision compensation circuit 457 depicted in FIG. 5 utilizes the same hardware to handle both 2-bit and 3-bit encodings. The inputs to the precision compensation circuit 457 include the weights from the weight tensor and the activation tensor mask. The output of the precision compensation circuit 457 includes precision adjustment parameters corresponding to the low-precision values in the intermediate tensor generated by the multiplier array 470. In some embodiments, these precision adjustment parameters include channel-wise adjustment parameters.
[0100] As shown in FIG. 5, the precision compensation circuit 457 includes a pair of ternary blocks (510 and 530) along with their respective mask process 502. The mask process 502 receives either a 2-bit encoding (e.g., a 2-bit mask value) or a 3-bit encoding (e.g., a 3-bit mask value) and generates a 2-bit encoding. Specifically, if the input is a 2-bit encoding, it passes through the mask process 502 unchanged; if the input is a 3-bit encoding, a mask split operation is performed where the 3-bit encoding is split into a pair of 2-bit encodings. More details on the mask split are shown in FIG. 6.
[0101] With the mask process 502, each ternary block (510 and 530) receives a 2-bit encoding from the weight mask and performs a channel-wise computation to generate a channel-specific adjustment parameter based on the 2-bit encoding and corresponding weight from the weight tensor to adjust the corresponding tensor element in the intermediate tensor.
[0102] If the activation tensor mask uses 2-bit encoding, the outputs of ternary blocks 510 and 530 are both passed through the selector. In this case, ternary blocks 510 and 530 process two channels of weights simultaneously.
[0103] If the activation tensor mask uses 3-bit encoding, each 3-bit mask value is split into a pair of 2-bit encodings-such as the first encoding with the sign bit and a high bit, and the second encoding with the sign bit and a low bit-which are processed by ternary blocks 510 and 530 in parallel. This means that ternary blocks 510 and 530 process the same channel simultaneously. Specifically, the outputs of ternary blocks 510 and 530 are combined through an adder 550 to generate the channel-specific adjustment parameter to adjust the corresponding tensor element in the intermediate tensor. Before feeding into the adder 550, the output of the ternary block handling the 2-bit encoding with the high bit needs to be shifted left to align with the output of the other ternary block handling the 2-bit encoding with the low bit.
[0104] Within each ternary block (510 or 530) , there are multiple ternary gates 512 working in parallel, handling weights from the same weight channel. The outputs of the ternary gates 512 are aggregated in an adder tree 518 to generate the channel-specific adjustment parameter to adjust the corresponding tensor element in the intermediate tensor.
[0105] Within each ternary gate 512, a three-way selector is implemented to process one weight from the weight tensor at a time. The three-way selector uses the 2-bit mask as the selection logic. For example, the different 2-bit values-01 (representing “+1” ) , 10 (representing “0” , more specifically, “-0” in FIG. 3) , and 11 (representing “-1” ) -are used to select one of three data paths: a bypass path (e.g., the weight remains the same) , a zero path (e.g., the weight is set to 0) , and a negative path (e.g., the sign bit of the weight is switched) .
[0106] Here, the use of ternary gates 512 within the precision compensation circuit replicates the functionality of multiplier circuits without employing actual multiplier gates. Specifically, the multiplication of the weights in the weight tensor and the corresponding low-bit mask values is performed using these ternary gates. This design choice reduces hardware costs and chip footprint by simplifying the computational logic.
[0107] In traditional hardware implementations, multiplication operations require circuitry composed of numerous logic gates and transistors to perform bit-wise multiplication. These circuits occupy substantial silicon area, increase power consumption, and add to manufacturing costs due to their complexity. In contrast, the ternary gates 512 in FIG. 5 perform multiplication through straightforward logical operations. Each ternary gate functions as a three-way selector, processing one weight from the weight tensor at a time using a 2-bit mask as the selection logic.
[0108] In comparison to multiplier circuits, the ternary gates 512 simplifies the logic required in the circuit by reducing the number of transistors compared to traditional multiplier circuits. Multipliers involve complex arrangements of adders and logic gates to handle bit-wise multiplication, leading to larger and more intricate designs. In contrast, ternary gates perform selection and sign inversion using fewer logic components, reducing power consumption. In addition, replacing multipliers with ternary gates 512 reduces the overall silicon area needed for the circuit. This decrease in silicon footprint allows more functionality to be integrated into the same chip area or enables a reduction in chip size, resulting in cost savings in silicon usage.
[0109] FIG. 6 illustrate an example method of sparse encoding that enables precision compensation, in accordance with various embodiments.
[0110] As explained above, the specific design of the bitmasks in this disclosure uses the same data format to carry multiple pieces of information. In particular, instead of using single bits in the bitmask to only differentiate high-magnitude tensor data and low-magnitude tensor data, the multi-bit bitmask in this disclosure uses two or more bits, including a sign bit and subsequent value bit (s) to carry precision information.
[0111] The top section of FIG. 6 illustrates a two-bits bitmask, in which the first bit is the sign bit, and the second bit (M0) is the value bit. With these two bits, four different values may be represented. For instance, the high-magnitude tensor data (denoted as NNZ in FIG. 6) may be represented using 00b (i.e., “0” ) , and the entries in the bitmask with 00b correspond to the positions of high-magnitude tensor data. The bits 11b (i.e., “-1” ) , 10b (i.e., “-0” ) , and 01b ( “1” ) in the bitmask represent three different quantization values of the low-magnitude tensor data.
[0112] The bottom section of FIG. 6 illustrates a three-bits bitmask, in which the first bit is the sign bit, and the following two bits M1 and M0 are the value bits. A person skilled in the art would use all three bits for each entry in the bitmask to represent 8 different values. However, the inventors of the present disclosure further exploit the potential of the three bits by combining the sign bit with each of the two values bits, forming a pair of two-bits representations. This way, multi-ternary representation may be achieved. The split of the 3-bit encoding in FIG. 6 provides an example on how the mask split in FIG. 5 works. For instance, the bin code 110b ( “-2” ) may have a first ternary value of 10b and a second ternary value of 11b. Each bin code in this case may carry two different ternary values.
[0113] This pattern can be extended to 5-bits bitmasks, using the first bit as the sign bit, combining with each of the subsequent bits to form the multi-ternary representations.
[0114] FIG. 7 illustrate an example process 700 of precision compensation for sparse neural network computation, in accordance with various embodiments. In some implementations, one or more process blocks of FIG. 7 may be performed by a device .
[0115] As shown in FIG. 7, process 700 may include generating a tensor mask for the activation tensor. The activation tensor is sparse and the tensor mask is a part of a sparse representation of the activation tensor. The sparse representation of the activation tensor cause loss of computation precision in in exchange for a reduced memory footprint. The tensor mask comprises (1) information of high-magnitude features in the activation tensor and (2) information of low-magnitude features in the activation tensor, wherein the information of low-magnitude features comprises encodings of the low-magnitude features configured to compensate the loss of computation precision (block 710) .
[0116] As also shown in FIG. 7, process 700 may include performing a neural network computation based on the weight tensor, the tensor mask, and the activation tensor to generate an intermediate tensor (block 720) . For example, the device may perform a neural network computation based on the weight tensor, the tensor mask, and the activation tensor to generate an intermediate tensor, as described above.
[0117] As further shown in FIG. 7, process 700 may include adjusting the intermediate tensor to compensate the loss of precision of the low-magnitude features based on the weight tensor and the tensor mask (block 730) . For example, the device may adjust the intermediate tensor to compensate the loss of precision of the low-magnitude features based on the weight tensor and the tensor mask, as described above.
[0118] As also shown in FIG. 7, process 700 may include performing summation operations based on the adjusted intermediate tensor and a previously cached tensor from an accumulate cache, thereby generating an output tensor of the neural network computation (block 740) . For example, the device may perform summation operations based on the adjusted intermediate tensor and a previously cached tensor from an accumulate cache, thereby generating an output tensor of the neural network computation, as described above.
[0119] Process 700 may include additional implementations, such as any single implementation or any combination of implementations described below and / or in connection with one or more other processes described elsewhere herein. In a first implementation, the performing the neural network computation may include: transforming, using a gather circuit, the weight tensor into a condensed tensor based on the tensor mask, the condensed tensor having weights in the weight tensor that correspond to the high-magnitude features in the activation tensor; and performing the neural network computation based on the condensed tensor and the activation tensor.
[0120] In a second implementation, alone or in combination with the first implementation, the generating the tensor mask for the weight tensor may include: generating a first tensor mask to cache position information of high-magnitude features in the activation tensor; and generating a second tensor mask to cache the encodings of low-magnitude features in the activation tensor.
[0121] In a third implementation, alone or in combination with the first and second implementation, the encodings of the low-magnitude features in the activation tensor are 2-bit or 3-bit encodings.
[0122] In a fourth implementation, alone or in combination with one or more of the first through third implementations, the adjusting the intermediate tensor to compensate the loss of precision may include: in response to the encodings of the low-magnitude features being 2-bit encodings, generating channel-specific adjusting parameters based on the 2-bit encodings and corresponding weights from the weight tensor, where the channel-specific adjusting parameters are used to adjust the corresponding tensor elements in the intermediate tensor.
[0123] In a fifth implementation, alone or in combination with one or more of the first through fourth implementations, the adjusting the intermediate tensor to compensate the loss of precision may include: in response to the encodings of the low-magnitude features being 3-bit encodings, splitting each 3-bit encoding into a pair of 2-bit encoding, generating a generating a channel-specific adjusting parameter based on the pair of 2-bit encodings and corresponding weights from the weight tensor, where the channel-specific adjusting parameter is used to adjust the corresponding tensor element in the intermediate tensor.
[0124] In a sixth implementation, alone or in combination with one or more of the first through fifth implementations, each 3-bit encoding may include a sign bit, a first bit, and a second bit, and the splitting the 3-bit encoding into the pair of 2-bit encoding may include: forming a first 2-bit encoding using the sign bit and the first bit; and forming a second 2-bit encoding using the sign bit and the second bit.
[0125] In a seventh implementation, alone or in combination with one or more of the first through sixth implementations, the encodings of the low-magnitude features in the activation tensor are K-bit encodings, where K is an integer greater than 3.
[0126] Although FIG. 7 shows example blocks of process 700, in some implementations, process 700 may include additional blocks, fewer blocks, different blocks, or differently arranged blocks than those depicted in FIG. 7. Additionally, or alternatively, two or more of the blocks of process 700 may be performed in parallel.
[0127] The performance of certain of the operations may be distributed among the processors, not only residing within a single machine, but deployed across a number of machines. In some example embodiments, the processors or processor-implemented engines may be located in a single geographic location (e.g., within a home environment, an office environment, or a server farm) . In other example embodiments, the processors or processor-implemented engines may be distributed across a number of geographic locations.
[0128] Each of the processes, methods, and algorithms described in the preceding sections may be embodied in, and fully or partially automated by, code modules executed by one or more computer systems or computer processors comprising computer hardware. The processes and algorithms may be implemented partially or wholly in application-specific circuit.
[0129] When the functions disclosed herein are implemented in the form of software functional circuits and sold or used as independent products, they can be stored in a processor executable non-volatile computer-readable storage medium. Particular technical solutions disclosed herein (in whole or in part) or aspects that contributes to current technologies may be embodied in the form of a software product. The software product may be stored in a storage medium, comprising a number of instructions to cause a computing device (which may be a personal computer, a server, a network device, and the like) to execute all or some steps of the methods of the embodiments of the present application. The storage medium may comprise a flash drive, a portable hard drive, ROM, RAM, a magnetic disk, an optical disc, another medium operable to store program code, or any combination thereof.
[0130] Particular embodiments further provide a system comprising a processor and a non-transitory computer-readable storage medium storing instructions executable by the processor to cause the system to perform operations corresponding to steps in any method of the embodiments disclosed above. Particular embodiments further provide a non-transitory computer-readable storage medium configured with instructions executable by one or more processors to cause the one or more processors to perform operations corresponding to steps in any method of the embodiments disclosed above.
[0131] Embodiments disclosed herein may be implemented through a cloud platform, a server or a server group (hereinafter collectively the “service system” ) that interacts with a client. The client may be a terminal device, or a client registered by a user at a platform, wherein the terminal device may be a mobile terminal, a personal computer (PC) , and any device that may be installed with a platform application program.
[0132] The various features and processes described above may be used independently of one another or may be combined in various ways. All possible combinations and sub-combinations are intended to fall within the scope of this disclosure. In addition, certain method or process blocks may be omitted in some implementations. The methods and processes described herein are also not limited to any particular sequence, and the blocks or states relating thereto can be performed in other sequences that are appropriate. For example, described blocks or states may be performed in an order other than that specifically disclosed, or multiple blocks or states may be combined in a single block or state. The example blocks or states may be performed in serial, in parallel, or in some other manner. Blocks or states may be added to or removed from the disclosed example embodiments. The exemplary systems and components described herein may be configured differently than described. For example, elements may be added to, removed from, or rearranged compared to the disclosed example embodiments.
[0133] The various operations of exemplary methods described herein may be performed, at least partially, by an algorithm. The algorithm may be comprised in program codes or instructions stored in a memory (e.g., a non-transitory computer-readable storage medium described above) . Such algorithm may comprise a machine learning algorithm. In some embodiments, a machine learning algorithm may not explicitly program computers to perform a function but can learn from training samples to make a prediction model that performs the function.
[0134] The various operations of exemplary methods described herein may be performed, at least partially, by one or more processors that are temporarily configured (e.g., by software) or permanently configured to perform the relevant operations. Whether temporarily or permanently configured, such processors may constitute processor-implemented engines that operate to perform one or more operations or functions described herein.
[0135] Similarly, the methods described herein may be at least partially processor-implemented, with a particular processor or processors being an example of hardware. For example, at least some of the operations of a method may be performed by one or more processors or processor-implemented engines. Moreover, the one or more processors may also operate to support performance of the relevant operations in a “cloud computing” environment or as a “software as a service” (SaaS) . For example, at least some of the operations may be performed by a group of computers (as examples of machines including processors) , with these operations being accessible via a network (e.g., the Internet) and via one or more appropriate interfaces (e.g., an Application Program Interface (API) ) .
[0136] The performance of certain of the operations may be distributed among the processors, not only residing within a single machine, but deployed across a number of machines. In some example embodiments, the processors or processor-implemented engines may be located in a single geographic location (e.g., within a home environment, an office environment, or a server farm) . In other example embodiments, the processors or processor-implemented engines may be distributed across a number of geographic locations.
[0137] Throughout this specification, plural instances may implement components, operations, or structures described as a single instance. Although individual operations of one or more methods are illustrated and described as separate operations, one or more of the individual operations may be performed concurrently, and nothing requires that the operations be performed in the order illustrated. Structures and functionality presented as separate components in example configurations may be implemented as a combined structure or component. Similarly, structures and functionality presented as a single component may be implemented as separate components. These and other variations, modifications, additions, and improvements fall within the scope of the subject matter herein.
[0138] As used herein, “or” is inclusive and not exclusive, unless expressly indicated otherwise or indicated otherwise by context. Therefore, herein, “A, B, or C” means “A, B, A and B, A and C, B and C, or A, B, and C, ” unless expressly indicated otherwise or indicated otherwise by context. Moreover, “and” is both joint and several, unless expressly indicated otherwise or indicated otherwise by context. Therefore, herein, “A and B” means “A and B, jointly or severally, ” unless expressly indicated otherwise or indicated otherwise by context. Moreover, plural instances may be provided for resources, operations, or structures described herein as a single instance. Additionally, boundaries between various resources, operations, engines, and data stores are somewhat arbitrary, and particular operations are illustrated in a context of specific illustrative configurations. Other allocations of functionality are envisioned and may fall within a scope of various embodiments of the present disclosure. In general, structures and functionality presented as separate resources in the example configurations may be implemented as a combined structure or resource. Similarly, structures and functionality presented as a single resource may be implemented as separate resources. These and other variations, modifications, additions, and improvements fall within a scope of embodiments of the present disclosure as represented by the appended claims. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.
[0139] The term “include” or “comprise” is used to indicate the existence of the subsequently declared features, but it does not exclude the addition of other features. Conditional language, such as, among others, “can, ” “could, ” “might, ” or “may, ” unless specifically stated otherwise, or otherwise understood within the context as used, is generally intended to convey that certain embodiments include, while other embodiments do not include, certain features, elements and / or steps. Thus, such conditional language is not generally intended to imply that features, elements and / or steps are in any way required for one or more embodiments or that one or more embodiments necessarily include logic for deciding, with or without user input or prompting, whether these features, elements and / or steps are included or are to be performed in any particular embodiment.
[0140] Although an overview of the subject matter has been described with reference to specific example embodiments, various modifications and changes may be made to these embodiments without departing from the broader scope of embodiments of the present disclosure. Such embodiments of the subject matter may be referred to herein, individually or collectively, by the term “invention” merely for convenience and without intending to voluntarily limit the scope of this application to any single disclosure or concept if more than one is, in fact, disclosed.
[0141] The embodiments illustrated herein are described in sufficient detail to enable those skilled in the art to practice the teachings disclosed. Other embodiments may be used and derived therefrom, such that structural and logical substitutions and changes may be made without departing from the scope of this disclosure. The Detailed Description, therefore, is not to be taken in a limiting sense, and the scope of various embodiments is defined only by the appended claims, along with the full range of equivalents to which such claims are entitled.
Claims
1.A tensor processing circuit with precision compensation for a neural network computation between a weight tensor and an activation tensor, comprising:a tensor cache configured to cache the weight tensor for the neural network computation;a tensor mask cache configured to cache a tensor mask corresponding to the activation tensor, wherein the activation tensor is sparse and the tensor mask is a part of a sparse representation of the activation tensor, the sparse representation of the activation tensor cause loss of computation precision in in exchange for a reduced memory footprint, and the tensor mask comprises (1) information of high-magnitude features in the activation tensor and (2) information of low-magnitude features in the activation tensor, wherein the information of low-magnitude features comprises encodings of the low-magnitude features configured to compensate the loss of computation precision;a computation circuit configured to perform the neural network computation based on the weight tensor, the tensor mask, and the activation tensor to generate an intermediate tensor;a precision compensation circuit configured to compensate the loss of computation precision by adjusting the intermediate tensor based on the weight tensor and the tensor mask; andan accumulation circuit configured to perform summation operations based on the adjusted intermediate tensor and a previously cached tensor from an accumulate cache, thereby generating an output tensor of the neural network computation.2.The tensor processing circuit of claim 1, wherein the computation circuit comprises:a gather circuit coupled to the tensor cache and the tensor mask cache, wherein the gather circuit is configured to gather weights in the weight tensor corresponding to the high-magnitude features in the activation tensor, consolidating the weights into a condensed tensor; anda multiplier array configured to receive the activation tensor and the condensed tensor from the gather circuit, and output the intermediate tensor.3.The tensor processing circuit of claim 1, wherein the tensor mask cache comprises a first tensor mask cache and a second tensor mask cache,the first tensor mask cache is configured to cache position information of high-magnitude features in the activation tensor, andthe second tensor mask cache is configured to cache the encodings of low-magnitude features in the activation tensor.4.The tensor processing circuit of claim 1, wherein:the computation circuit is coupled to the tensor cache and the tensor mask cache, and performs the neural network computation based on the high-magnitude features in the activation tensor, andthe precision compensation circuit is coupled to the tensor cache and the tensor mask cache, and performs precision compensation based on the low-magnitude features in the activation tensor.5.The tensor processing circuit of claim 3, wherein separation of the first tensor mask cache and the second tensor mask cache allows the computation circuit and the precision compensation circuit to execute in parallel.6.The tensor processing circuit of claim 1, wherein the encodings of the low-magnitude features in the activation tensor are 2-bit or 3-bit encodings.7.The tensor processing circuit of claim 1, wherein the precision compensation circuit comprises a plurality of ternary blocks, each comprising an adder tree configured to sum outputs from a plurality of ternary gates.8.The tensor processing circuit of claim 7, wherein:in response to the encodings of the low-magnitude features being 2-bit encodings, each ternary block is configured to generate a channel-specific adjustment parameter.9.The tensor processing circuit of claim 8, wherein the channel-specific adjustment parameter is used to adjust the corresponding tensor element in the intermediate tensor.10.The tensor processing circuit of claim 7, wherein:in response to the encodings of the low-magnitude features being 3-bit encodings, the precision compensation circuit further comprises a mask split circuit to split each 3-bit encoding into a pair of 2-bit encodings, and a pair of ternary blocks are configured to collectively generate, based on the pair of 2-bit encodings and corresponding weights, a channel-specific adjustment parameter for adjusting the corresponding tensor element in the intermediate tensor.11.The tensor processing circuit of claim 1, wherein the precision compensation circuit comprises a plurality of ternary gates, in lieu of binary multiplier gates, to perform multiplications between weights in the weight tensor and corresponding encodings in the tensor mask.12.The tensor processing circuit of claim 11, wherein the plurality of ternary gates result in a smaller chip size in comparison with using the binary multiplier gates.13.A method for compensating data precision in a sparsified neural network computation between a weight tensor and an activation tensor, comprising:generating a tensor mask for the activation tensor, wherein the activation tensor is sparse and the tensor mask is a part of a sparse representation of the activation tensor, the sparse representation of the activation tensor cause loss of computation precision in in exchange for a reduced memory footprint, and the tensor mask comprises (1) information of high-magnitude features in the activation tensor and (2) information of low-magnitude features in the activation tensor, wherein the information of low-magnitude features comprises encodings of the low-magnitude features configured to compensate the loss of computation precision;performing a neural network computation based on the weight tensor, the tensor mask, and the activation tensor to generate an intermediate tensor;adjusting the intermediate tensor to compensate the loss of computation precision of the low-magnitude features based on the weight tensor and the tensor mask; andperforming summation operations based on the adjusted intermediate tensor and a previously cached tensor from an accumulate cache, thereby generating an output tensor of the neural network computation.14.The method of claim 13, wherein the performing the neural network computation comprises:transforming, using a gather circuit, the weight tensor into a condensed tensor based on the tensor mask, the condensed tensor comprising weights in the weight tensor that correspond to the high-magnitude features in the activation tensor; andperforming the neural network computation based on the condensed tensor and the activation tensor.15.The method of claim 13, wherein the generating the tensor mask for the weight tensor comprises:generating a first tensor mask to cache position information of high-magnitude features in the activation tensor; andgenerating a second tensor mask to cache the encodings of low-magnitude features in the activation tensor.16.The method of claim 13, wherein the encodings of the low-magnitude features in the activation tensor are 2-bit or 3-bit encodings.17.The method of claim 13, wherein the adjusting the intermediate tensor to compensate the loss of computation precision comprises:in response to the encodings of the low-magnitude features being 2-bit encodings, generating channel-specific adjusting parameters based on the 2-bit encodings and corresponding weights from the weight tensor, wherein the channel-specific adjusting parameters are used to adjust the corresponding tensor elements in the intermediate tensor.18.The method of claim 13, wherein the adjusting the intermediate tensor to compensate the loss of computation precision comprises:in response to the encodings of the low-magnitude features being 3-bit encodings, splitting each 3-bit encoding into a pair of 2-bit encoding, and generating, based on the pair of 2-bit encodings and corresponding weights from the weight tensor, a channel-specific adjustment parameter for adjusting the corresponding tensor element in the intermediate tensor.19.The method of claim 18, wherein each 3-bit encoding comprises a sign bit, a first bit, and a second bit, and the splitting the 3-bit encoding into the pair of 2-bit encoding comprises:forming a first 2-bit encoding using the sign bit and the first bit; andforming a second 2-bit encoding using the sign bit and the second bit.20.The method of claim 13, wherein the encodings of the low-magnitude features in the activation tensor are K-bit encodings, wherein K is an integer greater than 3.