End-to-end click-through-rate prediction system built around a DCN-v2 model, stable C++ feature hashing, calibrated inference, Redis-backed calibration overrides, and a production-style gRPC serving API.
The project is designed for the 45M-example Criteo display advertising dataset and includes a lightweight synthetic path so the full train -> checkpoint -> predict loop can be tested locally without shipping the dataset.
- DCN-v2 CTR model in PyTorch with hashed categorical embeddings and explicit two-way feature crosses.
- Streaming Criteo TSV loader for 13 dense features and 26 categorical features.
- Custom pybind11 C++ feature hashing extension with a deterministic Python fallback.
- Platt-style sigmoid calibration saved in checkpoints and optionally overridden from Redis.
- gRPC API with single and batch prediction RPCs.
- Smoke tests that train a tiny model, reload the checkpoint, and run calibrated prediction.
flowchart LR
A["Criteo TSV or synthetic data"] --> B["CriteoPreprocessor"]
B --> C["C++ / Python feature hashing"]
C --> D["Hashed embeddings + dense features"]
D --> E["DCN-v2 cross network"]
D --> F["Deep MLP tower"]
E --> G["CTR logit"]
F --> G
G --> H["Sigmoid calibration"]
H --> I["gRPC Predict / BatchPredict"]
J["Redis calibration key"] --> H
Use Python 3.11 or 3.12. PyTorch wheels are not expected to work on the Homebrew Python 3.14 interpreter.
python3.12 -m venv .venv
. .venv/bin/activate
python -m pip install -e ".[dev]"
make PYTHON=.venv/bin/python proto
pytestTrain a tiny smoke checkpoint:
ad-ranker train \
--config configs/dcnv2_criteo.yaml \
--synthetic-examples 4096 \
--epochs 1 \
--output artifacts/smoke_model.ptRun a local prediction:
ad-ranker predict \
--checkpoint artifacts/smoke_model.pt \
--features examples/sample_request.jsonDownload the Criteo display advertising dataset separately and keep it under data/, which is intentionally gitignored.
Expected TSV column order:
label, I1-I13, C1-C26
Run training:
ad-ranker train \
--config configs/dcnv2_criteo.yaml \
--data data/criteo/train.txt \
--validation-data data/criteo/test.txt \
--epochs 2 \
--output artifacts/dcnv2_criteo.ptThe resume benchmark target for this project is 0.806 test AUC on Criteo with hashed categorical embeddings and feature crosses. The checked-in tests use synthetic data only, so they validate the pipeline mechanics rather than reproducing the full benchmark.
Start Redis if you want runtime calibration overrides:
docker compose up redisServe a checkpoint:
ad-ranker serve \
--checkpoint artifacts/dcnv2_criteo.pt \
--host 0.0.0.0 \
--port 50051 \
--redis-url redis://localhost:6379/0The gRPC service is defined in proto/ad_rank.proto. It exposes:
Predict(PredictRequest) -> PredictResponseBatchPredict(BatchPredictRequest) -> BatchPredictResponse
Benchmark a running server:
python scripts/benchmark_grpc.py \
--target localhost:50051 \
--requests 2000 \
--concurrency 32Checkpoints store a sigmoid calibrator:
{"scale": 1.0, "bias": 0.0}At serving time, Redis can override it from key ad_ranker:calibration:
redis-cli set ad_ranker:calibration '{"scale": 0.97, "bias": -0.04}'This lets calibration be refreshed without rebuilding the model artifact.
cpp/ pybind11 C++ feature hashing module
configs/ DCN-v2 Criteo training config
proto/ gRPC service definition
scripts/ protobuf helper and latency benchmark
src/neural_ad_ranking/ package source
tests/ hashing, model, training, prediction smoke tests
Current local validation:
6 passed
The smoke suite confirms deterministic hashing, feature-cross preprocessing, DCN-v2 forward shape, checkpoint creation, checkpoint reload, and calibrated prediction.