{"author":"jmorgan","children":[{"author":"maccam912","children":[{"author":"kirill5pol","children":[{"author":"liuliu","children":[{"author":"Tostino","children":[{"author":"liuliu","children":[],"created_at":"2023-09-14T17:04:06.000Z","created_at_i":1694711046,"id":37511634,"options":[],"parent_id":37511306,"points":null,"story_id":37509659,"text":"Yeah, but I was under the impression that for the same prompt, implementations are already share the KV cache. This area is so new so these obvious ideas might not get implemented as widely as I thought.","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T16:41:55.000Z","created_at_i":1694709715,"id":37511306,"options":[],"parent_id":37510742,"points":null,"story_id":37509659,"text":"You also have fine-tuned models for specific tasks that may see very similar inputs for a variety of outputs. Think an LLM trained on pulling out specific types of information, no matter where it was stored within the file. E.g. &quot;find the date of the shipment for product# 5432&quot; and then you pass in 10k json documents with a similar shape.","title":null,"type":"comment","url":null},{"author":"bestcoder69","children":[{"author":"rdedev","children":[],"created_at":"2023-09-14T20:44:01.000Z","created_at_i":1694724241,"id":37514587,"options":[],"parent_id":37513622,"points":null,"story_id":37509659,"text":"That would be pretty useful. I&#x27;m working on getting chatgpt to classify a dataset. So basically I use the same big prompt for a bunch of different small texts and ask chatgpt to generate the class label. Something like initializing the prompt state sounds good. Basically trade more processing time for more memory usage. Who know maybe openai is doing such optimization from their side","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T19:25:37.000Z","created_at_i":1694719537,"id":37513622,"options":[],"parent_id":37510742,"points":null,"story_id":37509659,"text":"Maybe if you have a model with a large context window, you stuff a document in the prompt as a prefix, then ask a bunch of different questions about the document?","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T16:03:44.000Z","created_at_i":1694707424,"id":37510742,"options":[],"parent_id":37510548,"points":null,"story_id":37509659,"text":"Not only batching. It works by serving different requests as long as they share the prefix.<p>This basically enables KV cache reuse when there is a prefix matching (from my shallow understanding of how KV cache works).<p>I failed to see how this help for local deployed LLM, unless you consider the case you ask the same question or with the same prefix are high (like always starts with &quot;please help me ...&quot;?)","title":null,"type":"comment","url":null},{"author":"fredliu","children":[],"created_at":"2023-09-14T18:46:52.000Z","created_at_i":1694717212,"id":37513072,"options":[],"parent_id":37510548,"points":null,"story_id":37509659,"text":"I might be wrong, but looks like this could help with speculative decoding which can already vastly improves the inference speed?","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T15:47:58.000Z","created_at_i":1694706478,"id":37510548,"options":[],"parent_id":37510415,"points":null,"story_id":37509659,"text":"Just from the abstract, this is primarily for batching inference, for batched inference using GPUs gives an order of magnitude speed increase so probably not something that usually makes sense to do on CPUs\u2026","title":null,"type":"comment","url":null},{"author":"brucethemoose2","children":[],"created_at":"2023-09-14T16:30:18.000Z","created_at_i":1694709018,"id":37511122,"options":[],"parent_id":37510415,"points":null,"story_id":37509659,"text":"Only if the CPU is serving multiple users, maybe.<p>LLMs can&#x27;t batch token generation for single users. Its sequential, each token depends on the next. In fact that&#x27;s a part of the paper: &quot;dumb&quot; batching will leave the GPU underutilized because responses aren&#x27;t all the same length, and they end up processing one token at a time at the end.","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T15:37:56.000Z","created_at_i":1694705876,"id":37510415,"options":[],"parent_id":37509659,"points":null,"story_id":37509659,"text":"Without understanding most of that paper, here&#x27;s a question for someone who might know more: can pagedattention work to make cpu inference faster too?","title":null,"type":"comment","url":null},{"author":"notpublic","children":[],"created_at":"2023-09-14T17:28:43.000Z","created_at_i":1694712523,"id":37512023,"options":[],"parent_id":37509659,"points":null,"story_id":37509659,"text":"source code: <a href=\"https:&#x2F;&#x2F;github.com&#x2F;vllm-project&#x2F;vllm\">https:&#x2F;&#x2F;github.com&#x2F;vllm-project&#x2F;vllm</a>","title":null,"type":"comment","url":null},{"author":"heliophobicdude","children":[{"author":"yelite","children":[{"author":"heliophobicdude","children":[],"created_at":"2023-09-22T20:28:25.000Z","created_at_i":1695414505,"id":37617335,"options":[],"parent_id":37515229,"points":null,"story_id":37509659,"text":"Thank you so much for the response! This is really good info!","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T21:41:36.000Z","created_at_i":1694727696,"id":37515229,"options":[],"parent_id":37513383,"points":null,"story_id":37509659,"text":"&gt; How doesn&#x27;t paging worsen speed performance though?<p>It does worsen the performance of the attention kernel, if comparing to kernels which takes keys and values in continuous memory layout.<p>&gt; Wouldn&#x27;t the speed improvements be coming from that instead? Don&#x27;t put an expected short input and output in the same batch as a big input and big output?<p>Actually it puts everything in the same batch. The reason for its high throughput is that sequences are removed from the batch as soon as it&#x27;s finished, and new sequences can be added to the batch on-the-fly if there is enough space in KV cache. This is called continuous batching (<a href=\"https:&#x2F;&#x2F;www.anyscale.com&#x2F;blog&#x2F;continuous-batching-llm-inference\" rel=\"nofollow noreferrer\">https:&#x2F;&#x2F;www.anyscale.com&#x2F;blog&#x2F;continuous-batching-llm-infere...</a>).<p>Paged attention and &quot;virtualized&quot; KV cache play an important role in an efficient implementation of continuous batching. Text generation in LLM is a dynamic process and it&#x27;s not possible to predict how long the output is when scheduling incoming requests. Therefore a dynamic approach is needed for KV cache allocation, even though it hurts the performance of attention.","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T19:09:23.000Z","created_at_i":1694718563,"id":37513383,"options":[],"parent_id":37509659,"points":null,"story_id":37509659,"text":"Ah, I see. This isn&#x27;t necessarily virtualizing the static weights but the variable -sized and data dependent key value caches. These caches are built up as you go through the sequence of tokens. Makes sense.<p>How doesn&#x27;t paging worsen speed performance though? If you are making more trips to the memory, then are you really just saving vram?<p>Also I see that vLLM which implements PagedAttention is also using a better scheduling? Wouldn&#x27;t the speed improvements be coming from that instead? Don&#x27;t put an expected short input and output in the same batch as a big input and big output?<p>What are the results of using the sequence-length only without virtualization?","title":null,"type":"comment","url":null}],"created_at":"2023-09-14T14:42:03.000Z","created_at_i":1694702523,"id":37509659,"options":[],"parent_id":null,"points":102,"story_id":37509659,"text":null,"title":"Efficient Memory Management for Large Language Model Serving with PagedAttention","type":"story","url":"https://arxiv.org/abs/2309.06180"}
