Workflow:Cohere ai Cohere python Model Finetuning
| Knowledge Sources | |
|---|---|
| Domains | LLMs, Fine_Tuning, Model_Training, API_Client |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
End-to-end process for fine-tuning Cohere language models on custom datasets through the Cohere Fine-tuning API, including dataset management, model creation, training monitoring, and inference with the fine-tuned model.
Description
This workflow covers the full lifecycle of fine-tuning a Cohere model: uploading and validating a training dataset, configuring the fine-tuning job with hyperparameters and base model selection, monitoring training progress through events and step metrics, and using the resulting fine-tuned model for inference. The SDK provides a dedicated finetuning sub-client with typed methods for all CRUD operations on fine-tuned models.
Usage
Execute this workflow when you need to adapt a Cohere base model to a specific domain, task, or communication style using your own training data. Fine-tuning is appropriate when prompt engineering alone does not achieve the required quality, and you have sufficient labeled examples in the appropriate format (e.g., instruction-tuning pairs for chat models, query-passage pairs for rerankers).
Execution Steps
Step 1: Prepare and Upload the Training Dataset
Create a dataset in the required format for your fine-tuning task type (chat, classify, or rerank). Upload it using the datasets sub-client (client.datasets.create), which accepts file uploads with a specified dataset_type. Wait for the dataset to pass validation.
Key considerations:
- Dataset types include chat-finetune-input, single-label-classification-finetune-input, reranker-finetune-input, and others
- The dataset undergoes server-side validation; poll with client.datasets.get() or use client.wait() to block until validated
- Validation statuses progress through unknown, queued, processing, validated, or failed
- The datasets.create method returns a DatasetsCreateResponse with the dataset ID
Step 2: Configure the Fine-tuning Settings
Build a FinetunedModel object with a Settings configuration specifying the base model, dataset ID, and hyperparameters. The Settings type encapsulates the base model reference, dataset reference, and an optional Hyperparameters object.
Key considerations:
- The base_model field references a BaseModel with name and base_type (e.g., BASE_TYPE_CHAT, BASE_TYPE_CLASSIFY)
- Hyperparameters include train_epochs, learning_rate, train_batch_size, early_stopping_patience, and early_stopping_threshold
- LoRA target modules can be configured (e.g., LORA_TARGET_MODULES_QV for query/value attention layers)
- Optional WandB configuration (WandbConfig) enables experiment tracking integration
Step 3: Create the Fine-tuned Model
Submit the fine-tuning job by calling client.finetuning.create_finetuned_model() with the configured FinetunedModel request. The API returns a CreateFinetunedModelResponse containing the model ID and initial status.
Key considerations:
- The model starts in a queued status and progresses through training states
- The response contains the finetuned_model object with an id field for subsequent queries
- Model names must be unique within the user's account
Step 4: Monitor Training Progress
Poll the fine-tuning job status using client.finetuning.get_finetuned_model() or list training events with client.finetuning.list_events(). Training step metrics provide loss values and other indicators at each training step.
Key considerations:
- Status values include STATUS_UNSPECIFIED, STATUS_FINETUNING, STATUS_DEPLOYING_API, STATUS_READY, STATUS_FAILED, STATUS_DELETED
- list_events() returns lifecycle events with timestamps (queued, started, completed, etc.)
- list_training_step_metrics() provides step-level metrics for monitoring convergence
- Pagination is supported via page_size and page_token parameters
Step 5: Use the Fine-tuned Model
Once the model reaches STATUS_READY, use its model ID as the model parameter in chat(), chat_stream(), or other inference endpoints. The fine-tuned model behaves identically to base models in terms of API interface.
Key considerations:
- The fine-tuned model ID is used directly in the model parameter of inference calls
- All inference features (streaming, tools, documents, response formats) work with fine-tuned models
- Fine-tuned models can be updated (name changes) or deleted via the finetuning sub-client
- Model listing supports pagination and ordering (e.g., by created_at)