Loading
Loading
MLOps (Machine Learning Operations) هو مجموعة الممارسات التي تجسر الفجوة بين تطوير نماذج ML وتشغيلها في الإنتاج.
بدون MLOps، يحدث هذا كثيراً:
from dataclasses import dataclass, field
from typing import List, Tuple
# ─── MLOps Maturity Model ──────────────────────────────────
@dataclass
class MLProject:
name: str
model_type: str
version: str = "1.0.0"
accuracy: float = 0.0
is_deployed: bool = False
tracking_enabled: bool = False
ci_cd_enabled: bool = False
monitoring_enabled: bool = False
def mlops_score(self) -> int:
return sum([
25 if self.tracking_enabled else 0,
25 if self.is_deployed else 0,
25 if self.ci_cd_enabled else 0,
25 if self.monitoring_enabled else 0,
])
def maturity_level(self) -> str:
s = self.mlops_score()
if s == 0: return "Level 0 — Manual (لا أتمتة)"
if s <= 25: return "Level 1 — Tracking"
if s <= 50: return "Level 2 — Deployed"
if s <= 75: return "Level 3 — CI/CD"
return "Level 4 — Full MLOps ✨"
def report(self):
score = self.mlops_score()
level = self.maturity_level()
print(f"\n📊 {self.name} (v{self.version})")
print(f" النوع : {self.model_type}")
print(f" Accuracy : {self.accuracy:.1%}")
print(f" Score : {score}/100 — {level}")
checks: List[Tuple[str, bool]] = [
("Experiment Tracking", self.tracking_enabled),
("Deployed to Prod", self.is_deployed),
("CI/CD Automated", self.ci_cd_enabled),
("Monitoring Active", self.monitoring_enabled),
]
for label, ok in checks:
icon = "✅" if ok else "❌"
print(f" {icon} {label}")
# ─── قبل MLOps ─────────────────────────────────────────────
print("🔬 الوضع بدون MLOps:")
print("-" * 50)
proto = MLProject(
name="sentiment-model", model_type="Text Classifier",
version="1.0.0", accuracy=0.89,
)
proto.report()
# ─── بعد MLOps ─────────────────────────────────────────────
print(f"\n🚀 الوضع بعد تطبيق MLOps:")
print("-" * 50)
prod = MLProject(
name="sentiment-model", model_type="Text Classifier",
version="2.3.1", accuracy=0.94,
is_deployed=True, tracking_enabled=True,
ci_cd_enabled=True, monitoring_enabled=True,
)
prod.report()
# ─── مكونات MLOps ──────────────────────────────────────────
print(f"\n\n🧱 مكونات MLOps الرئيسية:")
components = [
("Data Management", "DVC, Delta Lake", "إدارة وإصدار البيانات"),
("Experiment Track", "MLflow, W&B", "تتبع التجارب والمعاملات"),
("Model Registry", "MLflow, HuggingFace Hub", "تخزين وإصدار النماذج"),
("CI/CD", "GitHub Actions, Jenkins", "أتمتة الاختبار والنشر"),
("Serving", "FastAPI, TorchServe", "خدمة النموذج للإنتاج"),
("Monitoring", "Evidently, Grafana", "مراقبة الجودة والانجراف"),
]
for comp, tools, desc in components:
print(f" 📦 {comp:<20} — {desc}")
print(f" أدوات: {tools}")
print()