feat: add modular vLLM post-install patch framework with hybrid KV cache fix - #4879
Merged
Merged
Conversation
…che fix Add a patches/ module with auto-discovery registry for applying post-install patches to vLLM site-packages. This enables file-level patching that survives spawn subprocesses (unlike monkey-patching). First patch: LCM-based page size padding for hybrid attention models (Qwen3.5/3.6/3.6-MoE) that works around vllm-project/vllm#37121. Key improvements: - Use subprocess-based vLLM path resolution to handle uv-managed envs and .pth-injected parent site-packages - Model-family filtering (zero I/O for non-applicable models) - Idempotent with marker detection - Auto-discovery via pkgutil (add new patch = add new file) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
qinxuye
reviewed
May 7, 2026
Use model architectures instead of model family names for patch filtering. This automatically covers fine-tuned models and future models sharing the same architecture (e.g. Qwen3_5MoeForConditionalGeneration) without manual maintenance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover non-MoE Qwen3.5 models that also use hybrid attention and trigger the same KV cache page size issue. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Tests failed, seemed that the other model types are effected. |
Use getattr with fallback for model families that don't define _resolve_architectures (EmbeddingModelFamilyV2, RerankModelFamilyV2, ImageModelFamilyV2, AudioModelFamilyV2), preventing AttributeError when loading non-LLM models with virtual environments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
xinference/model/llm/vllm/patches/module with auto-discovery registry for applying post-install patches to vLLM site-packages.pth-injected parent site-packagesMotivation
Qwen3.5/3.6 models use hybrid attention (linear_attention + full_attention) with non-divisible KV cache page sizes. vLLM 0.20.x raises
NotImplementedErrorduringunify_kv_cache_spec_page_size(). The official fix (vllm-project/vllm#40128) has not been merged.Previous monkey-patching approach fails because vLLM's EngineCore uses
spawnmultiprocessing (due to CUDA initialization), which doesn't inherit in-memory patches. File-level patching solves this by modifying the source directly in site-packages.Design
pkgutil.iter_modulesscans for modules exposingPATCHattributearchitecturesset; uses_resolve_architectures()to cover fine-tuned models that inherit from built-in familiesimportlib.util.find_spec, handling.pthinjections and uv-managed envsChanges
xinference/model/llm/vllm/patches/__init__.pyxinference/model/llm/vllm/patches/_base.pyxinference/model/llm/vllm/patches/hybrid_kv_cache_page_size.pyxinference/core/worker.pymodel_name/architecturesparams to_prepare_virtual_env, callapply_vllm_patchesafter installRemoval condition
When vLLM officially merges the hybrid KV cache fix (tracking: vllm-project/vllm#37121, #38041), delete the patch file. The framework (
__init__.py,_base.py) can remain for future patches or be removed entirely (worker.py hasImportErrorguard).Test plan
Applied hybrid KV cache patch to .../kv_cache_utils.pyHybrid KV cache: padding max page size 1073152 -> 1081344NotImplementedErrorduring model initializationmodel_family="qwen3.6"gets patch applied via architecture inheritance