Model registry
এই পাঠে যা শিখবেন
- Model registry-এর core concept — registered model, version, alias
- Lifecycle stages ও promotion workflow
- MLflow Model Registry API — register, transition, load
- Governance ও audit trail patterns
১ · কেন registry
একটি team-এ ৫ data scientist, প্রত্যেকে নিজের laptop-এ model save করছেন। Production-এ deploy-এর সময় — "কোন model? কোন version? কে validated?"। Registry এই questions-এর single source of truth।
২ · Core concepts
Registered Model: a logical model name (e.g., "bangla-sentiment")।
Version: immutable artifact — version 1, 2, 3...।
Stage / Alias: mutable label — version 3 = Production, version 4 = Staging।
৩ · Lifecycle stages
- None / Dev: just registered, no testing।
- Staging: integration tested, shadow deployed।
- Production: serving real traffic।
- Archived: retired, kept for audit।
MLflow 2.0+ recommends aliases over stages — more flexible:
champion= current production।challenger= candidate competing।shadow= silent comparison।- Custom aliases for complex deployments।
৪ · MLflow Model Registry API
import mlflow
from mlflow.tracking import MlflowClient
mlflow.set_tracking_uri("http://mlflow:5000")
client = MlflowClient()
# ১. একটি training run থেকে register
with mlflow.start_run() as run:
mlflow.sklearn.log_model(
model,
artifact_path="model",
registered_model_name="bangla-sentiment",
signature=signature, # input/output schema
input_example=X_test.iloc[:5],
)
# ২. version metadata add
client.update_model_version(
name="bangla-sentiment",
version=4,
description="RF, n_est=200, AUC=0.94 on 2025-Q1 data",
)
client.set_model_version_tag("bangla-sentiment", 4, "data_version", "v3.2")
client.set_model_version_tag("bangla-sentiment", 4, "approved_by", "lead-ds")
# ৩. alias assign (modern way)
client.set_registered_model_alias(
name="bangla-sentiment",
alias="challenger",
version=4,
)
# ৪. promote — challenger → champion
client.set_registered_model_alias(
name="bangla-sentiment",
alias="champion",
version=4,
)
# ৫. load by alias — production code
model = mlflow.pyfunc.load_model("models:/bangla-sentiment@champion")
prediction = model.predict(input_df)
৫ · Promotion workflow
- Training run → automatic register।
- Smoke test pass → alias
candidate। - Performance test (offline metric) → tag pass।
- Shadow deployment 24 hours → metric compare।
- Manual review (lead-DS, product manager)।
- Canary deploy 5% traffic → 24 hours monitor।
- Full rollout → alias
champion। - Previous champion → alias
previous(rollback ready)।
৬ · Signature & input example
Registry-তে model log করার সময় signature include — input/output schema। Production-এ schema validation, training-serving skew prevent।
from mlflow.models.signature import infer_signature
# auto-infer from sample input/output
signature = infer_signature(X_train, model.predict(X_train))
mlflow.sklearn.log_model(
model,
artifact_path="model",
registered_model_name="bangla-sentiment",
signature=signature,
input_example=X_train.iloc[:3],
)
# Production-এ load → schema enforced
model = mlflow.pyfunc.load_model("models:/bangla-sentiment@champion")
# wrong schema → ValueError
prediction = model.predict(input_df)
৭ · Registry alternatives
- MLflow Model Registry (OSS): most common, self-hostable।
- SageMaker Model Registry: AWS native, integrated with SageMaker training/serving।
- Vertex AI Model Registry: GCP equivalent।
- Azure ML Model Registry: Azure native।
- Hugging Face Hub: public-facing, OSS model sharing।
- Comet, Neptune, W&B: SaaS alternatives।
ভাবনার প্রশ্ন
প্র ০১ "Promotion-এ কে control করে — DS, MLOps, business?" ভাল governance কেমন?
Promotion governance একটি collaborative process — clearly-defined roles + automated gates।
Recommended role split:
- DS: training, validation metric, candidate propose।
- MLOps: CI/CD gate, performance test, deployment।
- Lead-DS: approve based on metrics।
- Product manager: approve based on business risk।
- SRE/On-call: deployment timing।
Automated gates (no human bottleneck):
- Validation metric > baseline (configurable threshold)।
- Schema match।
- Performance regression test pass।
- Fairness gate (subgroup performance parity)।
- Latency < SLA।
Human gates:
- Major version (e.g., new architecture) → lead approval।
- Critical model (fraud, credit) → review board।
- Risk classification — minor patches auto-approved, major manual।
Anti-patterns:
- "Anyone can deploy" — accidents waiting।
- "Only one person can deploy" — bottleneck, single point of failure।
- "Human approval for every minor patch" — slow, frustration।
BD context:
- Bangladesh Bank ICT guideline + SOC 2 — formal approval log।
- Quarterly review board for high-risk models।
মূল উপলব্ধি: Governance = automated gates + judicious human checkpoints। Trust automation for routine; human for novel/risky। Audit log every promotion।
প্র ০২ "Rollback workflow — কীভাবে fast ও safe?"
Rollback should be the easiest operation — emergency button।
Alias-based rollback:
- Champion v5 → bug found → v4-এ alias point।
- Production code "champion" load → instant updated version।
- Time: seconds।
Considerations:
- Schema mismatch — v4 expects different feature, v5 added new। Need previous schema known।
- Dependency on data version — v4 trained on v3 data; if data also changed → match।
- Cache — production cache evict old prediction।
Practical rollback drill:
- Quarterly — rollback simulate। Real rollback in non-prod hour।
- Postmortem after each real rollback — learn।
- Documentation — "rollback runbook"।
K8s integration:
- Argo Rollouts — auto-rollback on metric breach।
- Health check failing → previous Deployment image revert।
- Combined: registry alias + K8s automation।
মূল উপলব্ধি: Rollback ease-of-use directly correlates with deployment confidence। Easy rollback → bold deployment। Painful rollback → conservative, slow iteration।
প্র ০৩ "Registry signature validation কেন important — concrete bug example।"
Signature = production safety net। Concrete example:
Bug story:
- Model v5 — added new feature "user_age_group" (categorical)।
- Production caller — old code, sending only old features।
- Without signature: model might silently accept None, predict wrong।
- With signature: load-time error — "missing column"।
- CI/CD catches before production traffic।
Other catches:
- Type mismatch — caller sending string, model expects int।
- Range — model expects normalized [0,1], caller sending raw।
- Output schema — caller expects single value, model returns multi-class।
Signature limit:
- Doesn't catch semantic mismatch — same column name, different meaning।
- "User_age" — int vs years vs group bucket — signature treats as int (same)।
- Documentation + naming convention required।
Best practice:
- Auto-infer signature from training data (mlflow infer_signature)।
- Log input_example — alongside signature, "what does this look like"।
- Production caller code — pydantic schema match registry signature।
মূল উপলব্ধি: Signature — fail-fast principle। Wrong input → immediate error, not subtle wrong output। Bug detection time: hours → seconds।
প্র ০৪ "Multi-region deployment — registry single source কীভাবে maintain?"
Multi-region — Bangladesh-Singapore-US — single registry replication strategy।
Pattern ১ — Single central registry:
- One MLflow instance, all regions read/write।
- Pros: simple, no consistency issues।
- Cons: latency for distant regions, single point of failure।
Pattern ২ — Replicated registry:
- Primary registry + read replicas in each region।
- Promotion writes to primary; reads from local।
- Pros: low read latency, better availability।
- Cons: write region consistency।
Pattern ৩ — Per-region registry + sync:
- Each region independent registry, automated sync।
- Pros: regional independence।
- Cons: drift risk, complex sync logic।
Practical Bangladesh setup:
- Primary registry: Mumbai region (lowest latency from BD)।
- Production model artifacts cached in each region's K8s।
- "Pull at deploy time" — model fetched once, reused।
Artifact caching:
- Each region S3 / GCS bucket।
- Cross-region replication on artifact upload।
- K8s pod-cache layer।
Consistency consideration:
- "Champion alias" — globally consistent want। Eventual consistency OK seconds-delay।
- For high-stakes (banking): strict consistency, slow promotion acceptable।
Bangladesh tier 1 city + tier 2:
- Tier 1 (Dhaka, Chittagong): low-latency to Mumbai।
- Tier 2 (Sylhet, Khulna): higher latency; local cache effective।
- Service mesh with regional failover।
মূল উপলব্ধি: Multi-region — registry centralized okay, artifacts replicate। Strict global consistency rare-need; eventual consistent registry + cached artifact = practical, fast।
অনুশীলন
-
Register: MLflow tracking server-এ একটি model register। Alias
challengerassign।উপরের code-এ
registered_model_nameset, তারপরset_registered_model_alias। UI-তে "Models" tab-এ দেখুন। -
Promotion:
challenger→championswap। Production code-এ "@champion" load করুন।client.set_registered_model_alias("name", "champion", version)→ load"models:/name@champion"। Always returns latest blessed। -
চিন্তা: Daraz-এর recommendation model। Promotion gate-এর ৫টি criteria লিখুন।
- NDCG@10 > baseline + 1%।
- Inference latency p99 < 50ms।
- Subgroup parity (geo + demographic) within 5%।
- Shadow deployment 24h, no anomaly।
- Lead DS + product manager approval।