IT Vizag
← MLOps: Shipping ML Models
Loading video…

MLOps: Shipping ML Models · Lesson 3 of 14 · 1 min read · 5 min video

Reproducible environments

Pin versions with requirements files and Docker so it runs the same everywhere.

📄 Download slides (PDF)

"It works on my machine" is the most common way ML projects break. A different version of pandas or scikit-learn can change results or crash the model at load time. Reproducible environments make your code run the same everywhere.

Pin your versions

List exact versions, not just package names:

# requirements.txt
pandas==2.2.3
scikit-learn==1.5.2
fastapi==0.115.6

A model saved with one scikit-learn version may not load, or may behave differently, in another. Pinning prevents silent surprises.

Virtual environments

Each project gets its own isolated set of packages:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Tools such as uv or Poetry do the same with lock files, which record every package your packages depend on too.

Docker: ship the whole box

A container packages your code, Python, the libraries and the system settings into one image that runs identically on your laptop, a teammate's machine and the cloud.

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY src/ src/
COPY model.pkl .
CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "8000"]

Fix randomness

Set random seeds for NumPy, scikit-learn and any deep learning library, so re-running training gives the same model. Record the seed in params.yaml.

Tip: Build the Docker image in CI, not on your laptop, so the image that's tested is exactly the one that's deployed.

In one line

Pin every version, isolate each project, set your seeds and package everything in a container, so the model behaves the same everywhere it runs.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend