Skip to content

Tighten non-GPU multiprocess adapter typing (replace Any with concrete IPC/MQ types)#328

Draft
Copilot wants to merge 3 commits into
ww21_PR_shmfrom
copilot/replace-any-annotations
Draft

Tighten non-GPU multiprocess adapter typing (replace Any with concrete IPC/MQ types)#328
Copilot wants to merge 3 commits into
ww21_PR_shmfrom
copilot/replace-any-annotations

Conversation

Copy link
Copy Markdown

Copilot AI commented May 30, 2026

This updates the non-GPU multiprocess adapter interfaces to use concrete protocol types instead of Any where appropriate, and aligns affected tests with the stricter key contract. The goal is to make the IPC boundary explicitly typed across base and concrete adapters without introducing a dependency on lmc_ops GPU format typing.

  • Adapter base typing hardening (adapter_connector/base.py)

    • mq_client now uses MessageQueueClient.
    • Abstract method key params now use IPCCacheEngineKey (prepare_store, commit_store, prepare_retrieve, commit_retrieve).
    • layout_hints now uses LayoutHints | None.
    • gpu_kv_format remains Any | None (no lmc_ops.GPUKVFormat typing import).
    • compute_kv_layout GPU format return element remains Any.
  • Concrete adapter signature alignment

    • adapter_connector/shm.py: updated mq_client and all key signatures to MessageQueueClient / IPCCacheEngineKey.
    • adapter_connector/pickle.py: same signature updates as SHM path.
  • Test key contract update (test_non_cuda_data_transfer.py)

    • Replaced plain string key usage in test_non_gpu_context_shm_store_retrieve_flow_with_mocked_mq with a proper IPCCacheEngineKey instance (_default_key()), and reused it across prepare/commit store/retrieve calls.

Example of the key change pattern:

key = _default_key()
store_result = context.prepare_store(key=key, instance_id=1)
assert context.commit_store(key, 1, store_views)
retrieve_views = context.prepare_retrieve(key=key, instance_id=1)
assert context.commit_retrieve(key, 1)
Original prompt

Replace all Any type annotations in lmcache/v1/multiprocess/adapter_connector/base.py with concrete types:

  1. mq_client: Anymq_client: MessageQueueClient (import from lmcache.v1.multiprocess.mq)
  2. key: Any in abstract methods (prepare_store, commit_store, prepare_retrieve, commit_retrieve) → key: IPCCacheEngineKey (import from lmcache.v1.multiprocess.custom_types)
  3. layout_hints: Any | Nonelayout_hints: LayoutHints | None (import from lmcache.v1.gpu_connector.utils)
  4. gpu_kv_format: Any | Nonegpu_kv_format: "lmc_ops.GPUKVFormat" | None (use TYPE_CHECKING import for lmcache.c_ops)
  5. Return type of compute_kv_layout: tuple[int, int, int, str, Any]tuple[int, int, int, str, "lmc_ops.GPUKVFormat"]

Also update lmcache/v1/multiprocess/adapter_connector/shm.py which has key: Any in its method signatures — change to key: IPCCacheEngineKey.

Also check lmcache/v1/multiprocess/adapter_connector/pickle.py (if it exists at that path or similar) for the same key: Any and mq_client: Any patterns.

For the test file tests/v1/multiprocess/test_non_cuda_data_transfer.py, find the test test_non_gpu_context_shm_store_retrieve_flow_with_mocked_mq which passes key="k" (a plain string) to context.prepare_store(key="k", instance_id=1). Fix it to use a proper IPCCacheEngineKey instance instead of a string. Look at how IPCCacheEngineKey is constructed elsewhere in the test suite (e.g. test_free_locks.py uses create_cache_key(0)) and use a similar approach. The IPCCacheEngineKey likely needs fields like model_name, worker_id, request_id, and token hash info — check its definition and construct a minimal valid instance.

Similarly fix any other places in the same test file where a plain string is passed as a key to these methods.

The following is the prior conversation context from the user's chat exploration (may be truncated):

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Replace Any type annotations with concrete types in adapter_connector Tighten non-GPU multiprocess adapter typing (replace Any with concrete IPC/MQ/GPU format types) May 30, 2026
Copilot finished work on behalf of hlin99 May 30, 2026 03:29
Copilot AI requested a review from hlin99 May 30, 2026 03:29
Copy link
Copy Markdown
Owner

@hlin99 hlin99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove lmc_ops.GPUKVFormat changes, we can use Any for lmc_ops.GPUKVFormat, i don't want to import lmc_ops

Copy link
Copy Markdown
Author

Copilot AI commented May 30, 2026

remove lmc_ops.GPUKVFormat changes, we can use Any for lmc_ops.GPUKVFormat, i don't want to import lmc_ops

Addressed in commit 9908844. I removed the lmc_ops.GPUKVFormat typing/import pattern in adapter_connector/base.py and switched those annotations back to Any.

Copilot AI changed the title Tighten non-GPU multiprocess adapter typing (replace Any with concrete IPC/MQ/GPU format types) Tighten non-GPU multiprocess adapter typing (replace Any with concrete IPC/MQ types) May 30, 2026
Copilot finished work on behalf of hlin99 May 30, 2026 03:38
Copilot AI requested a review from hlin99 May 30, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants