isa-model 0.2.0__py3-none-any.whl → 0.2.9__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.
Files changed (77) hide show
  1. isa_model/__init__.py +1 -1
  2. isa_model/core/storage/hf_storage.py +419 -0
  3. isa_model/deployment/__init__.py +52 -0
  4. isa_model/deployment/core/__init__.py +34 -0
  5. isa_model/deployment/core/deployment_config.py +356 -0
  6. isa_model/deployment/core/deployment_manager.py +549 -0
  7. isa_model/deployment/core/isa_deployment_service.py +401 -0
  8. isa_model/eval/factory.py +381 -140
  9. isa_model/inference/ai_factory.py +142 -240
  10. isa_model/inference/providers/ml_provider.py +50 -0
  11. isa_model/inference/services/audio/openai_tts_service.py +104 -3
  12. isa_model/inference/services/embedding/base_embed_service.py +112 -0
  13. isa_model/inference/services/embedding/ollama_embed_service.py +28 -2
  14. isa_model/inference/services/llm/__init__.py +2 -0
  15. isa_model/inference/services/llm/base_llm_service.py +111 -1
  16. isa_model/inference/services/llm/ollama_llm_service.py +234 -26
  17. isa_model/inference/services/llm/openai_llm_service.py +243 -28
  18. isa_model/inference/services/llm/triton_llm_service.py +481 -0
  19. isa_model/inference/services/ml/base_ml_service.py +78 -0
  20. isa_model/inference/services/ml/sklearn_ml_service.py +140 -0
  21. isa_model/inference/services/vision/__init__.py +3 -3
  22. isa_model/inference/services/vision/base_image_gen_service.py +161 -0
  23. isa_model/inference/services/vision/base_vision_service.py +177 -0
  24. isa_model/inference/services/vision/ollama_vision_service.py +143 -17
  25. isa_model/inference/services/vision/replicate_image_gen_service.py +139 -7
  26. isa_model/training/__init__.py +62 -32
  27. isa_model/training/cloud/__init__.py +22 -0
  28. isa_model/training/cloud/job_orchestrator.py +402 -0
  29. isa_model/training/cloud/runpod_trainer.py +454 -0
  30. isa_model/training/cloud/storage_manager.py +482 -0
  31. isa_model/training/core/__init__.py +23 -0
  32. isa_model/training/core/config.py +181 -0
  33. isa_model/training/core/dataset.py +222 -0
  34. isa_model/training/core/trainer.py +720 -0
  35. isa_model/training/core/utils.py +213 -0
  36. isa_model/training/factory.py +229 -198
  37. isa_model-0.2.9.dist-info/METADATA +465 -0
  38. isa_model-0.2.9.dist-info/RECORD +86 -0
  39. isa_model/core/model_router.py +0 -226
  40. isa_model/core/model_version.py +0 -0
  41. isa_model/core/resource_manager.py +0 -202
  42. isa_model/deployment/gpu_fp16_ds8/models/deepseek_r1/1/model.py +0 -120
  43. isa_model/deployment/gpu_fp16_ds8/scripts/download_model.py +0 -18
  44. isa_model/training/engine/llama_factory/__init__.py +0 -39
  45. isa_model/training/engine/llama_factory/config.py +0 -115
  46. isa_model/training/engine/llama_factory/data_adapter.py +0 -284
  47. isa_model/training/engine/llama_factory/examples/__init__.py +0 -6
  48. isa_model/training/engine/llama_factory/examples/finetune_with_tracking.py +0 -185
  49. isa_model/training/engine/llama_factory/examples/rlhf_with_tracking.py +0 -163
  50. isa_model/training/engine/llama_factory/factory.py +0 -331
  51. isa_model/training/engine/llama_factory/rl.py +0 -254
  52. isa_model/training/engine/llama_factory/trainer.py +0 -171
  53. isa_model/training/image_model/configs/create_config.py +0 -37
  54. isa_model/training/image_model/configs/create_flux_config.py +0 -26
  55. isa_model/training/image_model/configs/create_lora_config.py +0 -21
  56. isa_model/training/image_model/prepare_massed_compute.py +0 -97
  57. isa_model/training/image_model/prepare_upload.py +0 -17
  58. isa_model/training/image_model/raw_data/create_captions.py +0 -16
  59. isa_model/training/image_model/raw_data/create_lora_captions.py +0 -20
  60. isa_model/training/image_model/raw_data/pre_processing.py +0 -200
  61. isa_model/training/image_model/train/train.py +0 -42
  62. isa_model/training/image_model/train/train_flux.py +0 -41
  63. isa_model/training/image_model/train/train_lora.py +0 -57
  64. isa_model/training/image_model/train_main.py +0 -25
  65. isa_model-0.2.0.dist-info/METADATA +0 -327
  66. isa_model-0.2.0.dist-info/RECORD +0 -92
  67. isa_model-0.2.0.dist-info/licenses/LICENSE +0 -21
  68. /isa_model/training/{llm_model/annotation → annotation}/annotation_schema.py +0 -0
  69. /isa_model/training/{llm_model/annotation → annotation}/processors/annotation_processor.py +0 -0
  70. /isa_model/training/{llm_model/annotation → annotation}/storage/dataset_manager.py +0 -0
  71. /isa_model/training/{llm_model/annotation → annotation}/storage/dataset_schema.py +0 -0
  72. /isa_model/training/{llm_model/annotation → annotation}/tests/test_annotation_flow.py +0 -0
  73. /isa_model/training/{llm_model/annotation → annotation}/tests/test_minio copy.py +0 -0
  74. /isa_model/training/{llm_model/annotation → annotation}/tests/test_minio_upload.py +0 -0
  75. /isa_model/training/{llm_model/annotation → annotation}/views/annotation_controller.py +0 -0
  76. {isa_model-0.2.0.dist-info → isa_model-0.2.9.dist-info}/WHEEL +0 -0
  77. {isa_model-0.2.0.dist-info → isa_model-0.2.9.dist-info}/top_level.txt +0 -0
isa_model/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  isA_Model - A simple interface for AI model integration
3
3
  """
4
4
 
5
- __version__ = "0.2.0"
5
+ __version__ = "0.0.1"
@@ -0,0 +1,419 @@
1
+ """
2
+ HuggingFace Hub Storage Implementation
3
+
4
+ Provides storage capabilities using HuggingFace Hub as the backend.
5
+ Supports uploading trained models, managing versions, and metadata.
6
+ """
7
+
8
+ import os
9
+ import json
10
+ import logging
11
+ from typing import Optional, Dict, Any, List
12
+ from pathlib import Path
13
+ import tempfile
14
+ import shutil
15
+ from datetime import datetime
16
+
17
+ try:
18
+ from huggingface_hub import HfApi, create_repo, upload_folder, snapshot_download
19
+ from huggingface_hub.errors import HfHubHTTPError
20
+ HF_HUB_AVAILABLE = True
21
+ except ImportError:
22
+ HF_HUB_AVAILABLE = False
23
+
24
+ from ..model_storage import ModelStorage
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ class HuggingFaceStorage(ModelStorage):
30
+ """
31
+ HuggingFace Hub storage implementation for model management.
32
+
33
+ This storage backend uploads models to HuggingFace Hub and manages
34
+ them using the repository system. Perfect for sharing trained models
35
+ and maintaining versions.
36
+
37
+ Example:
38
+ ```python
39
+ from isa_model.core.storage import HuggingFaceStorage
40
+
41
+ storage = HuggingFaceStorage(
42
+ username="xenobordom",
43
+ token="your_hf_token"
44
+ )
45
+
46
+ # Save a trained model to HuggingFace Hub
47
+ await storage.save_model(
48
+ model_id="gemma-4b-alpaca-v1",
49
+ model_path="./trained_models/gemma-4b",
50
+ metadata={
51
+ "base_model": "google/gemma-2-4b-it",
52
+ "dataset": "tatsu-lab/alpaca",
53
+ "training_method": "LoRA + Unsloth"
54
+ }
55
+ )
56
+ ```
57
+ """
58
+
59
+ def __init__(self,
60
+ username: str = "xenobordom",
61
+ token: Optional[str] = None,
62
+ private: bool = False,
63
+ local_cache_dir: str = "./models/hf_cache"):
64
+ """
65
+ Initialize HuggingFace storage.
66
+
67
+ Args:
68
+ username: HuggingFace username (default: xenobordom)
69
+ token: HuggingFace API token (from env if not provided)
70
+ private: Whether to create private repositories
71
+ local_cache_dir: Local cache directory for downloaded models
72
+ """
73
+ if not HF_HUB_AVAILABLE:
74
+ raise ImportError("huggingface_hub is required. Install with: pip install huggingface_hub")
75
+
76
+ self.username = username
77
+ self.token = token or os.getenv("HF_TOKEN")
78
+ self.private = private
79
+ self.local_cache_dir = Path(local_cache_dir)
80
+ self.local_cache_dir.mkdir(parents=True, exist_ok=True)
81
+
82
+ if not self.token:
83
+ raise ValueError("HuggingFace token is required. Set HF_TOKEN environment variable or pass token parameter.")
84
+
85
+ # Initialize HF API
86
+ self.api = HfApi(token=self.token)
87
+
88
+ # Local metadata storage
89
+ self.metadata_file = self.local_cache_dir / "hf_models_metadata.json"
90
+ self._load_metadata()
91
+
92
+ logger.info(f"HuggingFace storage initialized for user: {self.username}")
93
+ logger.info(f"Local cache directory: {self.local_cache_dir}")
94
+
95
+ def _load_metadata(self):
96
+ """Load local metadata cache"""
97
+ if self.metadata_file.exists():
98
+ with open(self.metadata_file, 'r') as f:
99
+ self.metadata = json.load(f)
100
+ else:
101
+ self.metadata = {}
102
+ self._save_metadata()
103
+
104
+ def _save_metadata(self):
105
+ """Save local metadata cache"""
106
+ with open(self.metadata_file, 'w') as f:
107
+ json.dump(self.metadata, f, indent=2)
108
+
109
+ def _get_repo_id(self, model_id: str) -> str:
110
+ """Get full repository ID for a model"""
111
+ return f"{self.username}/{model_id}"
112
+
113
+ async def save_model(self, model_id: str, model_path: str, metadata: Dict[str, Any]) -> bool:
114
+ """
115
+ Save model to HuggingFace Hub.
116
+
117
+ Args:
118
+ model_id: Unique identifier for the model (will be repo name)
119
+ model_path: Local path to model files
120
+ metadata: Model metadata to include
121
+
122
+ Returns:
123
+ True if successful, False otherwise
124
+ """
125
+ try:
126
+ repo_id = self._get_repo_id(model_id)
127
+ source_path = Path(model_path)
128
+
129
+ logger.info(f"Uploading model {model_id} to HuggingFace Hub: {repo_id}")
130
+
131
+ # Create repository if it doesn't exist
132
+ try:
133
+ create_repo(
134
+ repo_id=repo_id,
135
+ token=self.token,
136
+ private=self.private,
137
+ exist_ok=True
138
+ )
139
+ logger.info(f"Repository created/verified: {repo_id}")
140
+ except Exception as e:
141
+ logger.warning(f"Repository creation warning: {e}")
142
+
143
+ # Prepare metadata for README
144
+ readme_content = self._generate_model_card(model_id, metadata)
145
+
146
+ # Create temporary directory for upload preparation
147
+ with tempfile.TemporaryDirectory() as temp_dir:
148
+ temp_path = Path(temp_dir)
149
+
150
+ # Copy model files
151
+ if source_path.is_file():
152
+ shutil.copy2(source_path, temp_path / source_path.name)
153
+ else:
154
+ # Copy entire directory
155
+ for item in source_path.rglob("*"):
156
+ if item.is_file():
157
+ relative_path = item.relative_to(source_path)
158
+ dest_path = temp_path / relative_path
159
+ dest_path.parent.mkdir(parents=True, exist_ok=True)
160
+ shutil.copy2(item, dest_path)
161
+
162
+ # Add README.md
163
+ with open(temp_path / "README.md", 'w') as f:
164
+ f.write(readme_content)
165
+
166
+ # Add metadata.json
167
+ enhanced_metadata = {
168
+ **metadata,
169
+ "model_id": model_id,
170
+ "repo_id": repo_id,
171
+ "uploaded_at": datetime.now().isoformat(),
172
+ "uploaded_by": self.username,
173
+ "storage_backend": "huggingface_hub"
174
+ }
175
+
176
+ with open(temp_path / "metadata.json", 'w') as f:
177
+ json.dump(enhanced_metadata, f, indent=2)
178
+
179
+ # Upload to HuggingFace Hub
180
+ upload_folder(
181
+ folder_path=str(temp_path),
182
+ repo_id=repo_id,
183
+ token=self.token,
184
+ commit_message=f"Upload {model_id} - {metadata.get('description', 'Model upload')}"
185
+ )
186
+
187
+ # Update local metadata
188
+ self.metadata[model_id] = {
189
+ **enhanced_metadata,
190
+ "local_cache_path": str(self.local_cache_dir / model_id),
191
+ "repo_url": f"https://huggingface.co/{repo_id}"
192
+ }
193
+ self._save_metadata()
194
+
195
+ logger.info(f"Model {model_id} uploaded successfully to {repo_id}")
196
+ return True
197
+
198
+ except Exception as e:
199
+ logger.error(f"Failed to save model {model_id} to HuggingFace Hub: {e}")
200
+ return False
201
+
202
+ async def load_model(self, model_id: str) -> Optional[Path]:
203
+ """
204
+ Load model from HuggingFace Hub.
205
+
206
+ Args:
207
+ model_id: Model identifier
208
+
209
+ Returns:
210
+ Path to local model files
211
+ """
212
+ try:
213
+ repo_id = self._get_repo_id(model_id)
214
+ local_path = self.local_cache_dir / model_id
215
+
216
+ # Check if already cached
217
+ if local_path.exists() and model_id in self.metadata:
218
+ logger.info(f"Using cached model {model_id}")
219
+ return local_path
220
+
221
+ logger.info(f"Downloading model {model_id} from HuggingFace Hub: {repo_id}")
222
+
223
+ # Download from HuggingFace Hub
224
+ snapshot_download(
225
+ repo_id=repo_id,
226
+ local_dir=str(local_path),
227
+ token=self.token,
228
+ local_dir_use_symlinks=False
229
+ )
230
+
231
+ # Load metadata if available
232
+ metadata_file = local_path / "metadata.json"
233
+ if metadata_file.exists():
234
+ with open(metadata_file, 'r') as f:
235
+ metadata = json.load(f)
236
+
237
+ self.metadata[model_id] = {
238
+ **metadata,
239
+ "local_cache_path": str(local_path),
240
+ "last_downloaded": datetime.now().isoformat()
241
+ }
242
+ self._save_metadata()
243
+
244
+ logger.info(f"Model {model_id} downloaded successfully")
245
+ return local_path
246
+
247
+ except HfHubHTTPError as e:
248
+ if e.response.status_code == 404:
249
+ logger.error(f"Model {model_id} not found on HuggingFace Hub")
250
+ else:
251
+ logger.error(f"Failed to load model {model_id}: {e}")
252
+ return None
253
+ except Exception as e:
254
+ logger.error(f"Failed to load model {model_id}: {e}")
255
+ return None
256
+
257
+ async def delete_model(self, model_id: str) -> bool:
258
+ """
259
+ Delete model from HuggingFace Hub and local cache.
260
+
261
+ Args:
262
+ model_id: Model identifier
263
+
264
+ Returns:
265
+ True if successful, False otherwise
266
+ """
267
+ try:
268
+ repo_id = self._get_repo_id(model_id)
269
+
270
+ # Delete from HuggingFace Hub
271
+ try:
272
+ self.api.delete_repo(repo_id=repo_id, token=self.token)
273
+ logger.info(f"Deleted repository {repo_id} from HuggingFace Hub")
274
+ except Exception as e:
275
+ logger.warning(f"Failed to delete repository {repo_id}: {e}")
276
+
277
+ # Delete local cache
278
+ local_path = self.local_cache_dir / model_id
279
+ if local_path.exists():
280
+ shutil.rmtree(local_path)
281
+ logger.info(f"Deleted local cache for {model_id}")
282
+
283
+ # Remove from metadata
284
+ if model_id in self.metadata:
285
+ del self.metadata[model_id]
286
+ self._save_metadata()
287
+
288
+ return True
289
+
290
+ except Exception as e:
291
+ logger.error(f"Failed to delete model {model_id}: {e}")
292
+ return False
293
+
294
+ async def get_metadata(self, model_id: str) -> Optional[Dict[str, Any]]:
295
+ """Get model metadata"""
296
+ return self.metadata.get(model_id)
297
+
298
+ async def list_models(self) -> Dict[str, Dict[str, Any]]:
299
+ """List all models managed by this storage"""
300
+ return self.metadata.copy()
301
+
302
+ def _generate_model_card(self, model_id: str, metadata: Dict[str, Any]) -> str:
303
+ """Generate a model card for HuggingFace Hub"""
304
+ base_model = metadata.get("base_model", "Unknown")
305
+ dataset = metadata.get("dataset", "Unknown")
306
+ training_method = metadata.get("training_method", "Unknown")
307
+ description = metadata.get("description", f"Fine-tuned {base_model}")
308
+
309
+ model_card = f"""---
310
+ license: apache-2.0
311
+ base_model: {base_model}
312
+ tags:
313
+ - generated_from_trainer
314
+ - isa-model
315
+ - {training_method.lower().replace(' ', '-')}
316
+ datasets:
317
+ - {dataset}
318
+ language:
319
+ - en
320
+ pipeline_tag: text-generation
321
+ ---
322
+
323
+ # {model_id}
324
+
325
+ {description}
326
+
327
+ ## Model Details
328
+
329
+ - **Base Model**: {base_model}
330
+ - **Training Dataset**: {dataset}
331
+ - **Training Method**: {training_method}
332
+ - **Uploaded by**: {self.username}
333
+ - **Framework**: ISA Model SDK
334
+
335
+ ## Training Details
336
+
337
+ """
338
+
339
+ # Add training configuration if available
340
+ if "config" in metadata:
341
+ config = metadata["config"]
342
+ model_card += f"""
343
+ ### Training Configuration
344
+
345
+ - **Epochs**: {config.get('num_epochs', 'Unknown')}
346
+ - **Batch Size**: {config.get('batch_size', 'Unknown')}
347
+ - **Learning Rate**: {config.get('learning_rate', 'Unknown')}
348
+ - **LoRA**: {'Yes' if config.get('use_lora', False) else 'No'}
349
+ """
350
+
351
+ if config.get('use_lora', False):
352
+ lora_config = config.get('lora_config', {})
353
+ model_card += f"""
354
+ ### LoRA Configuration
355
+
356
+ - **LoRA Rank**: {lora_config.get('lora_rank', 'Unknown')}
357
+ - **LoRA Alpha**: {lora_config.get('lora_alpha', 'Unknown')}
358
+ - **LoRA Dropout**: {lora_config.get('lora_dropout', 'Unknown')}
359
+ """
360
+
361
+ model_card += f"""
362
+
363
+ ## Usage
364
+
365
+ ```python
366
+ from transformers import AutoTokenizer, AutoModelForCausalLM
367
+
368
+ tokenizer = AutoTokenizer.from_pretrained("{self._get_repo_id(model_id)}")
369
+ model = AutoModelForCausalLM.from_pretrained("{self._get_repo_id(model_id)}")
370
+
371
+ # For inference
372
+ inputs = tokenizer("Your prompt here", return_tensors="pt")
373
+ outputs = model.generate(**inputs, max_length=100)
374
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
375
+ print(response)
376
+ ```
377
+
378
+ ## ISA Model SDK
379
+
380
+ This model was trained using the [ISA Model SDK](https://github.com/your-repo/isA_Model),
381
+ a comprehensive framework for training and deploying AI models.
382
+
383
+ """
384
+
385
+ return model_card
386
+
387
+ def get_public_url(self, model_id: str) -> str:
388
+ """Get public URL for a model on HuggingFace Hub"""
389
+ return f"https://huggingface.co/{self._get_repo_id(model_id)}"
390
+
391
+ async def update_model_metadata(self, model_id: str, new_metadata: Dict[str, Any]) -> bool:
392
+ """Update model metadata on HuggingFace Hub"""
393
+ try:
394
+ if model_id not in self.metadata:
395
+ logger.error(f"Model {model_id} not found in metadata")
396
+ return False
397
+
398
+ # Update local metadata
399
+ self.metadata[model_id].update(new_metadata)
400
+ self._save_metadata()
401
+
402
+ # Update README on HuggingFace Hub
403
+ repo_id = self._get_repo_id(model_id)
404
+ readme_content = self._generate_model_card(model_id, self.metadata[model_id])
405
+
406
+ self.api.upload_file(
407
+ path_or_fileobj=readme_content.encode('utf-8'),
408
+ path_in_repo="README.md",
409
+ repo_id=repo_id,
410
+ token=self.token,
411
+ commit_message=f"Update metadata for {model_id}"
412
+ )
413
+
414
+ logger.info(f"Updated metadata for model {model_id}")
415
+ return True
416
+
417
+ except Exception as e:
418
+ logger.error(f"Failed to update metadata for {model_id}: {e}")
419
+ return False
@@ -0,0 +1,52 @@
1
+ """
2
+ ISA Model Deployment Module
3
+
4
+ Provides comprehensive deployment capabilities for AI models including:
5
+ - Multi-cloud deployment (RunPod, AWS, GCP, Azure)
6
+ - Multiple inference engines (Triton, vLLM, TensorRT-LLM)
7
+ - Model optimization and containerization
8
+ - Deployment monitoring and management
9
+
10
+ Main Components:
11
+ - DeploymentManager: Orchestrates complete deployment workflow
12
+ - DeploymentConfig: Configuration classes for different deployment scenarios
13
+ - Cloud providers: RunPod, AWS, GCP, Azure integrations
14
+ - Inference engines: Triton, vLLM, TensorRT-LLM support
15
+ """
16
+
17
+ from .core.deployment_manager import DeploymentManager
18
+ from .core.deployment_config import (
19
+ DeploymentConfig,
20
+ DeploymentProvider,
21
+ InferenceEngine,
22
+ ModelConfig,
23
+ ModelFormat,
24
+ TritonConfig,
25
+ RunPodServerlessConfig,
26
+ create_gemma_runpod_triton_config,
27
+ create_local_triton_config
28
+ )
29
+
30
+ __all__ = [
31
+ # Main classes
32
+ "DeploymentManager",
33
+ "DeploymentConfig",
34
+
35
+ # Configuration classes
36
+ "ModelConfig",
37
+ "TritonConfig",
38
+ "RunPodServerlessConfig",
39
+
40
+ # Enums
41
+ "DeploymentProvider",
42
+ "InferenceEngine",
43
+ "ModelFormat",
44
+
45
+ # Helper functions
46
+ "create_gemma_runpod_triton_config",
47
+ "create_local_triton_config"
48
+ ]
49
+
50
+ # Version info
51
+ __version__ = "0.1.0"
52
+ __author__ = "ISA Model Team"
@@ -0,0 +1,34 @@
1
+ """
2
+ Deployment Core Module
3
+
4
+ Contains the core deployment functionality including configuration management
5
+ and deployment orchestration.
6
+ """
7
+
8
+ from .deployment_manager import DeploymentManager
9
+ from .deployment_config import (
10
+ DeploymentConfig,
11
+ DeploymentProvider,
12
+ InferenceEngine,
13
+ ModelConfig,
14
+ ModelFormat,
15
+ TritonConfig,
16
+ RunPodServerlessConfig,
17
+ create_gemma_runpod_triton_config,
18
+ create_local_triton_config
19
+ )
20
+ from .isa_deployment_service import ISADeploymentService
21
+
22
+ __all__ = [
23
+ "DeploymentManager",
24
+ "DeploymentConfig",
25
+ "DeploymentProvider",
26
+ "InferenceEngine",
27
+ "ModelConfig",
28
+ "ModelFormat",
29
+ "TritonConfig",
30
+ "RunPodServerlessConfig",
31
+ "ISADeploymentService",
32
+ "create_gemma_runpod_triton_config",
33
+ "create_local_triton_config"
34
+ ]