This application claims the benefit under 35 USC § 119(a) of Korean Patent Application No. 10-2020-0074268 filed on Jun. 18, 2020 in the Korean Intellectual Property Office, the entire disclosure of which is incorporated herein by reference for all purposes.
The following description relates to method, an accelerator, and an electronic device with tensor processing.
Independent hardware may be dedicated to artificial intelligence (AI) technology. For example, AI may perform inference and learning through predetermined operations. As such, various devices may be exclusive hardware for implementing and executing AI.
The exclusive hardware for AI may be implemented by, for example, a graphics processing unit (GPU), or implemented by a field-programmable gate array (FPGA), and an application-specific integrated circuit (ASIC) of changeable use.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
In one general aspect, a processor-implemented tensor processing method includes: receiving a request to process a neural network including a normalization layer by an accelerator; and generating an instruction executable by the accelerator in response to the request, wherein, by executing the instruction, the accelerator is configured to determine an intermediate tensor corresponding to a result of performing a portion of operations included in the normalization layer, by performing, in a channel axis direction, a convolution based on: a target tensor on which the portion of operations is to be performed; and a kernel having a number of input channels and a number of output channels determined based on the target tensor and including elements of scaling values determined based on the target tensor.
The accelerator may be configured to determine the intermediate tensor by extracting diagonal elements from a result tensor determined by the convolution based on the target tensor and the kernel.
The number of input channels of the kernel may be determined based on a number of elements of a normalization unit applied to the target tensor.
The number of elements of the normalization unit applied to the target tensor may be equal to a number of channels of the input tensor, and the number of input channels of the kernel may be equal to the number of channels of the input tensor.
The number of output channels of the kernel is determined based on a width length of the target tensor.
A scaling value of each of the elements included in the kernel may include a runtime value corresponding to the target tensor.
A scaling value of each of the elements included in the kernel may be equal to a value of a corresponding element in the target tensor.
The target tensor may be determined based on: an average subtraction tensor comprising values determined by subtracting a value of each of elements included in an input tensor of the normalization layer from an average value of the elements; and a constant value determined based on a number of elements of a normalization unit applied to the target tensor.
The target tensor may be determined by performing, in a channel axis direction, a convolution based on: the average subtraction tensor; and a second kernel having a number of input channels and a number of output channels determined based on the average subtraction tensor and including diagonal elements of scaling values determined based on the constant value.
The number of input channels and the number of output channels of the second kernel may be equal to the number of elements of the normalization unit, and the diagonal elements in the second kernel may have different scaling values from those of the remaining elements.
The constant value may be equal to a square root of the number of elements of a normalization unit applied to the target tensor, and the scaling values of the second kernel may be equal to an inverse of the square root.
The normalization layer may be configured to perform normalization using either one or both of an average and a variance determined based on values of one or more elements included in the target tensor.
The convolution may be performed between the kernel and an input tensor transformed such that elements included in the same channel are arranged in a line, and the intermediate tensor may be determined by transforming elements determined as a result of the convolution to the same form as the input tensor.
The convolution may be performed in the accelerator such that the target tensor is not transmitted outside the accelerator to perform an operation according to the normalization layer.
The accelerator may be included in either one of: a user terminal into which data to be inferred using the neural network is input; and a server that receives the data to be inferred from the user terminal.
A non-transitory computer-readable storage medium may store instructions that, when executed by a processor, configure the processor to perform the method.
In another general aspect, an accelerator includes: one or more processors configured to: determine a target tensor on which a portion of operations included in a normalization layer in a neural network is to be performed; determine a kernel having a number of input channels and a number of output channels determined based on the target tensor and including elements of scaling values determined based on the target tensor; and determine an intermediate tensor corresponding to a result of performing the portion of operations by performing, in a channel axis direction, a convolution based on the target tensor and the kernel.
The one or more processors may be configured to determine the intermediate tensor by extracting diagonal elements from a result tensor determined by the convolution based on the target tensor and the kernel.
The number of input channels determined of the kernel may be based on a number of elements of a normalization unit applied to the target tensor.
A scaling value of each of the elements included in the kernel may include a runtime value corresponding to the target tensor.
A scaling value of each of the elements included in the kernel may be equal to a value of a corresponding element in the target tensor.
In another general aspect, an electronic device includes: a host processor configured to generate an instruction executable by an accelerator in response to a request to process a neural network including a normalization layer by the accelerator; and the accelerator configured to, by executing the instruction, determine an intermediate tensor corresponding to a result of performing a portion of operations included in the normalization layer, by performing, in a channel axis direction, a convolution based on a target tensor on which the portion of operations is to be performed, and a kernel having a number of input channels and a number of output channels determined based on the target tensor and including elements of scaling values determined based on the target tensor.
In another general aspect, an electronic device includes: a host processor configured to generate an instruction in response to a request for a data inference result; and an accelerator configured to, by executing the instruction: perform operations of a normalization layer of a neural network by performing a convolution based on a target tensor, and a kernel having a number of input channels and a number of output channels determined based on the target tensor and including elements of scaling values determined based on the target tensor; and determine the data inference result based the performing of the operations.
The data inference result may be any one of a speech recognition, a machine translation, a machine interpretation, an object recognition, a pattern recognition, and computer vision.
Other features and aspects will be apparent from the following detailed description, the drawings, and the claims.
Throughout the drawings and the detailed description, unless otherwise described or provided, the same drawing reference numerals will be understood to refer to the same elements, features, and structures. The drawings may not be to scale, and the relative size, proportions, and depiction of elements in the drawings may be exaggerated for clarity, illustration, and convenience.
The following detailed description is provided to assist the reader in gaining a comprehensive understanding of the methods, apparatuses, and/or systems described herein. However, various changes, modifications, and equivalents of the methods, apparatuses, and/or systems described herein will be apparent after an understanding of the disclosure of this application. For example, the sequences of operations described herein are merely examples, and are not limited to those set forth herein, but may be changed as will be apparent after an understanding of the disclosure of this application, with the exception of operations necessarily occurring in a certain order. Also, descriptions of features that are known in the art, after an understanding of the disclosure of this application, may be omitted for increased clarity and conciseness.
Although terms of “first” or “second” are used herein to describe various members, components, regions, layers, or sections, these members, components, regions, layers, or sections are not to be limited by these terms. Rather, these terms are only used to distinguish one member, component, region, layer, or section from another member, component, region, layer, or section. Thus, a first member, component, region, layer, or section referred to in examples described herein may also be referred to as a second member, component, region, layer, or section without departing from the teachings of the examples.
Throughout the specification, when an element, such as a layer, region, or substrate, is described as being “on,” “connected to,” or “coupled to” another element, it may be directly “on,” “connected to,” or “coupled to” the other element, or there may be one or more other elements intervening therebetween. In contrast, when an element is described as being “directly on,” “directly connected to,” or “directly coupled to” another element, there can be no other elements intervening therebetween. Likewise, expressions, for example, “between” and “immediately between” and “adjacent to” and “immediately adjacent to” may also be construed as described in the foregoing.
The terminology used herein is for the purpose of describing particular examples only and is not to be limiting of the disclosure. As used herein, the singular forms “a”, “an”, and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. As used herein, the term “and/or” includes any one and any combination of any two or more of the associated listed items. As used herein, the terms “include,” “comprise,” and “have” specify the presence of stated features, numbers, operations, elements, components, and/or combinations thereof, but do not preclude the presence or addition of one or more other features, numbers, operations, elements, components, and/or combinations thereof. The use of the term “may” herein with respect to an example or embodiment (for example, as to what an example or embodiment may include or implement) means that at least one example or embodiment exists where such a feature is included or implemented, while all examples are not limited thereto.
Unless otherwise defined, all terms, including technical and scientific terms, used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure pertains consistent with and after an understanding of the present disclosure. Terms, such as those defined in commonly used dictionaries, are to be interpreted as having a meaning that is consistent with their meaning in the context of the relevant art and the present disclosure, and are not to be interpreted in an idealized or overly formal sense unless expressly so defined herein.
Hereinafter, examples will be described in detail with reference to the accompanying drawings. The following specific structural or functional descriptions are exemplary to merely describe the examples, and the scope of the examples is not limited to the descriptions provided in the present specification. Various changes and modifications can be made thereto by those of ordinary skill in the art based on an understanding of the disclosure of the present application. Like reference numerals in the drawings denote like elements, and a known function or configuration will be omitted herein.
Referring to
The host processor 110 may be a device that controls operations of components included in the electronic device 100, and may include, for example, a central processing unit (CPU). The host processor 110 may receive a request to process a neural network in the accelerator 140, and may generate an instruction executable by the accelerator 140 in response to the request. The request may be for data inference based on the neural network, and, in response to the generated instruction, the accelerator 140 may execute the neural network to obtain a data inference result for speech recognition, machine translation, machine interpretation, object recognition, pattern recognition, computer vision, and/or the like. The host processor 110 may transmit inference target data and parameters of the neural network to the accelerator 140.
The off-chip memory 120 may be a memory disposed outside the accelerator 140, and may be, for example, a dynamic random-access memory (DRAM) utilized as a main memory of the electronic device 100. The off-chip memory 120 may be accessed through the memory controller 130. The off-chip memory 120 may store the parameters of the neural network to be executed by the accelerator 140, and be utilized when an on-chip memory in the accelerator 140 is insufficient to execute the neural network by the accelerator 140.
The off-chip memory 120 may have a larger memory capacity than the on-chip memory in the accelerator 140. However, when the neural network is being executed, a memory access cost for the accelerator 140 accessing the off-chip memory 120 may be greater than a memory access cost for the accelerator 140 accessing the internal on-chip memory. The memory access cost may be a power and/or time required to access the corresponding memory and read or write data.
The accelerator 140 may be an AI accelerator that infers input data by executing the neural network according to the instruction of the host processor 110, and may be a separate processor different from the host processor 110. For example, the accelerator 140 may be a neural processing unit (NPU) (or neural processor), a graphics processing unit (GPU), or a tensor processing unit (TPU).
The accelerator 140 may process tasks that may be more efficiently processed by a separate exclusive processor (that is, the accelerator 140), rather than by the general-purpose host processor 110, due to the characteristics of the operations according to the neural network. In this example, the on-chip memory and one or more processing elements (PEs) included in the accelerator 140 may be utilized by the accelerator 140 in executing the neural network. The on-chip memory may be a global buffer included in the accelerator 140 and may be distinguished from the off-chip memory 120 disposed outside the accelerator 140. For example, the on-chip memory may be a scratchpad memory, a static random-access memory (SRAM), or the like that is accessible through an address space.
The neural network may include a plurality of layers. The neural network may include an input layer, a plurality of hidden layers, and an output layer. Each of the layers may include a plurality of nodes, also called artificial neurons. While the nodes may be referred to as “artificial neurons,” such reference is not intended to impart any relatedness with respect to how the neural network architecture computationally maps or thereby intuitively recognizes information and how a human's neurons operate. I.e., the term “artificial neurons” is merely a term of art referring to the hardware implemented nodes of the neural network. Each node may be a calculation unit having one or more inputs and an output, and the nodes may be connected to each other. A weight may be set for a connection between nodes, and the weight may be adjusted or changed. The weight may amplify, reduce, or maintain a relevant data value, thereby determining a degree of influence of the data value on a final result. Weighted inputs of nodes included in a previous layer may be input into each node included in the output layer. A process of inputting weighted data from a predetermined layer to the next layer may be referred to as propagation.
To improve the performance of the neural network, normalization may be applied to data transferred between layers. In other words, data distribution may be normalized through a series of operations such as obtaining an average and/or a variance of data transferred from one layer to a next layer and dividing, by the variance, a result of subtracting a value of each element of the corresponding data from the average value. The normalization applied to the neural network may include, for example, layer normalization and instance normalization. Layer normalization may be a technique for performing normalization in a channel direction regardless of the batch size, and may be applied to models in language field, such as speech recognition, machine translation, and machine interpretation. Instance normalization may be a technique for normalizing the entire image in unit of channels by performing normalization in the width and height directions, and may be applied to, for example, a generative adversarial network (GAN).
In addition, when an attention technique is applied to a neural network for image processing, global average pooling in which a pooling window is in the size equal to the size of the entire image may be performed, and neural networks to which global average pooling is applied may include, for example, a spatial pyramid pooling network (SPPNet) and a squeeze and excitation network (SENet).
As described above, operations for performing normalization by the neural network may include an operation for calculating the average and/or variance each time data is transferred between layers. For such operations, a typical electronic device may transfer the data to be normalized to a special operator such as a host processor outside an accelerator, and a result of calculation by the special operator may be received again by the accelerator, and accordingly such data movement of the typical electronic device may increase latency and power consumption. Accordingly, to improve the performance of the electronic device 100, the electronic device 100 of one or more embodiments may minimize data movements outside the accelerator 140 by performing, inside the accelerator 140, the operations to perform normalization by the neural network.
To implement operations that are not directly supported by the accelerator 140, square sum and/or square mean operations may be replaced with convolution operations. Kernels used for the convolution operations may be determined based on the data to be normalized. Through this, the accelerator 140 may obtain output data identical to outputs that would be generated by directly performing operations specified by the normalization layer based on the convolution operations, even when the convolution operations do not match the operations specified by the normalization layer. In summary, the accelerator 140 may obtain output data equivalent to the outputs of the normalization layer, without transmitting the data to the special operator such as the host processor 110 even without correction of the hardware architecture.
Hereinafter, a detailed description will be provided with reference to the following drawings.
Referring to
For data normalization, operations according to the first normalization layer may be performed, and a tensor in which a portion of such operations is already performed may correspond to the input tensor of
A kernel shown in
Convolution between the input tensor and the kernel may be performed in the channel axis direction. In
According to another example, in an accelerator including a shifter and/or a divider, an operation of dividing by the square root of the number of elements belonging to the normalization unit applied to the input tensor may be performed in the shifter and/or the divider, without the convolution operation described above.
Referring to
An input tensor in an example of
A kernel shown in
Also, each element in the kernel may have a scaling value determined based on the input tensor. The scaling value of each element included in the kernel may include a runtime value corresponding to a target tensor (e.g., the input tensor). For example, the scaling value of each element included in the kernel may be equal to a value of a corresponding element in the target tensor.
Convolution between the input tensor and the kernel may be performed in the channel axis direction. First, scaling values a/2, b/2, c/2, and d/2 in a first column included in the kernel may be convolved to the input tensor, whereby elements in a first channel of an initial tensor (e.g., a result tensor) may be determined. For example, the first element values a/2, b/2, c/2, and d/2 in each channel of the input tensor may be multiplied by corresponding scaling values a/2, b/2, c/2, and d/2 of the first column of the kernel, respectively, and based on the sum thereof, a value of a first element in a first channel of the initial tensor may be determined to be (a2+b2+c2+d2)/4. Through the convolution operation described above, the square sum of the first element values a/2, b/2, c/2, and d/2 in each channel of the input tensor may be obtained. In the initial tensor, a value of a second element in the first channel may be determined through a convolution operation between second element values e/2, f/2, g/2, and h/2 in each channel of the input tensor and corresponding scaling values a/2, b/2, c/2, and d/2 of the kernel. However, since the convolution operation is performed to obtain a square sum, the value of the second element in the first channel of the initial tensor may be discarded, which will be described later. Likewise, a value of a third element in the first channel of the initial tensor may be discarded as well.
Further, scaling values e/2, f/2, g/2, and h/2 in a second column included in the kernel may be convolved to the input tensor, whereby elements in a second channel of the initial tensor may be determined. For example, the second element values e/2, f/2, g/2, and h/2 in each channel of the input tensor may be multiplied by corresponding scaling values e/2, f/2, g/2, and h/2 of the second column of the kernel, respectively, and based on the sum thereof, a value of a second element in a second channel of the initial tensor may be determined to be (e2+f2+g2+h2)/4. Likewise, the remaining element values may be determined. Further, scaling values i/2, j/2, k/2, and l/2 in a third column included in the kernel may be convolved to the input tensor, whereby elements in a third channel of the initial tensor may be determined.
In the example of
The square sum of elements belonging to a normalization unit applied to the input tensor of
As such, without a tensor being transmitted outside the accelerator, the variance of the tensor input into the normalization layer through two convolutional layers may be obtained by a multiplier-accumulator (MAC) included in the accelerator, thereby reducing a memory access cost. When the accelerator includes a shifter and/or a divider, the operation described in
According to another example, the operation described in
While the height of the input tensor is “1” in the previous non-limiting example, when either the width or the height is not “1”, the input tensor may be reshaped to make either the width or the height “1”, then the operations described above may be performed, and the obtained output tensor may be reshaped again to the original input tensor shape.
In addition, while the batch of the input tensor is “1” in the previous descriptions, when the batch is not “1”, the operations described above may be performed independently for each batch.
Referring to
For data normalization, operations according to the second normalization layer should be performed, and a tensor in which a portion of such operations is already performed may correspond to the input tensor of
In order to apply the convolution operation performed in the channel axis direction described above with reference to
A kernel shown in
Convolution between the input tensor and the kernel may be performed in the channel axis direction, and In
According to another example, if an accelerator includes a shifter and/or a divider, a convolution operation requiring a convolutional layer may be replaced with a division operation to be performed by the shifter and/or the divider. By utilizing the shifter and/or the divider, the number of convolutional layers for performing normalization may be reduced by “1”.
Referring to
An input tensor in an example of
A kernel shown in
Also, each element in the kernel may have a scaling value determined based on the input tensor. The scaling value of each element included in the kernel may include a runtime value corresponding to a target tensor. For example, the scaling value of each element included in the kernel may be equal to a value of a corresponding element in the target tensor.
Convolution between the input tensor and the kernel may be performed in the channel axis direction. The descriptions provided above (e.g., of the convolution between the input tensor and the kernel of
In the example of
As such, when the convolution operation of
When the convolution operation of
According to another example, the operation described in
While the batch of the input tensor is “1” in the previous non-limiting examples, when the batch is not “1”, the operations described above may be performed independently for each batch.
Referring to
Referring to
Referring to
Referring to
The tensor processing method may be applied for training or inference at an algorithm end, a compiler end, hardware of a network using multi-head attention such as automatic speech recognition (ASR), or a transformer. In addition, even when a low-precision quantization scheme is applied to the tensor processing method, the performance gain may be secured while the system accuracy may remain the same.
The descriptions provided above with reference to
Referring to
The server 1000 may be a separate device different from a user terminal controlled by a user, and may communicate with the user terminal through a wired and/or wireless network. Data to be inferred using a neural network may be collected from the user terminal and transmitted to the server 1000 through the network, and the server 1000 may process a normalization layer included in the neural network by an accelerator 1020 according to the tensor processing methods described above with reference to
The user terminal may simply provide the user with the inference result received from the server 1000, or perform a subsequent operation based on the inference result.
Referring to
The electronic devices, host processors, off-chip memories, memory controllers, accelerators, servers, user terminals, electronic device 100, host processor 110, off-chip memory 120, memory controller 130, accelerator 140, server 1000, host processor 1010, accelerator 1020, user terminal 1100, host processor 1110, accelerator 1120, and other apparatuses, devices, units, modules, and components described herein with respect to
The methods illustrated in
Instructions or software to control computing hardware, for example, one or more processors or computers, to implement the hardware components and perform the methods as described above may be written as computer programs, code segments, instructions or any combination thereof, for individually or collectively instructing or configuring the one or more processors or computers to operate as a machine or special-purpose computer to perform the operations that are performed by the hardware components and the methods as described above. In one example, the instructions or software include machine code that is directly executed by the one or more processors or computers, such as machine code produced by a compiler. In another example, the instructions or software includes higher-level code that is executed by the one or more processors or computer using an interpreter. The instructions or software may be written using any programming language based on the block diagrams and the flow charts illustrated in the drawings and the corresponding descriptions used herein, which disclose algorithms for performing the operations that are performed by the hardware components and the methods as described above.
The instructions or software to control computing hardware, for example, one or more processors or computers, to implement the hardware components and perform the methods as described above, and any associated data, data files, and data structures, may be recorded, stored, or fixed in or on one or more non-transitory computer-readable storage media. Examples of a non-transitory computer-readable storage medium include read-only memory (ROM), random-access programmable read only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random-access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, non-volatile memory, CD-ROMs, CD-Rs, CD+Rs, CD-RWs, CD+RWs, DVD-ROMs, DVD-Rs, DVD+Rs, DVD-RWs, DVD+RWs, DVD-RAMs, BD-ROMs, BD-Rs, BD-R LTHs, BD-REs, Blue-ray or optical disk storage, hard disk drive (HDD), solid state drive (SSD), flash memory, a card type memory such as multimedia card micro or a card (for example, secure digital (SD) or extreme digital (XD)), magnetic tapes, floppy disks, magneto-optical data storage devices, optical data storage devices, hard disks, solid-state disks, and any other device that is configured to store the instructions or software and any associated data, data files, and data structures in a non-transitory manner and provide the instructions or software and any associated data, data files, and data structures to one or more processors or computers so that the one or more processors or computers can execute the instructions. In one example, the instructions or software and any associated data, data files, and data structures are distributed over network-coupled computer systems so that the instructions and software and any associated data, data files, and data structures are stored, accessed, and executed in a distributed fashion by the one or more processors or computers.
While this disclosure includes specific examples, it will be apparent after an understanding of the disclosure of this application that various changes in form and details may be made in these examples without departing from the spirit and scope of the claims and their equivalents. The examples described herein are to be considered in a descriptive sense only, and not for purposes of limitation. Descriptions of features or aspects in each example are to be considered as being applicable to similar features or aspects in other examples. Suitable results may be achieved if the described techniques are performed in a different order, and/or if components in a described system, architecture, device, or circuit are combined in a different manner, and/or replaced or supplemented by other components or their equivalents.
Number | Date | Country | Kind |
---|---|---|---|
10-2020-0074268 | Jun 2020 | KR | national |