lmcache-cli 0.4.5.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.
- lmcache/__init__.py +84 -0
- lmcache/_version.py +24 -0
- lmcache/cli/__init__.py +1 -0
- lmcache/cli/commands/__init__.py +34 -0
- lmcache/cli/commands/base.py +157 -0
- lmcache/cli/commands/bench/__init__.py +557 -0
- lmcache/cli/commands/bench/engine_bench/__init__.py +1 -0
- lmcache/cli/commands/bench/engine_bench/config.py +245 -0
- lmcache/cli/commands/bench/engine_bench/interactive/__init__.py +274 -0
- lmcache/cli/commands/bench/engine_bench/interactive/config.json +10 -0
- lmcache/cli/commands/bench/engine_bench/interactive/schema.py +352 -0
- lmcache/cli/commands/bench/engine_bench/interactive/state.py +327 -0
- lmcache/cli/commands/bench/engine_bench/interactive/terminal.py +291 -0
- lmcache/cli/commands/bench/engine_bench/progress.py +145 -0
- lmcache/cli/commands/bench/engine_bench/request_sender.py +232 -0
- lmcache/cli/commands/bench/engine_bench/stats.py +275 -0
- lmcache/cli/commands/bench/engine_bench/workloads/__init__.py +153 -0
- lmcache/cli/commands/bench/engine_bench/workloads/base.py +122 -0
- lmcache/cli/commands/bench/engine_bench/workloads/long_doc_permutator.py +435 -0
- lmcache/cli/commands/bench/engine_bench/workloads/long_doc_qa.py +281 -0
- lmcache/cli/commands/bench/engine_bench/workloads/multi_round_chat.py +337 -0
- lmcache/cli/commands/bench/engine_bench/workloads/random_prefill.py +178 -0
- lmcache/cli/commands/describe.py +310 -0
- lmcache/cli/commands/kvcache.py +133 -0
- lmcache/cli/commands/mock.py +75 -0
- lmcache/cli/commands/ping.py +113 -0
- lmcache/cli/commands/query/__init__.py +155 -0
- lmcache/cli/commands/query/prompt.py +134 -0
- lmcache/cli/commands/query/request.py +357 -0
- lmcache/cli/commands/server.py +99 -0
- lmcache/cli/commands/tool/__init__.py +63 -0
- lmcache/cli/commands/tool/cache_simulator.py +113 -0
- lmcache/cli/commands/trace/__init__.py +505 -0
- lmcache/cli/commands/trace/dispatch.py +249 -0
- lmcache/cli/commands/trace/driver.py +372 -0
- lmcache/cli/commands/trace/stats.py +289 -0
- lmcache/cli/documents/lmcache.txt +11 -0
- lmcache/cli/main.py +42 -0
- lmcache/cli/metrics/__init__.py +29 -0
- lmcache/cli/metrics/formatter.py +171 -0
- lmcache/cli/metrics/handler.py +94 -0
- lmcache/cli/metrics/metrics.py +161 -0
- lmcache/cli/metrics/section.py +77 -0
- lmcache/connections.py +173 -0
- lmcache/integration/__init__.py +2 -0
- lmcache/integration/base_service_factory.py +165 -0
- lmcache/integration/request_telemetry/__init__.py +1 -0
- lmcache/integration/request_telemetry/base.py +51 -0
- lmcache/integration/request_telemetry/factory.py +113 -0
- lmcache/integration/request_telemetry/fastapi.py +109 -0
- lmcache/integration/request_telemetry/noop.py +35 -0
- lmcache/integration/sglang/__init__.py +2 -0
- lmcache/integration/sglang/sglang_adapter.py +326 -0
- lmcache/integration/sglang/utils.py +39 -0
- lmcache/integration/vllm/__init__.py +1 -0
- lmcache/integration/vllm/lmcache_connector_v1.py +213 -0
- lmcache/integration/vllm/lmcache_connector_v1_085.py +150 -0
- lmcache/integration/vllm/lmcache_mp_connector_0180.py +1072 -0
- lmcache/integration/vllm/tests/test_mm_hash_utils.py +112 -0
- lmcache/integration/vllm/utils.py +433 -0
- lmcache/integration/vllm/vllm_multi_process_adapter.py +1090 -0
- lmcache/integration/vllm/vllm_service_factory.py +339 -0
- lmcache/integration/vllm/vllm_v1_adapter.py +1713 -0
- lmcache/logging.py +107 -0
- lmcache/native_storage_ops.pyi +230 -0
- lmcache/non_cuda_equivalents.py +1424 -0
- lmcache/observability.py +1958 -0
- lmcache/storage_backend/serde/__init__.py +1 -0
- lmcache/storage_backend/serde/cachegen_basics.py +210 -0
- lmcache/storage_backend/serde/cachegen_decoder.py +207 -0
- lmcache/storage_backend/serde/cachegen_encoder.py +394 -0
- lmcache/storage_backend/serde/serde.py +75 -0
- lmcache/tools/__init__.py +1 -0
- lmcache/tools/cache_simulator/README.md +392 -0
- lmcache/tools/cache_simulator/__init__.py +1 -0
- lmcache/tools/cache_simulator/docs/simulate_example.png +0 -0
- lmcache/tools/cache_simulator/docs/sweep_example.png +0 -0
- lmcache/tools/cache_simulator/gen_bench_dataset.py +360 -0
- lmcache/tools/cache_simulator/lru_cache.py +124 -0
- lmcache/tools/cache_simulator/plot_hit_rate.py +231 -0
- lmcache/tools/cache_simulator/simulator.py +795 -0
- lmcache/tools/controller_benchmark/README.md +161 -0
- lmcache/tools/controller_benchmark/__init__.py +1 -0
- lmcache/tools/controller_benchmark/__main__.py +331 -0
- lmcache/tools/controller_benchmark/benchmark.py +660 -0
- lmcache/tools/controller_benchmark/config.py +44 -0
- lmcache/tools/controller_benchmark/constants.py +10 -0
- lmcache/tools/controller_benchmark/handlers/__init__.py +46 -0
- lmcache/tools/controller_benchmark/handlers/admit.py +52 -0
- lmcache/tools/controller_benchmark/handlers/base.py +47 -0
- lmcache/tools/controller_benchmark/handlers/deregister.py +49 -0
- lmcache/tools/controller_benchmark/handlers/evict.py +52 -0
- lmcache/tools/controller_benchmark/handlers/heartbeat.py +56 -0
- lmcache/tools/controller_benchmark/handlers/p2p_lookup.py +47 -0
- lmcache/tools/controller_benchmark/handlers/register.py +56 -0
- lmcache/tools/mp_status_viewer/__init__.py +1 -0
- lmcache/tools/mp_status_viewer/__main__.py +95 -0
- lmcache/usage_context.py +417 -0
- lmcache/utils.py +665 -0
- lmcache/v1/__init__.py +2 -0
- lmcache/v1/api_server/__init__.py +2 -0
- lmcache/v1/api_server/__main__.py +537 -0
- lmcache/v1/basic_check.py +112 -0
- lmcache/v1/cache_controller/__init__.py +9 -0
- lmcache/v1/cache_controller/commands/__init__.py +15 -0
- lmcache/v1/cache_controller/commands/base.py +35 -0
- lmcache/v1/cache_controller/commands/full_sync.py +49 -0
- lmcache/v1/cache_controller/config.py +176 -0
- lmcache/v1/cache_controller/controller_manager.py +535 -0
- lmcache/v1/cache_controller/controllers/__init__.py +11 -0
- lmcache/v1/cache_controller/controllers/full_sync_tracker.py +473 -0
- lmcache/v1/cache_controller/controllers/kv_controller.py +439 -0
- lmcache/v1/cache_controller/controllers/registration_controller.py +282 -0
- lmcache/v1/cache_controller/executor.py +463 -0
- lmcache/v1/cache_controller/frontend/static/css/style.css +201 -0
- lmcache/v1/cache_controller/frontend/static/img/logo.png +0 -0
- lmcache/v1/cache_controller/frontend/static/index.html +234 -0
- lmcache/v1/cache_controller/frontend/static/js/controller_app.js +660 -0
- lmcache/v1/cache_controller/full_sync_sender.py +475 -0
- lmcache/v1/cache_controller/locks.py +149 -0
- lmcache/v1/cache_controller/message.py +828 -0
- lmcache/v1/cache_controller/observability.py +208 -0
- lmcache/v1/cache_controller/utils.py +679 -0
- lmcache/v1/cache_controller/worker.py +665 -0
- lmcache/v1/cache_engine.py +2058 -0
- lmcache/v1/cache_interface.py +19 -0
- lmcache/v1/check/__init__.py +74 -0
- lmcache/v1/check/check_mode_gen.py +86 -0
- lmcache/v1/check/check_mode_test_l2_adapter.py +284 -0
- lmcache/v1/check/check_mode_test_remote.py +155 -0
- lmcache/v1/check/check_mode_test_storage_manager.py +142 -0
- lmcache/v1/check/utils.py +571 -0
- lmcache/v1/compute/__init__.py +2 -0
- lmcache/v1/compute/attention/__init__.py +0 -0
- lmcache/v1/compute/attention/abstract.py +39 -0
- lmcache/v1/compute/attention/flash_attn.py +129 -0
- lmcache/v1/compute/attention/flash_infer_sparse.py +284 -0
- lmcache/v1/compute/attention/metadata.py +85 -0
- lmcache/v1/compute/attention/utils.py +14 -0
- lmcache/v1/compute/blend/__init__.py +7 -0
- lmcache/v1/compute/blend/blender.py +168 -0
- lmcache/v1/compute/blend/metadata.py +34 -0
- lmcache/v1/compute/blend/utils.py +63 -0
- lmcache/v1/compute/models/__init__.py +0 -0
- lmcache/v1/compute/models/base.py +141 -0
- lmcache/v1/compute/models/llama.py +9 -0
- lmcache/v1/compute/models/qwen3.py +24 -0
- lmcache/v1/compute/models/utils.py +68 -0
- lmcache/v1/compute/positional_encoding.py +199 -0
- lmcache/v1/config.py +848 -0
- lmcache/v1/config_base.py +848 -0
- lmcache/v1/distributed/api.py +248 -0
- lmcache/v1/distributed/config.py +321 -0
- lmcache/v1/distributed/error.py +64 -0
- lmcache/v1/distributed/eviction.py +192 -0
- lmcache/v1/distributed/eviction_policy/__init__.py +21 -0
- lmcache/v1/distributed/eviction_policy/factory.py +27 -0
- lmcache/v1/distributed/eviction_policy/lru.py +244 -0
- lmcache/v1/distributed/eviction_policy/noop.py +50 -0
- lmcache/v1/distributed/internal_api.py +170 -0
- lmcache/v1/distributed/l1_manager.py +835 -0
- lmcache/v1/distributed/l2_adapters/__init__.py +67 -0
- lmcache/v1/distributed/l2_adapters/base.py +360 -0
- lmcache/v1/distributed/l2_adapters/config.py +385 -0
- lmcache/v1/distributed/l2_adapters/factory.py +205 -0
- lmcache/v1/distributed/l2_adapters/fs_l2_adapter.py +747 -0
- lmcache/v1/distributed/l2_adapters/fs_native_l2_adapter.py +167 -0
- lmcache/v1/distributed/l2_adapters/mock_l2_adapter.py +516 -0
- lmcache/v1/distributed/l2_adapters/mooncake_store_l2_adapter.py +135 -0
- lmcache/v1/distributed/l2_adapters/native_connector_l2_adapter.py +468 -0
- lmcache/v1/distributed/l2_adapters/native_plugin_l2_adapter.py +199 -0
- lmcache/v1/distributed/l2_adapters/nixl_store_dynamic_l2_adapter.py +831 -0
- lmcache/v1/distributed/l2_adapters/nixl_store_l2_adapter.py +983 -0
- lmcache/v1/distributed/l2_adapters/plugin_l2_adapter.py +210 -0
- lmcache/v1/distributed/l2_adapters/resp_l2_adapter.py +176 -0
- lmcache/v1/distributed/memory_manager.py +179 -0
- lmcache/v1/distributed/storage_controller.py +39 -0
- lmcache/v1/distributed/storage_controllers/__init__.py +43 -0
- lmcache/v1/distributed/storage_controllers/eviction_controller.py +242 -0
- lmcache/v1/distributed/storage_controllers/prefetch_controller.py +830 -0
- lmcache/v1/distributed/storage_controllers/prefetch_policy.py +193 -0
- lmcache/v1/distributed/storage_controllers/store_controller.py +452 -0
- lmcache/v1/distributed/storage_controllers/store_policy.py +213 -0
- lmcache/v1/distributed/storage_manager.py +532 -0
- lmcache/v1/event_manager.py +145 -0
- lmcache/v1/exceptions/__init__.py +16 -0
- lmcache/v1/gpu_connector/__init__.py +126 -0
- lmcache/v1/gpu_connector/gpu_connectors.py +1906 -0
- lmcache/v1/gpu_connector/gpu_ops.py +85 -0
- lmcache/v1/gpu_connector/hpu_connector.py +326 -0
- lmcache/v1/gpu_connector/mock_gpu_connector.py +67 -0
- lmcache/v1/gpu_connector/utils.py +890 -0
- lmcache/v1/gpu_connector/xpu_connectors.py +916 -0
- lmcache/v1/health_monitor/__init__.py +1 -0
- lmcache/v1/health_monitor/base.py +587 -0
- lmcache/v1/health_monitor/checks/__init__.py +1 -0
- lmcache/v1/health_monitor/checks/remote_backend_check.py +304 -0
- lmcache/v1/health_monitor/constants.py +36 -0
- lmcache/v1/internal_api_server/__init__.py +0 -0
- lmcache/v1/internal_api_server/api_registry.py +59 -0
- lmcache/v1/internal_api_server/api_server.py +120 -0
- lmcache/v1/internal_api_server/common/__init__.py +1 -0
- lmcache/v1/internal_api_server/common/env_api.py +22 -0
- lmcache/v1/internal_api_server/common/loglevel_api.py +57 -0
- lmcache/v1/internal_api_server/common/metrics_api.py +29 -0
- lmcache/v1/internal_api_server/common/periodic_thread_api.py +138 -0
- lmcache/v1/internal_api_server/common/run_script_api.py +73 -0
- lmcache/v1/internal_api_server/common/thread_api.py +63 -0
- lmcache/v1/internal_api_server/controller/__init__.py +1 -0
- lmcache/v1/internal_api_server/controller/key_stats_api.py +81 -0
- lmcache/v1/internal_api_server/controller/worker_info_api.py +136 -0
- lmcache/v1/internal_api_server/utils.py +43 -0
- lmcache/v1/internal_api_server/vllm/__init__.py +1 -0
- lmcache/v1/internal_api_server/vllm/backend_api.py +221 -0
- lmcache/v1/internal_api_server/vllm/bypass_api.py +204 -0
- lmcache/v1/internal_api_server/vllm/cache_api.py +895 -0
- lmcache/v1/internal_api_server/vllm/chunk_statistics_api.py +141 -0
- lmcache/v1/internal_api_server/vllm/conf_api.py +147 -0
- lmcache/v1/internal_api_server/vllm/freeze_api.py +172 -0
- lmcache/v1/internal_api_server/vllm/hot_cache_api.py +184 -0
- lmcache/v1/internal_api_server/vllm/inference_api.py +65 -0
- lmcache/v1/internal_api_server/vllm/load_fs_chunks_api.py +320 -0
- lmcache/v1/internal_api_server/vllm/lookup_api.py +145 -0
- lmcache/v1/internal_api_server/vllm/version_api.py +25 -0
- lmcache/v1/kv_layer_groups.py +267 -0
- lmcache/v1/lazy_memory_allocator.py +284 -0
- lmcache/v1/lookup_client/__init__.py +25 -0
- lmcache/v1/lookup_client/abstract_client.py +77 -0
- lmcache/v1/lookup_client/async_lookup_message.py +50 -0
- lmcache/v1/lookup_client/chunk_statistics_lookup_client.py +200 -0
- lmcache/v1/lookup_client/factory.py +251 -0
- lmcache/v1/lookup_client/hit_limit_lookup_client.py +86 -0
- lmcache/v1/lookup_client/lmcache_async_lookup_client.py +407 -0
- lmcache/v1/lookup_client/lmcache_lookup_client.py +285 -0
- lmcache/v1/lookup_client/lmcache_lookup_client_bypass.py +99 -0
- lmcache/v1/lookup_client/mooncake_lookup_client.py +87 -0
- lmcache/v1/lookup_client/record_strategies/__init__.py +77 -0
- lmcache/v1/lookup_client/record_strategies/base.py +327 -0
- lmcache/v1/lookup_client/record_strategies/file_hash.py +130 -0
- lmcache/v1/lookup_client/record_strategies/memory_bloom_filter.py +81 -0
- lmcache/v1/manager.py +539 -0
- lmcache/v1/memory_management.py +2619 -0
- lmcache/v1/metadata.py +114 -0
- lmcache/v1/mp_observability/AGENTS.override.md +21 -0
- lmcache/v1/mp_observability/README.md +204 -0
- lmcache/v1/mp_observability/config.py +340 -0
- lmcache/v1/mp_observability/event.py +100 -0
- lmcache/v1/mp_observability/event_bus.py +313 -0
- lmcache/v1/mp_observability/otel_init.py +145 -0
- lmcache/v1/mp_observability/subscribers/__init__.py +28 -0
- lmcache/v1/mp_observability/subscribers/logging/__init__.py +19 -0
- lmcache/v1/mp_observability/subscribers/logging/l1.py +56 -0
- lmcache/v1/mp_observability/subscribers/logging/l2.py +73 -0
- lmcache/v1/mp_observability/subscribers/logging/lookup_hash.py +209 -0
- lmcache/v1/mp_observability/subscribers/logging/mp_server.py +90 -0
- lmcache/v1/mp_observability/subscribers/logging/sm.py +59 -0
- lmcache/v1/mp_observability/subscribers/metrics/__init__.py +20 -0
- lmcache/v1/mp_observability/subscribers/metrics/l0_lifecycle.py +290 -0
- lmcache/v1/mp_observability/subscribers/metrics/l1.py +55 -0
- lmcache/v1/mp_observability/subscribers/metrics/l1_lifecycle.py +166 -0
- lmcache/v1/mp_observability/subscribers/metrics/l2.py +121 -0
- lmcache/v1/mp_observability/subscribers/metrics/sm.py +69 -0
- lmcache/v1/mp_observability/subscribers/tracing/__init__.py +12 -0
- lmcache/v1/mp_observability/subscribers/tracing/mp_server.py +333 -0
- lmcache/v1/mp_observability/subscribers/tracing/span_registry.py +148 -0
- lmcache/v1/mp_observability/trace/__init__.py +50 -0
- lmcache/v1/mp_observability/trace/codecs.py +255 -0
- lmcache/v1/mp_observability/trace/decorator.py +147 -0
- lmcache/v1/mp_observability/trace/format.py +132 -0
- lmcache/v1/mp_observability/trace/lifecycle.py +83 -0
- lmcache/v1/mp_observability/trace/reader.py +167 -0
- lmcache/v1/mp_observability/trace/recorder.py +300 -0
- lmcache/v1/multiprocess/__init__.py +0 -0
- lmcache/v1/multiprocess/affinity_pool.py +102 -0
- lmcache/v1/multiprocess/blend_server_v2.py +891 -0
- lmcache/v1/multiprocess/config.py +253 -0
- lmcache/v1/multiprocess/custom_types.py +281 -0
- lmcache/v1/multiprocess/futures.py +194 -0
- lmcache/v1/multiprocess/gpu_context.py +511 -0
- lmcache/v1/multiprocess/http_server.py +235 -0
- lmcache/v1/multiprocess/mp_runtime_plugin_launcher.py +130 -0
- lmcache/v1/multiprocess/mq.py +732 -0
- lmcache/v1/multiprocess/protocol.py +86 -0
- lmcache/v1/multiprocess/protocols/README.md +213 -0
- lmcache/v1/multiprocess/protocols/__init__.py +127 -0
- lmcache/v1/multiprocess/protocols/base.py +89 -0
- lmcache/v1/multiprocess/protocols/blend.py +109 -0
- lmcache/v1/multiprocess/protocols/blend_v2.py +57 -0
- lmcache/v1/multiprocess/protocols/controller.py +53 -0
- lmcache/v1/multiprocess/protocols/debug.py +34 -0
- lmcache/v1/multiprocess/protocols/engine.py +146 -0
- lmcache/v1/multiprocess/protocols/observability.py +39 -0
- lmcache/v1/multiprocess/server.py +1134 -0
- lmcache/v1/multiprocess/session.py +190 -0
- lmcache/v1/multiprocess/token_hasher.py +441 -0
- lmcache/v1/offload_server/__init__.py +17 -0
- lmcache/v1/offload_server/abstract_server.py +37 -0
- lmcache/v1/offload_server/message.py +30 -0
- lmcache/v1/offload_server/zmq_server.py +122 -0
- lmcache/v1/periodic_thread.py +579 -0
- lmcache/v1/pin_monitor.py +246 -0
- lmcache/v1/plugin/__init__.py +0 -0
- lmcache/v1/plugin/runtime_plugin_launcher.py +211 -0
- lmcache/v1/protocol.py +317 -0
- lmcache/v1/rpc/__init__.py +17 -0
- lmcache/v1/rpc/transport.py +105 -0
- lmcache/v1/rpc/zmq_transport.py +213 -0
- lmcache/v1/rpc_utils.py +165 -0
- lmcache/v1/server/__init__.py +2 -0
- lmcache/v1/server/__main__.py +170 -0
- lmcache/v1/server/storage_backend/__init__.py +21 -0
- lmcache/v1/server/storage_backend/abstract_backend.py +80 -0
- lmcache/v1/server/storage_backend/local_backend.py +75 -0
- lmcache/v1/server/utils.py +21 -0
- lmcache/v1/standalone/__init__.py +1 -0
- lmcache/v1/standalone/__main__.py +583 -0
- lmcache/v1/standalone/manager.py +80 -0
- lmcache/v1/standalone/standalone_service_factory.py +86 -0
- lmcache/v1/storage_backend/__init__.py +313 -0
- lmcache/v1/storage_backend/abstract_backend.py +445 -0
- lmcache/v1/storage_backend/audit_backend.py +233 -0
- lmcache/v1/storage_backend/batched_message_sender.py +222 -0
- lmcache/v1/storage_backend/cache_policy/__init__.py +45 -0
- lmcache/v1/storage_backend/cache_policy/base_policy.py +87 -0
- lmcache/v1/storage_backend/cache_policy/fifo.py +58 -0
- lmcache/v1/storage_backend/cache_policy/lfu.py +105 -0
- lmcache/v1/storage_backend/cache_policy/lru.py +81 -0
- lmcache/v1/storage_backend/cache_policy/mru.py +61 -0
- lmcache/v1/storage_backend/connector/__init__.py +443 -0
- lmcache/v1/storage_backend/connector/audit_adapter.py +77 -0
- lmcache/v1/storage_backend/connector/audit_connector.py +320 -0
- lmcache/v1/storage_backend/connector/base_connector.py +379 -0
- lmcache/v1/storage_backend/connector/blackhole_adapter.py +21 -0
- lmcache/v1/storage_backend/connector/blackhole_connector.py +37 -0
- lmcache/v1/storage_backend/connector/eic_adapter.py +31 -0
- lmcache/v1/storage_backend/connector/eic_connector.py +757 -0
- lmcache/v1/storage_backend/connector/external_adapter.py +79 -0
- lmcache/v1/storage_backend/connector/fs_adapter.py +51 -0
- lmcache/v1/storage_backend/connector/fs_connector.py +403 -0
- lmcache/v1/storage_backend/connector/infinistore_adapter.py +56 -0
- lmcache/v1/storage_backend/connector/infinistore_connector.py +177 -0
- lmcache/v1/storage_backend/connector/instrumented_connector.py +219 -0
- lmcache/v1/storage_backend/connector/lm_adapter.py +31 -0
- lmcache/v1/storage_backend/connector/lm_connector.py +176 -0
- lmcache/v1/storage_backend/connector/mock_adapter.py +57 -0
- lmcache/v1/storage_backend/connector/mock_connector.py +349 -0
- lmcache/v1/storage_backend/connector/mooncakestore_adapter.py +43 -0
- lmcache/v1/storage_backend/connector/mooncakestore_connector.py +614 -0
- lmcache/v1/storage_backend/connector/redis_adapter.py +181 -0
- lmcache/v1/storage_backend/connector/redis_connector.py +828 -0
- lmcache/v1/storage_backend/connector/s3_adapter.py +59 -0
- lmcache/v1/storage_backend/connector/s3_connector.py +699 -0
- lmcache/v1/storage_backend/connector/sagemaker_hyperpod_adapter.py +233 -0
- lmcache/v1/storage_backend/connector/sagemaker_hyperpod_connector.py +987 -0
- lmcache/v1/storage_backend/connector/valkey_adapter.py +114 -0
- lmcache/v1/storage_backend/connector/valkey_connector.py +627 -0
- lmcache/v1/storage_backend/gds_backend.py +1199 -0
- lmcache/v1/storage_backend/job_executor/__init__.py +0 -0
- lmcache/v1/storage_backend/job_executor/base_executor.py +34 -0
- lmcache/v1/storage_backend/job_executor/pq_executor.py +235 -0
- lmcache/v1/storage_backend/local_cpu_backend.py +810 -0
- lmcache/v1/storage_backend/local_disk_backend.py +656 -0
- lmcache/v1/storage_backend/maru_backend.py +734 -0
- lmcache/v1/storage_backend/naive_serde/__init__.py +50 -0
- lmcache/v1/storage_backend/naive_serde/cachegen_basics.py +133 -0
- lmcache/v1/storage_backend/naive_serde/cachegen_decoder.py +135 -0
- lmcache/v1/storage_backend/naive_serde/cachegen_encoder.py +83 -0
- lmcache/v1/storage_backend/naive_serde/kivi_serde.py +22 -0
- lmcache/v1/storage_backend/naive_serde/naive_serde.py +18 -0
- lmcache/v1/storage_backend/naive_serde/serde.py +37 -0
- lmcache/v1/storage_backend/native_clients/connector_client_base.py +165 -0
- lmcache/v1/storage_backend/native_clients/resp_client.py +35 -0
- lmcache/v1/storage_backend/nixl_storage_backend.py +1400 -0
- lmcache/v1/storage_backend/p2p_backend.py +788 -0
- lmcache/v1/storage_backend/path_sharder.py +117 -0
- lmcache/v1/storage_backend/pd_backend.py +646 -0
- lmcache/v1/storage_backend/plugins/dax_backend.py +1443 -0
- lmcache/v1/storage_backend/plugins/rust_raw_block_backend.py +1361 -0
- lmcache/v1/storage_backend/remote_backend.py +624 -0
- lmcache/v1/storage_backend/resp_client.py +227 -0
- lmcache/v1/storage_backend/storage_backend_listener.py +19 -0
- lmcache/v1/storage_backend/storage_manager.py +1352 -0
- lmcache/v1/system_detection.py +110 -0
- lmcache/v1/token_database.py +551 -0
- lmcache/v1/transfer_channel/__init__.py +83 -0
- lmcache/v1/transfer_channel/abstract.py +285 -0
- lmcache/v1/transfer_channel/mock_memory_channel.py +156 -0
- lmcache/v1/transfer_channel/nixl_channel.py +639 -0
- lmcache/v1/transfer_channel/py_socket_channel.py +260 -0
- lmcache/v1/transfer_channel/transfer_utils.py +63 -0
- lmcache/v1/utils/__init__.py +1 -0
- lmcache/v1/utils/bloom_filter.py +109 -0
- lmcache/v1/utils/cache_utils.py +125 -0
- lmcache_cli-0.4.5.dev0.dist-info/METADATA +185 -0
- lmcache_cli-0.4.5.dev0.dist-info/RECORD +399 -0
- lmcache_cli-0.4.5.dev0.dist-info/WHEEL +5 -0
- lmcache_cli-0.4.5.dev0.dist-info/entry_points.txt +2 -0
- lmcache_cli-0.4.5.dev0.dist-info/licenses/LICENSE +201 -0
- lmcache_cli-0.4.5.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
Main RPC protocol for the LMCache core server and clients.
|
|
4
|
+
|
|
5
|
+
This module serves as the main entry point for the protocol system.
|
|
6
|
+
All protocol definitions are now organized in the protocols/ subdirectory:
|
|
7
|
+
- protocols/base.py: RequestType enum, HandlerType, ProtocolDefinition
|
|
8
|
+
- protocols/engine.py: Core KV cache operations (REGISTER, STORE, RETRIEVE, etc.)
|
|
9
|
+
- protocols/controller.py: Cache management operations (CLEAR, GET_CHUNK_SIZE)
|
|
10
|
+
- protocols/debug.py: Debug and testing operations (NOOP)
|
|
11
|
+
|
|
12
|
+
The protocol definitions are loaded and validated during initialization.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# Standard
|
|
16
|
+
from typing import Any, Optional
|
|
17
|
+
|
|
18
|
+
# First Party
|
|
19
|
+
from lmcache.v1.multiprocess.custom_types import IPCCacheEngineKey
|
|
20
|
+
from lmcache.v1.multiprocess.protocols import initialize_protocols
|
|
21
|
+
from lmcache.v1.multiprocess.protocols.base import HandlerType, RequestType
|
|
22
|
+
|
|
23
|
+
# Initialize the protocol system
|
|
24
|
+
# This loads all protocol definitions and validates them against the RequestType enum
|
|
25
|
+
_PROTOCOL_DEFINITIONS = initialize_protocols()
|
|
26
|
+
|
|
27
|
+
# Type aliases for backwards compatibility
|
|
28
|
+
InstanceID = int
|
|
29
|
+
KeyType = IPCCacheEngineKey
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_payload_classes(req_type: RequestType) -> list[Any]:
|
|
33
|
+
"""
|
|
34
|
+
Get the expected payload classes for a request type.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
req_type: The request type to look up
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
List of expected payload classes in order
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
ValueError: If the request type is not recognized
|
|
44
|
+
"""
|
|
45
|
+
if pd := _PROTOCOL_DEFINITIONS.get(req_type, None):
|
|
46
|
+
return pd.payload_classes
|
|
47
|
+
else:
|
|
48
|
+
raise ValueError(f"Invalid request type: {req_type}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_response_class(req_type: RequestType) -> Optional[Any]:
|
|
52
|
+
"""
|
|
53
|
+
Get the expected response class for a request type.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
req_type: The request type to look up
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Expected response class, or None if no response
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
ValueError: If the request type is not recognized
|
|
63
|
+
"""
|
|
64
|
+
if pd := _PROTOCOL_DEFINITIONS.get(req_type, None):
|
|
65
|
+
return pd.response_class
|
|
66
|
+
else:
|
|
67
|
+
raise ValueError(f"Invalid request type: {req_type}")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_handler_type(req_type: RequestType) -> HandlerType:
|
|
71
|
+
"""
|
|
72
|
+
Get the handler type for a request type.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
req_type: The request type to look up
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
The handler type (SYNC, BLOCKING, or NON_BLOCKING)
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
ValueError: If the request type is not recognized
|
|
82
|
+
"""
|
|
83
|
+
if pd := _PROTOCOL_DEFINITIONS.get(req_type, None):
|
|
84
|
+
return pd.handler_type
|
|
85
|
+
else:
|
|
86
|
+
raise ValueError(f"Invalid request type: {req_type}")
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Modular Protocol System
|
|
2
|
+
|
|
3
|
+
This directory contains the modular protocol definitions for the LMCache multiprocess system.
|
|
4
|
+
|
|
5
|
+
## Directory Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
protocols/
|
|
9
|
+
├── README.md # This file
|
|
10
|
+
├── __init__.py # Protocol initialization and registration
|
|
11
|
+
├── base.py # Common types (HandlerType, ProtocolDefinition)
|
|
12
|
+
├── engine.py # Engine operations (STORE, RETRIEVE, etc.)
|
|
13
|
+
├── controller.py # Controller operations (CLEAR, GET_CHUNK_SIZE)
|
|
14
|
+
└── debug.py # Debug operations (NOOP)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Design Overview
|
|
18
|
+
|
|
19
|
+
The protocol system is designed to be modular, extensible, and IDE-friendly:
|
|
20
|
+
|
|
21
|
+
1. **Static Enum with Validation**: The `RequestType` enum is defined statically in `base.py`:
|
|
22
|
+
- Provides perfect IDE autocomplete and type checking
|
|
23
|
+
- All request types visible to static analysis tools
|
|
24
|
+
- Validation ensures enum stays in sync with protocol definitions
|
|
25
|
+
|
|
26
|
+
2. **Protocol Modules**: Each module (engine, controller, debug) defines:
|
|
27
|
+
- `REQUEST_NAMES`: List of request type names (for validation)
|
|
28
|
+
- `get_protocol_definitions()`: Returns dict of name → ProtocolDefinition
|
|
29
|
+
|
|
30
|
+
3. **Validated Initialization**: The `__init__.py` module:
|
|
31
|
+
- Collects all protocol definitions from modules
|
|
32
|
+
- Validates each `RequestType` enum member has a definition
|
|
33
|
+
- Validates each definition has a corresponding enum member
|
|
34
|
+
- Ensures no duplicates or mismatches
|
|
35
|
+
|
|
36
|
+
4. **Main Entry Point**: The `protocol.py` file:
|
|
37
|
+
- Calls `initialize_protocols()` on import
|
|
38
|
+
- Provides backwards-compatible API
|
|
39
|
+
- Exports `RequestType`, helper functions, and types
|
|
40
|
+
|
|
41
|
+
## Adding New Protocols
|
|
42
|
+
|
|
43
|
+
To add new protocol operations:
|
|
44
|
+
|
|
45
|
+
### Option 1: Add to Existing Module
|
|
46
|
+
|
|
47
|
+
If your operation fits an existing category (engine/controller/debug):
|
|
48
|
+
|
|
49
|
+
1. **Add to the enum** in `protocols/base.py`:
|
|
50
|
+
```python
|
|
51
|
+
class RequestType(enum.Enum):
|
|
52
|
+
# ... existing members ...
|
|
53
|
+
YOUR_NEW_OP = enum.auto() # Add here
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
2. **Edit the appropriate protocol file** (e.g., `engine.py`):
|
|
57
|
+
- Add the request name to `REQUEST_NAMES`:
|
|
58
|
+
```python
|
|
59
|
+
REQUEST_NAMES = [
|
|
60
|
+
"EXISTING_OP",
|
|
61
|
+
"YOUR_NEW_OP", # Add here
|
|
62
|
+
]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
3. **Add the protocol definition** in `get_protocol_definitions()`:
|
|
66
|
+
```python
|
|
67
|
+
def get_protocol_definitions() -> dict[str, ProtocolDefinition]:
|
|
68
|
+
return {
|
|
69
|
+
# ... existing definitions ...
|
|
70
|
+
"YOUR_NEW_OP": ProtocolDefinition(
|
|
71
|
+
payload_classes=[int, str], # Your payload types
|
|
72
|
+
response_class=bool, # Your response type
|
|
73
|
+
handler_type=HandlerType.SYNC, # or BLOCKING
|
|
74
|
+
),
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
4. **Done!** The validation system will verify everything matches on import.
|
|
79
|
+
|
|
80
|
+
### Option 2: Create New Protocol Module
|
|
81
|
+
|
|
82
|
+
If you're adding a new category of operations:
|
|
83
|
+
|
|
84
|
+
1. **Add enum members** in `protocols/base.py`:
|
|
85
|
+
```python
|
|
86
|
+
class RequestType(enum.Enum):
|
|
87
|
+
# ... existing members ...
|
|
88
|
+
|
|
89
|
+
# Monitoring operations
|
|
90
|
+
HEALTH_CHECK = enum.auto()
|
|
91
|
+
GET_STATS = enum.auto()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
2. **Create a new protocol file** (e.g., `monitoring.py`):
|
|
95
|
+
```python
|
|
96
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
97
|
+
"""
|
|
98
|
+
Monitoring protocol definitions.
|
|
99
|
+
|
|
100
|
+
This module defines protocols for:
|
|
101
|
+
- HEALTH_CHECK: Check server health status
|
|
102
|
+
- GET_STATS: Get cache statistics
|
|
103
|
+
"""
|
|
104
|
+
from lmcache.v1.multiprocess.protocols.base import ProtocolDefinition, HandlerType
|
|
105
|
+
|
|
106
|
+
REQUEST_NAMES = [
|
|
107
|
+
"HEALTH_CHECK",
|
|
108
|
+
"GET_STATS",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
def get_protocol_definitions() -> dict[str, ProtocolDefinition]:
|
|
112
|
+
return {
|
|
113
|
+
"HEALTH_CHECK": ProtocolDefinition(
|
|
114
|
+
payload_classes=[],
|
|
115
|
+
response_class=dict,
|
|
116
|
+
handler_type=HandlerType.SYNC,
|
|
117
|
+
),
|
|
118
|
+
"GET_STATS": ProtocolDefinition(
|
|
119
|
+
payload_classes=[],
|
|
120
|
+
response_class=dict,
|
|
121
|
+
handler_type=HandlerType.SYNC,
|
|
122
|
+
),
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
3. **Register the module** in `__init__.py`:
|
|
127
|
+
```python
|
|
128
|
+
from lmcache.v1.multiprocess.protocols import monitoring # Import your module
|
|
129
|
+
|
|
130
|
+
def initialize_protocols():
|
|
131
|
+
protocol_modules = [
|
|
132
|
+
("engine", engine),
|
|
133
|
+
("controller", controller),
|
|
134
|
+
("debug", debug),
|
|
135
|
+
("monitoring", monitoring), # Add here
|
|
136
|
+
]
|
|
137
|
+
# ... rest of initialization ...
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
4. **Done!** The new operations are now available as:
|
|
141
|
+
- `RequestType.HEALTH_CHECK` (with full IDE autocomplete!)
|
|
142
|
+
- `RequestType.GET_STATS`
|
|
143
|
+
|
|
144
|
+
## Using the Protocol System
|
|
145
|
+
|
|
146
|
+
From any module in the codebase:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from lmcache.v1.multiprocess.protocol import (
|
|
150
|
+
RequestType,
|
|
151
|
+
HandlerType,
|
|
152
|
+
get_payload_classes,
|
|
153
|
+
get_response_class,
|
|
154
|
+
get_handler_type,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# Use request types
|
|
158
|
+
req_type = RequestType.STORE
|
|
159
|
+
|
|
160
|
+
# Get protocol information
|
|
161
|
+
payloads = get_payload_classes(req_type)
|
|
162
|
+
response = get_response_class(req_type)
|
|
163
|
+
handler = get_handler_type(req_type)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Validation
|
|
167
|
+
|
|
168
|
+
The initialization system validates at startup:
|
|
169
|
+
|
|
170
|
+
1. **Enum-Definition Sync**: Every `RequestType` enum member must have a protocol definition
|
|
171
|
+
2. **Definition-Enum Sync**: Every protocol definition must have a corresponding enum member
|
|
172
|
+
3. **No duplicates**: Same request name cannot be defined in multiple modules
|
|
173
|
+
4. **Complete definitions**: All names in `REQUEST_NAMES` must have definitions in `get_protocol_definitions()`
|
|
174
|
+
|
|
175
|
+
If validation fails, `ProtocolInitializationError` is raised with a descriptive message pointing to the issue.
|
|
176
|
+
|
|
177
|
+
### Example Error Messages
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
# If you add RequestType.NEW_OP but forget the definition:
|
|
181
|
+
ProtocolInitializationError: RequestType enum members {'NEW_OP'} have no protocol definitions.
|
|
182
|
+
Add definitions to the appropriate protocol module or remove from the enum.
|
|
183
|
+
|
|
184
|
+
# If you add a definition but forget the enum member:
|
|
185
|
+
ProtocolInitializationError: Protocol definition 'NEW_OP' in module 'engine'
|
|
186
|
+
has no corresponding RequestType enum member. Add 'RequestType.NEW_OP' to protocols/base.py
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Current Protocol Groups
|
|
190
|
+
|
|
191
|
+
### Engine Operations (`engine.py`)
|
|
192
|
+
Core KV cache operations:
|
|
193
|
+
- `REGISTER_KV_CACHE`: Register a KV cache instance
|
|
194
|
+
- `UNREGISTER_KV_CACHE`: Unregister a KV cache instance
|
|
195
|
+
- `STORE`: Store KV cache blocks to the server
|
|
196
|
+
- `RETRIEVE`: Retrieve KV cache blocks from the server
|
|
197
|
+
- `LOOKUP`: Check if keys exist in the cache
|
|
198
|
+
- `END_SESSION`: End a session and clean up resources
|
|
199
|
+
|
|
200
|
+
### Controller Operations (`controller.py`)
|
|
201
|
+
Cache management and configuration:
|
|
202
|
+
- `CLEAR`: Clear all caches in the server
|
|
203
|
+
- `GET_CHUNK_SIZE`: Get the chunk size configuration
|
|
204
|
+
|
|
205
|
+
### Debug Operations (`debug.py`)
|
|
206
|
+
Testing and monitoring:
|
|
207
|
+
- `NOOP`: No-operation command for testing/heartbeat
|
|
208
|
+
|
|
209
|
+
## Handler Types
|
|
210
|
+
|
|
211
|
+
- `HandlerType.SYNC`: Fast operations that run directly in the main loop
|
|
212
|
+
- `HandlerType.BLOCKING`: Operations that may block, run in a thread pool
|
|
213
|
+
- `HandlerType.NON_BLOCKING`: Not yet supported (for future async handlers)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
Protocol initialization and registration system.
|
|
4
|
+
|
|
5
|
+
This module provides the initialize_protocols() function that:
|
|
6
|
+
1. Collects protocol definitions from all protocol modules
|
|
7
|
+
2. Validates that the static RequestType enum matches protocol definitions
|
|
8
|
+
3. Ensures all enum members have definitions and vice versa
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# First Party
|
|
12
|
+
from lmcache.v1.multiprocess.protocols import (
|
|
13
|
+
blend,
|
|
14
|
+
blend_v2,
|
|
15
|
+
controller,
|
|
16
|
+
debug,
|
|
17
|
+
engine,
|
|
18
|
+
observability,
|
|
19
|
+
)
|
|
20
|
+
from lmcache.v1.multiprocess.protocols.base import (
|
|
21
|
+
HandlerType,
|
|
22
|
+
ProtocolDefinition,
|
|
23
|
+
RequestType,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ProtocolInitializationError(Exception):
|
|
28
|
+
"""Raised when there's an error during protocol initialization."""
|
|
29
|
+
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
_PROTOCOL_MODULES = [
|
|
34
|
+
("engine", engine),
|
|
35
|
+
("controller", controller),
|
|
36
|
+
("debug", debug),
|
|
37
|
+
("blend", blend),
|
|
38
|
+
("blend_v2", blend_v2),
|
|
39
|
+
("observability", observability),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def initialize_protocols() -> dict[RequestType, ProtocolDefinition]:
|
|
44
|
+
"""
|
|
45
|
+
Initialize the protocol system by collecting all protocol definitions
|
|
46
|
+
and validating them against the RequestType enum.
|
|
47
|
+
|
|
48
|
+
This function:
|
|
49
|
+
1. Collects protocol definitions from all protocol modules
|
|
50
|
+
2. Validates that each RequestType enum member has a definition
|
|
51
|
+
3. Validates that each definition has a corresponding enum member
|
|
52
|
+
4. Ensures no duplicate or orphaned definitions
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
protocol_definitions: Dict mapping RequestType enum values to
|
|
56
|
+
ProtocolDefinition
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
ProtocolInitializationError: If there are mismatches between enum and
|
|
60
|
+
definitions
|
|
61
|
+
"""
|
|
62
|
+
# Protocol modules to load
|
|
63
|
+
global _PROTOCOL_MODULES
|
|
64
|
+
|
|
65
|
+
# Step 1: Collect protocol definitions from all modules
|
|
66
|
+
protocol_definitions = {}
|
|
67
|
+
defined_names = set()
|
|
68
|
+
name_to_module: dict[str, str] = {}
|
|
69
|
+
|
|
70
|
+
for module_name, module in _PROTOCOL_MODULES:
|
|
71
|
+
module_defs = module.get_protocol_definitions()
|
|
72
|
+
|
|
73
|
+
# Check for duplicates across modules
|
|
74
|
+
for name in module_defs.keys():
|
|
75
|
+
if name in name_to_module:
|
|
76
|
+
raise ProtocolInitializationError(
|
|
77
|
+
f"Duplicate protocol definition '{name}' found in modules "
|
|
78
|
+
f"'{name_to_module[name]}' and '{module_name}'"
|
|
79
|
+
)
|
|
80
|
+
name_to_module[name] = module_name
|
|
81
|
+
|
|
82
|
+
# Validate that all names in REQUEST_NAMES have definitions
|
|
83
|
+
for name in module.REQUEST_NAMES:
|
|
84
|
+
if name not in module_defs:
|
|
85
|
+
raise ProtocolInitializationError(
|
|
86
|
+
f"Request name '{name}' in module '{module_name}' "
|
|
87
|
+
f"is listed in REQUEST_NAMES but has no protocol definition"
|
|
88
|
+
)
|
|
89
|
+
defined_names.add(name)
|
|
90
|
+
|
|
91
|
+
# Convert string names to enum values and store definitions
|
|
92
|
+
for name, definition in module_defs.items():
|
|
93
|
+
try:
|
|
94
|
+
enum_value = RequestType[name]
|
|
95
|
+
protocol_definitions[enum_value] = definition
|
|
96
|
+
except KeyError as err:
|
|
97
|
+
raise ProtocolInitializationError(
|
|
98
|
+
f"Protocol definition '{name}' in module '{module_name}' "
|
|
99
|
+
f"has no corresponding RequestType enum member. "
|
|
100
|
+
f"Add 'RequestType.{name}' to protocols/base.py"
|
|
101
|
+
) from err
|
|
102
|
+
|
|
103
|
+
# Step 2: Validate that all enum members have definitions
|
|
104
|
+
all_enum_names = {member.name for member in RequestType}
|
|
105
|
+
missing_definitions = all_enum_names - defined_names
|
|
106
|
+
|
|
107
|
+
if missing_definitions:
|
|
108
|
+
raise ProtocolInitializationError(
|
|
109
|
+
f"RequestType enum members {missing_definitions} have no protocol "
|
|
110
|
+
"definitions. Add definitions to the appropriate protocol module or "
|
|
111
|
+
"remove from the enum."
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Step 3: Validate that all definitions have enum members (already done in step 1)
|
|
115
|
+
# This is implicitly checked when we do RequestType[name]
|
|
116
|
+
|
|
117
|
+
return protocol_definitions
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# Export the base types for convenience
|
|
121
|
+
__all__ = [
|
|
122
|
+
"initialize_protocols",
|
|
123
|
+
"RequestType",
|
|
124
|
+
"ProtocolDefinition",
|
|
125
|
+
"HandlerType",
|
|
126
|
+
"ProtocolInitializationError",
|
|
127
|
+
]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
Base types and classes for the multiprocess protocol system.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# Standard
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Any, Optional
|
|
9
|
+
import enum
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HandlerType(enum.Enum):
|
|
13
|
+
"""
|
|
14
|
+
Defines how a protocol handler should be executed.
|
|
15
|
+
|
|
16
|
+
- SYNC: Handler runs directly in the main loop (fast, non-blocking operations)
|
|
17
|
+
- BLOCKING: Handler may block, run in a thread pool (I/O, slow operations)
|
|
18
|
+
- NON_BLOCKING: Not supported yet (for future async handlers)
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
SYNC = enum.auto()
|
|
22
|
+
BLOCKING = enum.auto()
|
|
23
|
+
NON_BLOCKING = enum.auto()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class RequestType(enum.Enum):
|
|
27
|
+
"""
|
|
28
|
+
Enum of all available request types in the protocol system.
|
|
29
|
+
|
|
30
|
+
When adding a new request type:
|
|
31
|
+
1. Add the enum member here
|
|
32
|
+
2. Add the protocol definition in the appropriate protocols/*.py file
|
|
33
|
+
3. The validation system will ensure they stay in sync
|
|
34
|
+
|
|
35
|
+
Organized by category:
|
|
36
|
+
- Engine operations: Core KV cache operations
|
|
37
|
+
- Controller operations: Cache management and configuration
|
|
38
|
+
- Debug operations: Testing and monitoring
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
# Engine operations
|
|
42
|
+
REGISTER_KV_CACHE = enum.auto()
|
|
43
|
+
UNREGISTER_KV_CACHE = enum.auto()
|
|
44
|
+
STORE = enum.auto()
|
|
45
|
+
RETRIEVE = enum.auto()
|
|
46
|
+
LOOKUP = enum.auto()
|
|
47
|
+
QUERY_PREFETCH_STATUS = enum.auto()
|
|
48
|
+
QUERY_PREFETCH_LOOKUP_HITS = enum.auto()
|
|
49
|
+
FREE_LOOKUP_LOCKS = enum.auto()
|
|
50
|
+
END_SESSION = enum.auto()
|
|
51
|
+
|
|
52
|
+
# Controller operations
|
|
53
|
+
CLEAR = enum.auto()
|
|
54
|
+
GET_CHUNK_SIZE = enum.auto()
|
|
55
|
+
PING = enum.auto()
|
|
56
|
+
|
|
57
|
+
# Observability operations
|
|
58
|
+
REPORT_BLOCK_ALLOCATION = enum.auto()
|
|
59
|
+
|
|
60
|
+
# Debug operations
|
|
61
|
+
NOOP = enum.auto()
|
|
62
|
+
|
|
63
|
+
# Blend operations
|
|
64
|
+
CB_REGISTER_KV_CACHE = enum.auto()
|
|
65
|
+
CB_UNREGISTER_KV_CACHE = enum.auto()
|
|
66
|
+
CB_STORE_PRE_COMPUTED = enum.auto()
|
|
67
|
+
CB_LOOKUP_PRE_COMPUTED = enum.auto()
|
|
68
|
+
CB_RETRIEVE_PRE_COMPUTED = enum.auto()
|
|
69
|
+
CB_STORE_FINAL = enum.auto()
|
|
70
|
+
|
|
71
|
+
# Blend V2 operations (use CBMatchResult instead of list[tuple[int, int]])
|
|
72
|
+
CB_LOOKUP_PRE_COMPUTED_V2 = enum.auto()
|
|
73
|
+
CB_RETRIEVE_PRE_COMPUTED_V2 = enum.auto()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class ProtocolDefinition:
|
|
78
|
+
"""
|
|
79
|
+
Defines the structure and behavior of a protocol request.
|
|
80
|
+
|
|
81
|
+
Attributes:
|
|
82
|
+
payload_classes: List of expected payload types in order
|
|
83
|
+
response_class: Expected response type, or None if no response
|
|
84
|
+
handler_type: How the handler should be executed (SYNC/BLOCKING/NON_BLOCKING)
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
payload_classes: list[Any]
|
|
88
|
+
response_class: Optional[Any]
|
|
89
|
+
handler_type: HandlerType
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
Debug protocol definitions for testing and monitoring.
|
|
4
|
+
|
|
5
|
+
This module defines the protocol for:
|
|
6
|
+
- NOOP: No-operation command for testing connectivity and as a heartbeat
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# First Party
|
|
10
|
+
from lmcache.v1.multiprocess.custom_types import IPCCacheEngineKey, KVCache
|
|
11
|
+
from lmcache.v1.multiprocess.protocols.base import HandlerType, ProtocolDefinition
|
|
12
|
+
|
|
13
|
+
# Define request names for this protocol group
|
|
14
|
+
REQUEST_NAMES = [
|
|
15
|
+
"CB_LOOKUP_PRE_COMPUTED",
|
|
16
|
+
"CB_STORE_PRE_COMPUTED",
|
|
17
|
+
"CB_RETRIEVE_PRE_COMPUTED",
|
|
18
|
+
"CB_STORE_FINAL",
|
|
19
|
+
"CB_REGISTER_KV_CACHE",
|
|
20
|
+
"CB_UNREGISTER_KV_CACHE",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_protocol_definitions() -> dict[str, ProtocolDefinition]:
|
|
25
|
+
"""
|
|
26
|
+
Returns protocol definitions for debug operations.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
Dictionary mapping request names to their protocol definitions
|
|
30
|
+
"""
|
|
31
|
+
return {
|
|
32
|
+
# Lookup pre-computed chunks
|
|
33
|
+
# Payload:
|
|
34
|
+
# - key: IPCCacheEngineKey - The key containing the token ids
|
|
35
|
+
# Returns: List of tuples (start, end) indicating the match ranges
|
|
36
|
+
"CB_LOOKUP_PRE_COMPUTED": ProtocolDefinition(
|
|
37
|
+
payload_classes=[IPCCacheEngineKey],
|
|
38
|
+
response_class=list[tuple[int, int]],
|
|
39
|
+
handler_type=HandlerType.BLOCKING,
|
|
40
|
+
),
|
|
41
|
+
# Store pre-computed chunks
|
|
42
|
+
# Payload:
|
|
43
|
+
# - key: IPCCacheEngineKey - The key containing the token ids
|
|
44
|
+
# - offset: int - The starting offset in the CB KV cache buffer
|
|
45
|
+
# - instance_id: int - Unique identifier for the vLLM instance
|
|
46
|
+
# - event_ipc_handle: bytes - IPC handle for event notification
|
|
47
|
+
# when the pre-computed chunks are ready
|
|
48
|
+
# Returns:
|
|
49
|
+
# - IPC handle bytes
|
|
50
|
+
# - boolean flag indicating if the store is successful
|
|
51
|
+
"CB_STORE_PRE_COMPUTED": ProtocolDefinition(
|
|
52
|
+
payload_classes=[IPCCacheEngineKey, int, int, bytes],
|
|
53
|
+
response_class=tuple[bytes, bool],
|
|
54
|
+
handler_type=HandlerType.BLOCKING,
|
|
55
|
+
),
|
|
56
|
+
# Retrieve pre-computed chunks
|
|
57
|
+
# Payload:
|
|
58
|
+
# - key: IPCCacheEngineKey - The key containing the token ids
|
|
59
|
+
# - ranges: List[tuple[int, int]] - List of tuples (start, end) indicating
|
|
60
|
+
# the match ranges to retrieve
|
|
61
|
+
# - offset: int - The starting offset in the CB KV cache buffer
|
|
62
|
+
# - instance_id: int - Unique identifier for the vLLM instance
|
|
63
|
+
# - event_ipc_handle: bytes - IPC handle for event notification when the
|
|
64
|
+
# retrieval is complete
|
|
65
|
+
# Returns:
|
|
66
|
+
# - IPC handle bytes
|
|
67
|
+
# - boolean flag indicating if the retrieval is successful
|
|
68
|
+
"CB_RETRIEVE_PRE_COMPUTED": ProtocolDefinition(
|
|
69
|
+
payload_classes=[IPCCacheEngineKey, list[tuple[int, int]], int, int, bytes],
|
|
70
|
+
response_class=tuple[bytes, bool],
|
|
71
|
+
handler_type=HandlerType.BLOCKING,
|
|
72
|
+
),
|
|
73
|
+
# Store final chunks after processing
|
|
74
|
+
# Payload:
|
|
75
|
+
# - key: IPCCacheEngineKey - The key containing the token ids
|
|
76
|
+
# - offset: int - The starting offset in the CB KV cache buffer
|
|
77
|
+
# - instance_id: int - Unique identifier for the vLLM instance
|
|
78
|
+
# - event_ipc_handle: bytes - IPC handle for event notification
|
|
79
|
+
# when the final chunks are stored
|
|
80
|
+
# Returns:
|
|
81
|
+
# - IPC handle bytes
|
|
82
|
+
# - boolean flag indicating if the store is successful
|
|
83
|
+
"CB_STORE_FINAL": ProtocolDefinition(
|
|
84
|
+
payload_classes=[IPCCacheEngineKey, int, int, bytes],
|
|
85
|
+
response_class=tuple[bytes, bool],
|
|
86
|
+
handler_type=HandlerType.BLOCKING,
|
|
87
|
+
),
|
|
88
|
+
# Register CB KV Cache
|
|
89
|
+
# Payload:
|
|
90
|
+
# - instance_id: int - Unique identifier for the vLLM instance
|
|
91
|
+
# - kv_cache: KVCache - The CB KV cache configuration
|
|
92
|
+
# - model_name: str - Name of the model associated with the engine
|
|
93
|
+
# - world_size: int - World size of the engine
|
|
94
|
+
# Returns: None
|
|
95
|
+
"CB_REGISTER_KV_CACHE": ProtocolDefinition(
|
|
96
|
+
payload_classes=[int, KVCache, str, int],
|
|
97
|
+
response_class=None,
|
|
98
|
+
handler_type=HandlerType.SYNC,
|
|
99
|
+
),
|
|
100
|
+
# Unregister CB KV Cache
|
|
101
|
+
# Payload:
|
|
102
|
+
# - instance_id: int - Unique identifier for the vLLM instance
|
|
103
|
+
# Returns: None
|
|
104
|
+
"CB_UNREGISTER_KV_CACHE": ProtocolDefinition(
|
|
105
|
+
payload_classes=[int],
|
|
106
|
+
response_class=None,
|
|
107
|
+
handler_type=HandlerType.SYNC,
|
|
108
|
+
),
|
|
109
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
Blend V2 protocol definitions.
|
|
4
|
+
|
|
5
|
+
This module defines the V2 variants of blend lookup/retrieve protocols that use
|
|
6
|
+
CBMatchResult instead of plain (start, end) integer tuples. CBMatchResult carries
|
|
7
|
+
old/cur position ranges plus the pre-computed chunk hash, enabling direct storage
|
|
8
|
+
key lookup without re-hashing on the server side.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# First Party
|
|
12
|
+
from lmcache.v1.multiprocess.custom_types import CBMatchResult, IPCCacheEngineKey
|
|
13
|
+
from lmcache.v1.multiprocess.protocols.base import HandlerType, ProtocolDefinition
|
|
14
|
+
|
|
15
|
+
# Define request names for this protocol group
|
|
16
|
+
REQUEST_NAMES = [
|
|
17
|
+
"CB_LOOKUP_PRE_COMPUTED_V2",
|
|
18
|
+
"CB_RETRIEVE_PRE_COMPUTED_V2",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_protocol_definitions() -> dict[str, ProtocolDefinition]:
|
|
23
|
+
"""
|
|
24
|
+
Returns protocol definitions for blend V2 lookup/retrieve operations.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
Dictionary mapping request names to their protocol definitions
|
|
28
|
+
"""
|
|
29
|
+
return {
|
|
30
|
+
# Lookup pre-computed chunks (V2)
|
|
31
|
+
# Payload:
|
|
32
|
+
# - key: IPCCacheEngineKey - The key containing the token ids
|
|
33
|
+
# Returns: List of CBMatchResult with match positions and chunk hashes
|
|
34
|
+
"CB_LOOKUP_PRE_COMPUTED_V2": ProtocolDefinition(
|
|
35
|
+
payload_classes=[IPCCacheEngineKey],
|
|
36
|
+
response_class=list[CBMatchResult],
|
|
37
|
+
handler_type=HandlerType.BLOCKING,
|
|
38
|
+
),
|
|
39
|
+
# Retrieve pre-computed chunks (V2)
|
|
40
|
+
# Payload:
|
|
41
|
+
# - key: IPCCacheEngineKey - The key containing the token ids
|
|
42
|
+
# - cb_match_result: list[CBMatchResult] - Match results returned by
|
|
43
|
+
# CB_LOOKUP_PRE_COMPUTED_V2, with per-chunk hashes
|
|
44
|
+
# and query positions
|
|
45
|
+
# - offset: int - The starting offset in the CB KV cache buffer
|
|
46
|
+
# - instance_id: int - Unique identifier for the vLLM instance
|
|
47
|
+
# - event_ipc_handle: bytes - IPC handle for event notification when the
|
|
48
|
+
# retrieval is complete
|
|
49
|
+
# Returns:
|
|
50
|
+
# - IPC handle bytes
|
|
51
|
+
# - boolean flag indicating if the retrieval is successful
|
|
52
|
+
"CB_RETRIEVE_PRE_COMPUTED_V2": ProtocolDefinition(
|
|
53
|
+
payload_classes=[IPCCacheEngineKey, list[CBMatchResult], int, int, bytes],
|
|
54
|
+
response_class=tuple[bytes, bool],
|
|
55
|
+
handler_type=HandlerType.BLOCKING,
|
|
56
|
+
),
|
|
57
|
+
}
|