isa-model 0.4.3__py3-none-any.whl → 0.4.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- isa_model/core/config.py +3 -3
- isa_model/core/logging/__init__.py +14 -13
- isa_model/core/models/model_manager.py +1 -69
- isa_model/core/models/model_storage.py +4 -2
- {isa_model-0.4.3.dist-info → isa_model-0.4.5.dist-info}/METADATA +6 -1
- {isa_model-0.4.3.dist-info → isa_model-0.4.5.dist-info}/RECORD +8 -22
- isa_model/core/logging/influx_logger.py +0 -523
- isa_model/core/security/secrets.py +0 -358
- isa_model/core/storage/hf_storage.py +0 -419
- isa_model/deployment/local/__init__.py +0 -31
- isa_model/deployment/local/config.py +0 -248
- isa_model/deployment/local/gpu_gateway.py +0 -607
- isa_model/deployment/local/health_checker.py +0 -428
- isa_model/deployment/local/provider.py +0 -586
- isa_model/deployment/local/tensorrt_service.py +0 -621
- isa_model/deployment/local/transformers_service.py +0 -644
- isa_model/deployment/local/vllm_service.py +0 -527
- isa_model/inference/services/custom_model_manager.py +0 -277
- isa_model/inference/services/llm/local_llm_service.py +0 -747
- isa_model/inference/services/vision/blip_vision_service.py +0 -359
- {isa_model-0.4.3.dist-info → isa_model-0.4.5.dist-info}/WHEEL +0 -0
- {isa_model-0.4.3.dist-info → isa_model-0.4.5.dist-info}/top_level.txt +0 -0
@@ -1,277 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
"""
|
5
|
-
Custom Model Manager - Handles registration and management of custom trained models
|
6
|
-
Provides integration for models trained through ISA Model training pipeline
|
7
|
-
"""
|
8
|
-
|
9
|
-
import logging
|
10
|
-
import json
|
11
|
-
import os
|
12
|
-
from typing import Dict, List, Any, Optional
|
13
|
-
from datetime import datetime
|
14
|
-
from dataclasses import dataclass, asdict
|
15
|
-
|
16
|
-
logger = logging.getLogger(__name__)
|
17
|
-
|
18
|
-
@dataclass
|
19
|
-
class CustomModelInfo:
|
20
|
-
"""Information about a custom model"""
|
21
|
-
model_id: str
|
22
|
-
model_name: str
|
23
|
-
model_type: str # 'text', 'vision', 'audio', etc.
|
24
|
-
provider: str
|
25
|
-
base_model: str # The base model this was fine-tuned from
|
26
|
-
training_date: str
|
27
|
-
model_path: str # Local path or HuggingFace repo
|
28
|
-
metadata: Dict[str, Any]
|
29
|
-
capabilities: List[str]
|
30
|
-
performance_metrics: Optional[Dict[str, float]] = None
|
31
|
-
deployment_config: Optional[Dict[str, Any]] = None
|
32
|
-
|
33
|
-
def to_dict(self) -> Dict[str, Any]:
|
34
|
-
return asdict(self)
|
35
|
-
|
36
|
-
class CustomModelManager:
|
37
|
-
"""
|
38
|
-
Manages custom trained models in the ISA Model ecosystem
|
39
|
-
Handles registration, discovery, and integration of custom models
|
40
|
-
"""
|
41
|
-
|
42
|
-
def __init__(self, models_registry_path: str = None):
|
43
|
-
self.models_registry_path = models_registry_path or os.path.join(
|
44
|
-
os.path.expanduser("~"), ".isa_model", "custom_models.json"
|
45
|
-
)
|
46
|
-
self._models: Dict[str, CustomModelInfo] = {}
|
47
|
-
self._load_models_registry()
|
48
|
-
|
49
|
-
def _load_models_registry(self):
|
50
|
-
"""Load custom models registry from file"""
|
51
|
-
if os.path.exists(self.models_registry_path):
|
52
|
-
try:
|
53
|
-
with open(self.models_registry_path, 'r', encoding='utf-8') as f:
|
54
|
-
models_data = json.load(f)
|
55
|
-
|
56
|
-
for model_data in models_data.get('models', []):
|
57
|
-
model_info = CustomModelInfo(**model_data)
|
58
|
-
self._models[model_info.model_id] = model_info
|
59
|
-
|
60
|
-
logger.info(f"Loaded {len(self._models)} custom models from registry")
|
61
|
-
except Exception as e:
|
62
|
-
logger.warning(f"Failed to load models registry: {e}")
|
63
|
-
self._models = {}
|
64
|
-
else:
|
65
|
-
# Create default registry with some ISA models
|
66
|
-
self._create_default_registry()
|
67
|
-
|
68
|
-
def _create_default_registry(self):
|
69
|
-
"""Create default registry with ISA models"""
|
70
|
-
default_models = [
|
71
|
-
CustomModelInfo(
|
72
|
-
model_id="isa-llm-service",
|
73
|
-
model_name="ISA LLM Service",
|
74
|
-
model_type="text",
|
75
|
-
provider="isa",
|
76
|
-
base_model="DialoGPT-small",
|
77
|
-
training_date="2024-12-19",
|
78
|
-
model_path="modal://isa-llm-inference",
|
79
|
-
metadata={
|
80
|
-
"description": "ISA custom LLM service with fallback support",
|
81
|
-
"parameters": "124M",
|
82
|
-
"context_length": 1024,
|
83
|
-
"languages": ["en", "zh"]
|
84
|
-
},
|
85
|
-
capabilities=["chat", "text_generation", "conversation"],
|
86
|
-
performance_metrics={
|
87
|
-
"perplexity": 3.2,
|
88
|
-
"bleu_score": 0.75,
|
89
|
-
"response_time_ms": 850
|
90
|
-
},
|
91
|
-
deployment_config={
|
92
|
-
"platform": "modal",
|
93
|
-
"gpu_type": "A10G",
|
94
|
-
"memory_gb": 16,
|
95
|
-
"concurrent_requests": 5
|
96
|
-
}
|
97
|
-
),
|
98
|
-
CustomModelInfo(
|
99
|
-
model_id="xenodennis/dialoGPT-small-20241219-v1",
|
100
|
-
model_name="ISA Fine-tuned DialoGPT",
|
101
|
-
model_type="text",
|
102
|
-
provider="huggingface",
|
103
|
-
base_model="microsoft/DialoGPT-small",
|
104
|
-
training_date="2024-12-19",
|
105
|
-
model_path="xenodennis/dialoGPT-small-20241219-v1",
|
106
|
-
metadata={
|
107
|
-
"description": "DialoGPT model fine-tuned with ISA training pipeline",
|
108
|
-
"parameters": "124M",
|
109
|
-
"trainable_parameters": "294K (LoRA)",
|
110
|
-
"training_steps": 1000,
|
111
|
-
"languages": ["en", "zh"]
|
112
|
-
},
|
113
|
-
capabilities=["chat", "text_generation", "dialogue"],
|
114
|
-
performance_metrics={
|
115
|
-
"final_loss": 2.1234,
|
116
|
-
"eval_loss": 2.3456,
|
117
|
-
"training_time_minutes": 15
|
118
|
-
}
|
119
|
-
),
|
120
|
-
CustomModelInfo(
|
121
|
-
model_id="isa-custom-embeddings",
|
122
|
-
model_name="ISA Custom Embeddings",
|
123
|
-
model_type="embedding",
|
124
|
-
provider="isa",
|
125
|
-
base_model="sentence-transformers/all-MiniLM-L6-v2",
|
126
|
-
training_date="2024-12-19",
|
127
|
-
model_path="local://models/isa-embeddings",
|
128
|
-
metadata={
|
129
|
-
"description": "Custom embeddings trained on ISA domain data",
|
130
|
-
"dimensions": 384,
|
131
|
-
"max_sequence_length": 512
|
132
|
-
},
|
133
|
-
capabilities=["embed", "similarity", "clustering"]
|
134
|
-
)
|
135
|
-
]
|
136
|
-
|
137
|
-
for model in default_models:
|
138
|
-
self._models[model.model_id] = model
|
139
|
-
|
140
|
-
self._save_models_registry()
|
141
|
-
logger.info(f"Created default registry with {len(default_models)} models")
|
142
|
-
|
143
|
-
def _save_models_registry(self):
|
144
|
-
"""Save models registry to file"""
|
145
|
-
try:
|
146
|
-
os.makedirs(os.path.dirname(self.models_registry_path), exist_ok=True)
|
147
|
-
|
148
|
-
registry_data = {
|
149
|
-
"version": "1.0",
|
150
|
-
"last_updated": datetime.now().isoformat(),
|
151
|
-
"models": [model.to_dict() for model in self._models.values()]
|
152
|
-
}
|
153
|
-
|
154
|
-
with open(self.models_registry_path, 'w', encoding='utf-8') as f:
|
155
|
-
json.dump(registry_data, f, indent=2, ensure_ascii=False)
|
156
|
-
|
157
|
-
logger.debug(f"Saved models registry to {self.models_registry_path}")
|
158
|
-
except Exception as e:
|
159
|
-
logger.error(f"Failed to save models registry: {e}")
|
160
|
-
|
161
|
-
def register_model(self, model_info: CustomModelInfo) -> bool:
|
162
|
-
"""Register a new custom model"""
|
163
|
-
try:
|
164
|
-
self._models[model_info.model_id] = model_info
|
165
|
-
self._save_models_registry()
|
166
|
-
logger.info(f"Registered custom model: {model_info.model_id}")
|
167
|
-
return True
|
168
|
-
except Exception as e:
|
169
|
-
logger.error(f"Failed to register model {model_info.model_id}: {e}")
|
170
|
-
return False
|
171
|
-
|
172
|
-
def unregister_model(self, model_id: str) -> bool:
|
173
|
-
"""Unregister a custom model"""
|
174
|
-
if model_id in self._models:
|
175
|
-
del self._models[model_id]
|
176
|
-
self._save_models_registry()
|
177
|
-
logger.info(f"Unregistered custom model: {model_id}")
|
178
|
-
return True
|
179
|
-
return False
|
180
|
-
|
181
|
-
def get_model(self, model_id: str) -> Optional[CustomModelInfo]:
|
182
|
-
"""Get custom model information"""
|
183
|
-
return self._models.get(model_id)
|
184
|
-
|
185
|
-
def list_models(self, model_type: str = None, provider: str = None) -> List[CustomModelInfo]:
|
186
|
-
"""List custom models with optional filtering"""
|
187
|
-
models = list(self._models.values())
|
188
|
-
|
189
|
-
if model_type:
|
190
|
-
models = [m for m in models if m.model_type == model_type]
|
191
|
-
|
192
|
-
if provider:
|
193
|
-
models = [m for m in models if m.provider == provider]
|
194
|
-
|
195
|
-
return models
|
196
|
-
|
197
|
-
def get_models_for_api(self) -> List[Dict[str, Any]]:
|
198
|
-
"""Get models in API format for model listing"""
|
199
|
-
api_models = []
|
200
|
-
|
201
|
-
for model in self._models.values():
|
202
|
-
api_model = {
|
203
|
-
"model_id": model.model_id,
|
204
|
-
"service_type": model.model_type,
|
205
|
-
"provider": model.provider,
|
206
|
-
"description": model.metadata.get("description", ""),
|
207
|
-
"capabilities": model.capabilities,
|
208
|
-
"custom": True,
|
209
|
-
"base_model": model.base_model,
|
210
|
-
"training_date": model.training_date
|
211
|
-
}
|
212
|
-
|
213
|
-
# Add performance metrics if available
|
214
|
-
if model.performance_metrics:
|
215
|
-
api_model["performance"] = model.performance_metrics
|
216
|
-
|
217
|
-
api_models.append(api_model)
|
218
|
-
|
219
|
-
return api_models
|
220
|
-
|
221
|
-
def search_models(self, query: str) -> List[CustomModelInfo]:
|
222
|
-
"""Search custom models by query"""
|
223
|
-
query_lower = query.lower()
|
224
|
-
matching_models = []
|
225
|
-
|
226
|
-
for model in self._models.values():
|
227
|
-
# Search in model_id, name, description, and capabilities
|
228
|
-
searchable_text = f"{model.model_id} {model.model_name} {model.metadata.get('description', '')} {' '.join(model.capabilities)}".lower()
|
229
|
-
|
230
|
-
if query_lower in searchable_text:
|
231
|
-
matching_models.append(model)
|
232
|
-
|
233
|
-
return matching_models
|
234
|
-
|
235
|
-
def get_deployment_config(self, model_id: str) -> Optional[Dict[str, Any]]:
|
236
|
-
"""Get deployment configuration for a model"""
|
237
|
-
model = self.get_model(model_id)
|
238
|
-
return model.deployment_config if model else None
|
239
|
-
|
240
|
-
def update_performance_metrics(self, model_id: str, metrics: Dict[str, float]) -> bool:
|
241
|
-
"""Update performance metrics for a model"""
|
242
|
-
model = self.get_model(model_id)
|
243
|
-
if model:
|
244
|
-
model.performance_metrics = metrics
|
245
|
-
self._save_models_registry()
|
246
|
-
return True
|
247
|
-
return False
|
248
|
-
|
249
|
-
def get_provider_models(self, provider: str) -> List[CustomModelInfo]:
|
250
|
-
"""Get all models for a specific provider"""
|
251
|
-
return [model for model in self._models.values() if model.provider == provider]
|
252
|
-
|
253
|
-
def get_stats(self) -> Dict[str, Any]:
|
254
|
-
"""Get statistics about custom models"""
|
255
|
-
models_by_type = {}
|
256
|
-
models_by_provider = {}
|
257
|
-
|
258
|
-
for model in self._models.values():
|
259
|
-
models_by_type[model.model_type] = models_by_type.get(model.model_type, 0) + 1
|
260
|
-
models_by_provider[model.provider] = models_by_provider.get(model.provider, 0) + 1
|
261
|
-
|
262
|
-
return {
|
263
|
-
"total_models": len(self._models),
|
264
|
-
"models_by_type": models_by_type,
|
265
|
-
"models_by_provider": models_by_provider,
|
266
|
-
"registry_path": self.models_registry_path
|
267
|
-
}
|
268
|
-
|
269
|
-
# Global instance
|
270
|
-
_custom_model_manager = None
|
271
|
-
|
272
|
-
def get_custom_model_manager() -> CustomModelManager:
|
273
|
-
"""Get the global custom model manager instance"""
|
274
|
-
global _custom_model_manager
|
275
|
-
if _custom_model_manager is None:
|
276
|
-
_custom_model_manager = CustomModelManager()
|
277
|
-
return _custom_model_manager
|