Fine-Tune the Mistral-7B Model
Follow this blog post for a comprehensive tutorial on how to fine-tune a Mistral 7B model.
All Anyscale models belong to the group of Large Language Models (LLMs).
These are some of the supported models:
- Mistral7B
- Llama-2-7b
- Llama-2-13b
- Llama-2-70b
- Code Llama
Let’s create a model to answer questions about MindsDB’s custom SQL syntax.
First, create an AnyScale engine, passing your Anyscale API key:
Then, create a model using this engine:
You can check model status with this command:
Once the status is complete, we can query for predictions:
On execution, we get:
If you followed one of the MindsDB tutorials before, you’ll see that the syntax provided by the model is not exactly as expected.
Now, we’ll fine-tune our model using a table that stores details about MindsDB’s custom SQL syntax.
Let’s connect to a DB that hosts a table we’ll use to fine-tune our model:
Now we can take a look at the fine-tuning data:
And here are the first few rows:
message_id | role | content | ||
---|---|---|---|---|
0 | system | You are a helpful assistant. Your task is to answer a user’s question regarding the SQL syntax supported by MindsDB, a machine learning product for training models and seamlessly deploying them where your data lives. | ||
1 | user | In the context of MindsDB: 1. Testing CREATE DATABASE | ||
2 | assistant | CREATE DATABASE example_db WITH ENGINE = "postgres", PARAMETERS = { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", ... }; | ||
Output: | ||||
status | ||||
------ | ||||
Query successfully completed | ||||
3 | system | You are a helpful assistant. Your task is to answer a user’s question regarding the SQL syntax supported by MindsDB, a machine learning product for… | ||
4 | user | In the context of MindsDB: 2. Testing Preview the Available Data Using SELECT |
Notice it is formatted as a series of chats that conform to the standard OpenAI chat format. Every message has a “role” and some “content”. By chaining together a series of messages, we can create a conversation.
Now, you can fine-tune a Mistral model with this data like so:
The FINETUNE
command creates a new version of the mistralai/Mistral-7B-Instruct-v0.1
model. You can query all available versions as below:
While the model is being generated and trained, it is not active. The model becomes active only after it completes generating and training.
Once the new version status is complete and active, we can query the model again, expecting a more accurate output.
On execution, we get:
If you have dynamic data that gets updated regularly, you can set up an automated fine-tuning as below.
Note that the data source must contain an incremental column, such as timestamp or integer, so MindsDB can pick up only the recently added data with the help of the LAST
keyword.
Here is how to create and schedule a job to fine-tune the model periodically.
Now your model will be fine-tuned with newly added data every day or every time there is new data available.