-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support both base conf and app conf (#328)
- Add support for base config and app config merge - Throw an error if no conf exists - Paths can be altered using env vars Signed-off-by: Avik Basu <[email protected]> Co-authored-by: Avik Basu <[email protected]>
- Loading branch information
Showing
8 changed files
with
98 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
stream_confs: | ||
mycustomconf: | ||
config_id: "mycustomconf" | ||
source: "prometheus" | ||
composite_keys: [ "namespace", "app" ] | ||
metrics: [ "namespace_app_rollouts_cpu_utilization", "namespace_app_rollouts_http_request_error_rate", "namespace_app_rollouts_memory_utilization" ] | ||
window_size: 12 | ||
numalogic_conf: | ||
model: | ||
name: "Conv1dVAE" | ||
conf: | ||
seq_len: 12 | ||
n_features: 3 | ||
latent_dim: 1 | ||
preprocess: | ||
- name: "StandardScaler" | ||
threshold: | ||
name: "MahalanobisThreshold" | ||
trainer: | ||
train_hours: 3 | ||
min_train_size: 100 | ||
pltrainer_conf: | ||
accelerator: cpu | ||
max_epochs: 5 | ||
redis_conf: | ||
url: "http://localhost:6222" | ||
port: 26379 | ||
expiry: 360 | ||
master_name: "mymaster" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,59 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from omegaconf import OmegaConf | ||
from pynumaflow.mapper import Mapper, MultiProcMapper | ||
|
||
from numalogic._constants import TESTS_DIR | ||
from numalogic.tools.exceptions import ConfigNotFoundError | ||
|
||
CONFIG_PATH = f"{TESTS_DIR}/udfs/resources/_config.yaml" | ||
BASE_CONFIG_PATH = f"{TESTS_DIR}/udfs/resources/_config3.yaml" | ||
APP_CONFIG_PATH = f"{TESTS_DIR}/udfs/resources/_config4.yaml" | ||
REDIS_AUTH = "123" | ||
|
||
|
||
class TestMainScript(unittest.TestCase): | ||
@patch.dict("os.environ", {"CONF_PATH": CONFIG_PATH, "REDIS_AUTH": REDIS_AUTH}) | ||
@patch.dict("os.environ", {"BASE_CONF_PATH": BASE_CONFIG_PATH, "REDIS_AUTH": REDIS_AUTH}) | ||
def test_init_server_01(self): | ||
from numalogic.udfs.__main__ import init_server | ||
|
||
server = init_server("preprocess", "sync") | ||
self.assertIsInstance(server, Mapper) | ||
|
||
@patch.dict("os.environ", {"CONF_PATH": CONFIG_PATH, "REDIS_AUTH": REDIS_AUTH}) | ||
@patch.dict("os.environ", {"BASE_CONF_PATH": BASE_CONFIG_PATH, "REDIS_AUTH": REDIS_AUTH}) | ||
def test_init_server_02(self): | ||
from numalogic.udfs.__main__ import init_server | ||
|
||
server = init_server("inference", "multiproc") | ||
self.assertIsInstance(server, MultiProcMapper) | ||
|
||
def test_conf_loader(self): | ||
from numalogic.udfs import load_pipeline_conf | ||
|
||
plconf = load_pipeline_conf(BASE_CONFIG_PATH, APP_CONFIG_PATH) | ||
base_conf = OmegaConf.load(BASE_CONFIG_PATH) | ||
app_conf = OmegaConf.load(APP_CONFIG_PATH) | ||
|
||
self.assertListEqual( | ||
list(plconf.stream_confs), | ||
list(base_conf["stream_confs"]) + list(app_conf["stream_confs"]), | ||
) | ||
|
||
def test_conf_loader_appconf_not_exist(self): | ||
from numalogic.udfs import load_pipeline_conf | ||
|
||
app_conf_path = "_random.yaml" | ||
plconf = load_pipeline_conf(BASE_CONFIG_PATH, app_conf_path) | ||
base_conf = OmegaConf.load(BASE_CONFIG_PATH) | ||
|
||
self.assertListEqual(list(plconf.stream_confs), list(base_conf["stream_confs"])) | ||
|
||
def test_conf_loader_err(self): | ||
from numalogic.udfs import load_pipeline_conf | ||
|
||
with self.assertRaises(ConfigNotFoundError): | ||
load_pipeline_conf("_random1.yaml", "_random2.yaml") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |