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
isa_model/training/core/utils.py
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Training Utilities
|
3
|
-
|
4
|
-
Helper functions and utilities for training operations.
|
5
|
-
"""
|
6
|
-
|
7
|
-
import os
|
8
|
-
import json
|
9
|
-
import logging
|
10
|
-
import datetime
|
11
|
-
from typing import Dict, Any, Optional, List
|
12
|
-
from pathlib import Path
|
13
|
-
|
14
|
-
logger = logging.getLogger(__name__)
|
15
|
-
|
16
|
-
|
17
|
-
class TrainingUtils:
|
18
|
-
"""Utility functions for training operations."""
|
19
|
-
|
20
|
-
@staticmethod
|
21
|
-
def generate_output_dir(model_name: str, training_type: str, base_dir: str = "training_outputs") -> str:
|
22
|
-
"""Generate a timestamped output directory."""
|
23
|
-
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
24
|
-
safe_model_name = model_name.replace("/", "_").replace(":", "_")
|
25
|
-
output_dir = os.path.join(base_dir, f"{safe_model_name}_{training_type}_{timestamp}")
|
26
|
-
return output_dir
|
27
|
-
|
28
|
-
@staticmethod
|
29
|
-
def save_training_args(args: Dict[str, Any], output_dir: str) -> None:
|
30
|
-
"""Save training arguments to file."""
|
31
|
-
args_path = Path(output_dir) / "training_args.json"
|
32
|
-
args_path.parent.mkdir(parents=True, exist_ok=True)
|
33
|
-
|
34
|
-
with open(args_path, 'w') as f:
|
35
|
-
json.dump(args, f, indent=2, default=str)
|
36
|
-
|
37
|
-
logger.info(f"Training arguments saved to: {args_path}")
|
38
|
-
|
39
|
-
@staticmethod
|
40
|
-
def load_training_args(output_dir: str) -> Dict[str, Any]:
|
41
|
-
"""Load training arguments from file."""
|
42
|
-
args_path = Path(output_dir) / "training_args.json"
|
43
|
-
|
44
|
-
if not args_path.exists():
|
45
|
-
raise FileNotFoundError(f"Training args not found: {args_path}")
|
46
|
-
|
47
|
-
with open(args_path, 'r') as f:
|
48
|
-
args = json.load(f)
|
49
|
-
|
50
|
-
return args
|
51
|
-
|
52
|
-
@staticmethod
|
53
|
-
def get_model_info(model_name: str) -> Dict[str, Any]:
|
54
|
-
"""Get information about a model."""
|
55
|
-
try:
|
56
|
-
from transformers import AutoConfig
|
57
|
-
|
58
|
-
config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
|
59
|
-
|
60
|
-
model_info = {
|
61
|
-
"model_name": model_name,
|
62
|
-
"model_type": config.model_type,
|
63
|
-
"vocab_size": getattr(config, 'vocab_size', None),
|
64
|
-
"hidden_size": getattr(config, 'hidden_size', None),
|
65
|
-
"num_layers": getattr(config, 'num_hidden_layers', None),
|
66
|
-
"num_attention_heads": getattr(config, 'num_attention_heads', None),
|
67
|
-
"max_position_embeddings": getattr(config, 'max_position_embeddings', None),
|
68
|
-
}
|
69
|
-
|
70
|
-
return model_info
|
71
|
-
|
72
|
-
except Exception as e:
|
73
|
-
logger.warning(f"Could not get model info for {model_name}: {e}")
|
74
|
-
return {"model_name": model_name, "error": str(e)}
|
75
|
-
|
76
|
-
@staticmethod
|
77
|
-
def estimate_memory_usage(
|
78
|
-
model_name: str,
|
79
|
-
batch_size: int = 1,
|
80
|
-
max_length: int = 1024,
|
81
|
-
use_lora: bool = True
|
82
|
-
) -> Dict[str, Any]:
|
83
|
-
"""Estimate memory usage for training."""
|
84
|
-
try:
|
85
|
-
model_info = TrainingUtils.get_model_info(model_name)
|
86
|
-
|
87
|
-
# Rough estimation based on model parameters
|
88
|
-
hidden_size = model_info.get('hidden_size', 4096)
|
89
|
-
num_layers = model_info.get('num_layers', 32)
|
90
|
-
vocab_size = model_info.get('vocab_size', 32000)
|
91
|
-
|
92
|
-
# Estimate model parameters (in millions)
|
93
|
-
param_count = (hidden_size * hidden_size * 12 * num_layers + vocab_size * hidden_size) / 1e6
|
94
|
-
|
95
|
-
# Base memory for model (assuming fp16)
|
96
|
-
model_memory_gb = param_count * 2 / 1024 # 2 bytes per parameter
|
97
|
-
|
98
|
-
# Training memory overhead (gradients, optimizer states, activations)
|
99
|
-
if use_lora:
|
100
|
-
training_overhead = 2.0 # LoRA reduces memory usage significantly
|
101
|
-
else:
|
102
|
-
training_overhead = 4.0 # Full fine-tuning needs more memory
|
103
|
-
|
104
|
-
# Batch and sequence length impact
|
105
|
-
sequence_memory = batch_size * max_length * hidden_size * 2 / (1024**3) # Activation memory
|
106
|
-
|
107
|
-
total_memory_gb = model_memory_gb * training_overhead + sequence_memory
|
108
|
-
|
109
|
-
return {
|
110
|
-
"estimated_params_millions": param_count,
|
111
|
-
"model_memory_gb": model_memory_gb,
|
112
|
-
"total_training_memory_gb": total_memory_gb,
|
113
|
-
"recommended_gpu": TrainingUtils._recommend_gpu(total_memory_gb),
|
114
|
-
"use_lora": use_lora,
|
115
|
-
"batch_size": batch_size,
|
116
|
-
"max_length": max_length
|
117
|
-
}
|
118
|
-
|
119
|
-
except Exception as e:
|
120
|
-
logger.warning(f"Could not estimate memory usage: {e}")
|
121
|
-
return {"error": str(e)}
|
122
|
-
|
123
|
-
@staticmethod
|
124
|
-
def _recommend_gpu(memory_gb: float) -> str:
|
125
|
-
"""Recommend GPU based on memory requirements."""
|
126
|
-
if memory_gb <= 8:
|
127
|
-
return "RTX 3080/4070 (8-12GB)"
|
128
|
-
elif memory_gb <= 16:
|
129
|
-
return "RTX 4080/4090 (16GB)"
|
130
|
-
elif memory_gb <= 24:
|
131
|
-
return "RTX A6000/4090 (24GB)"
|
132
|
-
elif memory_gb <= 40:
|
133
|
-
return "A100 40GB"
|
134
|
-
elif memory_gb <= 80:
|
135
|
-
return "A100 80GB"
|
136
|
-
else:
|
137
|
-
return "Multiple A100 80GB (Multi-GPU required)"
|
138
|
-
|
139
|
-
@staticmethod
|
140
|
-
def validate_training_config(config: Dict[str, Any]) -> List[str]:
|
141
|
-
"""Validate training configuration and return any issues."""
|
142
|
-
issues = []
|
143
|
-
|
144
|
-
# Check required fields
|
145
|
-
required_fields = ["model_name", "output_dir"]
|
146
|
-
for field in required_fields:
|
147
|
-
if field not in config:
|
148
|
-
issues.append(f"Missing required field: {field}")
|
149
|
-
|
150
|
-
# Check batch size
|
151
|
-
if config.get("batch_size", 0) <= 0:
|
152
|
-
issues.append("batch_size must be positive")
|
153
|
-
|
154
|
-
# Check learning rate
|
155
|
-
lr = config.get("learning_rate", 0)
|
156
|
-
if lr <= 0 or lr > 1:
|
157
|
-
issues.append("learning_rate should be between 0 and 1")
|
158
|
-
|
159
|
-
# Check epochs
|
160
|
-
if config.get("num_epochs", 0) <= 0:
|
161
|
-
issues.append("num_epochs must be positive")
|
162
|
-
|
163
|
-
# Check LoRA config
|
164
|
-
if config.get("use_lora", False):
|
165
|
-
lora_rank = config.get("lora_rank", 8)
|
166
|
-
if lora_rank <= 0 or lora_rank > 256:
|
167
|
-
issues.append("lora_rank should be between 1 and 256")
|
168
|
-
|
169
|
-
return issues
|
170
|
-
|
171
|
-
@staticmethod
|
172
|
-
def format_training_summary(
|
173
|
-
config: Dict[str, Any],
|
174
|
-
model_info: Dict[str, Any],
|
175
|
-
memory_estimate: Dict[str, Any]
|
176
|
-
) -> str:
|
177
|
-
"""Format a training summary for display."""
|
178
|
-
summary = []
|
179
|
-
summary.append("=" * 60)
|
180
|
-
summary.append("TRAINING CONFIGURATION SUMMARY")
|
181
|
-
summary.append("=" * 60)
|
182
|
-
|
183
|
-
# Model information
|
184
|
-
summary.append(f"Model: {config.get('model_name', 'Unknown')}")
|
185
|
-
summary.append(f"Model Type: {model_info.get('model_type', 'Unknown')}")
|
186
|
-
summary.append(f"Parameters: ~{memory_estimate.get('estimated_params_millions', 0):.1f}M")
|
187
|
-
|
188
|
-
# Training configuration
|
189
|
-
summary.append(f"\nTraining Configuration:")
|
190
|
-
summary.append(f" Training Type: {config.get('training_type', 'sft')}")
|
191
|
-
summary.append(f" Epochs: {config.get('num_epochs', 3)}")
|
192
|
-
summary.append(f" Batch Size: {config.get('batch_size', 4)}")
|
193
|
-
summary.append(f" Learning Rate: {config.get('learning_rate', 2e-5)}")
|
194
|
-
summary.append(f" Max Length: {config.get('max_length', 1024)}")
|
195
|
-
|
196
|
-
# LoRA configuration
|
197
|
-
if config.get('use_lora', True):
|
198
|
-
summary.append(f"\nLoRA Configuration:")
|
199
|
-
summary.append(f" LoRA Rank: {config.get('lora_rank', 8)}")
|
200
|
-
summary.append(f" LoRA Alpha: {config.get('lora_alpha', 16)}")
|
201
|
-
summary.append(f" LoRA Dropout: {config.get('lora_dropout', 0.05)}")
|
202
|
-
|
203
|
-
# Memory estimation
|
204
|
-
summary.append(f"\nMemory Estimation:")
|
205
|
-
summary.append(f" Estimated Memory: ~{memory_estimate.get('total_training_memory_gb', 0):.1f}GB")
|
206
|
-
summary.append(f" Recommended GPU: {memory_estimate.get('recommended_gpu', 'Unknown')}")
|
207
|
-
|
208
|
-
# Output
|
209
|
-
summary.append(f"\nOutput Directory: {config.get('output_dir', 'Unknown')}")
|
210
|
-
|
211
|
-
summary.append("=" * 60)
|
212
|
-
|
213
|
-
return "\n".join(summary)
|
@@ -1,281 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
"""
|
3
|
-
Intelligent Training System Example
|
4
|
-
|
5
|
-
This script demonstrates the capabilities of the intelligent training system:
|
6
|
-
- Natural language training request analysis
|
7
|
-
- Automatic model and resource selection
|
8
|
-
- Cost and performance optimization
|
9
|
-
- Training option comparison
|
10
|
-
- Best practices recommendations
|
11
|
-
|
12
|
-
Run this script to see the intelligent training system in action.
|
13
|
-
"""
|
14
|
-
|
15
|
-
import os
|
16
|
-
import sys
|
17
|
-
import json
|
18
|
-
from pathlib import Path
|
19
|
-
|
20
|
-
# Add the parent directory to path for imports
|
21
|
-
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent))
|
22
|
-
|
23
|
-
def main():
|
24
|
-
"""Demonstrate intelligent training capabilities."""
|
25
|
-
|
26
|
-
print("🧠 Intelligent Training System Demo")
|
27
|
-
print("=" * 50)
|
28
|
-
|
29
|
-
try:
|
30
|
-
# Import intelligent training components
|
31
|
-
from isa_model.training import (
|
32
|
-
IntelligentTrainingFactory,
|
33
|
-
INTELLIGENT_AVAILABLE
|
34
|
-
)
|
35
|
-
|
36
|
-
if not INTELLIGENT_AVAILABLE:
|
37
|
-
print("❌ Intelligent training features not available")
|
38
|
-
return
|
39
|
-
|
40
|
-
print("✅ Intelligent training system loaded successfully\n")
|
41
|
-
|
42
|
-
# Initialize intelligent factory
|
43
|
-
print("🔧 Initializing intelligent training factory...")
|
44
|
-
factory = IntelligentTrainingFactory()
|
45
|
-
|
46
|
-
# Example 1: Natural Language Training Request
|
47
|
-
print("\n" + "="*50)
|
48
|
-
print("📝 EXAMPLE 1: Natural Language Analysis")
|
49
|
-
print("="*50)
|
50
|
-
|
51
|
-
description = "Train a customer service chatbot for a medical company that can answer patient questions about symptoms and treatments in Chinese"
|
52
|
-
dataset_path = "medical_qa_chinese.json" # Hypothetical dataset
|
53
|
-
|
54
|
-
print(f"Request: {description}")
|
55
|
-
print(f"Dataset: {dataset_path}")
|
56
|
-
|
57
|
-
try:
|
58
|
-
recommendation = factory.analyze_training_request(
|
59
|
-
description=description,
|
60
|
-
dataset_source=dataset_path,
|
61
|
-
quality_target="high",
|
62
|
-
budget_limit=300.0,
|
63
|
-
time_limit=12
|
64
|
-
)
|
65
|
-
|
66
|
-
print(f"\n✅ Analysis completed successfully!")
|
67
|
-
print(f"📱 Recommended Model: {recommendation.model_name}")
|
68
|
-
print(f"🖥️ Recommended GPU: {recommendation.recommended_gpu}")
|
69
|
-
print(f"💰 Estimated Cost: ${recommendation.estimated_cost:.2f}")
|
70
|
-
print(f"⏱️ Estimated Time: {recommendation.estimated_time:.1f} hours")
|
71
|
-
|
72
|
-
except Exception as e:
|
73
|
-
print(f"❌ Analysis failed: {e}")
|
74
|
-
|
75
|
-
# Example 2: Training Options Comparison
|
76
|
-
print("\n" + "="*50)
|
77
|
-
print("📊 EXAMPLE 2: Training Options Comparison")
|
78
|
-
print("="*50)
|
79
|
-
|
80
|
-
description2 = "Fine-tune a code generation model for Python development"
|
81
|
-
dataset_path2 = "python_code_dataset.json"
|
82
|
-
|
83
|
-
print(f"Request: {description2}")
|
84
|
-
print(f"Comparing quality targets: fast, balanced, high")
|
85
|
-
|
86
|
-
try:
|
87
|
-
comparisons = factory.compare_training_options(
|
88
|
-
description=description2,
|
89
|
-
dataset_source=dataset_path2,
|
90
|
-
quality_targets=["fast", "balanced", "high"],
|
91
|
-
budget_limits=[50.0, 150.0, 300.0]
|
92
|
-
)
|
93
|
-
|
94
|
-
print(f"✅ Generated {len(comparisons)} training options for comparison")
|
95
|
-
|
96
|
-
except Exception as e:
|
97
|
-
print(f"❌ Comparison failed: {e}")
|
98
|
-
|
99
|
-
# Example 3: Best Practices
|
100
|
-
print("\n" + "="*50)
|
101
|
-
print("💡 EXAMPLE 3: Best Practices")
|
102
|
-
print("="*50)
|
103
|
-
|
104
|
-
task_types = ["chat", "classification", "generation"]
|
105
|
-
domains = ["medical", "legal", "general"]
|
106
|
-
|
107
|
-
for task_type in task_types:
|
108
|
-
for domain in domains:
|
109
|
-
try:
|
110
|
-
practices = factory.get_best_practices(task_type, domain)
|
111
|
-
if practices:
|
112
|
-
print(f"\n📋 {task_type.title()} + {domain.title()}:")
|
113
|
-
for practice in practices[:2]: # Show top 2
|
114
|
-
print(f" • {practice}")
|
115
|
-
except Exception as e:
|
116
|
-
continue
|
117
|
-
|
118
|
-
# Example 4: System Capabilities
|
119
|
-
print("\n" + "="*50)
|
120
|
-
print("🎯 EXAMPLE 4: System Capabilities")
|
121
|
-
print("="*50)
|
122
|
-
|
123
|
-
try:
|
124
|
-
capabilities = factory.get_supported_capabilities()
|
125
|
-
|
126
|
-
print(f"📱 Supported Models: {len(capabilities.get('task_types', []))} task types")
|
127
|
-
print(f"🌍 Supported Domains: {len(capabilities.get('domains', []))} domains")
|
128
|
-
print(f"🖥️ Available GPUs: {len(capabilities.get('gpu_types', []))} types")
|
129
|
-
print(f"☁️ Cloud Providers: {len(capabilities.get('cloud_providers', []))} providers")
|
130
|
-
|
131
|
-
print("\nTask Types:")
|
132
|
-
for task in capabilities.get('task_types', [])[:5]:
|
133
|
-
print(f" • {task}")
|
134
|
-
|
135
|
-
print("\nDomains:")
|
136
|
-
for domain in capabilities.get('domains', [])[:5]:
|
137
|
-
print(f" • {domain}")
|
138
|
-
|
139
|
-
print("\nGPU Types:")
|
140
|
-
for gpu in capabilities.get('gpu_types', [])[:5]:
|
141
|
-
print(f" • {gpu}")
|
142
|
-
|
143
|
-
except Exception as e:
|
144
|
-
print(f"❌ Failed to get capabilities: {e}")
|
145
|
-
|
146
|
-
# Example 5: Intelligence Statistics
|
147
|
-
print("\n" + "="*50)
|
148
|
-
print("📈 EXAMPLE 5: Intelligence Statistics")
|
149
|
-
print("="*50)
|
150
|
-
|
151
|
-
try:
|
152
|
-
stats = factory.get_intelligence_statistics()
|
153
|
-
|
154
|
-
if stats.get('intelligence_enabled'):
|
155
|
-
kb_stats = stats.get('knowledge_base', {})
|
156
|
-
print(f"📚 Knowledge Base:")
|
157
|
-
print(f" • Models: {kb_stats.get('total_models', 0)}")
|
158
|
-
print(f" • Best Practices: {kb_stats.get('best_practices', 0)}")
|
159
|
-
print(f" • Benchmarks: {kb_stats.get('benchmarks', 0)}")
|
160
|
-
|
161
|
-
resource_stats = stats.get('resource_optimizer', {})
|
162
|
-
print(f"🖥️ Resource Optimizer:")
|
163
|
-
print(f" • GPUs: {resource_stats.get('total_gpus', 0)}")
|
164
|
-
print(f" • Providers: {resource_stats.get('total_providers', 0)}")
|
165
|
-
print(f" • Avg Cost/Hour: ${resource_stats.get('avg_cost_per_hour', 0):.2f}")
|
166
|
-
|
167
|
-
except Exception as e:
|
168
|
-
print(f"❌ Failed to get statistics: {e}")
|
169
|
-
|
170
|
-
# Example 6: Recommendation Scenarios
|
171
|
-
print("\n" + "="*50)
|
172
|
-
print("🎭 EXAMPLE 6: Different Scenarios")
|
173
|
-
print("="*50)
|
174
|
-
|
175
|
-
scenarios = [
|
176
|
-
{
|
177
|
-
"name": "Budget-Conscious Student",
|
178
|
-
"description": "Create a simple English grammar checker",
|
179
|
-
"dataset": "grammar_corrections.json",
|
180
|
-
"budget": 25.0,
|
181
|
-
"time": 4,
|
182
|
-
"target": "fast"
|
183
|
-
},
|
184
|
-
{
|
185
|
-
"name": "Enterprise Company",
|
186
|
-
"description": "Advanced legal document analysis system",
|
187
|
-
"dataset": "legal_documents.json",
|
188
|
-
"budget": 1000.0,
|
189
|
-
"time": 24,
|
190
|
-
"target": "high"
|
191
|
-
},
|
192
|
-
{
|
193
|
-
"name": "Research Lab",
|
194
|
-
"description": "Multi-modal medical image description model",
|
195
|
-
"dataset": "medical_images_captions.json",
|
196
|
-
"budget": 500.0,
|
197
|
-
"time": 16,
|
198
|
-
"target": "balanced"
|
199
|
-
}
|
200
|
-
]
|
201
|
-
|
202
|
-
for scenario in scenarios:
|
203
|
-
print(f"\n👤 {scenario['name']}:")
|
204
|
-
print(f" Request: {scenario['description']}")
|
205
|
-
print(f" Budget: ${scenario['budget']}, Time: {scenario['time']}h, Target: {scenario['target']}")
|
206
|
-
|
207
|
-
try:
|
208
|
-
rec = factory.analyze_training_request(
|
209
|
-
description=scenario['description'],
|
210
|
-
dataset_source=scenario['dataset'],
|
211
|
-
quality_target=scenario['target'],
|
212
|
-
budget_limit=scenario['budget'],
|
213
|
-
time_limit=scenario['time']
|
214
|
-
)
|
215
|
-
|
216
|
-
print(f" → Model: {rec.model_name}")
|
217
|
-
print(f" → GPU: {rec.recommended_gpu}")
|
218
|
-
print(f" → Cost: ${rec.estimated_cost:.2f}")
|
219
|
-
print(f" → Confidence: {rec.confidence_score:.1%}")
|
220
|
-
|
221
|
-
except Exception as e:
|
222
|
-
print(f" ❌ Failed: {e}")
|
223
|
-
|
224
|
-
# Summary
|
225
|
-
print("\n" + "="*50)
|
226
|
-
print("✅ DEMO COMPLETED SUCCESSFULLY")
|
227
|
-
print("="*50)
|
228
|
-
print("The intelligent training system is ready to use!")
|
229
|
-
print("\nNext steps:")
|
230
|
-
print("1. Prepare your dataset in JSON format")
|
231
|
-
print("2. Use analyze_training_request() for recommendations")
|
232
|
-
print("3. Use train_with_recommendation() to start training")
|
233
|
-
print("4. Monitor progress and collect results")
|
234
|
-
|
235
|
-
except ImportError as e:
|
236
|
-
print(f"❌ Import error: {e}")
|
237
|
-
print("Make sure the isa_model package is properly installed")
|
238
|
-
except Exception as e:
|
239
|
-
print(f"❌ Demo failed: {e}")
|
240
|
-
import traceback
|
241
|
-
traceback.print_exc()
|
242
|
-
|
243
|
-
|
244
|
-
def create_sample_dataset():
|
245
|
-
"""Create a sample dataset for testing."""
|
246
|
-
sample_data = [
|
247
|
-
{
|
248
|
-
"instruction": "What are the symptoms of the common cold?",
|
249
|
-
"input": "",
|
250
|
-
"output": "Common cold symptoms include runny nose, sneezing, coughing, sore throat, mild headache, and fatigue."
|
251
|
-
},
|
252
|
-
{
|
253
|
-
"instruction": "How can I prevent getting sick?",
|
254
|
-
"input": "",
|
255
|
-
"output": "To prevent illness, wash your hands frequently, maintain a healthy diet, get adequate sleep, exercise regularly, and avoid close contact with sick people."
|
256
|
-
},
|
257
|
-
{
|
258
|
-
"instruction": "When should I see a doctor?",
|
259
|
-
"input": "I have a fever and cough for 3 days",
|
260
|
-
"output": "You should see a doctor if you have a persistent fever and cough for more than 3 days, especially if symptoms are worsening or you have difficulty breathing."
|
261
|
-
}
|
262
|
-
]
|
263
|
-
|
264
|
-
# Create sample dataset file
|
265
|
-
os.makedirs("sample_data", exist_ok=True)
|
266
|
-
with open("sample_data/medical_qa_sample.json", "w") as f:
|
267
|
-
json.dump(sample_data, f, indent=2)
|
268
|
-
|
269
|
-
print("📁 Created sample dataset: sample_data/medical_qa_sample.json")
|
270
|
-
|
271
|
-
|
272
|
-
if __name__ == "__main__":
|
273
|
-
print("🚀 Starting Intelligent Training System Demo\n")
|
274
|
-
|
275
|
-
# Create sample dataset
|
276
|
-
create_sample_dataset()
|
277
|
-
|
278
|
-
# Run main demo
|
279
|
-
main()
|
280
|
-
|
281
|
-
print("\n🎉 Demo finished! Thank you for trying the intelligent training system.")
|