用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-mlops --skill model-serving命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | model-serving |
| version | 2.0.0 |
| sasmp_version | 1.3.0 |
| description | Master model serving - inference optimization, scaling, deployment, edge serving |
| bonded_agent | 05-model-serving |
| bond_type | PRIMARY_BOND |
| category | deployment |
| difficulty | intermediate_to_advanced |
| estimated_hours | 35 |
| prerequisites | ["mlops-basics","training-pipelines"] |
| validation | {"pre_conditions":["Completed prerequisite skills","Trained model available"],"post_conditions":["Can deploy models with BentoML/Triton","Can optimize inference latency","Can configure auto-scaling"]} |
| observability | {"metrics":["models_deployed","inference_latency","optimization_speedup"]} |
Learn: Deploy ML models for production inference with optimization.
| Attribute | Value |
|---|---|
| Bonded Agent | 05-model-serving |
| Difficulty | Intermediate to Advanced |
| Duration | 35 hours |
| Prerequisites | mlops-basics, training-pipelines |
Platform Comparison:
| Platform | Multi-framework | Dynamic Batching | Kubernetes |
|---|---|---|---|
| TorchServe | PyTorch only | ✅ | ✅ |
| Triton | ✅ | ✅ | ✅ |
| BentoML | ✅ | ✅ | ✅ |
| Seldon | ✅ | ⚠️ | ✅ |
Service Definition:
import bentoml
from bentoml.io import JSON, NumpyNdarray
@bentoml.service(resources={"gpu": 1, "memory": "4Gi"})
class ModelService:
def __init__(self):
.model = bentoml.pytorch.load_model()
() -> :
torch.no_grad():
predictions = .model(input_array)
{: predictions.tolist()}
Exercises:
Optimization Techniques:
# 1. Dynamic Quantization
quantized_model = torch.quantization.quantize_dynamic(
model, {torch.nn.Linear}, dtype=torch.qint8
)
# 2. ONNX Export
torch.onnx.export(model, sample_input, "model.onnx")
# 3. TensorRT Conversion
import tensorrt as trt
# Convert ONNX to TensorRT for NVIDIA GPUs
Expected Speedups:
| Technique | Speedup | Accuracy Impact |
|---|---|---|
| FP16 | 2-3x | <1% |
| INT8 | 3-4x | 1-2% |
| TensorRT | 5-10x | <1% |
Kubernetes HPA:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: model-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: model-serving
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
# templates/serving.py
from fastapi import FastAPI
import torch
import numpy as np
app = FastAPI()
class ProductionServer:
def __init__(self, model_path: str):
self.model = torch.jit.load(model_path)
self.model.eval()
def predict(self, inputs: np.ndarray) -> np.ndarray:
with torch.no_grad():
tensor = torch.from_numpy(inputs)
outputs = self.model(tensor)
return outputs.numpy()
server = ProductionServer("model.pt")
@app.post("/predict")
async def predict(data: dict):
inputs = np.array(data["inputs"])
predictions = server.predict(inputs)
return {"predictions": predictions.tolist()}
| Issue | Cause | Solution |
|---|---|---|
| High latency | No optimization | Apply quantization, batching |
| Cold starts | Serverless | Pre-warming, min replicas |
| OOM | Model too large | Optimize, reduce batch size |
| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2024-12 | Production-grade with optimization |
| 1.0.0 | 2024-11 | Initial release |
Master ML experiment tracking - MLflow, W&B, Neptune, versioning, reproducibility
Master feature stores - Feast, data validation, versioning, online/offline serving
Production-grade ML infrastructure with Kubernetes, auto-scaling, and cost optimization
基于 SOC 职业分类