Skip to content

[MP] Support lazy import built-in l2 adapter#2905

Merged
maobaolong merged 4 commits intoLMCache:devfrom
maobaolong:lazyImport
Apr 14, 2026
Merged

[MP] Support lazy import built-in l2 adapter#2905
maobaolong merged 4 commits intoLMCache:devfrom
maobaolong:lazyImport

Conversation

@maobaolong
Copy link
Copy Markdown
Collaborator

@maobaolong maobaolong commented Mar 30, 2026

What this PR does / why we need it:

Transitions the L2 adapter discovery from an eager import model to a lazy loading approach.

Special notes for your reviewers:

If applicable:

  • this PR contains user facing changes - docs added
  • this PR contains unit tests

Note

Medium Risk
Changes adapter discovery/registration timing and error propagation by switching from eager imports to on-demand module loading, which could affect runtime initialization and CLI adapter listing if an adapter module has import-time side effects or missing deps.

Overview
Switches built-in L2 adapter discovery from eager package-wide imports to lazy, on-demand module loading: l2_adapters/__init__.py now records *_l2_adapter modules as pending, and factory.py imports them only when a specific adapter type is requested.

Updates config parsing and type listing to work with lazy loading (_ensure_config_loaded during --l2-adapter parsing; get_registered_l2_adapter_types() now forces loading all pending modules for complete CLI choices), and adds unit tests covering the new pending-module/ensure-load behavior plus docs describing the new self-registration workflow.

Reviewed by Cursor Bugbot for commit 2ff265a. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request transitions the L2 adapter discovery from an eager import model to a lazy loading approach. It adds a pending module registry and functions to defer module imports until an adapter is explicitly requested or the full registry is accessed. The review feedback highlights a violation of the project's style guide, as the new lazy loading feature was submitted without accompanying unit tests to verify its behavior and error handling.

Comment thread lmcache/v1/distributed/l2_adapters/factory.py
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
@maobaolong
Copy link
Copy Markdown
Collaborator Author

@sammshen @chunxiaozheng Would you like to take a look at this PR? Thanks!

@sammshen
Copy link
Copy Markdown
Contributor

sammshen commented Apr 8, 2026

will take a look tmrw!

Copy link
Copy Markdown
Contributor

@sammshen sammshen left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@KuntaiDu KuntaiDu left a comment

Choose a reason for hiding this comment

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

LGTM!

@maobaolong maobaolong enabled auto-merge (squash) April 12, 2026 02:58
@github-actions github-actions Bot added the full Run comprehensive tests on this PR label Apr 12, 2026
@maobaolong maobaolong merged commit 96e0be2 into LMCache:dev Apr 14, 2026
36 of 38 checks passed
ekaynar pushed a commit to ekaynar/LMCache that referenced this pull request Apr 15, 2026
* Support lazy import built-in l2 adapter

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* Update doc

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* Add UTs

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
ftian1 pushed a commit to ftian1/LMCache that referenced this pull request Apr 20, 2026
* Support lazy import built-in l2 adapter

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* Update doc

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* Add UTs

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full Run comprehensive tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants