Pular para o conteúdo principal

Capítulo 1: Servindo LLMs em Escala

Frameworks de Servimento de LLM​

FrameworkMelhor ParaPrincipais Recursos
vLLMAlto throughputPagedAttention, batching contínuo
TGIModelos HuggingFaceFlash attention, paralelismo de tensores
TritonMulti-frameworkBatching, ensemble de modelos
OllamaDeploy localConfiguração fácil, muitos modelos

Deploy do vLLM​

# Start vLLM server
from vllm import LLM, SamplingParams

llm = LLM(
model="meta-llama/Llama-2-7b-chat-hf",
tensor_parallel_size=2, # Use 2 GPUs
gpu_memory_utilization=0.9,
)

sampling_params = SamplingParams(
temperature=0.7,
top_p=0.95,
max_tokens=512
)

# Batch inference
prompts = ["What is MLOps?", "Explain LLMOps"]
outputs = llm.generate(prompts, sampling_params)

Respostas em Streaming​

from fastapi import FastAPI
from fastapi.responses import StreamingResponse

@app.post("/chat/stream")
async def stream_chat(request: ChatRequest):
async def generate():
async for token in llm.stream(request.message):
yield f"data: {token}\n\n"
yield "data: [DONE]\n\n"

return StreamingResponse(generate(), media_type="text/event-stream")

Próximo: Capítulo 2: Otimização de Inferência