FromZero2AI
CoursesPlaygroundBlog
Support on Ko-fi
LLM Fine-Tuning & Adaptation • Module C: Serving Fine-Tuned ModelsLesson 7: Serving Fine-Tuned Models in Production
PreviousNext

Lesson 7: Serving Fine-Tuned Models in Production

Merge LoRA adapters back into the base model for deployment, serve with vLLM for high-throughput inference, and run locally with Ollama. Compare serving options by latency and cost.

Built with AI for beginners. Free forever.

Support on Ko-fi•About•Blog•Privacy Policy•Terms of Service

Training a model is 20% of the work. Serving it reliably at low cost with good latency is the other 80%. This lesson covers the serving stack for fine-tuned open-source models.

Serving Options Explorer

Select a serving option to see when it fits, cost tier, latency characteristics, and deployment code.

HF Inference API

When to use: Prototyping and low-traffic scenarios where you want zero infrastructure setup. Push your model to the Hugging Face Hub and start calling it immediately.
Cost tier: Low (free tier for shared; $0.06–$0.60/hr for dedicated)
Latency: Medium — shared infrastructure means variable cold-start latency of 2–10 s
from huggingface_hub import InferenceClient

# After pushing your model to HF Hub:
hf_client = InferenceClient(model="your-username/llama-3b-product-extractor")

def extract_product(description: str) -> dict:
    import json
    prompt = (
        "### Instruction:\nExtract product JSON.\n\n"
        f"### Input:\n{description}\n\n"
        "### Response:\n"
    )
    response = hf_client.text_generation(
        prompt,
        max_new_tokens=200,
        do_sample=False,
        return_full_text=False,
    )
    return json.loads(response.strip())

result = extract_product("The Sony WH-1000XM5 headphones, priced at $349.99, feature 30hr battery.")
print(result)
# → {"name": "Sony WH-1000XM5", "price": "$349.99", "features": ["30hr battery"]}

Serving Options Compared

OptionLatencyCostWhen to Use
HF Inference APIMedium (shared)Low (free tier)Prototyping, low traffic
HF Dedicated EndpointFast (dedicated)Medium ($0.60–$6/hr)Production, consistent traffic
vLLM on GPU VMFastest (batching)GPU VM cost (~$1–3/hr)High traffic, optimized throughput
Modal / ReplicateMediumPer-token, no idle costBursty, unpredictable traffic
Ollama (local)VariableHardware cost onlyLocal dev, private data

Choosing your serving stack: Start with HF Inference API during development. Move to vLLM on a dedicated GPU when you cross 50 requests/minute. Use Modal or Replicate for unpredictable traffic spikes. GGUF/CPU for privacy-critical deployments.

vLLM tip: best for >100 requests/minute
GGUF quantization cuts 7B model size from 14 GB to 4 GB

You are ready for the capstone: fine-tuning a domain expert model end-to-end, deploying it, and benchmarking it against a prompted frontier model.