Build & Run#
Local install#
Requires Python 3.10+ and pip >= 23.
Smoke-test:
Run the test suite#
Expected on CPU, ignoring tests/test_e2e_live.py: 162 passed, 4 skipped when Helm and CUDA are unavailable. Branch coverage of src/kanx is 77%. pytest tests/test_distributed_smoke.py -q runs the MirroredStrategy and torch.distributed smokes on their own.
Train from the CLI#
bash scripts/train.sh # uses configs/default.yaml
bash scripts/train.sh configs/mnist.yaml # custom config
The checkpoint is written to checkpoints/kanx_model.keras by default
(configurable in YAML).
Benchmark#
Serve the REST API locally#
Docker#
docker build -t kanx:latest .
docker run --rm -p 8000:8000 \
-e KANX_CHECKPOINT=/app/checkpoints/kanx_model.keras \
-v $(pwd)/checkpoints:/app/checkpoints \
kanx:latest
Or via compose:
Kubernetes#
docker build -t kanx:latest .
kind load docker-image kanx:latest # if you use kind
kubectl apply -f k8s/
# or: helm install kanx-api charts/kanx
kubectl port-forward svc/kanx-api 8000:80
curl http://localhost:8000/api/health
See k8s/ — Deployment with rolling updates, Service, Ingress, HPA, PVC for
model storage. charts/kanx is the parameterized form of those objects. Use
one install path in a namespace.
Environment variables#
| Variable | Default | Used by |
|---|---|---|
KANX_CONFIG |
configs/default.yaml |
api/app.py startup |
KANX_CHECKPOINT |
checkpoints/kanx_model.keras |
api/app.py startup |
KANX_MAX_BATCH |
4096 |
/api/predict guard |
TF_CPP_MIN_LOG_LEVEL |
2 (recommended in prod) |
TensorFlow stderr noise |
Reproducibility#
Seeds Python random, numpy, tf.random and tf.keras.utils.set_random_seed
in one call. Called automatically by kanx.train.