This is a free preview of a paid episode. To hear more, visit blog.codingconfessions.com
This last Sunday we did a live session on Groq’s LPU and after that many people reached out to me for the recording of the session. Although, we do have a recording (which I sent out yesterday) - I feel watching a recording is not as effective as attending a session live because a lot of discussion is driven by questions.
So I thought I will make a video on this topic and share that with those of you who are interested in this topic. So if you did not attend the session then I recommend you watch this video instead of the recording. It is just under an hour long and if you watch it at 2x, you can finish it in half an hour.
If you have any follow up questions do reach out to me!
If you wish to purchase access to this video instead of becoming a paid subscriber, you can do so at this link:
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
SPEAKER_00Hi everyone, this is Abhinav from Confessions of a Code Addict. Last weekend we had a live session where we discussed the architecture of Drops LPU hardware and we learned why is it so fast for doing LLM inference. Many people expressed interest in the topic and they wanted to watch the recording. But I feel watching the recording is not as effective as attending a live session So I thought I'll record a dedicated video on this topic and share that with all of you.
SPEAKER_00So let's get started. So first of all, what is Grok? So Grok is a company which has been working on building custom hardware accelerators for doing deep learning model inference for quite a bit of time, for the last 4-5 years. And they came into the news recently when their custom hardware, which is called the language processing unit or the LPU, And that broke benchmarks for doing LLM inference.
SPEAKER_00So this benchmark is maintained by any skill. And as you can see, Grog's LPU was able to achieve a throughput of 185 tokens per second, which leaves behind all the other players in that space with quite a bit of margin. So they were able to achieve width. lpu so that is the topic of our discussion in this video we are going to learn the architecture of lpu and why is it so fast
SPEAKER_00Now LPU itself is a massively parallel and distributed system and at its core it is composed by connecting several smaller processors which are called the Tensor Streaming Processor or TSP in short. The TSP is again a custom chip designed by Grok. So in order to learn how LPU works we first have to learn what is this TSP and how that works and then we will talk about how Grok So, let us get started, but before we start I just want to clarify that all this information that I am going to provide in this video.
SPEAKER_00is based on two papers published by Grok in a computer architecture conference. So the first paper was published in 2020, which was on the denser streaming processor, which is TSP. And the second paper was published in 2022, where they extended their TSP hardware and made it distributed by connecting several TSPs together, and which ultimately led them to create the LPU.
SPEAKER_00So now let's get started. So I will start by first explaining the basic design philosophy that GROK has following the design of their hardware. And it is based on two simple principles. One, the first thing is having static control over all the computational resources. And the other thing is having deterministic execution of the instructions on the hardware. So, I'll elaborate on these two things in a bit.
SPEAKER_00First of all, let's take all of this in context of doing inference on deep learning models. So, Gronk was designing hardware explicitly with a single task in mind which is doing inference on deep learning model or doing similar sort of parallel program execution. So, a typical deep learning model looks like this where there are several layers and the output of one layer flows into as input into another layer and at each layer the weights of that layer are being multiplied by the input and then some sort of activation function gets applied so a lot of this computation can be parallelized for example at each layer you are doing matrix multiplication which has massive level of parallelism
SPEAKER_00that you can achieve by distributing the individual rows and columnar multiplication onto different computational units. Similarly, the activation functions on a vector or on a matrix can be applied in parallel on individual elements of that matrix or the vector. So a lot of parallelism is possible to achieve in such sort of computational problems. And Grok took advantage of the fact that when they are doing inference on a particular model, they have a lot of information available about the architecture of that model.
SPEAKER_00So for example, you would know how many layers are there in that model, what is the size of each layer, what are the activation functions that are being applied on each layer. In a nutshell, you know what are all the computations that have to be performed in order to do a single inference on this model. And then many of those computations can be done in parallel and some of those have to be done in sequence. so all that information is available at compile time and if you have enough computational resources available on the hardware then you should be able to schedule all those computations on those computational units on the hardware ahead of time and if you know that each individual instruction is going to take this much time you should be able to even predict that doing a single inference is going to take exactly this much amount of time
SPEAKER_00But that is the ideal scenario but such control is not really available on a conventional chip like the CPU or the GPU. So let's elaborate on that what do I mean by not having control over the computational units within the CPU. so this is like so this is the micro architecture of a modern x86 cpu core there is a single the inside view of a single code and it is divided into two parts the bottom part is where the actual computational units are present this is these are like for example the arithmetic operation units the load store units are for reading and writing memory the branch unit is for doing branch prediction
SPEAKER_00And these things are called functional units. But all of these are hidden behind the micro-architecture of that processor. What that means is, as programmers or even the compiler, we don't have visibility into all these individual functional units. We don't really have control or we are not really aware what individual functional units are available on the hardware. Instead the compiler compiles the program into sequence of instructions which are supported by the hardware and then
SPEAKER_00The CPU has an instruction control unit which actually fetches those instruction from memory and then based on the instruction, for example, if it is an arithmetic instruction, it will assign it for execution on one of these arithmetic operations unit. So, the CPU or this instruction control unit is sitting between our program and the actual function unit and it is deciding when an instruction is going to execute, how is it going to execute. So, as we do not have as much control as you want to be able to achieve a guaranteed level of performance on this hardware.
SPEAKER_00The other problem that these CPUs have is that There is a lot of non-determinism built into the hardware. This was done to achieve a higher level of instruction throughput and to reduce the instruction latency, but it makes things very non-deterministic. So for example, modern CPUs have a lot of instruction level parallelism, which basically means that these CPUs can execute
SPEAKER_00several instructions in parallel at any point of time and they might be executing instructions out of order and it can do speculative execution and things like that which basically means that we don't have guarantee when an instruction is going to execute, how long is it going to take. Sometimes it may take longer, sometimes it might finish faster. So the same instruction might have lower latency, higher latency, depending on different conditions.
SPEAKER_00And the other problem is that modern CPUs have multiple levels of caches again when instruction when an instruction is executing on the CPU if the data is available within the cache then that instruction will finish executing faster as opposed to if that data was coming from the main memory then the instruction has to wait for a lot So, all these factors when you see combine those together there is a lot of non determinism which hampers the or which makes it hard to guarantee that an instruction will finish executing within this much amount of time and as a result even a complete program will have a non deterministic factor
SPEAKER_00in its execution, so you can't really say that my program will finish executing in this much amount of time. Sometimes it might execute faster, sometimes it might take a longer amount of time. So these factors come into the play. And then GPUs also have similar issues. Although GPUs don't have instruction level but there are other factors within the architecture of the GPU.
SPEAKER_00So one thing is the actual functional units are again hidden behind the microarchitecture of a single core. So every core that you can see, the green boxes here, those represent a single core of the GPU. this is where the actual functional units are present so the arithmetic unit, memory units and all those things but again those are hidden behind a micro architecture so we don't have control over the execution of these program and we can't really
SPEAKER_00control these things. The other thing is, again, these GPUs also have caches and then there is shared memory, global memory, you have log contention, those things come into the picture which, again, produce a lot of non-determinism even when executing programs on the GPU. So, Crock designed their tensor screen processor such that it does not have these particular limitations which are present in conventional chips like the CPU and GPU.
SPEAKER_00So let's talk about the architecture of this PSP. So this is a picture I've taken from the Grok 2020 paper which talked about the architecture of DSP. So on the left hand side we have the view of a common multicore processor like a CPU or a GPU and each tile represents one CPU, one core, one processing core here. Within each core we have individual functional units where the actual execution really happens.
SPEAKER_00but grok designed their lpu sorry their tsp to have a flip design so they took the functional units outside of the course and arranged them in a grid like fashion in this grid each column is a homogenous collection of individual functional units so for example this VXM column here is functional unit which is capable of performing arithmetic operations and then this mem slices for doing memory reads and writes and basically there are other slices so this one column is
SPEAKER_00consist of functional units of one particular kind and those are called a functional slice or just a slice and then each tile in this grid is capable of executing instructions in SIMD fashion so SIMD is in single instruction multiple data so it can process up to vectors of size up to 16 elements. So, one tile can process 16 or 16 element vector and it will execute same instruction of all elements of that vector.
SPEAKER_00So, for example, if you want to add two vectors together element wise you are doing vector you could load those two vectors onto one of these tiles and execute the add instruction on that so it will add those two vectors together in a single instruction and then there are 20 such tiles in each slice which means each slice in total is capable of crossing a 320 element vector and then the other important thing about
SPEAKER_00these slices that they operate in a producer-consumer fashion. So, when one slice is working with a piece of data, it will produce a screen as its result. So, it works with some piece of data, execute some instruction, produces a result which is in the form of a screen and that screen gets passed on to the next slice which is waiting for that slice to arrive so that it can execute. and a new instruction on that slice.
SPEAKER_00So this produces a consumer relationship between the slices. So one slice produces a result and then another slice is able to consume those results. Now let's talk about execution of programs on this KSP.
This is a free preview of a paid episode. To hear more, visit blog.codingconfessions.com In the last video, we learned about copy-on-write (CoW) and understood its mechanics by digging inside the mmap pathway in the...
This is a free preview of a paid episode. To hear more, visit blog.codingconfessions.com In the last video, we discussed demand paging. Now, let’s move towards an even more interesting topic: copy-on-write (CoW). Just...
This is a free preview of a paid episode. To hear more, visit blog.codingconfessions.com In the previous video in our virtual memory series, we discussed demand paging. But that was mostly theoretical, explaining how...
This is a free preview of a paid episode. To hear more, visit blog.codingconfessions.com Welcome back to the video series on virtual memory based on my article on the same topic. It is also available in ebook format on...
This is a free preview of a paid episode. To hear more, visit blog.codingconfessions.com This is a short aside in our virtual memory series. We have talked extensively about the size of a virtual address and the virtual...