Workflow:Mistralai Client python Finetuning Job Management
| Knowledge Sources | |
|---|---|
| Domains | LLMs, Fine_Tuning, Model_Training, Python_SDK |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
End-to-end process for creating and managing fine-tuning jobs on the Mistral AI platform, from dataset upload through job execution and model management.
Description
This workflow covers the complete lifecycle of fine-tuning a Mistral AI model using the Python SDK. It includes uploading training and validation datasets in JSONL format, creating fine-tuning jobs with configurable hyperparameters, monitoring job progress, and managing the resulting fine-tuned models. The SDK provides a Files API for dataset management and a FineTuning.Jobs API for job lifecycle operations including creation, listing, retrieval, cancellation, and starting of jobs.
Usage
Execute this workflow when you need to adapt a base Mistral model to a specific domain, task, or style by training on custom datasets. This is appropriate when prompt engineering alone does not achieve the desired model behavior and you have a curated dataset of instruction-response pairs for supervised fine-tuning.
Execution Steps
Step 1: Prepare Training Data
Create training and optional validation datasets in JSONL format. Each line should contain a structured example following the instruction-tuning format expected by the model. Ensure data quality, deduplication, and proper formatting before upload.
Key considerations:
- Data must be in JSONL (JSON Lines) format
- Each line typically contains messages in the chat completion format
- Validation data is optional but recommended for monitoring overfitting
- Data quality directly impacts fine-tuning results
Step 2: Upload Dataset Files
Use the Files API to upload training and validation JSONL files to the Mistral platform. Each upload returns a file object with an ID that is used to reference the dataset in the fine-tuning job.
Key considerations:
- Call client.files.upload() with a File object containing file_name and content (file handle)
- Files can be streamed for large datasets
- Store the returned file IDs for use in job creation
- Files can be listed, retrieved, downloaded, and deleted via the Files API
Step 3: Create Fine-Tuning Job
Create a fine-tuning job specifying the base model, training file references (with optional weights), validation file references, and hyperparameters such as learning rate, number of epochs, and batch size.
Key considerations:
- Call client.fine_tuning.jobs.create() with model, training_files, and hyperparameters
- Training files are specified as dicts with file_id and optional weight
- Hyperparameters use the CompletionTrainingParametersIn model
- Key hyperparameters: training_steps, learning_rate, warmup_steps
- The job starts in a queued state
Step 4: Monitor Job Progress
Poll the job status periodically using the job retrieval endpoint, or list all jobs to check their statuses. Jobs progress through states: queued, started, running, and completed (or failed/cancelled).
Key considerations:
- Call client.fine_tuning.jobs.get(job_id=...) to check status
- Call client.fine_tuning.jobs.list() with pagination parameters (page, page_size)
- Jobs can be filtered by status
- Training metrics become available during and after training
Step 5: Start or Cancel Job
If the job requires manual start, use the start endpoint. Jobs can also be cancelled if no longer needed. Cancellation is only possible while the job is queued or running.
Key considerations:
- Call client.fine_tuning.jobs.start(job_id=...) to manually start a queued job
- Call client.fine_tuning.jobs.cancel(job_id=...) to cancel a running or queued job
- Cancelled jobs cannot be resumed
Step 6: Manage Fine-Tuned Model
After a successful fine-tuning job, the resulting model can be listed, retrieved, updated, archived, or deleted through the Models API. The fine-tuned model ID can be used in chat completion requests like any other model.
Key considerations:
- Fine-tuned models appear in client.models.list()
- Models can be archived/unarchived for organization
- Model metadata can be updated via client.models.update()
- Deleting a model is permanent
Step 7: Clean Up Resources
Delete uploaded training and validation files that are no longer needed to free storage.
Key considerations:
- Call client.files.delete(file_id=...) for each uploaded file
- Verify file deletion to avoid accumulating unused storage