A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 16, 04:30 UTC
[Doc] add documentation for disaggregated prefilling (#11197)
Signed-off-by: Kuntai Du <kuntai@uchicago.edu>
Kuntai Du committed
Dec 15, 2024 at 13:31 UTC
38e599d6a84bb7477030a5488035cd23f529b644
4 files changed
+70
docs/source/assets/usage/disagg_prefill/abstraction.jpg
Binary files /dev/null and b/docs/source/assets/usage/disagg_prefill/abstraction.jpg differ
docs/source/assets/usage/disagg_prefill/overview.jpg
Binary files /dev/null and b/docs/source/assets/usage/disagg_prefill/overview.jpg differ
docs/source/index.rst
+1
@@ -114,6 +114,7 @@ Documentation
114
usage/engine_args
115
usage/env_vars
116
usage/usage_stats
117
+ usage/disagg_prefill
118
119
.. toctree::
120
:maxdepth: 1
docs/source/usage/disagg_prefill.rst
new
+69
@@ -0,0 +1,69 @@
1
+.. _disagg_prefill:
2
+
3
+Disaggregated prefilling (experimental)
4
+=======================================
5
+
6
+This page introduces you the disaggregated prefilling feature in vLLM. This feature is experimental and subject to change.
7
+
8
+Why disaggregated prefilling?
9
+-----------------------------
10
+
11
+Two main reasons:
12
+
13
+* **Tuning time-to-first-token (TTFT) and inter-token-latency (ITL) separately**. Disaggregated prefilling put prefill and decode phase of LLM inference inside different vLLM instances. This gives you the flexibility to assign different parallel strategies (e.g. ``tp`` and ``pp``) to tune TTFT without affecting ITL, or to tune ITL without affecting TTFT.
14
+* **Controlling tail ITL**. Without disaggregated prefilling, vLLM may insert some prefill jobs during the decoding of one request. This results in higher tail latency. Disaggregated prefilling helps you solve this issue and control tail ITL. Chunked prefill with a proper chunk size also can achieve the same goal, but in practice it's hard to figure out the correct chunk size value. So disaggregated prefilling is a much more reliable way to control tail ITL.
15
+
16
+.. note::
17
+ Disaggregated prefill DOES NOT improve throughput.
18
+
19
+Usage example
20
+-------------
21
+
22
+Please refer to ``examples/disaggregated_prefill.sh`` for the example usage of disaggregated prefilling.
23
+
24
+
25
+Benchmarks
26
+----------
27
+
28
+Please refer to ``benchmarks/disagg_benchmarks/`` for disaggregated prefilling benchmarks.
29
+
30
+
31
+Development
32
+-----------
33
+
34
+We implement disaggregated prefilling by running 2 vLLM instances. One for prefill (we call it prefill instance) and one for decode (we call it decode instance), and then use a connector to transfer the prefill KV caches and results from prefill instance to decode instance.
35
+
36
+All disaggregated prefilling implementation is under ``vllm/distributed/kv_transfer``.
37
+
38
+Key abstractions for disaggregated prefilling:
39
+
40
+* **Connector**: Connector allows **kv consumer** to retrieve the KV caches of a batch of request from **kv producer**.
41
+* **LookupBuffer**: LookupBuffer provides two API: ``insert`` KV cache and ``drop_select`` KV cache. The semantics of ``insert`` and ``drop_select`` are similar to SQL, where ``insert`` inserts a KV cache into the buffer, and ``drop_select`` returns the KV cache that matches the given condition and drop it from the buffer.
42
+* **Pipe**: A single-direction FIFO pipe for tensor transmission. It supports ``send_tensor`` and ``recv_tensor``.
43
+
44
+.. note::
45
+ ``insert`` is non-blocking operation but ``drop_select`` is blocking operation.
46
+
47
+Here is a figure illustrating how the above 3 abstractions are organized:
48
+
49
+.. image:: /assets/usage/disagg_prefill/abstraction.jpg
50
+ :alt: Disaggregated prefilling abstractions
51
+
52
+The workflow of disaggregated prefilling is as follows:
53
+
54
+.. image:: /assets/usage/disagg_prefill/overview.jpg
55
+ :alt: Disaggregated prefilling workflow
56
+
57
+The ``buffer`` corresponds to ``insert`` API in LookupBuffer, and the ``drop_select`` corresponds to ``drop_select`` API in LookupBuffer.
58
+
59
+
60
+Third-party contributions
61
+-------------------------
62
+
63
+Disaggregated prefilling is highly related to infrastructure, so vLLM relies on third-party connectors for production-level disaggregated prefilling (and vLLM team will actively review and merge new PRs for third-party connectors).
64
+
65
+We recommend three ways of implementations:
66
+
67
+* **Fully-customized connector**: Implement your own ``Connector``, and call third-party libraries to send and receive KV caches, and many many more (like editing vLLM's model input to perform customized prefilling, etc). This approach gives you the most control, but at the risk of being incompatible with future vLLM versions.
68
+* **Database-like connector**: Implement your own ``LookupBuffer`` and support the ``insert`` and ``drop_select`` APIs just like SQL.
69
+* **Distributed P2P connector**: Implement your own ``Pipe`` and support the ``send_tensor`` and ``recv_tensor`` APIs, just like `torch.distributed`.