Sub topic 15
Fine-tuning, Provisioned Throughput, and External Models
This chapter covers three options for when the default pay-per-token Foundation Model APIs no longer fit: customizing a model, reserving capacity, and routing to models hosted elsewhere. It assumes you have called a served model from Python, can read an evaluation result, and know what a serving endpoint is.
When the defaults stop fitting
Most applications start with a pay-per-token foundation model and a good prompt. Three problems push you toward something else:
- Quality: the model misses your domain's style, format, or vocabulary even with good prompts and retrieval.
- Performance: you need predictable latency and throughput, or rate limits on shared capacity block you.
- Choice of provider: you must use a model that Databricks does not host, or one your organization already licenses.
Each problem has a matching feature. The table summarizes them.
| Need | Feature | What changes |
|---|---|---|
| Better task fit | Fine-tuning | The model weights change |
| Steady throughput | Provisioned throughput | Capacity is reserved for you |
| Third-party model | External model endpoint | Databricks proxies requests to another provider |
Fine-tuning
Fine-tuning continues training a base model on your own examples so it learns a behavior, such as a fixed output format or a tone. It teaches behavior well. It teaches facts poorly, and facts go stale. For facts, use RAG from the earlier chapters.
Try these steps first, in order:
- Improve the system prompt and add examples to it.
- Add retrieval if the model lacks knowledge.
- Measure with your evaluation dataset. Fine-tune only if a gap remains.
Fine-tuning needs a training dataset of prompt and response pairs, stored in Unity Catalog or a volume. Data quality matters more than volume, so a few hundred clean examples often beat thousands of noisy ones. Keep a held-out set and score both the base and tuned models with the same scorers. The tuned model is registered in Unity Catalog, so the governance from earlier chapters applies to it.
Which base models can be tuned, and how, changes between releases. Check the current Databricks documentation before you plan.
Provisioned throughput
Pay-per-token endpoints share capacity and have rate limits. Provisioned throughput serves a model on capacity reserved for you. You pay for the reserved capacity whether or not you use it, instead of paying per token.
Choose it when:
- the application is in production with steady or high traffic,
- you need consistent latency,
- you serve a fine-tuned model, which needs dedicated capacity.
Capacity is set in units of tokens per second. You pick a range, and the endpoint can scale between the minimum and maximum. If you set the minimum to zero, the endpoint can scale to zero when idle, but the first request after idle waits for a cold start.
External models
An external model endpoint is a serving endpoint that forwards requests to a model hosted by another provider. Your code still calls the same chat completions client, so switching providers means changing the endpoint name, not the application.
Benefits of the proxy approach:
- One interface for all models.
- Provider API keys stay in Databricks secrets, not in application code.
- AI Gateway features such as rate limits and usage tracking apply to the endpoint.
The provider bills you directly. Also, your data leaves Databricks, so check that this meets your data policies.
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
client = w.serving_endpoints.get_open_ai_client()
# The same call works for a pay-per-token, provisioned, or external endpoint.
for endpoint in ["<pay-per-token-endpoint>", "<external-endpoint>"]:
response = client.chat.completions.create(
model=endpoint,
messages=[{"role": "user", "content": "Reply with the single word: ready"}],
max_tokens=10,
)
print(endpoint, "->", response.choices[0].message.content)Because the interface is the same, you can run your evaluation dataset against several endpoints and compare quality and cost before you commit.
Exercise
Your support bot gives correct answers but always ignores the required JSON output format, even after prompt changes. Traffic is light. Which feature do you try first, and does it require provisioned throughput?
Show answer
Fine-tune a model on examples of the required JSON format, after confirming with your evaluation set that prompt changes did not close the gap. Serving a fine-tuned model needs dedicated capacity, so it would be served with provisioned throughput even though traffic is light.
Exercise
Why is an external model endpoint useful if you already call the OpenAI-compatible client?
Show answer
The endpoint keeps the provider key in Databricks secrets, gives you one interface for all models, and lets AI Gateway apply rate limits and usage tracking. Switching providers only changes the endpoint name.