-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[Misc] Enable vLLM to Dynamically Load LoRA from a Remote Server #10546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
397ed64
Dynamic LoRA plugin
1320607
Check lora_resolver output before adding to lora_requests
f489204
Merge remote-tracking branch 'origin/main' into dynamic_lora_resolver
6088b36
add base_model_name to LoRaResolver.resolve_lora and make resolve_lor…
91ab230
Fix precommit check
e4886bc
update lora resolver test
a152aa9
comment out engine_client.add_lora
9d1c422
use atomic counter as lora_int_id
e0a2cef
Re add engine_client.add_lora
eeb7772
Merge remote-tracking branch 'origin/main' into dynamic_lora_resolver
9ca98c1
Test for LoRA Resolver
02c33da
Rename lora/test_lora_resolver to lora/test_resolver
0c5c109
Add VLLM_ALLOW_RUNTIME_LORA_UPDATING flag check
c5c172d
Add documentation for LoRAResolver plugin
19af34c
Fix doc new line
c72da0e
Add engine.generate lora_request assertion for successful completion …
b577d2b
Rename generate_lora_request to called_lora_request
82f8e40
Add example of LoRAResolver
3b47f94
Minor doc update, remove redundant word
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from typing import Optional | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm.lora.request import LoRARequest | ||
| from vllm.lora.resolver import LoRAResolver, LoRAResolverRegistry | ||
|
|
||
|
|
||
| class DummyLoRAResolver(LoRAResolver): | ||
| """A dummy LoRA resolver for testing.""" | ||
|
|
||
| async def resolve_lora(self, lora_name: str) -> Optional[LoRARequest]: | ||
| if lora_name == "test_lora": | ||
| return LoRARequest(lora_name=lora_name, | ||
| lora_path="/dummy/path", | ||
| lora_int_id=abs(hash(lora_name))) | ||
| return None | ||
|
|
||
|
|
||
| def test_resolver_registry_registration(): | ||
| """Test basic resolver registration functionality.""" | ||
| registry = LoRAResolverRegistry | ||
| resolver = DummyLoRAResolver() | ||
|
|
||
| # Register a new resolver | ||
| registry.register_resolver("dummy", resolver) | ||
| assert "dummy" in registry.get_supported_resolvers() | ||
|
|
||
| # Get registered resolver | ||
| retrieved_resolver = registry.get_resolver("dummy") | ||
| assert retrieved_resolver is resolver | ||
|
|
||
|
|
||
| def test_resolver_registry_duplicate_registration(): | ||
| """Test registering a resolver with an existing name.""" | ||
| registry = LoRAResolverRegistry | ||
| resolver1 = DummyLoRAResolver() | ||
| resolver2 = DummyLoRAResolver() | ||
|
|
||
| registry.register_resolver("dummy", resolver1) | ||
| registry.register_resolver("dummy", resolver2) | ||
|
|
||
| assert registry.get_resolver("dummy") is resolver2 | ||
|
|
||
|
|
||
| def test_resolver_registry_unknown_resolver(): | ||
| """Test getting a non-existent resolver.""" | ||
| registry = LoRAResolverRegistry | ||
|
|
||
| with pytest.raises(KeyError, match="not found"): | ||
| registry.get_resolver("unknown_resolver") | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_dummy_resolver_resolve(): | ||
| """Test the dummy resolver's resolve functionality.""" | ||
| dummy_resolver = DummyLoRAResolver() | ||
|
|
||
| # Test successful resolution | ||
| result = await dummy_resolver.resolve_lora("test_lora") | ||
| assert isinstance(result, LoRARequest) | ||
| assert result.lora_name == "test_lora" | ||
| assert result.lora_path == "/dummy/path" | ||
|
|
||
| # Test failed resolution | ||
| result = await dummy_resolver.resolve_lora("nonexistent_lora") | ||
| assert result is None |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from dataclasses import dataclass, field | ||
| from typing import AbstractSet, Dict, Optional | ||
|
|
||
| from vllm.logger import init_logger | ||
| from vllm.lora.request import LoRARequest | ||
|
|
||
| logger = init_logger(__name__) | ||
|
|
||
|
|
||
| class LoRAResolver(ABC): | ||
| """Base class for LoRA adapter resolvers. | ||
|
|
||
| This class defines the interface for resolving and fetching LoRA adapters. | ||
| Implementations of this class should handle the logic for locating and | ||
| downloading LoRA adapters from various sources (e.g. S3, cloud storage, | ||
| etc.). | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def resolve_lora(self, lora_name: str) -> Optional[LoRARequest]: | ||
| """Abstract method to resolve and fetch a LoRA model adapter. | ||
|
|
||
| Implements logic to locate and download LoRA adapter based on the name. | ||
| Implementations might fetch from a blob storage or other sources. | ||
|
|
||
| Args: | ||
| lora_name: The name or identifier of the LoRA model to resolve. | ||
|
|
||
| Returns: | ||
| Optional[LoRARequest]: The resolved LoRA model information, or None | ||
| if the LoRA model cannot be found. | ||
| """ | ||
| pass | ||
|
|
||
|
|
||
| @dataclass | ||
| class _LoRAResolverRegistry: | ||
| resolvers: Dict[str, LoRAResolver] = field(default_factory=dict) | ||
|
|
||
| def get_supported_resolvers(self) -> AbstractSet[str]: | ||
| """Get all registered resolver names.""" | ||
| return self.resolvers.keys() | ||
|
|
||
| def register_resolver( | ||
| self, | ||
| resolver_name: str, | ||
| resolver: LoRAResolver, | ||
| ) -> None: | ||
| """Register a LoRA resolver. | ||
| Args: | ||
| resolver_name: Name to register the resolver under. | ||
| resolver: The LoRA resolver instance to register. | ||
| """ | ||
| if resolver_name in self.resolvers: | ||
| logger.warning( | ||
| "LoRA resolver %s is already registered, and will be " | ||
| "overwritten by the new resolver instance %s.", resolver_name, | ||
| resolver) | ||
|
|
||
| self.resolvers[resolver_name] = resolver | ||
|
|
||
| def get_resolver(self, resolver_name: str) -> LoRAResolver: | ||
| """Get a registered resolver instance by name. | ||
| Args: | ||
| resolver_name: Name of the resolver to get. | ||
| Returns: | ||
| The resolver instance. | ||
| Raises: | ||
| KeyError: If the resolver is not found in the registry. | ||
| """ | ||
| if resolver_name not in self.resolvers: | ||
| raise KeyError( | ||
| f"LoRA resolver '{resolver_name}' not found. " | ||
| f"Available resolvers: {list(self.resolvers.keys())}") | ||
| return self.resolvers[resolver_name] | ||
|
|
||
|
|
||
| LoRAResolverRegistry = _LoRAResolverRegistry() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.