You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/EN/source/tutorial/multi_level_cache_deployment.rst
+28-2Lines changed: 28 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,26 @@ LightLLM's multi-level cache system adopts a hierarchical design:
37
37
38
38
**Working Principle:**
39
39
40
-
1. The current mechanism creates an exact backup copy of GPU cache data in CPU cache, not just storing content that doesn't fit in GPU cache
40
+
1. Cache placement is controlled by ``--cache_placement_strategy``, which selects either legacy cascading copies or adaptive tier placement
41
41
2. L1, L2, and L3 caches all use LRU eviction strategy for data management
42
42
3. To avoid frequent disk writes in L3 cache, you can use the LIGHTLLM_DISK_CACHE_PROMPT_LIMIT_LENGTH environment variable to control the minimum length threshold for writes. If set to 0, all L2 data will be written to L3 cache
43
43
4. During queries, L1 is checked first to find the longest matching prefix, then L2 is queried to continue extending the longest matching prefix, and finally L3 is queried for the remaining part
44
44
45
+
Cache Placement Strategies
46
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
47
+
48
+
``--cache_placement_strategy`` controls where completed-request KV Cache is stored:
49
+
50
+
- ``adaptive`` (default): During cold start, it first collects 128 requests to quickly establish an initial boundary between GPU and the lower-tier cache path. It then keeps a sliding window of the latest 512 requests and updates the boundary every 36 placement steps. Short requests stay on GPU; long requests move to CPU, or follow the asynchronous CPU → Disk path when Disk is enabled. Because Disk must pass through CPU, the effective lower-tier capacity is the larger of CPU and Disk capacity rather than their sum. By default, only 80% of physical GPU token capacity is used for placement estimation, leaving capacity for running requests. Until the initial small window is full and a boundary is available, placement uses ``legacy`` behavior.
51
+
- ``legacy``: Preserves the previous cascading-copy behavior. A request always remains in GPU cache and is also copied to every enabled lower tier. Enabling CPU cache stores it in GPU and CPU; enabling Disk cache as well stores it in GPU, CPU, and Disk.
52
+
53
+
When ``--enable_cpu_cache`` is not enabled, this option does not change runtime behavior and every completed request uses GPU cache only.
54
+
55
+
.. note::
56
+
57
+
Disk cache is populated asynchronously through CPU cache, so ``--enable_cpu_cache`` must also be enabled when using Disk cache.
58
+
The ``LIGHTLLM_DISK_CACHE_PROMPT_LIMIT_LENGTH`` minimum write threshold applies to both strategies.
59
+
45
60
**Applicable Scenarios:**
46
61
47
62
- Ultra-long text processing (e.g., million-token level context)
@@ -69,7 +84,8 @@ Suitable for most scenarios, significantly increasing cache capacity while maint
69
84
--mem_fraction 0.88 \
70
85
--enable_cpu_cache \
71
86
--cpu_cache_storage_size 400 \
72
-
--cpu_cache_token_page_size 64
87
+
--cpu_cache_token_page_size 64 \
88
+
--cache_placement_strategy adaptive
73
89
74
90
**Parameter Description:**
75
91
@@ -99,6 +115,9 @@ CPU Cache Parameters
99
115
- Larger page sizes (e.g., 256) are suitable for bulk data migration, improving transfer efficiency
100
116
- This value needs to balance memory utilization and transfer overhead
101
117
118
+
- ``--cache_placement_strategy adaptive``: **Cache placement strategy**. Adaptive tier placement is the default; use ``legacy`` to retain the previous GPU + CPU cascading-copy behavior
119
+
- ``LIGHTLLM_CACHE_PLACEMENT_GPU_CAPACITY_RATIO=0.8``: Ratio of physical GPU token capacity used by adaptive placement estimation. The default is ``0.8`` and the valid range is ``(0, 1]``
120
+
102
121
**Performance Optimization Suggestions:**
103
122
104
123
1. **Using Hugepages**: Execute the following commands and set the LIGHTLLM_HUGE_PAGE_ENABLE environment variable to enable huge page mode. Enabling huge page memory can significantly improve service startup speed. If you find the service takes too long to start, you can enable huge page mode for acceleration. Note that huge page mode will occupy memory space for the long term
@@ -132,6 +151,7 @@ Suitable for ultra-long text or extremely high-concurrency scenarios, providing
132
151
--enable_cpu_cache \
133
152
--cpu_cache_storage_size 400 \
134
153
--cpu_cache_token_page_size 256 \
154
+
--cache_placement_strategy adaptive \
135
155
--enable_disk_cache \
136
156
--disk_cache_storage_size 1000 \
137
157
--disk_cache_dir /mnt/ssd/disk_cache_dir
@@ -156,6 +176,12 @@ In addition to the two-level cache, add the following parameters:
156
176
- Strongly recommended to use SSD/NVMe storage, avoid using HDD (performance difference can be 10-100x)
157
177
- Ensure the directory has sufficient read/write permissions and disk space
158
178
179
+
To use the legacy three-level cascading-copy behavior, change the strategy argument to:
0 commit comments