lmcache-cli 0.5.9rc2.dev0__py3-none-any.whl → 0.5.9rc4.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. lmcache/_version.py +3 -3
  2. lmcache/cli/commands/base.py +47 -0
  3. lmcache/cli/commands/bench/server_bench/allocator.py +29 -3
  4. lmcache/cli/commands/bench/server_bench/arguments.py +13 -1
  5. lmcache/cli/commands/bench/server_bench/cases/baseline.py +87 -1
  6. lmcache/cli/commands/bench/server_bench/client.py +6 -5
  7. lmcache/cli/commands/bench/server_bench/config.py +5 -0
  8. lmcache/cli/commands/describe.py +207 -33
  9. lmcache/cli/commands/memory.py +13 -11
  10. lmcache/cli/commands/query/_request.py +8 -0
  11. lmcache/cli/commands/query/engine_command.py +8 -0
  12. lmcache/cli/commands/server.py +13 -12
  13. lmcache/integration/atom/multi_process_adapter.py +24 -6
  14. lmcache/integration/sglang/unified_lmcache_mp_connector.py +25 -1
  15. lmcache/integration/tensorrt_llm/tensorrt_mp_adapter.py +23 -4
  16. lmcache/integration/vllm/lmcache_mp_connector.py +85 -42
  17. lmcache/integration/vllm/mp_server_launcher.py +16 -1
  18. lmcache/integration/vllm/vllm_multi_process_adapter.py +64 -17
  19. lmcache/lmcache_frontend/app.py +110 -7
  20. lmcache/lmcache_frontend/static/js/app.js +126 -100
  21. lmcache/lmcache_native.pyi +0 -3
  22. lmcache/tools/cache_simulator/trace_analyze.py +21 -8
  23. lmcache/usage_telemetry/metric_specs.py +3 -8
  24. lmcache/usage_telemetry/mp_continuous.py +2 -18
  25. lmcache/v1/client/heartbeat.py +32 -15
  26. lmcache/v1/common/kv_format/specs/base.py +2 -1
  27. lmcache/v1/common/utils.py +2 -2
  28. lmcache/v1/distributed/api.py +4 -0
  29. lmcache/v1/distributed/internal_api.py +4 -0
  30. lmcache/v1/distributed/key_codec.py +29 -2
  31. lmcache/v1/distributed/l1_manager/base.py +6 -0
  32. lmcache/v1/distributed/l2_adapters/base.py +8 -0
  33. lmcache/v1/distributed/l2_adapters/dax_l2_adapter.py +100 -40
  34. lmcache/v1/distributed/l2_adapters/fs_l2_adapter.py +3 -18
  35. lmcache/v1/distributed/l2_adapters/gdr_peer_l2_adapter.py +284 -0
  36. lmcache/v1/distributed/l2_adapters/native_connector_l2_adapter.py +10 -5
  37. lmcache/v1/distributed/l2_adapters/nixl_store_dynamic_l2_adapter.py +35 -2
  38. lmcache/v1/distributed/l2_adapters/nixl_store_l2_adapter.py +74 -29
  39. lmcache/v1/distributed/l2_adapters/p2p_l2_adapter.py +333 -3
  40. lmcache/v1/distributed/l2_adapters/raw_block/core.py +55 -24
  41. lmcache/v1/distributed/serde/fp8.py +12 -2
  42. lmcache/v1/distributed/storage_controllers/prefetch_controller.py +100 -7
  43. lmcache/v1/distributed/storage_manager.py +28 -0
  44. lmcache/v1/distributed/transfer_channel/abstract.py +19 -0
  45. lmcache/v1/distributed/transfer_channel/impl/nixl_impl.py +28 -0
  46. lmcache/v1/memory_management.py +51 -34
  47. lmcache/v1/memory_orchestrator/_proto_gen/__init__.py +1 -1
  48. lmcache/v1/mp_coordinator/config.py +3 -5
  49. lmcache/v1/mp_coordinator/http_apis/dependencies.py +19 -41
  50. lmcache/v1/mp_coordinator/http_apis/instances_api.py +1 -1
  51. lmcache/v1/mp_coordinator/registrar.py +6 -41
  52. lmcache/v1/mp_coordinator/schemas.py +2 -13
  53. lmcache/v1/mp_coordinator/views/key_directory.py +0 -30
  54. lmcache/v1/multiprocess/config.py +4 -4
  55. lmcache/v1/multiprocess/engine_context.py +16 -140
  56. lmcache/v1/multiprocess/engine_module.py +8 -2
  57. lmcache/v1/multiprocess/http_server.py +1 -1
  58. lmcache/v1/multiprocess/modules/blend/lookup.py +44 -12
  59. lmcache/v1/multiprocess/modules/blend/module.py +10 -13
  60. lmcache/v1/multiprocess/modules/blend/retrieve.py +1 -1
  61. lmcache/v1/multiprocess/modules/blend/store.py +2 -2
  62. lmcache/v1/multiprocess/modules/engine_driven_transfer.py +10 -2
  63. lmcache/v1/multiprocess/modules/lmcache_driven_transfer.py +9 -3
  64. lmcache/v1/multiprocess/modules/lookup.py +92 -9
  65. lmcache/v1/multiprocess/modules/management.py +28 -22
  66. lmcache/v1/multiprocess/plugin_modules/qstore.py +1 -1
  67. lmcache/v1/multiprocess/server.py +2 -15
  68. lmcache/v1/multiprocess/session.py +3 -3
  69. lmcache/v1/multiprocess/transport/grpc_impl/aio_server.py +2 -2
  70. lmcache/v1/platform/base/ipc_wrapper.py +36 -1
  71. lmcache/v1/platform/devices/musa/__init__.py +0 -5
  72. lmcache/v1/platform/devices/musa/format_capabilities.py +4 -6
  73. lmcache/v1/platform/devices/npu/event_ipc.py +30 -1
  74. lmcache/v1/platform/torch_ops/mp_mem_kernels.py +7 -11
  75. lmcache/v1/transport/auth.py +1 -1
  76. lmcache/v1/transport/grpc/_proto_gen/__init__.py +1 -1
  77. lmcache/v1/transport/grpc/_proto_gen/_generate.py +4 -1
  78. lmcache/v1/transport/grpc/descriptors.py +2 -2
  79. lmcache/v1/transport/grpc/protos/management_service.proto +10 -10
  80. lmcache/v1/transport/request_client.py +6 -4
  81. {lmcache_cli-0.5.9rc2.dev0.dist-info → lmcache_cli-0.5.9rc4.dev0.dist-info}/METADATA +1 -1
  82. {lmcache_cli-0.5.9rc2.dev0.dist-info → lmcache_cli-0.5.9rc4.dev0.dist-info}/RECORD +86 -89
  83. lmcache/v1/common/kv_format/specs/nl_x_nbbs_one_hs.py +0 -68
  84. lmcache/v1/common/kv_format/specs/two_x_nl_x_nb_bs_nh_hs.py +0 -65
  85. lmcache/v1/common/kv_format/specs/two_x_nl_x_nbbs_nh_hs.py +0 -70
  86. lmcache/v1/mp_coordinator/http_apis/config_api.py +0 -26
  87. {lmcache_cli-0.5.9rc2.dev0.dist-info → lmcache_cli-0.5.9rc4.dev0.dist-info}/WHEEL +0 -0
  88. {lmcache_cli-0.5.9rc2.dev0.dist-info → lmcache_cli-0.5.9rc4.dev0.dist-info}/entry_points.txt +0 -0
  89. {lmcache_cli-0.5.9rc2.dev0.dist-info → lmcache_cli-0.5.9rc4.dev0.dist-info}/licenses/LICENSE +0 -0
  90. {lmcache_cli-0.5.9rc2.dev0.dist-info → lmcache_cli-0.5.9rc4.dev0.dist-info}/top_level.txt +0 -0
lmcache/_version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.5.9rc2.dev0'
22
- __version_tuple__ = version_tuple = (0, 5, 9, 'rc2', 'dev0')
21
+ __version__ = version = '0.5.9rc4.dev0'
22
+ __version_tuple__ = version_tuple = (0, 5, 9, 'rc4', 'dev0')
23
23
 
24
- __commit_id__ = commit_id = 'g51428bcc2'
24
+ __commit_id__ = commit_id = 'g1f3b3a473'
@@ -6,6 +6,7 @@ from __future__ import annotations
6
6
 
7
7
  # Standard
8
8
  from collections.abc import Sequence
9
+ from pathlib import Path
9
10
  import abc
10
11
  import argparse
11
12
  import sys
@@ -60,6 +61,52 @@ def nonnegative_int(value: str) -> int:
60
61
  return count
61
62
 
62
63
 
64
+ def missing_grpc_bindings_hint(error: ImportError) -> str | None:
65
+ """Return how to produce the binding *error* shows as missing, or ``None``.
66
+
67
+ An editable ``pip install -e .`` runs the generator from ``build_py``, but
68
+ setuptools downgrades a failing custom ``build_py`` to a warning, so a
69
+ missing ``grpcio-tools`` leaves a package that imports without the
70
+ bindings and the commands that need them fail with an import error that
71
+ hides the cause. The failing import itself names what is missing, so the
72
+ remedy is tied to it and offered for nothing else. It runs the generator
73
+ from the repository, so it is only offered for a package installed from a
74
+ source checkout, where ``requirements/proto.txt`` sits next to it; the
75
+ ``lmcache-cli`` wheel ships without the bindings too, and its users get
76
+ ``None`` so that the caller's reinstall advice stands.
77
+
78
+ Args:
79
+ error: The ``ImportError`` raised while loading the command's runtime.
80
+
81
+ Returns:
82
+ The remedy, or ``None`` when *error* does not report a missing binding
83
+ or the package is not installed from a source checkout.
84
+ """
85
+ # <repository>/lmcache/cli/commands/base.py
86
+ repository_root = Path(__file__).resolve().parents[3]
87
+ if not (repository_root / "requirements" / "proto.txt").is_file():
88
+ return None
89
+ name = error.name
90
+ if name is None:
91
+ return None
92
+ if error.path is None:
93
+ # "No module named <package>.<binding>": the binding is the leaf.
94
+ package, _, binding = name.rpartition(".")
95
+ if not binding.endswith(("_pb2", "_pb2_grpc")):
96
+ return None
97
+ else:
98
+ # "cannot import name <binding> from <package>": the name is the package.
99
+ package = name
100
+ if not package.endswith("._proto_gen"):
101
+ return None
102
+ return (
103
+ "This installation is missing LMCache's generated gRPC bindings. "
104
+ "From the repository root, regenerate them with:\n"
105
+ " pip install -r requirements/proto.txt\n"
106
+ " python lmcache/v1/transport/grpc/_proto_gen/_generate.py"
107
+ )
108
+
109
+
63
110
  def _route_head(tokens: Sequence[str]) -> tuple[str | None, list[str]]:
64
111
  """Split the current level's route head off the remaining tokens.
65
112
 
@@ -27,22 +27,48 @@ class RequestBlocks:
27
27
 
28
28
 
29
29
  class BlockAllocator:
30
- """Single-threaded, request-exclusive allocation without prefix sharing."""
30
+ """Single-threaded, request-exclusive allocation without prefix sharing.
31
+
32
+ The server's null block (``--null-block-id``, default ``0``) is never
33
+ handed out: the MP server drops every chunk whose block ids are all
34
+ null, so allocating it would silently lose data (issue #6741).
35
+ An id outside the pool (e.g. the server's ``-1`` marker) reserves
36
+ nothing, as on the server: ids are non-negative, so the marker never
37
+ collides with a real block.
38
+ """
31
39
 
32
40
  def __init__(
33
41
  self,
34
42
  groups: int,
35
43
  capacity: int,
36
44
  *,
45
+ null_block_id: int = 0,
37
46
  allocation_order: Literal["sequential", "random"] = "sequential",
38
47
  seed: int = 0,
39
48
  ) -> None:
40
- """Create one free pool per group with a reproducible allocation order."""
49
+ """Create one free pool per group with a reproducible allocation order.
50
+
51
+ Args:
52
+ groups: Number of engine groups, each with its own pool.
53
+ capacity: Block id space size per group (ids ``0..capacity-1``);
54
+ the null block is excluded, leaving ``capacity - 1``
55
+ allocatable blocks when it is in range.
56
+ null_block_id: The server's null block marker. An id inside
57
+ the pool is reserved away; an id outside it (e.g. ``-1``)
58
+ reserves nothing, mirroring the server, whose block ids are
59
+ non-negative and never equal such a marker.
60
+ allocation_order: Hand out the lowest free ids or sample randomly.
61
+ seed: Seed for the random allocation order.
62
+
63
+ Raises:
64
+ ValueError: If groups or capacity is negative or the allocation
65
+ order is unsupported.
66
+ """
41
67
  if groups < 0 or capacity < 0:
42
68
  raise ValueError("groups and capacity must be non-negative")
43
69
  if allocation_order not in ("sequential", "random"):
44
70
  raise ValueError(f"unsupported allocation order: {allocation_order}")
45
- self._free = [set(range(capacity)) for _ in range(groups)]
71
+ self._free = [set(range(capacity)) - {null_block_id} for _ in range(groups)]
46
72
  self._allocation_order = allocation_order
47
73
  self._random = random.Random(seed)
48
74
 
@@ -143,7 +143,10 @@ def add_server_arguments(parser: argparse.ArgumentParser) -> None:
143
143
  "--num-blocks",
144
144
  type=int,
145
145
  default=1024,
146
- help="Paged blocks (default: 1024)",
146
+ help=(
147
+ "Fallback block count per group, including any reserved null block "
148
+ "(default: 1024)"
149
+ ),
147
150
  )
148
151
  kv.add_argument(
149
152
  "--block-size",
@@ -151,6 +154,15 @@ def add_server_arguments(parser: argparse.ArgumentParser) -> None:
151
154
  default=16,
152
155
  help="Tokens per block (default: 16)",
153
156
  )
157
+ kv.add_argument(
158
+ "--null-block-id",
159
+ type=int,
160
+ default=0,
161
+ help=(
162
+ "Match the server's --null-block-id (default: 0). "
163
+ "An ID in [0, NB) reserves one block per group."
164
+ ),
165
+ )
154
166
 
155
167
  parser.add_argument(
156
168
  "--start",
@@ -16,10 +16,18 @@ import time
16
16
  from lmcache.cli.commands.bench.server_bench.cases.base import BenchResult
17
17
  from lmcache.cli.commands.bench.server_bench.client import (
18
18
  LookupResult,
19
+ RequestContext,
19
20
  ServerBenchClient,
20
21
  TransferResult,
21
22
  )
22
23
 
24
+ # A STORE reply can arrive before the stored objects are visible to lookups
25
+ # (lmcache_driven mode commits them with a later stream callback). A warm
26
+ # LOOKUP that fully misses, or hits only a prefix, right after a successful cold
27
+ # STORE is retried for at most this long before it is accepted as a real one.
28
+ _VISIBILITY_RETRY_INTERVAL_S = 0.01
29
+ _VISIBILITY_RETRY_BUDGET_S = 0.5
30
+
23
31
 
24
32
  def _lookup_succeeded(outcome: _RequestOutcome | None) -> bool:
25
33
  return outcome is not None and outcome.lookup.succeeded
@@ -33,6 +41,21 @@ def _transfer_succeeded(transfer: TransferResult | None) -> bool:
33
41
  )
34
42
 
35
43
 
44
+ def _not_yet_visible(lookup: LookupResult) -> bool:
45
+ """Whether a warm LOOKUP may still be racing the cold STORE: nothing found,
46
+ or only a prefix found."""
47
+ return lookup.is_full_miss or lookup.is_partial_hit
48
+
49
+
50
+ def _stored_new_chunks(outcome: _RequestOutcome | None) -> bool:
51
+ """Return whether a cold request stored chunks the warm one must find."""
52
+ return (
53
+ outcome is not None
54
+ and outcome.store is not None
55
+ and _transfer_succeeded(outcome.store)
56
+ )
57
+
58
+
36
59
  @dataclass(frozen=True)
37
60
  class _RequestOutcome:
38
61
  """Outcome of one cold or warm request."""
@@ -122,7 +145,13 @@ class BaselineBenchCase:
122
145
 
123
146
  time.sleep(self.interval_seconds)
124
147
 
125
- warm_outcome = self._execute_request(client, sequence_id, "warm")
148
+ warm_outcome = self._execute_request(
149
+ client,
150
+ sequence_id,
151
+ "warm",
152
+ expect_visible=_stored_new_chunks(cold_outcome),
153
+ log=log,
154
+ )
126
155
  self._record_request_latencies(result, "warm", warm_outcome)
127
156
 
128
157
  result.completed_runs += 1
@@ -218,6 +247,8 @@ class BaselineBenchCase:
218
247
  client: ServerBenchClient,
219
248
  sequence_id: int,
220
249
  request_kind: Literal["cold", "warm"],
250
+ expect_visible: bool = False,
251
+ log: Callable[[str], None] | None = None,
221
252
  ) -> _RequestOutcome | None:
222
253
  # First Party
223
254
  from lmcache.cli.commands.bench.server_bench.helpers import _build_token_ids
@@ -233,6 +264,8 @@ class BaselineBenchCase:
233
264
 
234
265
  try:
235
266
  lookup = client.lookup(request)
267
+ if expect_visible:
268
+ lookup = self._retry_until_visible(client, request, lookup, log)
236
269
  if not lookup.succeeded:
237
270
  return _RequestOutcome(lookup=lookup)
238
271
 
@@ -290,3 +323,56 @@ class BaselineBenchCase:
290
323
  )
291
324
  finally:
292
325
  client.release_request(request)
326
+
327
+ @staticmethod
328
+ def _retry_until_visible(
329
+ client: ServerBenchClient,
330
+ request: RequestContext,
331
+ lookup: LookupResult,
332
+ log: Callable[[str], None] | None,
333
+ ) -> LookupResult:
334
+ """Re-run a warm LOOKUP that missed, or only partly hit, a just-completed STORE.
335
+
336
+ The STORE reply does not mean the objects are readable yet: the warm
337
+ LOOKUP can miss everything, or see just a cached prefix while the newly
338
+ stored chunks are still write-locked. The retry is bounded, so a store
339
+ the server really dropped still shows as a miss or a partial hit.
340
+ """
341
+ deadline = time.monotonic() + _VISIBILITY_RETRY_BUDGET_S
342
+ retries = 0
343
+ while _not_yet_visible(lookup) and time.monotonic() < deadline:
344
+ time.sleep(_VISIBILITY_RETRY_INTERVAL_S)
345
+ # The sleep may cross the deadline; do not start a LOOKUP after it.
346
+ if time.monotonic() >= deadline:
347
+ break
348
+ lookup = client.lookup(request)
349
+ retries += 1
350
+ if retries and log is not None:
351
+ if not lookup.succeeded:
352
+ log(
353
+ " [seq %d/warm] LOOKUP retried %d time(s); the last retry "
354
+ "failed: %s" % (request.sequence_id, retries, lookup.error)
355
+ )
356
+ elif lookup.is_full_miss:
357
+ log(
358
+ " [seq %d/warm] LOOKUP retried %d time(s); cold STORE "
359
+ "still not visible after retry budget"
360
+ % (request.sequence_id, retries)
361
+ )
362
+ elif lookup.is_partial_hit:
363
+ log(
364
+ " [seq %d/warm] LOOKUP retried %d time(s); cold STORE "
365
+ "still not fully visible after retry budget (%d of %d chunks)"
366
+ % (
367
+ request.sequence_id,
368
+ retries,
369
+ lookup.hit_chunks,
370
+ lookup.total_chunks,
371
+ )
372
+ )
373
+ else:
374
+ log(
375
+ " [seq %d/warm] LOOKUP retried %d time(s) until the cold "
376
+ "STORE was visible" % (request.sequence_id, retries)
377
+ )
378
+ return lookup
@@ -250,15 +250,16 @@ class ServerBenchClient:
250
250
  ready.set()
251
251
  for future in warmup:
252
252
  future.result(timeout=self._config.transfer_timeout_s)
253
+ self._allocator = BlockAllocator(
254
+ self._num_engine_group_infos,
255
+ self._num_blocks,
256
+ null_block_id=self._config.null_block_id,
257
+ allocation_order=self._config.block_allocation,
258
+ )
253
259
  except BaseException:
254
260
  self.close()
255
261
  raise
256
262
 
257
- self._allocator = BlockAllocator(
258
- self._num_engine_group_infos,
259
- self._num_blocks,
260
- allocation_order=self._config.block_allocation,
261
- )
262
263
  self._started = True
263
264
 
264
265
  def create_request(
@@ -36,6 +36,9 @@ class BenchConfig:
36
36
  concurrency: Number of clients sending requests at the same time.
37
37
  isolated_ipc: Whether clients use the isolated IPC policy.
38
38
  block_allocation: Allocate the lowest free IDs or sample free IDs randomly.
39
+ null_block_id: Server null block id; an id inside the block pool
40
+ is excluded from allocation, an id outside it (e.g. ``-1``)
41
+ reserves nothing, mirroring the server.
39
42
  transfer_timeout_s: Positive, finite shared wait budget per transfer call.
40
43
  """
41
44
 
@@ -53,6 +56,7 @@ class BenchConfig:
53
56
  isolated_ipc: bool = False
54
57
  block_allocation: Literal["sequential", "random"] = "sequential"
55
58
  transfer_timeout_s: float = 10.0
59
+ null_block_id: int = 0
56
60
 
57
61
  def __post_init__(self) -> None:
58
62
  if self.mode not in ("cpu", "gpu"):
@@ -157,5 +161,6 @@ def parse_args_to_config(args: argparse.Namespace) -> BenchConfig:
157
161
  concurrency=int(getattr(args, "concurrency", 1)),
158
162
  isolated_ipc=args.isolated_ipc,
159
163
  block_allocation=getattr(args, "block_allocation", "sequential"),
164
+ null_block_id=int(getattr(args, "null_block_id", 0)),
160
165
  transfer_timeout_s=float(getattr(args, "transfer_timeout", 10.0)),
161
166
  )