Skip to content
Back to skills

Ml Pipeline Guide

BSecurity

Build and deploy reproducible production ML pipelines for research

  • 3,639 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 6, 2026
devopspythongobashgitci/cddocumentation

Security analysis

B89/100
  • highPerforms destructive filesystem operations
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned June 6, 2026

npx -y skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill ml-pipeline-guide --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ml Pipeline Guide?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ml Pipeline Guide
[![Security: B β€” Skills Directory](https://www.skillsdirectory.com/api/skills/brycewang-stanford-ml-pipeline-guide/badge)](https://www.skillsdirectory.com/skills/brycewang-stanford-ml-pipeline-guide)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ml-pipeline-guide
description: "Build and deploy reproducible production ML pipelines for research"
metadata:
  openclaw:
    emoji: "πŸ”§"
    category: "domains"
    subcategory: "ai-ml"
    keywords: ["MLOps", "pipeline", "deployment", "reproducibility", "feature engineering", "CI/CD"]
    source: "https://github.com/mlflow/mlflow"
---

# ML Pipeline Guide

## Overview

Machine learning research increasingly demands reproducible, end-to-end pipelines that go beyond a single training script. A research ML pipeline encompasses data ingestion, feature engineering, model training, evaluation, experiment tracking, and artifact management. Without a structured pipeline, research results become difficult to reproduce, ablation studies become error-prone, and collaborators cannot build on prior work.

This guide covers the practical tools and patterns for building ML pipelines in an academic research context. The focus is on reproducibility, experiment tracking, and the transition from notebook prototyping to structured experiments. The patterns use MLflow, DVC, and standard Python tooling -- chosen because they are open source, widely adopted in published research, and require minimal infrastructure.

Unlike industry MLOps guides that emphasize deployment at scale, this guide prioritizes the research workflow: running many experiments, tracking what changed between runs, and producing results that reviewers can verify.

## Pipeline Architecture

A research ML pipeline typically has five stages:

```
Data Ingestion β†’ Feature Engineering β†’ Training β†’ Evaluation β†’ Artifact Storage
     β”‚                  β”‚                 β”‚            β”‚              β”‚
     β”œβ”€β”€ raw data       β”œβ”€β”€ transforms    β”œβ”€β”€ model    β”œβ”€β”€ metrics    β”œβ”€β”€ models
     β”œβ”€β”€ splits         β”œβ”€β”€ features      β”œβ”€β”€ logs     β”œβ”€β”€ plots      β”œβ”€β”€ configs
     └── metadata       └── cache         └── ckpts    └── tables     └── reports
```

### Directory Structure for Reproducible Research

```
project/
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ base.yaml           # Default hyperparameters
β”‚   β”œβ”€β”€ experiment_001.yaml  # Experiment-specific overrides
β”‚   └── sweep.yaml          # Hyperparameter search space
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/                # Immutable original data
β”‚   β”œβ”€β”€ processed/          # Cleaned and transformed
β”‚   └── splits/             # Train/val/test splits (versioned)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ data/               # Data loading and preprocessing
β”‚   β”œβ”€β”€ features/           # Feature engineering
β”‚   β”œβ”€β”€ models/             # Model definitions
β”‚   β”œβ”€β”€ training/           # Training loops
β”‚   └── evaluation/         # Metrics and visualization
β”œβ”€β”€ experiments/            # MLflow/W&B experiment logs
β”œβ”€β”€ notebooks/              # Exploratory analysis only
β”œβ”€β”€ tests/                  # Unit tests for pipeline components
β”œβ”€β”€ Makefile                # Reproducible commands
β”œβ”€β”€ requirements.txt        # Pinned dependencies
└── dvc.yaml                # Data version control pipeline
```

## Experiment Tracking with MLflow

```python
import mlflow
import mlflow.pytorch
from pathlib import Path

def run_experiment(config: dict):
    """Run a single experiment with full tracking."""
    mlflow.set_experiment(config["experiment_name"])

    with mlflow.start_run(run_name=config.get("run_name")):
        # Log configuration
        mlflow.log_params({
            "model": config["model_name"],
            "learning_rate": config["lr"],
            "batch_size": config["batch_size"],
            "epochs": config["epochs"],
            "optimizer": config["optimizer"],
            "seed": config["seed"],
        })

        # Log environment
        mlflow.log_param("python_version", sys.version)
        mlflow.log_param("torch_version", torch.__version__)
        mlflow.log_param("cuda_version", torch.version.cuda)

        # Training
        model = build_model(config)
        for epoch in range(config["epochs"]):
            train_loss = train_one_epoch(model, train_loader, optimizer)
            val_loss, val_metrics = evaluate(model, val_loader)

            mlflow.log_metrics({
                "train_loss": train_loss,
                "val_loss": val_loss,
                **{f"val_{k}": v for k, v in val_metrics.items()},
            }, step=epoch)

        # Log final model
        mlflow.pytorch.log_model(model, "model")

        # Log artifacts (plots, configs)
        mlflow.log_artifact(config_path)
        save_evaluation_plots(model, test_loader, "plots/")
        mlflow.log_artifacts("plots/")

        return val_metrics
```

## Data Versioning with DVC

```yaml
# dvc.yaml -- Pipeline definition
stages:
  prepare_data:
    cmd: python src/data/prepare.py --config configs/base.yaml
    deps:
      - src/data/prepare.py
      - data/raw/
    outs:
      - data/processed/
    params:
      - configs/base.yaml:
          - data.split_ratio
          - data.random_seed

  extract_features:
    cmd: python src/features/extract.py --config configs/base.yaml
    deps:
      - src/features/extract.py
      - data/processed/
    outs:
      - data/features/
    params:
      - configs/base.yaml:
          - features

  train:
    cmd: python src/training/train.py --config configs/base.yaml
    deps:
      - src/training/train.py
      - src/models/
      - data/features/
    outs:
      - models/
    metrics:
      - metrics.json:
          cache: false
    plots:
      - plots/training_curve.csv:
          x: epoch
          y: loss
```

```bash
# Reproduce the full pipeline
dvc repro

# Compare experiments
dvc metrics diff

# Push data to remote storage
dvc push
```

## Configuration Management with Hydra

```python
import hydra
from omegaconf import DictConfig, OmegaConf

@hydra.main(config_path="configs", config_name="base", version_base=None)
def main(cfg: DictConfig):
    print(OmegaConf.to_yaml(cfg))

    model = build_model(
        name=cfg.model.name,
        hidden_dim=cfg.model.hidden_dim,
        num_layers=cfg.model.num_layers,
    )

    train(
        model=model,
        lr=cfg.training.lr,
        epochs=cfg.training.epochs,
        batch_size=cfg.training.batch_size,
    )

# Override from command line:
# python train.py training.lr=1e-4 model.hidden_dim=512
# python train.py --multirun training.lr=1e-3,1e-4,1e-5
```

```yaml
# configs/base.yaml
model:
  name: resnet50
  hidden_dim: 256
  num_layers: 4

training:
  lr: 1e-3
  epochs: 100
  batch_size: 32
  optimizer: adamw
  weight_decay: 0.01

data:
  dataset: cifar10
  split_ratio: [0.8, 0.1, 0.1]
  random_seed: 42
  augmentation: true
```

## Feature Engineering Patterns

```python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.impute import SimpleImputer
import joblib

def build_feature_pipeline(numeric_cols: list, categorical_cols: list) -> Pipeline:
    """Build a reproducible feature engineering pipeline."""
    numeric_transformer = Pipeline([
        ("imputer", SimpleImputer(strategy="median")),
        ("scaler", StandardScaler()),
    ])

    categorical_transformer = Pipeline([
        ("imputer", SimpleImputer(strategy="most_frequent")),
        ("encoder", OneHotEncoder(handle_unknown="ignore", sparse_output=False)),
    ])

    preprocessor = ColumnTransformer([
        ("num", numeric_transformer, numeric_cols),
        ("cat", categorical_transformer, categorical_cols),
    ])

    return preprocessor

# Save and load for reproducibility
preprocessor.fit(X_train)
joblib.dump(preprocessor, "artifacts/preprocessor.pkl")
# Later: preprocessor = joblib.load("artifacts/preprocessor.pkl")
```

## Makefile for Reproducibility

```makefile
.PHONY: setup data train evaluate all clean

setup:
	pip install -r requirements.txt
	dvc pull

data:
	python src/data/prepare.py --config configs/base.yaml

train:
	python src/training/train.py --config configs/base.yaml

evaluate:
	python src/evaluation/evaluate.py --config configs/base.yaml

all: setup data train evaluate

sweep:
	python src/training/train.py --multirun \
		training.lr=1e-3,1e-4,1e-5 \
		model.hidden_dim=128,256,512

clean:
	rm -rf outputs/ multirun/ __pycache__/
```

## Best Practices

- **Never modify raw data.** All transformations should be scripted and reproducible.
- **Pin every dependency version** including CUDA, cuDNN, and OS-level libraries.
- **Separate configuration from code.** Use YAML/JSON configs, not hardcoded values.
- **Track experiments from day one.** Retrofitting experiment tracking is painful.
- **Write tests for data preprocessing.** Shape mismatches and silent data corruption are common.
- **Use `Makefile` or `dvc repro`** so any collaborator can reproduce results with one command.
- **Version your data alongside your code** using DVC, Git-LFS, or cloud storage with manifests.

## References

- [MLflow documentation](https://mlflow.org/docs/latest/) -- Experiment tracking and model registry
- [DVC documentation](https://dvc.org/doc) -- Data version control for ML
- [Hydra documentation](https://hydra.cc/) -- Configuration management framework
- [Cookiecutter Data Science](https://drivendata.github.io/cookiecutter-data-science/) -- Project structure template
- [Made With ML](https://madewithml.com/) -- MLOps best practices for researchers

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…