Plugin L2 Adapter Framework for MP Mode#2715
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the extensibility of LMCache by introducing a plugin-based architecture for L2 adapters in multi-process (MP) mode. This change allows external developers to integrate custom L2 storage solutions seamlessly, fostering a more modular and adaptable caching system. The new design streamlines the process of adding new adapter types by moving towards a self-registration model, reducing the need for modifications to the core framework when new adapters are introduced. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a well-designed plugin framework for L2 adapters, which is a great step towards making LMCache more extensible. However, it introduces a significant security risk by allowing arbitrary Python modules to be imported based on user-supplied configuration strings, potentially leading to Remote Code Execution (RCE) if the configuration source is untrusted or the Python search path is compromised. It is recommended to restrict allowed modules to a specific namespace or use a more secure plugin discovery mechanism. Additionally, my review suggests improving robustness through more specific error logging and enhancing the consistency of the new plugin architecture.
1fe31df to
414e1d4
Compare
| "L2AdapterInterface" % (config.module_path, config.class_name) | ||
| ) | ||
|
|
||
| return adapter_cls(**kwargs, **config.adapter_params) |
There was a problem hiding this comment.
@maobaolong adapter_cls(**kwargs, **config.adapter_params) is not very universal, I think adapter_cls( config.adapter_params, **kwargs) is more suitable, what do you think?
9a914cf to
ce6aad4
Compare
|
@maobaolong Do we need a rebase after #2704 is merged? |
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
b648381 to
52675f6
Compare
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
|
@ApostaC @chunxiaozheng As #2704 merged, this PR can be reviewed again, thanks! |
ApostaC
left a comment
There was a problem hiding this comment.
LGTM in general. Mostly nit comments
| from lmcache.v1.distributed.l2_adapters.base import ( | ||
| L2AdapterInterface, | ||
| ) | ||
|
|
||
| # First Party | ||
| from lmcache.v1.distributed.l2_adapters.base import L2AdapterInterface as _L2AI |
There was a problem hiding this comment.
nit: We have imported L2AdapterInterface both in TYPE_CHECKING and normal import. Import them once should be enough
| Constructor accepts either an | ||
| ``InMemoryL2AdapterConfig`` instance (matching | ||
| the built-in adapter convention) **or** a plain | ||
| dict (legacy plugin mode) for backward compatibility. |
There was a problem hiding this comment.
What's the meaning of "legacy plugin mode" and "backward compatibility" here? I suppose the plugin system a new module introduced by this PR?
There was a problem hiding this comment.
This is for a middle state of my development. Updated the comment.
|
|
||
| def _create_plugin_adapter( | ||
| config: L2AdapterConfigBase, | ||
| l1_memory_desc: "Optional[L1MemoryDesc]" = None, |
There was a problem hiding this comment.
The l1_memory_desc is never used in L2 plugins. Is it expected, or do we have some reason to ignore it?
If the plugin needs to register memory (like using RDMA), the l1_memory_desc will be useful.
There was a problem hiding this comment.
l1_memory_desc is now forwarded to the plugin adapter constructor via **kwargs when it is not None. This way, plugins that need to register L1 memory (e.g., for RDMA) can access it through the l1_memory_desc keyword argument, while existing plugins that don't need it remain unaffected.
There was a problem hiding this comment.
Can we add some simple unit tests to secure the registration and initialization process of the plugin adapters? In this case, the future PRs will be less likely to break the L2 plugins system.
There was a problem hiding this comment.
Added! The new tests in test_l2_adapter_factory.py
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
|
@ApostaC Thanks for the review, PTAL. |
chunxiaozheng
left a comment
There was a problem hiding this comment.
Thanks for the contribution, I have tested in my env, LGTM!
* Plugin L2 Adapter Framework for MP Mode Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Remove useless file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix related failed UT. Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Skip if not import lmc_external_l2_adapter Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add comments from chunxiaozheng Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Adapter existing adapter constructor Signed-off-by: baoloongmao <baoloongmao@tencent.com> * address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> * add missing Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
* Plugin L2 Adapter Framework for MP Mode Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Remove useless file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix related failed UT. Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Skip if not import lmc_external_l2_adapter Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add comments from chunxiaozheng Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Adapter existing adapter constructor Signed-off-by: baoloongmao <baoloongmao@tencent.com> * address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> * add missing Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com> Signed-off-by: Aaron Wu <aaron.wu@dell.com>
* Plugin L2 Adapter Framework for MP Mode Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Remove useless file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix related failed UT. Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Skip if not import lmc_external_l2_adapter Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add comments from chunxiaozheng Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Adapter existing adapter constructor Signed-off-by: baoloongmao <baoloongmao@tencent.com> * address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> * add missing Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
* Plugin L2 Adapter Framework for MP Mode Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Remove useless file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix related failed UT. Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Skip if not import lmc_external_l2_adapter Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add comments from chunxiaozheng Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Adapter existing adapter constructor Signed-off-by: baoloongmao <baoloongmao@tencent.com> * address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> * add missing Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
* Plugin L2 Adapter Framework for MP Mode Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Remove useless file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix related failed UT. Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Skip if not import lmc_external_l2_adapter Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add comments from chunxiaozheng Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Adapter existing adapter constructor Signed-off-by: baoloongmao <baoloongmao@tencent.com> * address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> * add missing Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
* Plugin L2 Adapter Framework for MP Mode Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Remove useless file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix related failed UT. Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Skip if not import lmc_external_l2_adapter Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add comments from chunxiaozheng Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Adapter existing adapter constructor Signed-off-by: baoloongmao <baoloongmao@tencent.com> * address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> * add missing Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> * fix Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
What this PR does / why we need it:
Adds a "plugin" L2 adapter type that allows third-party developers to extend LMCache with custom L2 storage backends in MP mode — without modifying any LMCache source code.
--l2-adapter '{"type":"plugin","module_path":"lmc_external_l2_adapter","class_name":"InMemoryL2Adapter","adapter_params":{"max_size_gb":1.0,"mock_bandwidth_gb":20.0}}'E2E test(TP=1, chunk_size=256, prompt_tokens=272)
python3 -m lmcache.v1.multiprocess.server \ --host localhost --port 15556 --chunk-size 256 --l1-size-gb 5 \ --eviction-policy LRU --max-workers 1 \ --l2-adapter '{"type":"plugin","module_path":"lmc_external_l2_adapter","class_name":"InMemoryL2Adapter","adapter_params":{"max_size_gb":1.0,"mock_bandwidth_gb":20.0}}'Step 3: Send long prompt (272 tokens > 256 chunk_size) twice
Result: Both requests succeed (prompt_tokens=272, completion_tokens=512).
Server logs confirm:
Special notes for your reviewers:
If applicable: