> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sulie.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Model Tuning

> Learn how to manage datasets for real-time forecasting and fine-tuning.

Sulie’s platform enables easy fine-tuning of the Mimosa foundation model to meet specific forecasting needs. This process leverages LoRA (Low-Rank Adaptation) for efficient training, allowing you to adapt the model’s performance with minimal setup.

<Info>
  **Info:** Fine-tuning in Sulie is fully automated, including hyperparameter tuning and deployment, so you can focus on refining forecasts rather than handling MLOps complexities.
</Info>

## Fine-Tuning Overview

Sulie’s fine-tuning feature uses automated hyperparameter tuning to identify the most effective model parameters. The **Weighted Quantile Loss (WQL)** metric evaluates performance, ensuring each iteration yields optimal results.

### Requirements

* A **Dataset** or **pandas DataFrame** with at least 1,000 data points in the target column is required to initiate fine-tuning.
* Upon completion, Sulie automatically deploys your fine-tuned model, making it accessible via the same `forecast` interface.

### Notifications

* Once a fine-tuning job completes, you’ll receive a confirmation email with the job’s status and performance summary.

## Starting a Fine-Tuning Job

To initiate a fine-tuning job, use the `fine_tune` method on the Sulie client. You can specify the target column and provide an optional description to identify the fine-tuning job. Below is an example with a `pandas.DataFrame`.

```python theme={null}
import pandas as pd
from sulie import Sulie

# Initialize the Sulie client
client = Sulie(api_key="your_api_key_here")

# Example data for fine-tuning
df = pd.DataFrame({
    'timestamp': pd.date_range(start='2023-01-01', periods=1000, freq='H'),
    'solar_demand': [...],  # hourly solar energy demand
    'location': ['Plant A', 'Plant B', ...]
})

# Start a fine-tuning job
fine_tune_job = client.fine_tune(
    dataset=df,                   # pandas DataFrame or a Sulie Dataset
    target_col='solar_demand',        # target column for fine-tuning
    description="Fine-tuning solar demand model"
)
```

### Parameters for `fine_tune`

| Name          | Description                                                                 | Default      |
| ------------- | --------------------------------------------------------------------------- | ------------ |
| `dataset`     | A `Dataset` or `pandas.DataFrame` containing time series data for training. | **Required** |
| `target_col`  | Name of the column to optimize (forecast target).                           | **Required** |
| `id_col`      | Name of the column to group the DataFrame into series.                      | `None`       |
| `description` | Optional description of the fine-tuning job.                                | `None`       |

Each fine-tuned model is automatically deployed with a unique model name, ready for immediate inference.

## Monitoring Fine-Tuning Jobs

To view the status of fine-tuning jobs, use the `list_fine_tuning_jobs` method, which provides a comprehensive list of all ongoing and completed fine-tuning jobs.

```python theme={null}
# Retrieve and print the list of fine-tuning jobs
fine_tuning_jobs = client.list_fine_tuning_jobs()
for job in fine_tuning_jobs:
    print(f"Job ID: {job.id}, Status: {job.status}, Description: {job.description}")
```

The output will include details such as job ID, status, and description, helping you monitor job progress.

## Listing Deployed Models

You can view all deployed fine-tuned models using `list_custom_models`, which retrieves a list of all models available for inference.

```python theme={null}
# Retrieve and print the list of deployed custom models
custom_models = client.list_custom_models()
for model in custom_models:
    print(f"Model ID: {model.id}, Name: {model.name}, Deployed: {model.is_deployed}")
```

The `list_custom_models` method provides details on each model, including its ID, name, and deployment status, making it easy to identify and manage your deployed models.

Here's how the documentation could look with an example on running forecasts using a custom model, incorporating both the `list_custom_models` and `get_model` methods for model retrieval.

***

# Forecasting with Custom Models

Once you have fine-tuned a model, it is deployed automatically and available for custom forecasting. You can choose from your list of custom models or retrieve a specific model by name. This allows you to run forecasts with your personalized model, adapting to specific business requirements or forecast parameters.

## Retrieving a Custom Model for Forecasting

To use a custom model, you first need to retrieve it. You can either:

1. Use `list_custom_models` to select from all available models, or
2. Use `get_model` with a model name to retrieve a specific model directly.

Here's a step-by-step example that demonstrates listing available models, selecting a model, and then using it to run a forecast.

```python theme={null}
# Step 1: List available custom models
custom_models = client.list_custom_models()
for model in custom_models:
    print(f"Model ID: {model.id}, Name: {model.name}, Status: {model.status}")

# Step 2: Choose a model by name or ID
selected_model_name = "solar_demand_model_v1"  # example name; replace with actual model name from list
custom_model = client.get_model(selected_model_name)

# Step 3: Run a forecast using the selected custom model
forecast = client.forecast(
    dataset=df,
    target_col='solar_demand',
    id_col='location',
    timestamp_col='timestamp',
    frequency='H',
    horizon=24,  # forecast for the next 24 hours
    model=custom_model.name,  # specify the custom model name
)
print(forecast)
```

### Parameters for `get_model`

| Name         | Description                        | Default      |
| ------------ | ---------------------------------- | ------------ |
| `model_name` | The name of the model to retrieve. | **Required** |
