Przejdź do treści
Biblioteka skilli
DevOps i chmura · Budowanie i kod

model-serving

/model-serving

Prowadzi przez wdrożenie wytrenowanego modelu za API: usługi inferencji we FastAPI, bezpieczne ładowanie artefaktów, walidacja żądań, batching, ONNX, kwantyzacja i monitoring.

Licencja
MIT
Ostatnia zmiana repozytorium
05.06.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 05.06.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Prowadzi przez wdrożenie wytrenowanego modelu za API: usługi inferencji we FastAPI, bezpieczne ładowanie artefaktów, walidacja żądań, batching, ONNX, kwantyzacja i monitoring.

Oryginalny opis (EN)

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.

Jak działa

  1. Overview
  2. When to use
  3. Minimal FastAPI service
  4. Production checklist
  5. Speed: ONNX + quantization
  6. Monitoring (don't deploy blind)
  7. Pitfalls
  8. Hand-off
Sekcje z nagłówków SKILL.md, w oryginale · 81 linii, 375 słów
Podgląd SKILL.md
---
name: model-serving
description: 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.
---

# 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

```python
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

```python
# 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`/`joblib` from 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.

Wersje

W bazie nie ma innych skilli o nazwie model-serving.

Migawka bazy z 28.10.2026 · wersja paczki b627ed578113 (skrót SHA-256 całej paczki)

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100model-serving-and-scaling
    Prowadzi wdrożenie modeli ML i LLM do inferencji online: autoskalowanie, budżety opóźnień, batching, wdrożenia canary i shadow oraz kontrolę kosztów, a także wybór między serwowaniem wsadowym, online i strumieniowym.
  • 90deploy-serve
    Projektuje i konfiguruje infrastrukturę serwowania modeli: skalowanie punktów końcowych, batching i przydział GPU.
  • 100tei-triton-serving
    Opisuje wydajne serwowanie modeli embeddingów i rerankerów w produkcji: HuggingFace TEI na GPU, Docker, kwantyzacja ONNX i FP16, dynamic batching, NVIDIA Triton i NIM.
  • 100triton
    Serwuje wytrenowane modele ML przez HTTP i gRPC w NVIDIA Triton Inference Server: ONNX, TensorRT, PyTorch, TensorFlow, OpenVINO, dynamic batching, ensembles, wersjonowanie i metryki Prometheus.
  • 100fai-inference-optimization
    Optymalizuje opóźnienia i przepustowość inferencji modeli: batching, kwantyzacja, cache, ponowne użycie KV-cache oraz dobór sprzętu i SKU.
  • 100vllm
    Obsługuje, konfiguruje, testuje wydajność i diagnozuje serwery inferencji vLLM: Docker i Kubernetes, konfiguracja modeli z kwantyzacją, API zgodne z OpenAI, benchmarki, continuous batching i aktualizacje z rollbackiem.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.