Spaces:
Running
Running
Commit ·
eedbcec
1
Parent(s): 22a359f
feat(config): add ModelSelector for profile-aware model picking
Browse filesRoutes NER, embedding, and translation model choices through the
runtime profile so low-profile deployments use small fast models
and high-profile deployments use larger accurate models.
Helper functions: get_max_workers(), get_batch_size(),
get_graph_depth(), get_investigation_layers(), get_cache_ttl()
- config/model_selector.py +55 -0
config/model_selector.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
BharatGraph - Phase 31: Model Selector
|
| 3 |
+
Picks the right AI model variant based on the runtime profile.
|
| 4 |
+
LOW -> smallest/fastest models (CPU-only, fits in 2GB RAM)
|
| 5 |
+
HIGH -> larger/more accurate models (GPU or high-RAM server)
|
| 6 |
+
Pure ASCII.
|
| 7 |
+
"""
|
| 8 |
+
from config.runtime_profile import PROFILE
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
MODEL_VARIANTS = {
|
| 12 |
+
"ner": {
|
| 13 |
+
"low": "xx_ent_wiki_sm",
|
| 14 |
+
"medium": "en_core_web_sm",
|
| 15 |
+
"high": "en_core_web_trf",
|
| 16 |
+
},
|
| 17 |
+
"embeddings": {
|
| 18 |
+
"low": "sentence-transformers/paraphrase-MiniLM-L3-v2",
|
| 19 |
+
"medium": "sentence-transformers/all-MiniLM-L6-v2",
|
| 20 |
+
"high": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
| 21 |
+
},
|
| 22 |
+
"translation": {
|
| 23 |
+
"low": "Helsinki-NLP/opus-mt-en-hi",
|
| 24 |
+
"medium": "Helsinki-NLP/opus-mt-en-hi",
|
| 25 |
+
"high": "Helsinki-NLP/opus-mt-en-ROMANCE",
|
| 26 |
+
},
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_model(task: str) -> str:
|
| 31 |
+
"""Return the model name for a task given the current runtime profile."""
|
| 32 |
+
profile_name = PROFILE.name
|
| 33 |
+
variants = MODEL_VARIANTS.get(task, {})
|
| 34 |
+
model = variants.get(profile_name, variants.get("medium", ""))
|
| 35 |
+
return model
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def get_max_workers() -> int:
|
| 39 |
+
return PROFILE["max_workers"]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def get_batch_size() -> int:
|
| 43 |
+
return PROFILE["batch_size"]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def get_graph_depth() -> int:
|
| 47 |
+
return PROFILE["graph_depth"]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def get_investigation_layers() -> int:
|
| 51 |
+
return PROFILE["investigation_layers"]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def get_cache_ttl() -> int:
|
| 55 |
+
return PROFILE["cache_ttl_seconds"]
|