isa-model 0.4.0__py3-none-any.whl → 0.4.4__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/client.py +466 -43
- isa_model/core/cache/redis_cache.py +12 -3
- isa_model/core/config/config_manager.py +230 -3
- isa_model/core/config.py +90 -0
- isa_model/core/database/direct_db_client.py +114 -0
- isa_model/core/database/migration_manager.py +563 -0
- isa_model/core/database/migrations.py +21 -1
- isa_model/core/database/supabase_client.py +154 -19
- isa_model/core/dependencies.py +316 -0
- isa_model/core/discovery/__init__.py +19 -0
- isa_model/core/discovery/consul_discovery.py +190 -0
- isa_model/core/logging/__init__.py +54 -0
- isa_model/core/logging/influx_logger.py +523 -0
- isa_model/core/logging/loki_logger.py +160 -0
- isa_model/core/models/__init__.py +27 -18
- isa_model/core/models/config_models.py +625 -0
- isa_model/core/models/deployment_billing_tracker.py +430 -0
- isa_model/core/models/model_manager.py +35 -80
- isa_model/core/models/model_metadata.py +690 -0
- isa_model/core/models/model_repo.py +174 -18
- isa_model/core/models/system_models.py +857 -0
- isa_model/core/repositories/__init__.py +9 -0
- isa_model/core/repositories/config_repository.py +912 -0
- isa_model/core/services/intelligent_model_selector.py +399 -21
- isa_model/core/types.py +1 -0
- isa_model/deployment/__init__.py +5 -48
- isa_model/deployment/core/__init__.py +2 -31
- isa_model/deployment/core/deployment_manager.py +1278 -370
- isa_model/deployment/modal/__init__.py +8 -0
- isa_model/deployment/modal/config.py +136 -0
- isa_model/deployment/{services/auto_hf_modal_deployer.py → modal/deployer.py} +1 -1
- isa_model/deployment/modal/services/__init__.py +3 -0
- isa_model/deployment/modal/services/audio/__init__.py +1 -0
- isa_model/deployment/modal/services/embedding/__init__.py +1 -0
- isa_model/deployment/modal/services/llm/__init__.py +1 -0
- isa_model/deployment/modal/services/llm/isa_llm_service.py +424 -0
- isa_model/deployment/modal/services/video/__init__.py +1 -0
- isa_model/deployment/modal/services/vision/__init__.py +1 -0
- isa_model/deployment/models/org-org-acme-corp-tenant-a-service-llm-20250825-225822/tenant-a-service_modal_service.py +48 -0
- isa_model/deployment/models/org-test-org-123-prefix-test-service-llm-20250825-225822/prefix-test-service_modal_service.py +48 -0
- isa_model/deployment/models/test-llm-service-llm-20250825-204442/test-llm-service_modal_service.py +48 -0
- isa_model/deployment/models/test-monitoring-gpt2-llm-20250825-212906/test-monitoring-gpt2_modal_service.py +48 -0
- isa_model/deployment/models/test-monitoring-gpt2-llm-20250825-213009/test-monitoring-gpt2_modal_service.py +48 -0
- isa_model/deployment/storage/__init__.py +5 -0
- isa_model/deployment/storage/deployment_repository.py +824 -0
- isa_model/deployment/triton/__init__.py +10 -0
- isa_model/deployment/triton/config.py +196 -0
- isa_model/deployment/triton/configs/__init__.py +1 -0
- isa_model/deployment/triton/provider.py +512 -0
- isa_model/deployment/triton/scripts/__init__.py +1 -0
- isa_model/deployment/triton/templates/__init__.py +1 -0
- isa_model/inference/__init__.py +47 -1
- isa_model/inference/ai_factory.py +137 -10
- isa_model/inference/legacy_services/__init__.py +21 -0
- isa_model/inference/legacy_services/model_evaluation.py +637 -0
- isa_model/inference/legacy_services/model_service.py +573 -0
- isa_model/inference/legacy_services/model_serving.py +717 -0
- isa_model/inference/legacy_services/model_training.py +561 -0
- isa_model/inference/models/__init__.py +21 -0
- isa_model/inference/models/inference_config.py +551 -0
- isa_model/inference/models/inference_record.py +675 -0
- isa_model/inference/models/performance_models.py +714 -0
- isa_model/inference/repositories/__init__.py +9 -0
- isa_model/inference/repositories/inference_repository.py +828 -0
- isa_model/inference/services/audio/base_stt_service.py +184 -11
- isa_model/inference/services/audio/openai_stt_service.py +22 -6
- isa_model/inference/services/embedding/ollama_embed_service.py +15 -3
- isa_model/inference/services/embedding/resilient_embed_service.py +285 -0
- isa_model/inference/services/llm/__init__.py +10 -2
- isa_model/inference/services/llm/base_llm_service.py +335 -24
- isa_model/inference/services/llm/cerebras_llm_service.py +628 -0
- isa_model/inference/services/llm/helpers/llm_adapter.py +9 -4
- isa_model/inference/services/llm/helpers/llm_prompts.py +342 -0
- isa_model/inference/services/llm/helpers/llm_utils.py +321 -23
- isa_model/inference/services/llm/huggingface_llm_service.py +581 -0
- isa_model/inference/services/llm/ollama_llm_service.py +9 -2
- isa_model/inference/services/llm/openai_llm_service.py +33 -16
- isa_model/inference/services/llm/yyds_llm_service.py +8 -2
- isa_model/inference/services/vision/__init__.py +22 -1
- isa_model/inference/services/vision/helpers/image_utils.py +8 -5
- isa_model/inference/services/vision/isa_vision_service.py +65 -4
- isa_model/inference/services/vision/openai_vision_service.py +19 -10
- isa_model/inference/services/vision/vgg16_vision_service.py +257 -0
- isa_model/serving/api/cache_manager.py +245 -0
- isa_model/serving/api/dependencies/__init__.py +1 -0
- isa_model/serving/api/dependencies/auth.py +194 -0
- isa_model/serving/api/dependencies/database.py +139 -0
- isa_model/serving/api/error_handlers.py +284 -0
- isa_model/serving/api/fastapi_server.py +172 -22
- isa_model/serving/api/middleware/auth.py +8 -2
- isa_model/serving/api/middleware/security.py +23 -33
- isa_model/serving/api/middleware/tenant_context.py +414 -0
- isa_model/serving/api/routes/analytics.py +4 -1
- isa_model/serving/api/routes/config.py +645 -0
- isa_model/serving/api/routes/deployment_billing.py +315 -0
- isa_model/serving/api/routes/deployments.py +138 -2
- isa_model/serving/api/routes/gpu_gateway.py +440 -0
- isa_model/serving/api/routes/health.py +32 -12
- isa_model/serving/api/routes/inference_monitoring.py +486 -0
- isa_model/serving/api/routes/local_deployments.py +448 -0
- isa_model/serving/api/routes/tenants.py +575 -0
- isa_model/serving/api/routes/unified.py +680 -18
- isa_model/serving/api/routes/webhooks.py +479 -0
- isa_model/serving/api/startup.py +68 -54
- isa_model/utils/gpu_utils.py +311 -0
- {isa_model-0.4.0.dist-info → isa_model-0.4.4.dist-info}/METADATA +71 -24
- isa_model-0.4.4.dist-info/RECORD +180 -0
- isa_model/core/security/secrets.py +0 -358
- isa_model/core/storage/hf_storage.py +0 -419
- isa_model/core/storage/minio_storage.py +0 -0
- isa_model/deployment/cloud/__init__.py +0 -9
- isa_model/deployment/cloud/modal/__init__.py +0 -10
- isa_model/deployment/core/deployment_config.py +0 -356
- isa_model/deployment/core/isa_deployment_service.py +0 -401
- isa_model/deployment/gpu_int8_ds8/app/server.py +0 -66
- isa_model/deployment/gpu_int8_ds8/scripts/test_client.py +0 -43
- isa_model/deployment/gpu_int8_ds8/scripts/test_client_os.py +0 -35
- isa_model/deployment/runtime/deployed_service.py +0 -338
- isa_model/deployment/services/__init__.py +0 -9
- isa_model/deployment/services/auto_deploy_vision_service.py +0 -538
- isa_model/deployment/services/model_service.py +0 -332
- isa_model/deployment/services/service_monitor.py +0 -356
- isa_model/deployment/services/service_registry.py +0 -527
- isa_model/eval/__init__.py +0 -92
- isa_model/eval/benchmarks/__init__.py +0 -27
- isa_model/eval/benchmarks/multimodal_datasets.py +0 -460
- isa_model/eval/benchmarks.py +0 -701
- isa_model/eval/config/__init__.py +0 -10
- isa_model/eval/config/evaluation_config.py +0 -108
- isa_model/eval/evaluators/__init__.py +0 -24
- isa_model/eval/evaluators/audio_evaluator.py +0 -727
- isa_model/eval/evaluators/base_evaluator.py +0 -503
- isa_model/eval/evaluators/embedding_evaluator.py +0 -742
- isa_model/eval/evaluators/llm_evaluator.py +0 -472
- isa_model/eval/evaluators/vision_evaluator.py +0 -564
- isa_model/eval/example_evaluation.py +0 -395
- isa_model/eval/factory.py +0 -798
- isa_model/eval/infrastructure/__init__.py +0 -24
- isa_model/eval/infrastructure/experiment_tracker.py +0 -466
- isa_model/eval/isa_benchmarks.py +0 -700
- isa_model/eval/isa_integration.py +0 -582
- isa_model/eval/metrics.py +0 -951
- isa_model/eval/tests/unit/test_basic.py +0 -396
- isa_model/serving/api/routes/evaluations.py +0 -579
- isa_model/training/__init__.py +0 -168
- isa_model/training/annotation/annotation_schema.py +0 -47
- isa_model/training/annotation/processors/annotation_processor.py +0 -126
- isa_model/training/annotation/storage/dataset_manager.py +0 -131
- isa_model/training/annotation/storage/dataset_schema.py +0 -44
- isa_model/training/annotation/tests/test_annotation_flow.py +0 -109
- isa_model/training/annotation/tests/test_minio copy.py +0 -113
- isa_model/training/annotation/tests/test_minio_upload.py +0 -43
- isa_model/training/annotation/views/annotation_controller.py +0 -158
- isa_model/training/cloud/__init__.py +0 -22
- isa_model/training/cloud/job_orchestrator.py +0 -402
- isa_model/training/cloud/runpod_trainer.py +0 -454
- isa_model/training/cloud/storage_manager.py +0 -482
- isa_model/training/core/__init__.py +0 -26
- isa_model/training/core/config.py +0 -181
- isa_model/training/core/dataset.py +0 -222
- isa_model/training/core/trainer.py +0 -720
- isa_model/training/core/utils.py +0 -213
- isa_model/training/examples/intelligent_training_example.py +0 -281
- isa_model/training/factory.py +0 -424
- isa_model/training/intelligent/__init__.py +0 -25
- isa_model/training/intelligent/decision_engine.py +0 -643
- isa_model/training/intelligent/intelligent_factory.py +0 -888
- isa_model/training/intelligent/knowledge_base.py +0 -751
- isa_model/training/intelligent/resource_optimizer.py +0 -839
- isa_model/training/intelligent/task_classifier.py +0 -576
- isa_model/training/storage/__init__.py +0 -24
- isa_model/training/storage/core_integration.py +0 -439
- isa_model/training/storage/training_repository.py +0 -552
- isa_model/training/storage/training_storage.py +0 -628
- isa_model-0.4.0.dist-info/RECORD +0 -182
- /isa_model/deployment/{cloud/modal → modal/services/audio}/isa_audio_chatTTS_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/audio}/isa_audio_fish_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/audio}/isa_audio_openvoice_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/audio}/isa_audio_service_v2.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/embedding}/isa_embed_rerank_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/video}/isa_video_hunyuan_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/vision}/isa_vision_ocr_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/vision}/isa_vision_qwen25_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/vision}/isa_vision_table_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/vision}/isa_vision_ui_service.py +0 -0
- /isa_model/deployment/{cloud/modal → modal/services/vision}/isa_vision_ui_service_optimized.py +0 -0
- /isa_model/deployment/{services → modal/services/vision}/simple_auto_deploy_vision_service.py +0 -0
- {isa_model-0.4.0.dist-info → isa_model-0.4.4.dist-info}/WHEEL +0 -0
- {isa_model-0.4.0.dist-info → isa_model-0.4.4.dist-info}/top_level.txt +0 -0
@@ -1,751 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Knowledge Base for Training Intelligence
|
3
|
-
|
4
|
-
This module provides a comprehensive knowledge base containing:
|
5
|
-
- Model specifications and capabilities
|
6
|
-
- Training best practices and benchmarks
|
7
|
-
- Performance metrics and cost data
|
8
|
-
- Historical training results
|
9
|
-
- Resource requirements and recommendations
|
10
|
-
|
11
|
-
The knowledge base serves as the brain of the intelligent training system.
|
12
|
-
"""
|
13
|
-
|
14
|
-
import logging
|
15
|
-
import json
|
16
|
-
from typing import Dict, List, Optional, Any, Tuple
|
17
|
-
from dataclasses import dataclass, field, asdict
|
18
|
-
from datetime import datetime
|
19
|
-
import os
|
20
|
-
from pathlib import Path
|
21
|
-
|
22
|
-
logger = logging.getLogger(__name__)
|
23
|
-
|
24
|
-
|
25
|
-
@dataclass
|
26
|
-
class ModelSpec:
|
27
|
-
"""Model specification and metadata."""
|
28
|
-
|
29
|
-
name: str
|
30
|
-
model_type: str # "llm", "sd", "cv", "audio"
|
31
|
-
parameters: int # Number of parameters
|
32
|
-
|
33
|
-
# Capabilities
|
34
|
-
supported_tasks: List[str]
|
35
|
-
supported_domains: List[str]
|
36
|
-
context_length: int = 2048
|
37
|
-
|
38
|
-
# Performance characteristics
|
39
|
-
quality_score: float = 0.0 # 0.0 to 1.0
|
40
|
-
speed_score: float = 0.0 # 0.0 to 1.0
|
41
|
-
efficiency_score: float = 0.0 # 0.0 to 1.0
|
42
|
-
|
43
|
-
# Training characteristics
|
44
|
-
optimal_dataset_size: int = 10000
|
45
|
-
min_dataset_size: int = 100
|
46
|
-
supports_lora: bool = True
|
47
|
-
supports_full_finetuning: bool = True
|
48
|
-
|
49
|
-
# Resource requirements
|
50
|
-
min_gpu_memory: int = 8 # GB
|
51
|
-
recommended_gpu_memory: int = 16 # GB
|
52
|
-
training_time_factor: float = 1.0 # Relative to baseline
|
53
|
-
|
54
|
-
# Cost estimates (per hour)
|
55
|
-
estimated_cost_per_hour: float = 0.0
|
56
|
-
|
57
|
-
# Metadata
|
58
|
-
is_popular: bool = False
|
59
|
-
is_open_source: bool = True
|
60
|
-
release_date: Optional[str] = None
|
61
|
-
description: str = ""
|
62
|
-
|
63
|
-
# Configuration defaults
|
64
|
-
default_config: Dict[str, Any] = field(default_factory=dict)
|
65
|
-
lora_targets: List[str] = field(default_factory=list)
|
66
|
-
|
67
|
-
def __post_init__(self):
|
68
|
-
if not self.lora_targets and self.supports_lora:
|
69
|
-
self.lora_targets = ["q_proj", "v_proj", "k_proj", "o_proj"]
|
70
|
-
|
71
|
-
|
72
|
-
@dataclass
|
73
|
-
class BestPractice:
|
74
|
-
"""Training best practice recommendation."""
|
75
|
-
|
76
|
-
task_type: str
|
77
|
-
domain: str
|
78
|
-
recommendation: str
|
79
|
-
reason: str
|
80
|
-
confidence: float
|
81
|
-
source: str = "expert_knowledge"
|
82
|
-
created_at: datetime = field(default_factory=datetime.now)
|
83
|
-
|
84
|
-
|
85
|
-
@dataclass
|
86
|
-
class PerformanceBenchmark:
|
87
|
-
"""Performance benchmark data."""
|
88
|
-
|
89
|
-
model_name: str
|
90
|
-
task_type: str
|
91
|
-
dataset_name: str
|
92
|
-
|
93
|
-
# Performance metrics
|
94
|
-
accuracy: Optional[float] = None
|
95
|
-
bleu_score: Optional[float] = None
|
96
|
-
rouge_score: Optional[float] = None
|
97
|
-
perplexity: Optional[float] = None
|
98
|
-
|
99
|
-
# Training metrics
|
100
|
-
training_time: Optional[float] = None # hours
|
101
|
-
training_cost: Optional[float] = None # USD
|
102
|
-
gpu_type: Optional[str] = None
|
103
|
-
|
104
|
-
# Configuration used
|
105
|
-
config: Dict[str, Any] = field(default_factory=dict)
|
106
|
-
|
107
|
-
# Metadata
|
108
|
-
source: str = "benchmark"
|
109
|
-
created_at: datetime = field(default_factory=datetime.now)
|
110
|
-
|
111
|
-
|
112
|
-
class KnowledgeBase:
|
113
|
-
"""
|
114
|
-
Comprehensive knowledge base for training intelligence.
|
115
|
-
|
116
|
-
This class manages all the knowledge required for intelligent training decisions:
|
117
|
-
- Model specifications and capabilities
|
118
|
-
- Training best practices and guidelines
|
119
|
-
- Performance benchmarks and historical data
|
120
|
-
- Resource requirements and cost estimates
|
121
|
-
|
122
|
-
Example:
|
123
|
-
```python
|
124
|
-
kb = KnowledgeBase()
|
125
|
-
|
126
|
-
# Get model recommendations
|
127
|
-
models = kb.recommend_models(
|
128
|
-
task_type="chat",
|
129
|
-
domain="medical",
|
130
|
-
dataset_size=5000,
|
131
|
-
quality_target="high"
|
132
|
-
)
|
133
|
-
|
134
|
-
# Get best practices
|
135
|
-
practices = kb.get_best_practices("chat", "medical")
|
136
|
-
```
|
137
|
-
"""
|
138
|
-
|
139
|
-
def __init__(self, data_dir: Optional[str] = None):
|
140
|
-
"""
|
141
|
-
Initialize knowledge base.
|
142
|
-
|
143
|
-
Args:
|
144
|
-
data_dir: Directory to store/load knowledge base data
|
145
|
-
"""
|
146
|
-
self.data_dir = data_dir or os.path.join(os.getcwd(), "knowledge_base")
|
147
|
-
os.makedirs(self.data_dir, exist_ok=True)
|
148
|
-
|
149
|
-
# Initialize data structures
|
150
|
-
self.models: Dict[str, ModelSpec] = {}
|
151
|
-
self.best_practices: List[BestPractice] = []
|
152
|
-
self.benchmarks: List[PerformanceBenchmark] = []
|
153
|
-
self.dataset_info: Dict[str, Dict[str, Any]] = {}
|
154
|
-
|
155
|
-
# Load existing data
|
156
|
-
self._load_knowledge_base()
|
157
|
-
|
158
|
-
# Initialize with default knowledge if empty
|
159
|
-
if not self.models:
|
160
|
-
self._initialize_default_knowledge()
|
161
|
-
|
162
|
-
logger.info(f"Knowledge base initialized with {len(self.models)} models")
|
163
|
-
|
164
|
-
def recommend_models(
|
165
|
-
self,
|
166
|
-
task_type: str,
|
167
|
-
domain: str = "general",
|
168
|
-
dataset_size: int = 10000,
|
169
|
-
quality_target: str = "balanced",
|
170
|
-
constraints: Optional[Dict[str, Any]] = None
|
171
|
-
) -> List[Dict[str, Any]]:
|
172
|
-
"""
|
173
|
-
Recommend models for a specific task and requirements.
|
174
|
-
|
175
|
-
Args:
|
176
|
-
task_type: Type of task (chat, classification, etc.)
|
177
|
-
domain: Domain/industry
|
178
|
-
dataset_size: Size of training dataset
|
179
|
-
quality_target: Quality target (fast, balanced, high)
|
180
|
-
constraints: Additional constraints (budget, time, etc.)
|
181
|
-
|
182
|
-
Returns:
|
183
|
-
List of recommended models with scores
|
184
|
-
"""
|
185
|
-
constraints = constraints or {}
|
186
|
-
|
187
|
-
# Filter models by task compatibility
|
188
|
-
compatible_models = []
|
189
|
-
for model_name, model_spec in self.models.items():
|
190
|
-
if self._is_model_compatible(model_spec, task_type, domain, dataset_size):
|
191
|
-
score = self._score_model(
|
192
|
-
model_spec, task_type, domain, dataset_size, quality_target, constraints
|
193
|
-
)
|
194
|
-
|
195
|
-
model_dict = asdict(model_spec)
|
196
|
-
model_dict["suitability_score"] = score
|
197
|
-
model_dict["task_suitability"] = score / 100.0 # Normalize
|
198
|
-
|
199
|
-
# Ensure trainer_type is set based on model_type
|
200
|
-
if "trainer_type" not in model_dict or not model_dict["trainer_type"]:
|
201
|
-
if model_spec.model_type == "llm":
|
202
|
-
model_dict["trainer_type"] = "llm"
|
203
|
-
elif model_spec.model_type == "sd":
|
204
|
-
model_dict["trainer_type"] = "sd"
|
205
|
-
elif model_spec.model_type == "ml":
|
206
|
-
model_dict["trainer_type"] = "ml"
|
207
|
-
else:
|
208
|
-
model_dict["trainer_type"] = "llm" # Default
|
209
|
-
|
210
|
-
compatible_models.append(model_dict)
|
211
|
-
|
212
|
-
# Sort by suitability score
|
213
|
-
compatible_models.sort(key=lambda x: x["suitability_score"], reverse=True)
|
214
|
-
|
215
|
-
return compatible_models[:10] # Return top 10
|
216
|
-
|
217
|
-
def _is_model_compatible(
|
218
|
-
self,
|
219
|
-
model_spec: ModelSpec,
|
220
|
-
task_type: str,
|
221
|
-
domain: str,
|
222
|
-
dataset_size: int
|
223
|
-
) -> bool:
|
224
|
-
"""Check if model is compatible with requirements."""
|
225
|
-
# Check task compatibility
|
226
|
-
if task_type not in model_spec.supported_tasks and "general" not in model_spec.supported_tasks:
|
227
|
-
return False
|
228
|
-
|
229
|
-
# Check domain compatibility
|
230
|
-
if domain not in model_spec.supported_domains and "general" not in model_spec.supported_domains:
|
231
|
-
return False
|
232
|
-
|
233
|
-
# Check minimum dataset size
|
234
|
-
if dataset_size < model_spec.min_dataset_size:
|
235
|
-
return False
|
236
|
-
|
237
|
-
return True
|
238
|
-
|
239
|
-
def _score_model(
|
240
|
-
self,
|
241
|
-
model_spec: ModelSpec,
|
242
|
-
task_type: str,
|
243
|
-
domain: str,
|
244
|
-
dataset_size: int,
|
245
|
-
quality_target: str,
|
246
|
-
constraints: Dict[str, Any]
|
247
|
-
) -> float:
|
248
|
-
"""Score a model's suitability for the task."""
|
249
|
-
score = 0.0
|
250
|
-
|
251
|
-
# Base compatibility score
|
252
|
-
if task_type in model_spec.supported_tasks:
|
253
|
-
score += 30
|
254
|
-
elif "general" in model_spec.supported_tasks:
|
255
|
-
score += 15
|
256
|
-
|
257
|
-
if domain in model_spec.supported_domains:
|
258
|
-
score += 20
|
259
|
-
elif "general" in model_spec.supported_domains:
|
260
|
-
score += 10
|
261
|
-
|
262
|
-
# Quality vs speed preference
|
263
|
-
if quality_target == "high":
|
264
|
-
score += model_spec.quality_score * 25
|
265
|
-
elif quality_target == "fast":
|
266
|
-
score += model_spec.speed_score * 25
|
267
|
-
else: # balanced
|
268
|
-
score += (model_spec.quality_score + model_spec.speed_score) * 12.5
|
269
|
-
|
270
|
-
# Efficiency bonus
|
271
|
-
score += model_spec.efficiency_score * 10
|
272
|
-
|
273
|
-
# Popularity bonus
|
274
|
-
if model_spec.is_popular:
|
275
|
-
score += 5
|
276
|
-
|
277
|
-
# Dataset size compatibility
|
278
|
-
if dataset_size >= model_spec.optimal_dataset_size:
|
279
|
-
score += 10
|
280
|
-
else:
|
281
|
-
# Penalty for suboptimal dataset size
|
282
|
-
ratio = dataset_size / model_spec.optimal_dataset_size
|
283
|
-
score += ratio * 10
|
284
|
-
|
285
|
-
# Budget constraints
|
286
|
-
if constraints.get("budget"):
|
287
|
-
budget = constraints["budget"]
|
288
|
-
estimated_cost = model_spec.estimated_cost_per_hour * 10 # Assume 10 hours
|
289
|
-
if estimated_cost <= budget:
|
290
|
-
score += 5
|
291
|
-
else:
|
292
|
-
score -= 10
|
293
|
-
|
294
|
-
# Time constraints
|
295
|
-
if constraints.get("time"):
|
296
|
-
time_limit = constraints["time"]
|
297
|
-
estimated_time = 10 * model_spec.training_time_factor # Assume 10 base hours
|
298
|
-
if estimated_time <= time_limit:
|
299
|
-
score += 5
|
300
|
-
else:
|
301
|
-
score -= 10
|
302
|
-
|
303
|
-
# Model preferences
|
304
|
-
if constraints.get("preferences"):
|
305
|
-
preferences = constraints["preferences"]
|
306
|
-
if preferences:
|
307
|
-
for pref in preferences:
|
308
|
-
if pref.lower() in model_spec.name.lower():
|
309
|
-
score += 15
|
310
|
-
|
311
|
-
return max(0.0, score)
|
312
|
-
|
313
|
-
def get_best_practices(self, task_type: str, domain: str = "general") -> List[BestPractice]:
|
314
|
-
"""Get best practices for a specific task and domain."""
|
315
|
-
practices = []
|
316
|
-
|
317
|
-
for practice in self.best_practices:
|
318
|
-
if (practice.task_type == task_type or practice.task_type == "general") and \
|
319
|
-
(practice.domain == domain or practice.domain == "general"):
|
320
|
-
practices.append(practice)
|
321
|
-
|
322
|
-
# Sort by confidence
|
323
|
-
practices.sort(key=lambda x: x.confidence, reverse=True)
|
324
|
-
|
325
|
-
return practices
|
326
|
-
|
327
|
-
def get_performance_benchmarks(
|
328
|
-
self,
|
329
|
-
model_name: Optional[str] = None,
|
330
|
-
task_type: Optional[str] = None
|
331
|
-
) -> List[PerformanceBenchmark]:
|
332
|
-
"""Get performance benchmarks."""
|
333
|
-
benchmarks = []
|
334
|
-
|
335
|
-
for benchmark in self.benchmarks:
|
336
|
-
if model_name and benchmark.model_name != model_name:
|
337
|
-
continue
|
338
|
-
if task_type and benchmark.task_type != task_type:
|
339
|
-
continue
|
340
|
-
benchmarks.append(benchmark)
|
341
|
-
|
342
|
-
return benchmarks
|
343
|
-
|
344
|
-
def get_dataset_info(self, dataset_name: str) -> Optional[Dict[str, Any]]:
|
345
|
-
"""Get information about a dataset."""
|
346
|
-
return self.dataset_info.get(dataset_name)
|
347
|
-
|
348
|
-
def add_model(self, model_spec: ModelSpec) -> None:
|
349
|
-
"""Add a new model to the knowledge base."""
|
350
|
-
self.models[model_spec.name] = model_spec
|
351
|
-
self._save_models()
|
352
|
-
logger.info(f"Added model to knowledge base: {model_spec.name}")
|
353
|
-
|
354
|
-
def add_best_practice(self, practice: BestPractice) -> None:
|
355
|
-
"""Add a best practice to the knowledge base."""
|
356
|
-
self.best_practices.append(practice)
|
357
|
-
self._save_best_practices()
|
358
|
-
logger.info(f"Added best practice: {practice.task_type}/{practice.domain}")
|
359
|
-
|
360
|
-
def add_benchmark(self, benchmark: PerformanceBenchmark) -> None:
|
361
|
-
"""Add a performance benchmark."""
|
362
|
-
self.benchmarks.append(benchmark)
|
363
|
-
self._save_benchmarks()
|
364
|
-
logger.info(f"Added benchmark: {benchmark.model_name}/{benchmark.task_type}")
|
365
|
-
|
366
|
-
def update_from_training_result(self, training_result: Dict[str, Any]) -> None:
|
367
|
-
"""Update knowledge base from training results."""
|
368
|
-
# Extract information from training result
|
369
|
-
model_name = training_result.get("model_name")
|
370
|
-
task_type = training_result.get("task_type")
|
371
|
-
|
372
|
-
if model_name and task_type:
|
373
|
-
# Create benchmark from result
|
374
|
-
benchmark = PerformanceBenchmark(
|
375
|
-
model_name=model_name,
|
376
|
-
task_type=task_type,
|
377
|
-
dataset_name=training_result.get("dataset_name", "unknown"),
|
378
|
-
training_time=training_result.get("training_time"),
|
379
|
-
training_cost=training_result.get("training_cost"),
|
380
|
-
gpu_type=training_result.get("gpu_type"),
|
381
|
-
config=training_result.get("config", {}),
|
382
|
-
source="training_result"
|
383
|
-
)
|
384
|
-
|
385
|
-
self.add_benchmark(benchmark)
|
386
|
-
|
387
|
-
def _initialize_default_knowledge(self) -> None:
|
388
|
-
"""Initialize knowledge base with default models and best practices."""
|
389
|
-
# Add popular LLM models
|
390
|
-
self._add_llm_models()
|
391
|
-
|
392
|
-
# Add Stable Diffusion models
|
393
|
-
self._add_sd_models()
|
394
|
-
|
395
|
-
# Add ML models
|
396
|
-
self._add_ml_models()
|
397
|
-
|
398
|
-
# Add best practices
|
399
|
-
self._add_default_best_practices()
|
400
|
-
|
401
|
-
# Add dataset information
|
402
|
-
self._add_default_dataset_info()
|
403
|
-
|
404
|
-
# Save to disk
|
405
|
-
self._save_knowledge_base()
|
406
|
-
|
407
|
-
logger.info("Initialized knowledge base with default data")
|
408
|
-
|
409
|
-
def _add_llm_models(self) -> None:
|
410
|
-
"""Add LLM models to knowledge base."""
|
411
|
-
llm_models = [
|
412
|
-
ModelSpec(
|
413
|
-
name="google/gemma-2-2b-it",
|
414
|
-
model_type="llm",
|
415
|
-
parameters=2_000_000_000,
|
416
|
-
supported_tasks=["chat", "classification", "generation", "summarization"],
|
417
|
-
supported_domains=["general", "technical", "education"],
|
418
|
-
context_length=2048,
|
419
|
-
quality_score=0.7,
|
420
|
-
speed_score=0.9,
|
421
|
-
efficiency_score=0.8,
|
422
|
-
optimal_dataset_size=5000,
|
423
|
-
min_dataset_size=100,
|
424
|
-
min_gpu_memory=8,
|
425
|
-
recommended_gpu_memory=12,
|
426
|
-
training_time_factor=0.6,
|
427
|
-
estimated_cost_per_hour=0.5,
|
428
|
-
is_popular=True,
|
429
|
-
is_open_source=True,
|
430
|
-
description="Lightweight Gemma model optimized for efficiency",
|
431
|
-
default_config={"learning_rate": 2e-5, "batch_size": 4, "lora_rank": 8}
|
432
|
-
),
|
433
|
-
ModelSpec(
|
434
|
-
name="google/gemma-2-4b-it",
|
435
|
-
model_type="llm",
|
436
|
-
parameters=4_000_000_000,
|
437
|
-
supported_tasks=["chat", "classification", "generation", "summarization", "reasoning"],
|
438
|
-
supported_domains=["general", "technical", "education", "medical"],
|
439
|
-
context_length=2048,
|
440
|
-
quality_score=0.8,
|
441
|
-
speed_score=0.7,
|
442
|
-
efficiency_score=0.8,
|
443
|
-
optimal_dataset_size=10000,
|
444
|
-
min_dataset_size=200,
|
445
|
-
min_gpu_memory=12,
|
446
|
-
recommended_gpu_memory=16,
|
447
|
-
training_time_factor=0.8,
|
448
|
-
estimated_cost_per_hour=0.8,
|
449
|
-
is_popular=True,
|
450
|
-
is_open_source=True,
|
451
|
-
description="Balanced Gemma model with good performance and efficiency",
|
452
|
-
default_config={"learning_rate": 2e-5, "batch_size": 2, "lora_rank": 16}
|
453
|
-
),
|
454
|
-
ModelSpec(
|
455
|
-
name="google/gemma-2-7b-it",
|
456
|
-
model_type="llm",
|
457
|
-
parameters=7_000_000_000,
|
458
|
-
supported_tasks=["chat", "classification", "generation", "summarization", "reasoning", "code"],
|
459
|
-
supported_domains=["general", "technical", "education", "medical", "legal"],
|
460
|
-
context_length=4096,
|
461
|
-
quality_score=0.9,
|
462
|
-
speed_score=0.6,
|
463
|
-
efficiency_score=0.7,
|
464
|
-
optimal_dataset_size=20000,
|
465
|
-
min_dataset_size=500,
|
466
|
-
min_gpu_memory=16,
|
467
|
-
recommended_gpu_memory=24,
|
468
|
-
training_time_factor=1.0,
|
469
|
-
estimated_cost_per_hour=1.2,
|
470
|
-
is_popular=True,
|
471
|
-
is_open_source=True,
|
472
|
-
description="High-quality Gemma model for demanding tasks",
|
473
|
-
default_config={"learning_rate": 1e-5, "batch_size": 1, "lora_rank": 32}
|
474
|
-
),
|
475
|
-
ModelSpec(
|
476
|
-
name="microsoft/DialoGPT-medium",
|
477
|
-
model_type="llm",
|
478
|
-
parameters=345_000_000,
|
479
|
-
supported_tasks=["chat", "generation"],
|
480
|
-
supported_domains=["general", "customer_service"],
|
481
|
-
context_length=1024,
|
482
|
-
quality_score=0.6,
|
483
|
-
speed_score=0.95,
|
484
|
-
efficiency_score=0.9,
|
485
|
-
optimal_dataset_size=2000,
|
486
|
-
min_dataset_size=50,
|
487
|
-
min_gpu_memory=4,
|
488
|
-
recommended_gpu_memory=8,
|
489
|
-
training_time_factor=0.3,
|
490
|
-
estimated_cost_per_hour=0.3,
|
491
|
-
is_popular=True,
|
492
|
-
is_open_source=True,
|
493
|
-
description="Fast conversational model for chatbots",
|
494
|
-
default_config={"learning_rate": 5e-5, "batch_size": 8, "lora_rank": 4}
|
495
|
-
),
|
496
|
-
ModelSpec(
|
497
|
-
name="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
498
|
-
model_type="llm",
|
499
|
-
parameters=1_100_000_000,
|
500
|
-
supported_tasks=["chat", "generation"],
|
501
|
-
supported_domains=["general", "education"],
|
502
|
-
context_length=2048,
|
503
|
-
quality_score=0.5,
|
504
|
-
speed_score=0.95,
|
505
|
-
efficiency_score=0.9,
|
506
|
-
optimal_dataset_size=1000,
|
507
|
-
min_dataset_size=50,
|
508
|
-
min_gpu_memory=4,
|
509
|
-
recommended_gpu_memory=6,
|
510
|
-
training_time_factor=0.4,
|
511
|
-
estimated_cost_per_hour=0.2,
|
512
|
-
is_popular=True,
|
513
|
-
is_open_source=True,
|
514
|
-
description="Extremely lightweight model for resource-constrained environments",
|
515
|
-
default_config={"learning_rate": 3e-5, "batch_size": 8, "lora_rank": 8}
|
516
|
-
)
|
517
|
-
]
|
518
|
-
|
519
|
-
for model in llm_models:
|
520
|
-
self.models[model.name] = model
|
521
|
-
|
522
|
-
def _add_sd_models(self) -> None:
|
523
|
-
"""Add Stable Diffusion models."""
|
524
|
-
sd_models = [
|
525
|
-
ModelSpec(
|
526
|
-
name="runwayml/stable-diffusion-v1-5",
|
527
|
-
model_type="sd",
|
528
|
-
parameters=860_000_000,
|
529
|
-
supported_tasks=["image_generation", "image_editing"],
|
530
|
-
supported_domains=["art", "design", "general"],
|
531
|
-
context_length=77,
|
532
|
-
quality_score=0.8,
|
533
|
-
speed_score=0.6,
|
534
|
-
efficiency_score=0.7,
|
535
|
-
optimal_dataset_size=1000,
|
536
|
-
min_dataset_size=20,
|
537
|
-
min_gpu_memory=8,
|
538
|
-
recommended_gpu_memory=12,
|
539
|
-
training_time_factor=1.2,
|
540
|
-
estimated_cost_per_hour=1.0,
|
541
|
-
is_popular=True,
|
542
|
-
is_open_source=True,
|
543
|
-
description="Popular Stable Diffusion model for image generation",
|
544
|
-
default_config={"learning_rate": 1e-6, "batch_size": 1}
|
545
|
-
)
|
546
|
-
]
|
547
|
-
|
548
|
-
for model in sd_models:
|
549
|
-
self.models[model.name] = model
|
550
|
-
|
551
|
-
def _add_ml_models(self) -> None:
|
552
|
-
"""Add traditional ML models."""
|
553
|
-
ml_models = [
|
554
|
-
ModelSpec(
|
555
|
-
name="xgboost_classifier",
|
556
|
-
model_type="ml",
|
557
|
-
parameters=1000, # Approximate
|
558
|
-
supported_tasks=["classification", "regression"],
|
559
|
-
supported_domains=["general", "financial", "medical"],
|
560
|
-
context_length=0,
|
561
|
-
quality_score=0.8,
|
562
|
-
speed_score=0.9,
|
563
|
-
efficiency_score=0.95,
|
564
|
-
optimal_dataset_size=10000,
|
565
|
-
min_dataset_size=100,
|
566
|
-
min_gpu_memory=2,
|
567
|
-
recommended_gpu_memory=4,
|
568
|
-
training_time_factor=0.1,
|
569
|
-
estimated_cost_per_hour=0.1,
|
570
|
-
is_popular=True,
|
571
|
-
is_open_source=True,
|
572
|
-
description="Gradient boosting classifier for tabular data",
|
573
|
-
default_config={"n_estimators": 100, "learning_rate": 0.1}
|
574
|
-
),
|
575
|
-
ModelSpec(
|
576
|
-
name="random_forest_classifier",
|
577
|
-
model_type="ml",
|
578
|
-
parameters=1000,
|
579
|
-
supported_tasks=["classification", "regression"],
|
580
|
-
supported_domains=["general", "financial", "medical"],
|
581
|
-
context_length=0,
|
582
|
-
quality_score=0.7,
|
583
|
-
speed_score=0.8,
|
584
|
-
efficiency_score=0.9,
|
585
|
-
optimal_dataset_size=5000,
|
586
|
-
min_dataset_size=100,
|
587
|
-
min_gpu_memory=2,
|
588
|
-
recommended_gpu_memory=4,
|
589
|
-
training_time_factor=0.2,
|
590
|
-
estimated_cost_per_hour=0.05,
|
591
|
-
is_popular=True,
|
592
|
-
is_open_source=True,
|
593
|
-
description="Random forest classifier for tabular data",
|
594
|
-
default_config={"n_estimators": 100, "max_depth": 10}
|
595
|
-
)
|
596
|
-
]
|
597
|
-
|
598
|
-
for model in ml_models:
|
599
|
-
self.models[model.name] = model
|
600
|
-
|
601
|
-
def _add_default_best_practices(self) -> None:
|
602
|
-
"""Add default best practices."""
|
603
|
-
practices = [
|
604
|
-
BestPractice(
|
605
|
-
task_type="chat",
|
606
|
-
domain="general",
|
607
|
-
recommendation="Use LoRA with rank 8-16 for chat models",
|
608
|
-
reason="LoRA provides good performance while reducing training time and memory usage",
|
609
|
-
confidence=0.9
|
610
|
-
),
|
611
|
-
BestPractice(
|
612
|
-
task_type="chat",
|
613
|
-
domain="medical",
|
614
|
-
recommendation="Use higher learning rates (3e-5) for medical domain adaptation",
|
615
|
-
reason="Medical terminology requires stronger adaptation from general models",
|
616
|
-
confidence=0.8
|
617
|
-
),
|
618
|
-
BestPractice(
|
619
|
-
task_type="classification",
|
620
|
-
domain="general",
|
621
|
-
recommendation="Use batch size 8-16 for classification tasks",
|
622
|
-
reason="Larger batch sizes improve stability for classification training",
|
623
|
-
confidence=0.85
|
624
|
-
),
|
625
|
-
BestPractice(
|
626
|
-
task_type="generation",
|
627
|
-
domain="general",
|
628
|
-
recommendation="Use gradient accumulation for large models",
|
629
|
-
reason="Maintains effective batch size while reducing memory usage",
|
630
|
-
confidence=0.9
|
631
|
-
)
|
632
|
-
]
|
633
|
-
|
634
|
-
self.best_practices.extend(practices)
|
635
|
-
|
636
|
-
def _add_default_dataset_info(self) -> None:
|
637
|
-
"""Add default dataset information."""
|
638
|
-
self.dataset_info = {
|
639
|
-
"tatsu-lab/alpaca": {
|
640
|
-
"size": 52000,
|
641
|
-
"format": "alpaca",
|
642
|
-
"language": "english",
|
643
|
-
"domain": "general",
|
644
|
-
"quality": "high"
|
645
|
-
},
|
646
|
-
"Open-Orca/OpenOrca": {
|
647
|
-
"size": 4200000,
|
648
|
-
"format": "sharegpt",
|
649
|
-
"language": "english",
|
650
|
-
"domain": "general",
|
651
|
-
"quality": "high"
|
652
|
-
},
|
653
|
-
"microsoft/DialoGPT-medium": {
|
654
|
-
"size": 147000000,
|
655
|
-
"format": "conversational",
|
656
|
-
"language": "english",
|
657
|
-
"domain": "general",
|
658
|
-
"quality": "medium"
|
659
|
-
}
|
660
|
-
}
|
661
|
-
|
662
|
-
def _load_knowledge_base(self) -> None:
|
663
|
-
"""Load knowledge base from disk."""
|
664
|
-
try:
|
665
|
-
self._load_models()
|
666
|
-
self._load_best_practices()
|
667
|
-
self._load_benchmarks()
|
668
|
-
self._load_dataset_info()
|
669
|
-
except Exception as e:
|
670
|
-
logger.warning(f"Failed to load knowledge base: {e}")
|
671
|
-
|
672
|
-
def _save_knowledge_base(self) -> None:
|
673
|
-
"""Save knowledge base to disk."""
|
674
|
-
try:
|
675
|
-
self._save_models()
|
676
|
-
self._save_best_practices()
|
677
|
-
self._save_benchmarks()
|
678
|
-
self._save_dataset_info()
|
679
|
-
except Exception as e:
|
680
|
-
logger.error(f"Failed to save knowledge base: {e}")
|
681
|
-
|
682
|
-
def _load_models(self) -> None:
|
683
|
-
"""Load models from disk."""
|
684
|
-
models_file = os.path.join(self.data_dir, "models.json")
|
685
|
-
if os.path.exists(models_file):
|
686
|
-
with open(models_file, 'r') as f:
|
687
|
-
data = json.load(f)
|
688
|
-
for name, model_data in data.items():
|
689
|
-
self.models[name] = ModelSpec(**model_data)
|
690
|
-
|
691
|
-
def _save_models(self) -> None:
|
692
|
-
"""Save models to disk."""
|
693
|
-
models_file = os.path.join(self.data_dir, "models.json")
|
694
|
-
with open(models_file, 'w') as f:
|
695
|
-
data = {name: asdict(model) for name, model in self.models.items()}
|
696
|
-
json.dump(data, f, indent=2, default=str)
|
697
|
-
|
698
|
-
def _load_best_practices(self) -> None:
|
699
|
-
"""Load best practices from disk."""
|
700
|
-
practices_file = os.path.join(self.data_dir, "best_practices.json")
|
701
|
-
if os.path.exists(practices_file):
|
702
|
-
with open(practices_file, 'r') as f:
|
703
|
-
data = json.load(f)
|
704
|
-
self.best_practices = [BestPractice(**item) for item in data]
|
705
|
-
|
706
|
-
def _save_best_practices(self) -> None:
|
707
|
-
"""Save best practices to disk."""
|
708
|
-
practices_file = os.path.join(self.data_dir, "best_practices.json")
|
709
|
-
with open(practices_file, 'w') as f:
|
710
|
-
data = [asdict(practice) for practice in self.best_practices]
|
711
|
-
json.dump(data, f, indent=2, default=str)
|
712
|
-
|
713
|
-
def _load_benchmarks(self) -> None:
|
714
|
-
"""Load benchmarks from disk."""
|
715
|
-
benchmarks_file = os.path.join(self.data_dir, "benchmarks.json")
|
716
|
-
if os.path.exists(benchmarks_file):
|
717
|
-
with open(benchmarks_file, 'r') as f:
|
718
|
-
data = json.load(f)
|
719
|
-
self.benchmarks = [PerformanceBenchmark(**item) for item in data]
|
720
|
-
|
721
|
-
def _save_benchmarks(self) -> None:
|
722
|
-
"""Save benchmarks to disk."""
|
723
|
-
benchmarks_file = os.path.join(self.data_dir, "benchmarks.json")
|
724
|
-
with open(benchmarks_file, 'w') as f:
|
725
|
-
data = [asdict(benchmark) for benchmark in self.benchmarks]
|
726
|
-
json.dump(data, f, indent=2, default=str)
|
727
|
-
|
728
|
-
def _load_dataset_info(self) -> None:
|
729
|
-
"""Load dataset info from disk."""
|
730
|
-
dataset_file = os.path.join(self.data_dir, "datasets.json")
|
731
|
-
if os.path.exists(dataset_file):
|
732
|
-
with open(dataset_file, 'r') as f:
|
733
|
-
self.dataset_info = json.load(f)
|
734
|
-
|
735
|
-
def _save_dataset_info(self) -> None:
|
736
|
-
"""Save dataset info to disk."""
|
737
|
-
dataset_file = os.path.join(self.data_dir, "datasets.json")
|
738
|
-
with open(dataset_file, 'w') as f:
|
739
|
-
json.dump(self.dataset_info, f, indent=2)
|
740
|
-
|
741
|
-
def get_statistics(self) -> Dict[str, Any]:
|
742
|
-
"""Get knowledge base statistics."""
|
743
|
-
return {
|
744
|
-
"total_models": len(self.models),
|
745
|
-
"llm_models": len([m for m in self.models.values() if m.model_type == "llm"]),
|
746
|
-
"sd_models": len([m for m in self.models.values() if m.model_type == "sd"]),
|
747
|
-
"ml_models": len([m for m in self.models.values() if m.model_type == "ml"]),
|
748
|
-
"best_practices": len(self.best_practices),
|
749
|
-
"benchmarks": len(self.benchmarks),
|
750
|
-
"datasets": len(self.dataset_info)
|
751
|
-
}
|