What to Expect
This script demonstrates how to use the Instructor library for fine-tuning a Python function that performs three-digit multiplication. It uses Pydantic for type validation and logging features to generate a fine-tuning dataset.
How to Run
Prerequisites
- Python 3.9
Instructorlibrary
Steps
-
Install Dependencies
If you haven't already installed the required libraries, you can do so using pip:pip install instructor pydantic -
Set Up Logging
The script uses Python's built-inloggingmodule to log the fine-tuning process. Ensure you have write permissions in the directory where the log filemath_finetunes.jsonlwill be saved. -
Run the Script
Navigate to the directory containingscript.pyand run it:python three_digit_mul.pyThis will execute the script, running the function ten times with random three-digit numbers for multiplication. The function outputs and logs are saved in
math_finetunes.jsonl. -
Fine-Tuning
Once you have the log file, you can run a fine-tuning job using the followingInstructorCLI command:instructor jobs create-from-file math_finetunes.jsonlWait for the fine-tuning job to complete.
If you have validation date you can run:
instructor jobs create-from-file math_finetunes.jsonl --n-epochs 4 --validation-file math_finetunes_val.jsonl
Output
That's it! You've successfully run the script and can now proceed to fine-tune your model.
Dispatch
Once you have the model you can replace the model in three_digit_mul_dispatch.py with the model you just fine-tuned and run the script again. This time, the script will use the fine-tuned model to predict the output of the function.