Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

CI/CD for Machine Learning Models

By Kokil Thapa | Last reviewed: September 2026

Shipping a model from a notebook to production breaks teams that treat machine learning like ordinary application code. CI/CD for machine learning models adds data validation, training reproducibility, model metrics gates, and artifact versioning on top of standard build-and-deploy automation. I integrate LLM and prediction APIs into Laravel and WordPress systems regularly, but I do not train models myself. The pipelines below reflect what works when a web team owns deployment while data scientists own training. If you already run GitLab CI/CD for PHP projects, much of the tooling overlap will feel familiar.

What is CI/CD for machine learning models and how is it different from regular CI/CD?

Standard CI/CD compiles code, runs unit tests, builds a container, and deploys a binary. Machine learning CI/CD must also verify training data, reproduce experiments, store model weights, and compare evaluation metrics against a baseline before anything reaches users.

That extra surface area is why teams borrow the term MLOps. The distinction matters in practice. A green PHPUnit run does not prove your fraud classifier still works after a schema change in the payments table.

On client projects where I wire prediction endpoints into booking or legal-tech portals, the ML team often hands off a versioned artifact. My job is to ensure the pipeline never deploys an untagged pickle file from someone's laptop. The same discipline I apply to MLOps vs DevOps for model deployment applies here: separate concerns, shared gates.

ML CI/CD Pipeline OverviewSourceGit + DVCValidateData + CodeTrainGPU JobRegisterMLflowMetric GateF1 > baselinePackageDocker imageDeployStaging → ProdProduction Monitoring LoopDrift alerts trigger retrain or rollback
End-to-end CI/CD for machine learning models: validate data, train, gate on metrics, register artifacts, deploy, then monitor.

The table below summarises the main differences engineers hit on day one.

DimensionApplication CI/CDML Model CI/CD
Primary artifactCompiled binary or containerModel weights + inference code + feature schema
Test signalUnit and integration testsData tests + metric benchmarks + inference smoke tests
VersioningGit commit SHAGit SHA + dataset hash + experiment run ID
Build timeSeconds to minutesMinutes to hours on GPU runners
Rollback unitPrevious container tagPrevious model version in registry
Post-deploy riskLogic bugs, downtimeSilent accuracy decay, data drift

Teams that skip these differences often paste a Flask wrapper around a notebook export and call it done. That works until the first schema drift or package conflict in production.

How do you build a CI/CD pipeline for machine learning models step by step?

A practical pipeline has six stages. You can collapse some on small teams, but you should not skip the gates.

  1. Lint and unit-test training code. Run Ruff or flake8, pytest on feature-engineering functions, and type checks. Treat training scripts like application code.
  2. Validate input data. Check row counts, null rates, schema, and distribution shifts against a reference profile. Tools like Great Expectations or Pandera fit here.
  3. Train or fine-tune. Trigger on merge to main or on a schedule. Pin random seeds, log hyperparameters, and write metrics to an experiment tracker.
  4. Evaluate against thresholds. Compare validation F1, RMSE, or business KPI against the production champion. Fail the pipeline if the candidate is worse.
  5. Register and package. Push the model to a registry, build a Docker image with pinned dependencies, and tag everything with the Git SHA.
  6. Deploy with promotion rules. Auto-deploy to staging. Production requires manual approval or a canary with automated rollback.

Example GitLab CI pipeline for model training and deploy

GitLab CI is a strong default if you already use it for Laravel or PHP apps. The pattern mirrors what I run on sister legal-tech sites with Deployer, but the train stage needs a GPU runner tag.

# .gitlab-ci.yml — ML model CI/CD skeleton
stages:
  - validate
  - train
  - evaluate
  - package
  - deploy

variables:
  MLFLOW_TRACKING_URI: "https://mlflow.internal.example.com"
  MODEL_NAME: "document-classifier"

validate_data:
  stage: validate
  image: python:3.12-slim
  script:
    - pip install great-expectations pandas pyarrow
    - python scripts/validate_training_data.py --suite configs/data_suite.json

train_model:
  stage: train
  tags: [gpu]
  image: pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime
  script:
    - pip install -r requirements-train.txt
    - python train.py --config configs/train.yaml --seed 42
  artifacts:
    paths: [outputs/model/, metrics.json]
    expire_in: 7 days

evaluate_model:
  stage: evaluate
  image: python:3.12-slim
  script:
    - pip install mlflow scikit-learn
    - python scripts/evaluate.py --metrics metrics.json --min-f1 0.82
  needs: [train_model]

package_inference:
  stage: package
  image: docker:27
  services: [docker:27-dind]
  script:
    - docker build -t registry.example.com/${MODEL_NAME}:${CI_COMMIT_SHA} inference/
    - docker push registry.example.com/${MODEL_NAME}:${CI_COMMIT_SHA}

deploy_staging:
  stage: deploy
  script:
    - kubectl set image deploy/${MODEL_NAME} app=registry.example.com/${MODEL_NAME}:${CI_COMMIT_SHA} -n staging
  environment: staging

Store secrets in GitLab masked variables, not in the repo. The same rules from CI/CD secrets management best practices apply to API keys for cloud GPU providers and model registries.

Track datasets alongside code

Git alone cannot version a 40 GB Parquet file sensibly. Pair Git with DVC or lakeFS so every pipeline run references an immutable dataset hash. When someone asks why March predictions differ from February, you need that hash in the run metadata.

For smaller teams, even an S3 path with a manifest file committed to Git beats ad hoc downloads. Document the path in your README and enforce it in CI with a checksum step.

Build Stages in Order1. Lint2. Data3. Train4. Evalpytest + mypy on feature codeGreat Expectations suite vs reference profileGPU job logs params + metrics to MLflowFail pipeline if F1 below champion threshold
Sequential CI/CD stages for machine learning models with concrete tooling at each gate.

Which CI/CD tools work best for machine learning pipelines in 2026?

There is no single winner. Pick based on where your team already lives and whether you need managed GPU scheduling.

  • GitLab CI: Best when you already deploy Laravel or PHP apps on the same platform. GPU runners are self-hosted but integration is clean.
  • GitHub Actions: Fine for lint, data validation, and calling remote training APIs. Heavy local GPU training usually goes to SageMaker or Vertex instead.
  • Kubeflow Pipelines / Tekton: Kubernetes-native option when every stage runs as a container. Pairs with KServe model serving on Kubernetes.
  • Managed MLOps: AWS SageMaker Pipelines, Azure ML, and Vertex AI Pipelines reduce ops burden at higher cost.
  • MLflow: Not a CI runner, but the registry and experiment layer most teams wire into whichever CI tool they pick.

Compare GitHub Actions and GitLab CI for your org before committing. The GitHub Actions vs GitLab CI guide for 2026 covers runner costs, secret handling, and monorepo patterns that transfer directly to ML repos.

For Nepal-based teams on tight budgets, self-hosted GitLab on a VPS plus spot GPU instances often beats fully managed pipelines. Expect Rs 15,000–25,000/month (~USD 110–185) for a modest setup versus Rs 50,000+ (~USD 370) for managed MLOps at low volume. Your mileage depends on training frequency.

App CI/CD vs ML CI/CDApplication CI/CDGit push → unit testsBuild Docker imageDeploy to productionArtifact: container tagML Model CI/CDGit push + data hashTrain + metric gateRegister model versionArtifact: weights + schemaML adds data + metrics gates app pipelines skip
Side-by-side comparison of application CI/CD and CI/CD for machine learning models.

How do you validate and test ML models in a CI/CD pipeline?

Testing splits into three layers. Skipping any one creates a class of production bug that unit tests cannot catch.

Data and feature tests

Run these on every pull request that touches training data or feature code. Check column types, allowed categorical values, and maximum null percentages. A broken upstream ETL job should fail CI before it poisons the next training run.

Model quality gates

After training, compare the candidate against your champion model on a held-out validation set. Store baselines in MLflow or a JSON file in the repo for small projects. Hard-fail if accuracy drops more than two points or if latency on a sample batch exceeds your SLA.

Align this with code coverage gates in CI thinking: define thresholds upfront and let the pipeline enforce them without human negotiation every release.

Inference smoke tests

Build the inference container in CI and send ten representative payloads to the /predict endpoint. Assert response schema, status codes, and that outputs fall within expected ranges. This catches ONNX export errors and missing dependency pins that training tests miss.

# scripts/evaluate.py — fail CI when model underperforms
import json, sys

with open("metrics.json") as f:
    metrics = json.load(f)

MIN_F1 = float(sys.argv[sys.argv.index("--min-f1") + 1])
CHAMPION_F1 = 0.84

f1 = metrics["validation_f1"]
if f1 < MIN_F1:
    print(f"FAIL: F1 {f1:.3f} below minimum {MIN_F1}")
    sys.exit(1)
if f1 < CHAMPION_F1 - 0.02:
    print(f"FAIL: F1 {f1:.3f} regressed vs champion {CHAMPION_F1}")
    sys.exit(1)
print(f"PASS: F1 {f1:.3f}")

Log every evaluation result to your experiment tracker. Future you will need to explain why version 47 shipped and 46 did not. See model versioning and registries for registry layout patterns that keep staging and production pointers explicit.

How do you deploy and monitor machine learning models after CI/CD?

Deployment is where ML CI/CD reconnects with the web systems most teams already operate. The model becomes a stateless API behind the same load balancer as your Laravel or Node app.

Deployment patterns that work in production

Blue-green: Swap traffic between two identical environments. Rollback means repointing the load balancer to the previous model version. I use the same idea described in CI/CD blue-green deployment for PHP apps.

Canary: Route five percent of traffic to the new model. Watch error rate and business metrics for an hour before full promotion. Safer when bad predictions cost money but do not crash servers.

Shadow mode: Run the new model alongside production without serving its output to users. Compare predictions offline. Slower, but useful for regulated domains.

Once the model is live, expose it through a REST endpoint your application calls server-side. The guide to deploying a machine learning model as an API covers FastAPI and reverse-proxy patterns I have used when integrating predictions into client portals.

Monitoring closes the loop

CI/CD gets the model out the door. Monitoring keeps it accurate. Track input feature distributions, prediction latency, error rates, and downstream business KPIs. Alert when distributions drift beyond a threshold.

That feedback should trigger a retrain pipeline or an automatic rollback to the last registered good version. Read monitoring ML models in production for drift for concrete metrics and alert thresholds.

Post-Deploy Monitoring LoopLive Model v12Serving predictionsLog FeaturesInput distributionsTrack Latencyp95 < 200msBusiness KPIConversion rateDrift DetectedPSI > 0.2Auto RollbackRegistry v11
Monitoring loop after CI/CD deploys a machine learning model: detect drift, then rollback or retrain.

Security and compliance in ML pipelines

Scan repos for leaked API keys with gitleaks in CI. Pin Python dependencies and rebuild images on CVE alerts. Treat training datasets with the same access controls as production databases.

Fold these checks into your existing DevSecOps workflow. The DevSecOps shift-left guide applies directly to ML repos that store credentials for cloud storage and model endpoints.

When I connect OpenAI or other LLM APIs into Laravel apps for AI integration and automation, the CI pipeline validates prompt templates and runs contract tests against mocked responses. The model weights live with the vendor, but the integration code still needs the same gates.

Key Takeaways

  • CI/CD for machine learning models must version datasets and model artifacts, not just Git commits.
  • Fail pipelines on data validation errors and metric regressions before any deploy stage runs.
  • Reuse GitLab CI or GitHub Actions if your team already runs them for application code.
  • Register every promoted model in MLflow or an equivalent registry with staging and production aliases.
  • Deploy with blue-green or canary patterns and wire monitoring alerts back into retrain or rollback pipelines.
  • Keep inference smoke tests in CI to catch export and dependency failures that training tests miss.

People Also Ask

Do you need GPUs in your CI/CD pipeline for every model?

No. Many teams run lint, data validation, and lightweight tests on cheap CPU runners. They trigger GPU training only on merges to main or on a nightly schedule. For API-based models from OpenAI or similar vendors, CI validates integration code and skips local training entirely.

What is the difference between MLOps and CI/CD for ML?

CI/CD is the automation pipeline itself. MLOps is the broader practice that includes experiment tracking, feature stores, monitoring, and governance around that pipeline. You can run CI/CD without a full MLOps platform, but production teams usually grow into both.

How often should you retrain models in CI/CD?

Retrain when monitoring detects drift, when new labelled data arrives, or on a fixed schedule that matches how fast your domain changes. Fraud models may retrain daily. Document classifiers for stable legal forms might retrain monthly. Let data drift metrics drive the schedule, not calendar habit alone.

Can small teams implement ML CI/CD without Kubernetes?

Yes. A GitLab runner, Docker, MLflow on a single VPS, and a FastAPI container behind Nginx covers many use cases. Kubernetes helps at scale but adds ops overhead small Nepal teams often cannot staff. Start simple and add complexity when traffic demands it.

Ship models with the same discipline as application code

CI/CD for machine learning models is not optional once predictions touch customers or internal workflows. Define your stages, enforce metric gates, register every artifact, and connect monitoring back to retrain or rollback. The tooling varies, but the discipline matches any production system I have maintained since 2010.

If you need help wiring model APIs into a Laravel portal, setting up GitLab CI runners, or hardening deployment on Ubuntu, review the Gulfbizlist platform portfolio for multi-service delivery examples or use the JSON formatter to inspect pipeline webhook payloads during setup. For hands-on pipeline design scoped to your stack, contact us or explore custom software development services.

Frequently Asked Questions

CI/CD for machine learning models automates code tests, data checks, training jobs, metric validation, model packaging, and staged deployment. Unlike application CI/CD, it treats datasets and model artifacts as first-class inputs and blocks releases when accuracy or drift thresholds fail.

Application CI/CD compiles code, runs unit tests, builds a container, and deploys a binary in seconds to minutes. ML CI/CD must also verify training data, reproduce experiments, store model weights, and compare evaluation metrics against a baseline. Primary artifacts become model weights plus inference code and feature schema, versioned by Git SHA, dataset hash, and experiment run ID. Build times stretch to minutes or hours on GPU runners, and post-deploy risks include silent accuracy decay and data drift rather than only logic bugs or downtime.

A practical pipeline runs six gates: lint and unit-test training code; validate input data for schema, null rates, and distribution shifts; train or fine-tune with pinned seeds and logged hyperparameters; evaluate against metric thresholds versus your production champion; register and package the model into a registry and Docker image tagged with the Git SHA; then deploy with promotion rules such as auto-staging and manual or canary production approval. Small teams can collapse stages but should not skip the gates.

There is no single winner. GitLab CI fits teams already deploying Laravel or PHP on the same platform, with self-hosted GPU runners. GitHub Actions handles lint, data validation, and remote training API calls well. Kubeflow Pipelines or Tekton suit Kubernetes-native setups paired with KServe. Managed options like AWS SageMaker Pipelines, Azure ML, and Vertex AI Pipelines reduce ops burden at higher cost. MLflow is not a CI runner but serves as the registry and experiment layer most teams wire into whichever CI tool they already use.

Self-hosted GitLab on a VPS plus spot GPU instances typically runs Rs 15,000–25,000/month (~USD 110–185). Fully managed MLOps at low volume often exceeds Rs 50,000/month (~USD 370). Actual cost depends on training frequency.

No. Run lint, data validation, and lightweight tests on CPU runners. Trigger GPU training only on merges to main or on a schedule. API-based models skip local training entirely.

CI/CD is the automation pipeline itself—the scripted stages that validate, train, evaluate, package, and deploy. MLOps is the broader practice covering experiment tracking, feature stores, monitoring, and governance around that pipeline. You can run CI/CD without a full MLOps platform, but production teams usually grow into both. The article treats CI/CD as the delivery mechanism and MLOps as the operational discipline that keeps models accurate after release.

Testing splits into three layers. Data and feature tests run on every pull request touching training data, checking column types, allowed categorical values, and null percentages so broken ETL fails before the next training run. Model quality gates compare validation F1, RMSE, or business KPIs against your champion and hard-fail on regressions. Inference smoke tests build the container in CI, send representative payloads to the predict endpoint, and assert response schema, status codes, and output ranges to catch ONNX export errors and missing dependency pins.

Git alone cannot sensibly version a 40 GB Parquet file. Pair Git with DVC or lakeFS so every pipeline run references an immutable dataset hash stored in run metadata. When predictions differ month to month, that hash explains why. Smaller teams can commit an S3 path with a manifest file to Git, document the path in the README, and enforce it in CI with a checksum step. Either approach beats ad hoc downloads from someone's laptop.

The model becomes a stateless API behind the same load balancer as your Laravel or Node app. Blue-green deployment swaps traffic between two environments and rolls back by repointing to the previous model version. Canary routing sends five percent of traffic to the new model while watching error rates and business metrics before full promotion. Shadow mode runs the new model alongside production without serving its output, comparing predictions offline—slower but useful for regulated domains.

Monitoring closes the loop CI/CD opens. Track input feature distributions, prediction latency, error rates, and downstream business KPIs. Alert when distributions drift beyond a threshold. That feedback should trigger a retrain pipeline or an automatic rollback to the last registered good version in your model registry. Without this loop, silent accuracy decay goes unnoticed until business metrics drop, which is a post-deploy risk unit tests cannot catch.

Retrain when monitoring detects drift, when new labelled data arrives, or on a fixed schedule matching how fast your domain changes. Fraud models may retrain daily; document classifiers for stable legal forms might retrain monthly. Let data drift metrics drive the schedule rather than calendar habit alone. CI/CD should wire monitoring alerts back into the retrain pipeline so drift detection automatically kicks off a new training run with the same validation gates.

Yes. A GitLab runner, Docker, MLflow on a single VPS, and a FastAPI container behind Nginx covers many use cases. Kubernetes helps at scale but adds ops overhead small Nepal teams often cannot staff. Start simple and add complexity when traffic demands it. The article explicitly recommends this stack over jumping straight to Kubeflow or managed Kubernetes MLOps when budget and headcount are limited.

Scan repos for leaked API keys with gitleaks in CI. Pin Python dependencies and rebuild Docker images when CVE alerts land. Treat training datasets with the same access controls as production databases. Store secrets in GitLab masked variables, not in the repository—the same rules that apply to CI/CD secrets management for application code. Fold these checks into your existing DevSecOps workflow, especially for credentials tied to cloud storage, GPU providers, and model endpoints.

The pipeline hard-fails and blocks deployment. Evaluation scripts compare validation F1, RMSE, or business KPIs against a minimum threshold and your production champion model. If accuracy drops more than two points versus the champion or falls below the defined minimum, CI exits with a failure and nothing reaches staging or production. Log every evaluation result to MLflow or your experiment tracker so you can explain why version 47 shipped and version 46 did not.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: