- Posted on
- • Artificial Intelligence
Artificial Intelligence Model Management
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
AI Model Management on Linux: A Bash-First Playbook
If your AI model “works on my GPU” but fails, drifts, or can’t be reproduced elsewhere, you don’t have a modeling problem—you have a model management problem. In fast-moving teams, models, data, and environments change constantly. Without a system to version, track, package, and promote models, you’ll lose time to manual fixes, costly regressions, and audit headaches.
This guide shows you how to manage AI models end-to-end using Linux and Bash-friendly tooling. You’ll get practical steps, real-world examples, and ready-to-run commands. We’ll lean on Git, Git LFS, DVC, MLflow, and containers (Podman/Docker) so you can build a reproducible, automatable model lifecycle.
Why model management matters
Models are more than code: they bundle data, parameters, and environments. All must be versioned together.
Reproducibility and auditability are now table stakes for production ML and compliance.
Data drift is inevitable; standardized evaluation and promotion gates prevent silent regressions.
Teams move faster when artifacts are discoverable, comparable, and deployable with one command.
Prerequisites: Install essential tools
Install Git, Git LFS, Python, pip/venv, jq, and curl.
- Debian/Ubuntu (apt):
sudo apt update
sudo apt install -y git git-lfs python3 python3-venv python3-pip jq curl
- Fedora/RHEL/CentOS (dnf):
# On RHEL/CentOS you may need EPEL for git-lfs:
# sudo dnf install -y epel-release
sudo dnf install -y git git-lfs python3 python3-pip python3-virtualenv jq curl
- openSUSE (zypper):
sudo zypper refresh
sudo zypper install -y git git-lfs python3 python3-pip python3-virtualenv jq curl
Then initialize Git LFS once:
git lfs install
Optional but recommended: Containers for consistent runtime.
- Debian/Ubuntu (apt):
# Prefer Podman (rootless by default)
sudo apt install -y podman
# Or Docker
sudo apt install -y docker.io
sudo systemctl enable --now docker
- Fedora/RHEL/CentOS (dnf):
sudo dnf install -y podman
# Or Docker engine (moby)
sudo dnf install -y moby-engine
sudo systemctl enable --now docker
- openSUSE (zypper):
sudo zypper install -y podman
# Or Docker
sudo zypper install -y docker
sudo systemctl enable --now docker
Upgrade pip and create a project venv:
python3 -m pip install --upgrade pip
python3 -m venv .venv
. .venv/bin/activate
Core workflow: 5 actionable steps
1) Version everything: code, data, and models with Git LFS + DVC
Git handles code and metadata, Git LFS stores large binaries, and DVC versions datasets and model artifacts while keeping your repo lean. This keeps data lineage and model provenance intact.
Install DVC (choose remotes you need: s3, gdrive, ssh, etc.):
pip install "dvc[s3,gdrive,ssh]"
Initialize your project:
git init
dvc init
mkdir -p data/raw data/processed models src
Add data with DVC (not to Git directly):
dvc add data/raw
git add data/raw.dvc .gitignore .dvc
git commit -m "Track raw data with DVC"
Configure a remote (example: S3; adapt for your storage):
dvc remote add -d storage s3://my-bucket/my-project
# Optionally: dvc remote modify storage endpointurl https://s3.my-cloud.example
git commit -m "Add default DVC remote"
Push data and artifacts:
dvc push
Create a reproducible pipeline:
# Example training stage with metrics and model artifact
dvc stage add -n train \
-d data/processed -d src/train.py \
-o models/model.pkl -M metrics.json \
python src/train.py --in data/processed --out models/model.pkl --metrics metrics.json
git add dvc.yaml dvc.lock src/train.py
git commit -m "Add train pipeline"
dvc repro
dvc push
Real-world example: A fraud team reduced onboarding time from weeks to days by DVC-tracking historical datasets and retrainable pipelines; auditors can now reconstruct exactly which data and code produced the current model.
2) Track experiments with MLflow
MLflow centralizes parameters, metrics, and artifacts so you can compare runs and avoid stale “final_final_model.pkl” chaos.
Install MLflow:
pip install mlflow
Start the UI (SQLite-backed, local dev):
mlflow ui --backend-store-uri sqlite:///mlruns.db --host 0.0.0.0 --port 5000 &
Instrument your training script:
# src/train.py (snippet)
import json, argparse
import mlflow, mlflow.sklearn
parser = argparse.ArgumentParser()
parser.add_argument("--in", dest="ind", required=True)
parser.add_argument("--out", dest="outd", required=True)
parser.add_argument("--metrics", dest="metrics", default="metrics.json")
args = parser.parse_args()
with mlflow.start_run():
# ... load data, train model -> model, accuracy, f1, etc.
accuracy = 0.9123
f1 = 0.901
mlflow.log_param("feature_set", "v2")
mlflow.log_metric("accuracy", accuracy)
mlflow.log_metric("f1", f1)
# Save model artifact in MLflow format too (optional)
# mlflow.sklearn.log_model(model, "model")
with open(args.metrics, "w") as f:
json.dump({"accuracy": accuracy, "f1": f1}, f)
Kick off runs via DVC or directly:
python src/train.py --in data/processed --out models/model.pkl --metrics metrics.json
Open http://localhost:5000 to compare experiments by metrics, params, and artifacts.
3) Make environments reproducible: venv + lockfiles + containers
Capture dependencies:
pip install -r requirements.txt # if you have one
pip freeze > requirements.lock.txt
git add requirements.lock.txt
git commit -m "Lock Python deps"
Containerize for consistent deploys. Example Dockerfile (works with Podman or Docker):
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.lock.txt .
RUN pip install --no-cache-dir -r requirements.lock.txt
COPY . .
CMD ["python", "src/serve.py"]
Build and run:
# Podman
podman build -t mymodel:0.1.0 .
podman run --rm -p 8080:8080 mymodel:0.1.0
# Or Docker
docker build -t mymodel:0.1.0 .
docker run --rm -p 8080:8080 mymodel:0.1.0
Real-world example: A search relevance team eliminated “works on my machine” incidents by pinning images and promoting only signed, scanned images through environments.
4) Register and serve models (MLflow or Hugging Face)
Option A: Serve with MLflow (local artifact or specific run):
# If your training logged an MLflow model under "model":
# Replace <RUN_ID> with the actual run ID from mlflow UI.
mlflow models serve -m "runs:/<RUN_ID>/model" -p 8080
Option B: Publish to Hugging Face Hub (discoverability/versioning). Install the CLI:
pip install huggingface_hub
Upload:
huggingface-cli login
huggingface-cli repo create my-model-repo --type model
git clone https://huggingface.co/<your-username>/my-model-repo
cd my-model-repo
git lfs install
cp ../models/model.pkl . # or model.onnx, safetensors, etc.
git add .
git commit -m "Add model v0.1.0"
git push
You can now pull this model across servers with Git LFS and integrate it into CI/CD.
5) Automate evaluation and promotion gates with Bash
Gate releases on metrics to avoid regressions. Example promote-if-good.sh:
#!/usr/bin/env bash
set -euo pipefail
THRESH_ACC="${THRESH_ACC:-0.90}"
METRICS_FILE="${1:-metrics.json}"
acc=$(jq -r '.accuracy' "$METRICS_FILE")
echo "Accuracy: $acc (threshold: $THRESH_ACC)"
awk -v a="$acc" -v t="$THRESH_ACC" 'BEGIN{exit !(a>=t)}' || {
echo "Gate failed: accuracy below threshold"
exit 1
}
# Tag model version and push artifacts
ver="v$(date +%Y.%m.%d-%H%M)"
git tag -a "model-$ver" -m "Promoted: accuracy $acc"
git push --tags
# Push DVC-tracked data/models to remote
dvc push
echo "Promotion complete: model-$ver"
Use it in CI:
dvc repro
./promote-if-good.sh metrics.json
Extend this by:
Comparing against a baseline metrics.json (previous prod)
Writing a promotion record to MLflow
Building and signing a container image after passing gates
Real-world example: A demand forecasting team auto-promotes only if MAPE improves by ≥2% and accuracy >= defined SLA; otherwise, runs are archived with context for fast rollback.
Putting it together: A minimal repo layout
.
├─ data/
│ ├─ raw/ # DVC-tracked
│ └─ processed/ # DVC-tracked
├─ models/ # DVC-tracked outputs
├─ src/
│ ├─ train.py
│ └─ serve.py
├─ dvc.yaml
├─ requirements.txt
├─ requirements.lock.txt
├─ Dockerfile
└─ promote-if-good.sh
Conclusion and next steps
Model management is how you turn modeling wins into reliable business outcomes. By versioning data and models with DVC, tracking experiments in MLflow, pinning environments, and enforcing promotion gates, you’ll ship faster with fewer surprises.
Your next steps: 1) Initialize DVC in your current repo and add your datasets. 2) Add MLflow logging to your training script and compare two runs today. 3) Lock your dependencies and build a container image. 4) Add the promotion script to your CI and enforce a simple accuracy threshold.
Need a starting point? Create a fresh repo, copy the snippets above, and wire them together. In under an hour, you’ll have a reproducible, auditable, Bash-driven model lifecycle on Linux.