Skip to content

Commit 4596c27

Browse files
Add LM-Inline provider and unit tests
1 parent 86ce2de commit 4596c27

File tree

16 files changed

+1279
-158
lines changed

16 files changed

+1279
-158
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module: llama_stack_provider_lmeval.inline
2+
config_class: llama_stack_provider_lmeval.config.LMEvalEvalProviderConfig
3+
pip_packages: ["lm-eval"]
4+
api_dependencies: ["inference", "files"]
5+
optional_api_dependencies: []

providers.d/remote/eval/trustyai_lmeval.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ adapter:
22
adapter_type: lmeval
33
pip_packages: ["kubernetes"]
44
config_class: llama_stack_provider_lmeval.config.LMEvalEvalProviderConfig
5-
module: llama_stack_provider_lmeval
5+
module: llama_stack_provider_lmeval.remote
66
api_dependencies: ["inference"]
77
optional_api_dependencies: []

run-inline.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "2"
2+
image_name: trustyai-lmeval
3+
apis:
4+
- inference
5+
- eval
6+
- files
7+
providers:
8+
inference:
9+
- provider_id: vllm
10+
provider_type: remote::vllm
11+
config:
12+
url: ${env.VLLM_URL:=http://localhost:8080/v1}
13+
max_tokens: ${env.VLLM_MAX_TOKENS:=4096}
14+
api_token: ${env.VLLM_API_TOKEN:=fake}
15+
tls_verify: ${env.VLLM_TLS_VERIFY:=false}
16+
eval:
17+
- provider_id: trustyai_lmeval
18+
provider_type: inline::trustyai_lmeval
19+
config:
20+
base_url: ${env.BASE_URL:=http://localhost:8321/v1}
21+
use_k8s: ${env.USE_K8S:=false}
22+
files:
23+
- provider_id: meta-reference-files
24+
provider_type: inline::localfs
25+
config:
26+
storage_dir: ${env.FILES_STORAGE_DIR:=~/.llama/distributions/trustyai-lmeval/files}
27+
metadata_store:
28+
type: sqlite
29+
db_path: ${env.METADATA_STORE_DB_PATH:=~/.llama/distributions/trustyai-lmeval}/registry.db}
30+
external_providers_dir: ./providers.d
Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +0,0 @@
1-
import logging
2-
3-
from llama_stack.apis.datatypes import Api
4-
from llama_stack.providers.datatypes import ProviderSpec
5-
6-
from .config import LMEvalEvalProviderConfig
7-
from .lmeval import LMEval
8-
from .provider import get_provider_spec
9-
10-
# Set up logging
11-
logger = logging.getLogger(__name__)
12-
13-
14-
async def get_adapter_impl(
15-
config: LMEvalEvalProviderConfig,
16-
deps: dict[Api, ProviderSpec] | None = None,
17-
) -> LMEval:
18-
"""Get an LMEval implementation from the configuration.
19-
20-
Args:
21-
config: LMEval configuration
22-
deps: Optional dependencies for testing/injection
23-
24-
Returns:
25-
Configured LMEval implementation
26-
27-
Raises:
28-
Exception: If configuration is invalid
29-
"""
30-
try:
31-
if deps is None:
32-
deps = {}
33-
34-
# Extract base_url from config if available
35-
base_url = None
36-
if hasattr(config, "model_args") and config.model_args:
37-
for arg in config.model_args:
38-
if arg.get("name") == "base_url":
39-
base_url = arg.get("value")
40-
logger.debug(f"Using base_url from config: {base_url}")
41-
break
42-
43-
return LMEval(config=config)
44-
except Exception as e:
45-
raise Exception(f"Failed to create LMEval implementation: {str(e)}") from e
46-
47-
48-
__all__ = [
49-
# Factory methods
50-
"get_adapter_impl",
51-
# Configurations
52-
"LMEval",
53-
"get_provider_spec",
54-
]

src/llama_stack_provider_lmeval/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass, field
6+
from pathlib import Path
67
from typing import Any
78

89
from llama_stack.apis.eval import BenchmarkConfig, EvalCandidate
@@ -125,6 +126,8 @@ class LMEvalEvalProviderConfig:
125126
metadata: dict[str, Any] | None = None
126127
# TLS configuration - structured approach
127128
tls: TLSConfig | None = None
129+
base_dir: Path = Path(__file__).parent
130+
results_dir: Path = base_dir / "results"
128131

129132
def __post_init__(self):
130133
"""Validate the configuration"""
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""LMEval Inline Eval Llama Stack provider."""
2+
3+
import logging
4+
5+
from llama_stack.apis.datatypes import Api
6+
from llama_stack.providers.datatypes import ProviderSpec
7+
8+
from llama_stack_provider_lmeval.config import LMEvalEvalProviderConfig
9+
10+
from .lmeval import LMEvalInline
11+
12+
logger = logging.getLogger(__name__)
13+
14+
15+
async def get_provider_impl(
16+
config: LMEvalEvalProviderConfig,
17+
deps: dict[Api, ProviderSpec] | None = None,
18+
) -> LMEvalInline:
19+
"""Get an inline Eval implementation from the configuration.
20+
21+
Args:
22+
config: LMEvalEvalProviderConfig
23+
deps: Optional[dict[Api, Any]] = None - can be ProviderSpec or API instances
24+
25+
Returns:
26+
Configured LMEval Inline implementation
27+
28+
Raises:
29+
Exception: If configuration is invalid
30+
"""
31+
try:
32+
if deps is None:
33+
deps = {}
34+
35+
# Extract base_url from config if available
36+
base_url = None
37+
if hasattr(config, "model_args") and config.model_args:
38+
for arg in config.model_args:
39+
if arg.get("name") == "base_url":
40+
base_url = arg.get("value")
41+
logger.debug("Using base_url from config: %s", base_url)
42+
break
43+
44+
return LMEvalInline(config=config, deps=deps)
45+
except Exception as e:
46+
raise RuntimeError(f"Failed to create LMEval implementation: {str(e)}") from e
47+
48+
49+
__all__ = [
50+
"get_provider_impl",
51+
"LMEvalInline",
52+
]

0 commit comments

Comments
 (0)