Skip to content

Commit c5d2527

Browse files
committed
Add config validation
Signed-off-by: Kunjan Patel <[email protected]>
1 parent b30051a commit c5d2527

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

examples/dynamic-lora-sidecar/sidecar/sidecar.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
import yaml
33
import time
4+
from jsonschema import validate
45
from watchfiles import awatch
56
import ipaddress
67
from dataclasses import dataclass
@@ -43,16 +44,30 @@ class LoraReconciler:
4344
Reconciles adapters registered on vllm server with adapters listed in configmap in current state
4445
"""
4546

46-
def __init__(self):
47+
def __init__(self, config_validation=True):
4748
self.health_check_timeout = datetime.timedelta(seconds=300)
4849
self.health_check_interval = datetime.timedelta(seconds=15)
49-
50+
self.config_validation = config_validation
51+
52+
def validate_config(self, c)-> bool:
53+
try:
54+
with open('validation.yaml', 'r') as f:
55+
schema = yaml.safe_load(f)
56+
validate(instance=c, schema=schema)
57+
return True
58+
except Exception as e:
59+
logging.error(f"Cannot load config {CONFIG_MAP_FILE} validation error: {e}")
60+
return False
61+
5062
@property
5163
def config(self):
5264
"""Load configmap into memory"""
5365
try:
66+
5467
with open(CONFIG_MAP_FILE, "r") as f:
5568
c = yaml.safe_load(f)
69+
if self.config_validation and not self.validate_config(c):
70+
return {}
5671
if c is None:
5772
c = {}
5873
c = c.get("vLLMLoRAConfig",{})

examples/dynamic-lora-sidecar/sidecar/test_sidecar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def setUp(self, mock_get, mock_file):
101101
mock_response = getMockResponse()
102102
mock_response.json.return_value = RESPONSES["v1/models"]
103103
mock_get.return_value = mock_response
104-
self.reconciler = LoraReconciler()
104+
self.reconciler = LoraReconciler(False)
105105
self.maxDiff = None
106106

107107
@patch("sidecar.requests.get")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
title: vLLMLoRAConfig
2+
description: Configuration for vLLM LoRA adapters
3+
type: object
4+
properties:
5+
vLLMLoRAConfig:
6+
type: object
7+
properties:
8+
host:
9+
type: string
10+
description: Model server's host
11+
default: localhost
12+
port:
13+
type: integer
14+
description: Model server's port
15+
default: 8000
16+
name:
17+
type: string
18+
description: Name of this config
19+
ensureExist:
20+
type: object
21+
description: List of models to ensure existence on specified model server
22+
properties:
23+
models:
24+
type: array
25+
description: List of LoRA adapter configurations
26+
items:
27+
type: object
28+
properties:
29+
base_model:
30+
type: string
31+
description: Base model for LoRA adapter
32+
id:
33+
type: string
34+
description: Unique ID of LoRA adapter
35+
source:
36+
type: string
37+
description: Path (remote or local) to LoRA adapter
38+
required:
39+
- id
40+
- source
41+
required:
42+
- models
43+
ensureNotExist:
44+
type: object
45+
description: List of models to ensure non-existence on specified model server
46+
properties:
47+
models:
48+
type: array
49+
description: List of LoRA adapter configurations
50+
items:
51+
type: object
52+
properties:
53+
base_model:
54+
type: string
55+
description: Base model for LoRA adapter
56+
id:
57+
type: string
58+
description: Unique ID of LoRA adapter
59+
source:
60+
type: string
61+
description: Path (remote or local) to LoRA adapter
62+
required:
63+
- id
64+
- source
65+
required:
66+
- models
67+
required:
68+
- host
69+
- port
70+
- name
71+
required:
72+
- vLLMLoRAConfig

0 commit comments

Comments
 (0)