|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +import os |
| 3 | +import shutil |
| 4 | + |
| 5 | +import pytest |
| 6 | +from huggingface_hub import snapshot_download |
| 7 | + |
| 8 | +from vllm.plugins.lora_resolvers.filesystem_resolver import FilesystemResolver |
| 9 | + |
| 10 | +MODEL_NAME = "mistralai/Mistral-7B-v0.1" |
| 11 | +LORA_NAME = "typeof/zephyr-7b-beta-lora" |
| 12 | +PA_NAME = "swapnilbp/llama_tweet_ptune" |
| 13 | + |
| 14 | + |
| 15 | +@pytest.fixture(scope='module') |
| 16 | +def adapter_cache(request, tmpdir_factory): |
| 17 | + # Create dir that mimics the structure of the adapter cache |
| 18 | + adapter_cache = tmpdir_factory.mktemp( |
| 19 | + request.module.__name__) / "adapter_cache" |
| 20 | + return adapter_cache |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture(scope="module") |
| 24 | +def zephyr_lora_files(): |
| 25 | + return snapshot_download(repo_id=LORA_NAME) |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture(scope="module") |
| 29 | +def pa_files(): |
| 30 | + return snapshot_download(repo_id=PA_NAME) |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.asyncio |
| 34 | +async def test_filesystem_resolver(adapter_cache, zephyr_lora_files): |
| 35 | + model_files = adapter_cache / LORA_NAME |
| 36 | + shutil.copytree(zephyr_lora_files, model_files) |
| 37 | + |
| 38 | + fs_resolver = FilesystemResolver(adapter_cache) |
| 39 | + assert fs_resolver is not None |
| 40 | + |
| 41 | + lora_request = await fs_resolver.resolve_lora(MODEL_NAME, LORA_NAME) |
| 42 | + assert lora_request is not None |
| 43 | + assert lora_request.lora_name == LORA_NAME |
| 44 | + assert lora_request.lora_path == os.path.join(adapter_cache, LORA_NAME) |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.asyncio |
| 48 | +async def test_missing_adapter(adapter_cache): |
| 49 | + fs_resolver = FilesystemResolver(adapter_cache) |
| 50 | + assert fs_resolver is not None |
| 51 | + |
| 52 | + missing_lora_request = await fs_resolver.resolve_lora(MODEL_NAME, "foobar") |
| 53 | + assert missing_lora_request is None |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.asyncio |
| 57 | +async def test_nonlora_adapter(adapter_cache, pa_files): |
| 58 | + model_files = adapter_cache / PA_NAME |
| 59 | + shutil.copytree(pa_files, model_files) |
| 60 | + |
| 61 | + fs_resolver = FilesystemResolver(adapter_cache) |
| 62 | + assert fs_resolver is not None |
| 63 | + |
| 64 | + pa_request = await fs_resolver.resolve_lora(MODEL_NAME, PA_NAME) |
| 65 | + assert pa_request is None |
0 commit comments