Fine-tuning an LLM on Databricks is as much a planning exercise as a training exercise. This playbook gives you a repeatable workflow for versioning data in Delta Lake, selecting a practical training approach, tracking experiments with MLflow, estimating run costs, and deciding whether a model is ready for production.
Overview
A reliable Databricks fine-tuning project should answer four questions before a training job begins:
- Which model, dataset version, and training method are being used?
- What will the run cost under the selected compute configuration?
- How will quality be measured against the base model and a simpler baseline?
- How will the resulting model be packaged, deployed, monitored, and rolled back?
The platform is useful because these concerns can be handled in one governed environment. Delta Lake can hold versioned training and evaluation data, while MLflow can record parameters, metrics, artifacts, and model versions. Hugging Face Transformers, PEFT, or another supported training framework can provide the fine-tuning loop. The exact libraries, runtimes, GPU types, and serving options should be checked against the Databricks documentation and your workspace configuration before implementation.
Fine-tuning is not automatically the best answer for every LLM application. If the problem is missing or changing knowledge, a retrieval-augmented generation workflow may be more appropriate. If the problem is inconsistent instructions, start with prompt engineering and a regression test set. Fine-tuning is most useful when the model needs to learn a repeatable behavior, format, style, classification boundary, or domain-specific response pattern that prompting alone does not deliver consistently.
For related decisions, compare this workflow with the Databricks RAG tutorial and the Databricks prompt engineering guide.
How to estimate
Build the estimate before creating the final training job. The purpose is not to predict the bill to the cent; it is to expose the assumptions that drive cost and make alternatives comparable.
Use this basic model:
Estimated training cost = hourly compute rate × number of workers × elapsed training hours + storage, job, and supporting-service costs
If the workspace uses a different billing model, substitute the relevant unit in place of the hourly rate. Record whether the rate includes only compute or also includes other charges. Keep training, evaluation, data preparation, and inference estimates separate. Combining them can make an inexpensive training run appear expensive, or hide the ongoing cost of serving the model.
Estimate elapsed time from a small pilot rather than from the number of examples alone. A pilot should use a representative sample and record:
- Number of training examples and tokens processed
- Sequence length and packing strategy
- Batch size, gradient accumulation, and number of epochs
- GPU or accelerator configuration
- Steps per second, evaluation duration, checkpoint frequency, and failures
For example, suppose an illustrative pilot uses two workers at an assumed rate of R currency units per worker-hour and runs for H hours. Its compute estimate is 2 × R × H. This is a planning example, not a current Databricks price. Replace R with the applicable workspace rate, and add storage and other charges separately. Run a low, expected, and high scenario by changing H and the worker count. A range is more useful than false precision.
Track the estimate and the actual result in an MLflow run or an accompanying Delta table. Include the pricing reference date, runtime identifier, cluster configuration, dataset version, and job duration. This creates an audit trail when a future run costs more or less than expected.
Inputs and assumptions
1. Data and versioning
Store the source examples in a governed Delta table or another controlled repository, then create explicit training, validation, and test snapshots. Do not let the test set change during experimentation. Record a dataset version, data-preparation code version, filtering rules, and any redaction or deduplication steps.
For instruction tuning, use a consistent schema such as system context, user instruction, and assistant response. For classification, store the label definition and permitted labels with the dataset. For preference tuning, document how preference pairs were created and what makes one answer better than another. Data quality usually affects the outcome more than adding another round of unexamined hyperparameter changes.
2. Model and training method
Record the base model identifier, tokenizer, context length, precision, and license or usage constraints relevant to your organization. Decide whether full-parameter training is necessary. Parameter-efficient methods such as adapters or low-rank updates can reduce memory requirements and make experiments easier to compare, but they still require validation on your task.
Keep an initial hyperparameter template in source control:
base_model: "model-identifier-to-verify"
dataset_version: "delta-table-version-or-run-id"
method: "peft-or-full-fine-tune"
max_sequence_length: 2048
learning_rate: 0.00002
num_train_epochs: 2
per_device_batch_size: 2
gradient_accumulation_steps: 8
warmup_ratio: 0.03
evaluation_strategy: "steps"
evaluation_steps: 200
save_steps: 200
random_seed: 42
compute_profile: "workspace-specific-cluster-config"
These values are starting assumptions, not universal recommendations. Tune one or two influential variables at a time, keep the seed where practical, and avoid selecting a model solely because it performs well on a single test slice.
3. Compute and runtime
Select a Databricks runtime and compute configuration that supports the chosen framework and accelerator. Verify compatibility among the runtime, CUDA or driver components where applicable, Transformers, PEFT, PyTorch, and MLflow packages. Pin package versions for reproducibility and test the environment with a short smoke run before committing to a longer job.
Use autoscaling or interruption-prone capacity only when the workload and checkpoint strategy can tolerate it. Save checkpoints to durable storage, but choose checkpoint frequency deliberately: frequent saves improve recovery while increasing storage and I/O overhead.
4. Evaluation plan
Define success before training. Include task metrics such as exact match, F1, accuracy, or structured-output validity where appropriate. For generative tasks, combine automated checks with a reviewed sample. Measure helpfulness and correctness separately when possible, and include adversarial, long-input, ambiguous, and out-of-domain examples.
Compare at least three systems: the base model, the fine-tuned model, and a prompt-only or retrieval-based baseline if relevant. Use the same test set and inference settings. The Databricks LLM evaluation guide provides a useful companion framework for test sets and regression testing.
Worked examples
Example A: structured support classification
A team wants an LLM to assign a support message to one of twelve categories and return a strict JSON object. It first creates a versioned Delta dataset, removes duplicate examples, and reserves a test set containing rare categories and difficult wording. A short pilot measures throughput and identifies whether sequence length or evaluation frequency is the main time driver.
The team logs the base model, adapter configuration, data version, labels, seed, training duration, and compute estimate in MLflow. It then compares the base model with a prompt-only baseline and the fine-tuned adapter. Success requires both improved classification quality and valid JSON output. If the adapter improves average accuracy but performs poorly on rare categories, the team revises the data balance or label definitions before increasing compute.
Example B: domain-specific response style
A documentation team wants answers to follow a consistent internal format. Before fine-tuning, it tests a prompt template and retrieval from approved documentation. If the required facts change frequently, retrieval remains important even after tuning because fine-tuning should not be treated as a replacement for current source data.
The training estimate includes data preparation, one pilot, several controlled experiments, final training, and evaluation. The production decision considers quality, latency, model size, adapter management, and the cost of serving. A cheaper training run is not a success if it creates an expensive or difficult-to-monitor deployment.
Compact cost and evaluation checklist
- Write down the compute rate or billing unit and its effective date.
- Estimate low, expected, and high elapsed time.
- Separate pilot, final training, evaluation, storage, and serving costs.
- Version the dataset, code, runtime, packages, and model artifacts.
- Log every run in MLflow, including failed runs and configuration changes.
- Compare against the base model and a non-fine-tuned baseline.
- Check quality by slice, not only by an overall average.
- Test safety, privacy, prompt injection resistance, and structured-output validity where applicable.
- Define a rollback model and a monitoring owner before deployment.
When to recalculate
Recalculate the estimate whenever a cost-driving input changes: compute type, worker count, runtime, package stack, dataset size, sequence length, epoch count, checkpoint policy, or expected number of experiments. Recalculate after pricing or billing inputs change, and whenever a benchmark shows a material change in throughput or quality.
Review the evaluation plan on the same schedule. Add representative production failures to a governed test set, but keep a protected regression set unchanged so improvements remain comparable. Recheck drift when user language, product terminology, labels, or source documents change. A model that passed its original evaluation may no longer meet requirements after the task evolves.
Before each production release, create a short decision record containing the current cost estimate, actual run cost, dataset version, evaluation results, known failure modes, and rollback plan. If the objective is changing knowledge rather than behavior, reassess whether retrieval or prompt optimization is a better investment than another fine-tuning run. For deployment and governance considerations, consult the Databricks AI governance checklist and the AI inference cost and performance optimization checklist.
The practical next step is to run one small, representative pilot, record its actual throughput and quality, and update the worksheet before scaling. Repeating that cycle turns Databricks fine-tuning from a one-off experiment into a measurable model development process.