Finetuning Module

Finetuning Module#

The finetuning module plays a crucial role, encompassing three primary functions: implementing the database schema serialization method, generating the finetuning dataset, and conducting finetuning of a Large Language Model (LLM) on the curated dataset.

Each family of LLMs necessitates a unique serialization method tailored to optimize its performance. This customization ensures that the serialization process aligns perfectly with the specific architectural nuances and processing capabilities of each LLM family. At present, our focus is on the GPT family of models, as provided by OpenAI. These models, known for their advanced NL2SQL capabilities.

Abstract finetuning Class#

All implementations of the context store must inherit from the abstract FinetuningModel class and implement the following methods.

FinetuningModel#

This class serves as an abstract base for fine-tuning models, providing a structured framework for managing the fine-tuning process.

class FinetuningModel(storage)

Initializes the FinetuningModel instance with the application storage.

Parameters:

storage (DB) – The storage system

abstract count_tokens(self, messages: dict) int

Counts the number of tokens in the provided messages, a necessary step in preparing data for fine-tuning. We need this information primarily to avoid exceeding the maximum token limit of the model.

Parameters:

messages (dict) – A dictionary containing messages (system, user, assistant) to be tokenized.

Returns:

The total count of tokens.

Return type:

int

abstract create_fintuning_dataset(self)

Abstract method to create a dataset suitable for fine-tuning. This involves processing and structuring data according to the model’s requirements.

abstract create_fine_tuning_job(self)

Initiates a fine-tuning job. This method should encompass all the necessary steps to start the fine-tuning process on the prepared dataset.

abstract retrieve_finetuning_job(self) Finetuning

Retrieves the current status or results of a fine-tuning job.

Returns:

An instance of the Finetuning class representing the finetuning job.

Return type:

Finetuning

abstract cancel_finetuning_job(self) Finetuning

Cancels an ongoing fine-tuning job.

Returns:

An updated instance of the Finetuning class reflecting the job’s cancellation.

Return type:

Finetuning