Skip to content

Commit 51ec7fe

Browse files
authored
Expose MockAsyncLM in load_model_by_name (#42)
* Expose MockAsyncLM in load_model_by_name * Update test_llm.py
1 parent a00239b commit 51ec7fe

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

genlm/backend/llm/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def load_model_by_name(name, backend=None, llm_opts=None):
1010
1111
Args:
1212
name (str): Hugging Face model name (e.g. "gpt2", "meta-llama/Llama-3.2-1B-Instruct")
13-
backend (str, optional): Backend to use for inference. Can be "vllm" or "hf".
13+
backend (str, optional): Backend to use for inference. Can be "vllm", "hf" or "mock".
1414
If None, defaults to "vllm" if CUDA is available, otherwise "hf".
1515
llm_opts (dict, optional): Additional options to pass to the backend constructor.
1616
See AsyncVirtualLM and AsyncTransformer documentation for details.
@@ -31,6 +31,8 @@ def load_model_by_name(name, backend=None, llm_opts=None):
3131
return AsyncVirtualLM.from_name(name, **llm_opts)
3232
elif backend == "hf":
3333
return AsyncTransformer.from_name(name, **llm_opts)
34+
elif backend == "mock":
35+
return MockAsyncLM.from_name(name, **llm_opts)
3436
else:
3537
raise ValueError(f"Invalid backend: {backend}")
3638

tests/test_llm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ async def test_mock_async_llm():
226226
mock_async_llm.clear_cache() # no-op
227227

228228

229+
def test_load_model_by_name_mock():
230+
load_model_by_name("gpt2", backend="mock")
231+
232+
229233
def test_load_model_by_name_error():
230234
with pytest.raises(ValueError):
231235
load_model_by_name("gpt2", backend="invalid")

0 commit comments

Comments
 (0)