Earlier quoted context omitted.
> The CPU launch cost of a graph is tiny Absolutely not; it’s comparable to the launch overhead of a kernel.
Fair enough. I should have clarified that “approximately the cost of a single kernel launch” is pretty much what I meant by “tiny”. What I was getting at was that a “megakernel” and a captured graph should have similar launch costs.
Compiling LLMs into a MegaKernel: A path to low-latency inference
51–60 of 79 posts
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#52Earlier quoted context omitted.
Isn't that easily accomplished by setting up a local deployment and then yanking the network cable? Anything that can quickly run a capable LLM is going to be a pretty beefy box though. More like LLM in an expensive space heater.
I was thinking more like those Bitcoin mining usb Asics that used to be a thing, but instead of becoming ewaste, you can still use them to talk with chatgpt 2 or whatever. I'm picturing an llm appliance.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#53Earlier quoted context omitted.
I was thinking more like those Bitcoin mining usb Asics that used to be a thing, but instead of becoming ewaste, you can still use them to talk with chatgpt 2 or whatever. I'm picturing an llm appliance.
There is no magic ASIC that can get around needing to do hundreds of watts worth of computations and having on the order of hundreds of gigabytes of very fast memory. Otherwise the major players would be doing that instead of (quite literally) investing in nuclear reactors to power their future data center expansions.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#54And unlike a lot of research, the code actually runs well. I can reproduce the results using Modal GPUs, leaving the code here: https://github.com/mirage-project/mirage/pull/327/files
Triton + FlashInfer: Prompt length 39, generate length 264, per-token latency 19.189573345762312 ms
MPK: Prompt length 39, generate length 334, per-token latency 7.71875 ms
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#551. How fine grain is each task? In a traditional matrix multiplication kernel, for example, each thread block is responsible for a small output tile of the resulting matrix. In Mirage's mega kernel, would there correspondingly be a task for each small output tile?
2. How does the Mirage compiler form the task graph? Does it have domain knowledge of every operator's data flow at the granularity of individual elements? Again taking matmul as an example: a given output output tile requires the correspond M_BLOCK rows of the A matrix. If the A matrix was itself an output of a prior matmul (+ nonlinearity), the dependees would be all of output tile tasks corresponding to those M_BLOCK rows of the operator that produced A?
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#56Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#57The improvement is real! And unlike a lot of research, the code actually runs well. I can reproduce the results using Modal GPUs, leaving the code here: https://github.com/mirage-project/mirage/pull/327/files Triton + FlashInfer: Prompt length 39, generate length 264, per-token latency 19.189573345762312 ms MPK: Prompt length 39, generate length 334, per-token latency 7.71875 ms
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#58A question for the author(s) since they seem to be very responsive to this thread :). 1. How fine grain is each task? In a traditional matrix multiplication kernel, for example, each thread block is responsible for a small output tile of the resulting matrix. In Mirage's mega kernel, would there correspondingly be a task for each small output tile? 2. How does the Mirage compiler form the task graph? Does it have dom…
2. TL;DR: MPK automatically analyzes inter-task dependencies by tracking the input and output tensors associated with each task. A longer version: Longer version: MPK uses imap, omap, and fmap (see Section 2 of the Mirage paper) to determine each task’s input and output tensors. A dependency is introduced between task A and task B if A produces any tensor elements that B consumes—that is, if A's outputs overlap with B's inputs.
> Again taking matmul as an example: a given output output tile requires the correspond M_BLOCK rows of the A matrix. If the A matrix was itself an output of a prior matmul (+ nonlinearity), the dependees would be all of output tile tasks corresponding to those M_BLOCK rows of the operator that produced A?
Exactly. In this case, all output tile tasks that consume those M_BLOCK rows of A will depend on all tasks responsible for producing the corresponding parts of A in the previous operator.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#59Earlier quoted context omitted.
> The CPU launch cost of a graph is tiny Absolutely not; it’s comparable to the launch overhead of a kernel.
Fair enough. I should have clarified that “approximately the cost of a single kernel launch” is pretty much what I meant by “tiny”. What I was getting at was that a “megakernel” and a captured graph should have similar launch costs.
I'm not sure it applies so well in LLMs though (should read the paper...).
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#60Earlier quoted context omitted.
I was thinking more like those Bitcoin mining usb Asics that used to be a thing, but instead of becoming ewaste, you can still use them to talk with chatgpt 2 or whatever. I'm picturing an llm appliance.
There is no magic ASIC that can get around needing to do hundreds of watts worth of computations and having on the order of hundreds of gigabytes of very fast memory. Otherwise the major players would be doing that instead of (quite literally) investing in nuclear reactors to power their future data center expansions.
This is "gaming PC" territory, not "space heater". I mean people already have PS5's and whatnot in their homes.
The hundreds of gigabytes thing exists because the big cloud LLM providers went down the increasing parameter count path. That way is a dead end and we've reached negative returns already.
Prompt engineering + finetunes is the future, but you need developer brains for that, not TFLOPs.