Skip to content

vllm.plugins.lora_resolvers.filesystem_resolver

FilesystemResolver

Bases: LoRAResolver

Source code in vllm/plugins/lora_resolvers/filesystem_resolver.py
class FilesystemResolver(LoRAResolver):

    def __init__(self, lora_cache_dir: str):
        self.lora_cache_dir = lora_cache_dir

    async def resolve_lora(self, base_model_name: str,
                           lora_name: str) -> Optional[LoRARequest]:
        lora_path = os.path.join(self.lora_cache_dir, lora_name)
        if os.path.exists(lora_path):
            adapter_config_path = os.path.join(self.lora_cache_dir, lora_name,
                                               "adapter_config.json")
            if os.path.exists(adapter_config_path):
                with open(adapter_config_path) as file:
                    adapter_config = json.load(file)
                if adapter_config["peft_type"] == "LORA" and adapter_config[
                        "base_model_name_or_path"] == base_model_name:
                    lora_request = LoRARequest(lora_name=lora_name,
                                               lora_int_id=abs(
                                                   hash(lora_name)),
                                               lora_path=lora_path)
                    return lora_request
        return None

lora_cache_dir instance-attribute

lora_cache_dir = lora_cache_dir

__init__

__init__(lora_cache_dir: str)
Source code in vllm/plugins/lora_resolvers/filesystem_resolver.py
def __init__(self, lora_cache_dir: str):
    self.lora_cache_dir = lora_cache_dir

resolve_lora async

resolve_lora(
    base_model_name: str, lora_name: str
) -> Optional[LoRARequest]
Source code in vllm/plugins/lora_resolvers/filesystem_resolver.py
async def resolve_lora(self, base_model_name: str,
                       lora_name: str) -> Optional[LoRARequest]:
    lora_path = os.path.join(self.lora_cache_dir, lora_name)
    if os.path.exists(lora_path):
        adapter_config_path = os.path.join(self.lora_cache_dir, lora_name,
                                           "adapter_config.json")
        if os.path.exists(adapter_config_path):
            with open(adapter_config_path) as file:
                adapter_config = json.load(file)
            if adapter_config["peft_type"] == "LORA" and adapter_config[
                    "base_model_name_or_path"] == base_model_name:
                lora_request = LoRARequest(lora_name=lora_name,
                                           lora_int_id=abs(
                                               hash(lora_name)),
                                           lora_path=lora_path)
                return lora_request
    return None

register_filesystem_resolver

register_filesystem_resolver()

Register the filesystem LoRA Resolver with vLLM

Source code in vllm/plugins/lora_resolvers/filesystem_resolver.py
def register_filesystem_resolver():
    """Register the filesystem LoRA Resolver with vLLM"""

    lora_cache_dir = envs.VLLM_LORA_RESOLVER_CACHE_DIR
    if lora_cache_dir:
        if not os.path.exists(lora_cache_dir) or not os.path.isdir(
                lora_cache_dir):
            raise ValueError(
                "VLLM_LORA_RESOLVER_CACHE_DIR must be set to a valid directory \
                for Filesystem Resolver plugin to function")
        fs_resolver = FilesystemResolver(lora_cache_dir)
        LoRAResolverRegistry.register_resolver("Filesystem Resolver",
                                               fs_resolver)

    return