fqih/.mycc-setup/ml-deployment

Claude Code and agent skill by fqih/.mycc-setup

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when deploying ML models to production — model serving frameworks (FastAPI, BentoML, vLLM, Ollama, KServe, Triton), monitoring, autoscaling, ONNX/TensorRT optimization, GPU serving. Trigger on "deploy model", "model serving", "inference", "vllm", "triton", "fastapi model".

Install

npx vskill@latest install fqih/.mycc-setup/ml-deployment

SKILL.md

The same SKILL.md was published earlier as fqih/.mycc-setup/ml-deployment.

ml-deployment

Production serving patterns untuk ML models — bukan prototype.

Serving framework selection

FrameworkBest forProsCons
FastAPI + UvicornCustom inference, small modelSimple, flexibleManual scaling, no batching
BentoMLMid-size, full pipelinePipeline versioning, multi-modelLearning curve
vLLMLLM serving (HuggingFace)PagedAttention, very fastLLM-only
OllamaLocal/edge LLMZero-config, single binarySingle-machine
Text Generation Inference (HF)LLM serving prodMulti-GPU, quantizationLLM-only
Triton Inference ServerMulti-model, GPUBatching, concurrentHeavy setup
KServeKubernetes-nativeCloud-nativeNeeds K8s
TorchServePyTorch modelsAWS-supportedPyTorch-only
TensorFlow ServingTF modelsBattle-testedTF-only
ONNX RuntimeCross-framework ONNXPortable, fastNeed ONFX conversion

Pick by scenario:

  • LLM, production, GPU available → vLLM
  • LLM, local dev → Ollama (sudah ada di skill local-ml-gpu)
  • Custom inference, sklearn/PyTorch → BentoML atau FastAPI
  • K8s setup → KServe
  • Multi-model GPU server → Triton

FastAPI pattern (most common)

python
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import joblib
import numpy as np
from contextlib import asynccontextmanager
model = None
@asynccontextmanager
async def lifespan(app: FastAPI):
global model
model = joblib.load("model.pkl")
yield
# cleanup if needed
app = FastAPI(lifespan=lifespan)
class PredictRequest(BaseModel):
features: list[float]
class PredictResponse(BaseModel):
prediction: float
confidence: float
model_version: str
@app.post("/predict", response_model=PredictResponse)
async def predict(req: PredictRequest) -> PredictResponse:
if model is None:
raise HTTPException(503, "Model not loaded")
arr = np.array([req.features])
prob = model.predict_proba(arr)[0]
pred = model.predict(arr)[0]
return PredictResponse(
prediction=float(pred),
confidence=float(prob.max()),
model_version="1.0.0",
)
# Run: uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4

BentoML pattern

python
import bentoml
from bentoml.io import JSON
# Save model
@bentoml.artifacts
class SklearnModelArtifact:
def __init__(self, model):
self.model = model
@bentoml.service(
resources={"cpu": "2"},
traffic={"timeout": 30},
)
class PredictService:
model_ref = bentoml.models.BentoModel("classifier:latest")
def predict(self, features: JSON) -> JSON:
arr = np.array([features["data"]])
prob = self.model_ref.predict_proba(arr)[0]
return {"prediction": int(self.model_ref.predict(arr)[0]),
"confidence": float(prob.max())}
# Build + serve
# bentoml build
# bentoml serve PredictService:latest

vLLM pattern (LLM serving)

python
from vllm import LLM, SamplingParams
llm = LLM(
model="meta-llama/Llama-3.1-8B-Instruct",
tensor_parallel_size=1, # multi-GPU
gpu_memory_utilization=0.85,
quantization="awq", # atau "gptq", "bitsandbytes"
)
# Single inference
sampling = SamplingParams(temperature=0.7, top_p=0.9, max_tokens=256)
outputs = llm.generate(["Halo, siapa kamu?"], sampling)
# OpenAI-compatible server
# vllm serve meta-llama/Llama-3.1-8B-Instruct --port 8000

ONNX optimization

Convert PyTorch/sklearn ke ONNX untuk inference lebih cepat + portable:

python
import torch
import onnx
# Export
model = MyModel()
model.load_state_dict(torch.load("model.pt"))
model.eval()
dummy = torch.randn(1, 3, 224, 224)
torch.onnx.export(
model,
dummy,
"model.onnx",
input_names=["input"],
output_names=["output"],
dynamic_axes={"input": {0: "batch"}, "output": {0: "batch"}},
opset_version=17,
)
# Run via ONNX Runtime
import onnxruntime as ort
sess = ort.InferenceSession("model.onnx", providers=["CUDAExecutionProvider"])
outputs = sess.run(None, {"input": dummy.numpy()})

Untuk AMD ROCm: providers=["ROCMExecutionProvider"].

Batching untuk throughput

python
# Dynamic batching — kumpulkan request dalam window, kirim sebagai batch
from collections import deque
import asyncio
batch_queue = deque(maxlen=32)
async def predict_batched(features_list):
batch_queue.append(features_list)
if len(batch_queue) >= 8 or timeout_reached():
batch = list(batch_queue)
batch_queue.clear()
arr = np.array(batch)
return model.predict(arr)

Triton + BentoML punya dynamic batching built-in.

Quantization

MethodSize reductionAccuracy lossTool
FP32 → FP162xMinimalNative
FP32 → INT8 (PTQ)4x~1%ONNX Runtime, TFLite
FP16 → INT4 (GPTQ)4x~2-3%AutoGPTQ
FP16 → INT4 (AWQ)4x~1-2%AutoAWQ
FP16 → INT4 (bitsandbytes)4x~2%bitsandbytes

Untuk LLM: AWQ atau GPTQ untuk quality terbaik.

Monitoring

Track per-request:

  • Latency (p50, p95, p99)
  • Throughput (req/s)
  • Error rate
  • Input distribution drift
  • Output confidence drift
  • GPU util + VRAM
python
from prometheus_client import Counter, Histogram
REQUEST_COUNT = Counter("ml_requests_total", "Total predict requests", ["model", "status"])
LATENCY = Histogram("ml_request_duration_seconds", "Request latency", ["model"])
@app.post("/predict")
async def predict(req: PredictRequest):
with LATENCY.labels(model="classifier").1").time():
try:
result = model.predict(...)
REQUEST_COUNT.labels(model="classifier", status="success").inc()
return result
except Exception as e:
REQUEST_COUNT.labels(model="classifier", status="error").inc()
raise

Plus: log input/output ke MLflow untuk tracking produksi + retraining data.

Autoscaling

TriggerWhen
CPU/GPU util > 70%Scale up
Queue depth > NScale up
Latency p95 > SLOScale up
Request rate < baselineScale down

Platform:

  • Kubernetes + HPA (HorizontalPodAutoscaler)
  • Cloud Run / App Runner: traffic-based auto
  • Modal, Replicate, BentoCloud: managed

Health checks

python
@app.get("/health")
async def health():
return {"status": "ok", "model_loaded": model is not None}
@app.get("/ready")
async def ready():
# lebih strict — cek model bisa inference
if model is None:
raise HTTPException(503)
test = model.predict(np.zeros((1, NUM_FEATURES)))
return {"status": "ready"}

Common pitfalls

PitfallSolusi
Model load blocking startupUse lifespan async context manager
Input validation skipPydantic strict types, return 422 for bad input
GPU OOM saat concurrentDynamic batching + max concurrent = 1 per GPU
Cold start slowWarm-up inference di startup, cache weights in memory
Numerical drift across versionsPin numpy/torch versions di lock file
PII leak di logsRedact/hash sensitive fields sebelum log
Model artifact di repo (besar)Simpan di S3/GCS/HF Hub, download at startup
No rollback planVersioning via BentoML/MLflow registry, stage transitions

Checklist before prod

  • [ ] Load test: target RPS tercapai
  • [ ] Latency p95 < SLO
  • [ ] Error rate < 0.1%
  • [ ] GPU/CPU headroom untuk 2x peak
  • [ ] Health + ready endpoints
  • [ ] Metrics ke Prometheus
  • [ ] Logs structured (JSON)
  • [ ] Model version + git SHA di response
  • [ ] Graceful shutdown (in-flight finish)
  • [ ] Rollback tested

Invokation

Auto-trigger saat:

  • Edit file yang import bentoml, vllm, fastapi + model
  • User sebut "deploy", "serve", "inference", "endpoint"
  • Code pattern: predict/score/forward + http endpoint

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/fqih/.mycc-setup/ml-deployment/badge)](https://verified-skill.com/skills/fqih/.mycc-setup/ml-deployment)

Something wrong with this skill or its page? Tell us.