-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathload_models.py
More file actions
56 lines (42 loc) · 1.6 KB
/
Copy pathload_models.py
File metadata and controls
56 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Load the models required by the test suite."""
import asyncio
from contextlib import contextmanager
from typing import Generator
import lmstudio as lms
from tests.support import (
EXPECTED_EMBEDDING_ID,
EXPECTED_LLM_ID,
EXPECTED_VLM_ID,
LLM_LOAD_CONFIG,
TOOL_LLM_ID,
)
from .unload_models import unload_models
# LM Studio may default to JIT handling for models loaded with `getOrLoad`,
# so ensure we restore a regular non-JIT instance with no TTL set
@contextmanager
def print_load_result(model_identifier: str) -> Generator[None, None, None]:
try:
yield
except lms.LMStudioModelNotFoundError:
print(f"Load error: {model_identifier!r} is not yet downloaded")
else:
print(f"Loaded: {model_identifier!r}")
async def _load_llm(client: lms.AsyncClient, model_identifier: str) -> None:
with print_load_result(model_identifier):
await client.llm.load_new_instance(
model_identifier, config=LLM_LOAD_CONFIG, ttl=None
)
async def _load_embedding_model(client: lms.AsyncClient, model_identifier: str) -> None:
with print_load_result(model_identifier):
await client.embedding.load_new_instance(model_identifier, ttl=None)
async def reload_models() -> None:
await unload_models()
async with lms.AsyncClient() as client:
await asyncio.gather(
_load_llm(client, EXPECTED_LLM_ID),
_load_llm(client, EXPECTED_VLM_ID),
_load_llm(client, TOOL_LLM_ID),
_load_embedding_model(client, EXPECTED_EMBEDDING_ID),
)
if __name__ == "__main__":
asyncio.run(reload_models())