model-serving
Skill11 starsChanged 6 months agoMITView on GitHub
Use when deploying a trained model behind an API. Covers FastAPI inference services, loading artifacts safely, request validation, batching, ONNX/quantization for speed, health checks, and monitoring.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- DamonRabie/agents_librarytheir own version, first seen Aug 22, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- DamonRabie/agents_library★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- data-cleaningSkill
- experiment-trackingSkill
- exploratory-data-analysisSkill
- feature-engineeringSkill
- hyperparameter-tuningSkill
- imbalanced-dataSkill
- llm-finetuningSkill
- ml-debuggingSkill
- model-evaluationSkill
- pandas-patternsSkill
- pytorch-training-loopSkill
- rag-pipelineSkill
- reproducible-mlSkill
- sklearn-pipelinesSkill
The file
Files
Model Serving
Overview
Serving turns a saved model into a reliable, low-latency API. The concerns shift from accuracy to latency, throughput, robustness, and observability. The model artifact and its preprocessing must travel together (use the pipeline from sklearn-pipelines).
When to use
- A validated model needs to be callable by other systems.
- Moving from notebook to production.
Minimal FastAPI service
from fastapi import FastAPI
from pydantic import BaseModel
import joblib, numpy as np
app = FastAPI()
model = joblib.load("model.joblib") # full pipeline: preprocessing + estimator
class Features(BaseModel):
age: float
income: float
country: str
plan: str
@app.get("/health")
def health():
return {"status": "ok"}
@app.post("/predict")
def predict(f: Features):
import pandas as pd
X = pd.DataFrame([f.model_dump()])
proba = float(model.predict_proba(X)[0, 1])
return {"probability": proba, "label": int(proba >= 0.5)}Run: uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4.
Production checklist
- Load the model once at startup, not per request.
- Validate inputs with Pydantic; return 422 on bad payloads.
- Health/readiness endpoints for orchestrators (k8s).
- Batch requests where possible to raise throughput.
- Timeouts + graceful degradation for downstream calls.
- Version the model in the response (
model_version) for traceability. - Pin the artifact's training env — preprocessing must match training exactly.
Speed: ONNX + quantization
# Export sklearn/torch model to ONNX, then serve with onnxruntime
import onnxruntime as ort
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
out = sess.run(None, {"input": X.astype(np.float32)})ONNX runtime + dynamic quantization often gives 2-4x CPU speedups. For LLMs, use vLLM/TGI rather than rolling your own.
Monitoring (don't deploy blind)
- Operational: latency p50/p95/p99, error rate, throughput.
- ML-specific: input feature drift, prediction distribution shift, and (when labels arrive) live metric decay.
- Alert on drift — a silently degrading model is worse than a down one.
Pitfalls
- Training/serving skew — different preprocessing in prod than training. Ship the pipeline, not just the estimator.
- Loading the model per request — kills latency.
- No input validation — one bad payload takes down the worker.
pickle/joblibfrom untrusted sources — only load artifacts you produced.- No monitoring — you won't notice drift until users do.
Hand-off
A containerized, monitored endpoint serving the exact pipeline that model-evaluation validated and experiment-tracking registered.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

