Skip to content

Tầng model và serving

Tầng model và serving quyết định model nào chạy inference, chạy ở đâu, request được route như thế nào và toàn bộ stack phía trên phải sống trong giới hạn vận hành nào.

Model layer không phải workflow framework. Nó quyết định năng lực suy luận, chi phí, độ trễ, context window, khả năng tool-calling và boundary dữ liệu.

Layer này sở hữu điều gì

Mối quan tâmVì sao quan trọng
Model capabilityCoding, planning, extraction, classification, tool calling, chất lượng đa ngôn ngữ
Context windowAgent có đủ chứa specs, logs, retrieved context và diffs không
LatencyProduct có cảm giác interactive hay batch-oriented
CostHệ thống có scale được sau demo không
Data boundaryPrompt và output có được rời khỏi môi trường kiểm soát không
AvailabilityKhi provider lỗi thì có fallback model hoặc queue không
Serving operationsTeam có phải quản lý GPU capacity, scaling, upgrades và monitoring không

Provider-hosted vs self-hosted

OptionHợp nhất khiTradeoff
Hosted frontier modelreasoning khó, coding, multimodal, tool usecost, latency, data boundary concerns
Hosted smaller modelclassification, extraction, simple routingreasoning yếu hơn
Local/self-hosted modeldata control, offline, cost predictabilityops burden, capability thường yếu hơn frontier
Model routertối ưu mixed workloadcần policy và observability

Hosted models thường là cách nhanh nhất để có capability cao. Self-hosted models hợp khi data boundary, workload lớn có thể dự đoán, offline operation hoặc platform control quan trọng hơn maximum frontier capability.

Model router pattern

mermaid
flowchart LR
    A[Application hoặc agent harness] --> B[Model router]
    B --> C[Hosted frontier model]
    B --> D[Cheaper hosted model]
    B --> E[Local/self-hosted model]
    E --> F[vLLM / Ollama / TGI]
    B --> G[Cost, latency, safety, context policy]

Model router hữu ích khi mỗi loại task cần model khác nhau:

TaskRouting choice tốt
Architecture reasoningstrongest reasoning model
Code generationstrong coding model
Classificationcheaper fast model
Embeddingembedding-specific model
Summarization dữ liệu nhạy cảmlocal hoặc private model
Bulk extractioncheaper model có structured-output checks

Router không nên chỉ là một switch statement. Nó phải log quyết định, enforce data policy, track cost và cho phép evaluate từng route.

Local LLM pattern

Local models có giá trị khi:

  1. Dữ liệu không được rời khỏi môi trường kiểm soát.
  2. Workload đủ lặp lại để justify infrastructure.
  3. Task không cần frontier-level reasoning.
  4. Team vận hành được GPU, model updates, quantization và serving metrics.

Local serving không tự động rẻ hơn. Cần tính GPU utilization, maintenance, latency tuning, evaluation và incident response.

Decision matrix

ConstraintNên ưu tiên
Chất lượng reasoning cao nhấtHosted frontier model
Data boundary nghiêm ngặtLocal/self-hosted hoặc private managed deployment
Nhiều call đơn giản volume caoSmaller hosted model hoặc local batch serving
Nhiều team với use case khác nhauLiteLLM-style gateway/router
Cần offline operationLocal/self-hosted
Cần thử nghiệm nhanhHosted model trước
Enterprise regulated deploymentRouter có audit, retention và approval policy

Hướng dẫn adoption step-by-step

  1. Liệt kê workloads: coding, support, RAG answering, extraction, classification, summarization, embeddings.
  2. Gắn risk cho từng workload: public, internal, confidential, regulated.
  3. Định nghĩa capability cần có: context length, tool calling, structured output, multilingual support, latency.
  4. Bắt đầu với một hosted model cho path khó nhất và một cheaper model cho path đơn giản.
  5. Chỉ thêm model router khi đã có ít nhất hai routing policy thật.
  6. Chỉ thêm self-hosted serving sau khi evals chứng minh local model đủ tốt.
  7. Log route, model, token count, latency, failure và cost cho mọi call.
  8. Thêm fallback policy cho outage, rate limit và quality regression.

Failure modes

Failure modeHậu quảCách tránh
Chọn model yếu cho coding phức tạpAgent trông như thiếu discipline nhưng thật ra model underpoweredCapability evals trước rollout
Không có routing policyExpensive models xử lý cả task trivialCost-aware routing
Không data classificationPrompt confidential đi sai providerData boundary policy
Self-host quá sớmPlatform team biến thành GPU operations teamChứng minh bằng cost và data analysis
Không fallbackProvider outage thành product outageFallback và queue policy
Không telemetryCost và latency problems vô hìnhObservability per model route

References

Built as a static bilingual AI engineering stack guide.