Tutorial: Fine Tune Llama3.1 8B with Lumino SDK
The rapid advancements in open-source models like Llama-3.1 demonstrate the growing potential of smaller, fine-tuned models that can rival even the top closed-source alternatives. Lumino allows you to fine-tune Llama-3.1 8B on your proprietary datasets, creating powerful, accurate, and fully owned AI models.
In this guide, we’ll walk through how to fine-tune a Llama-3.1 8B model using the Lumino SDK on a sample dataset, transforming a base model into a fine-tuned, high-performance model for your specific needs. Our example will cover everything from dataset preparation to running evaluations, showing how a base model can be elevated to outperform larger models.
What You Will Learn
- How to prepare and format your dataset for fine-tuning
- Uploading datasets to Lumino using the SDK
- Initiating fine-tuning jobs with customizable parameters
- Running evaluations to assess model performance
Prerequisites
- Lumino SDK: Install using
pip install lumino
- API Key: Obtain it from the Lumino dashboard, and set it up as an environment variable:
Dataset Preparation
To begin, let’s prepare a dataset for fine-tuning. In this tutorial, we’ll use a simple trivia-based dataset. If you’re following along, feel free to create or use any dataset that fits your use case.
Example Dataset - Original Format
Formatting the Dataset to JSONL
To use this dataset with the Lumino SDK, we need to convert it to a .jsonl format, where each line represents a structured conversation between a system, user, and assistant. Here’s a Python script that formats the dataset into the correct structure for fine-tuning:
Result: formatted_encyclopedia.jsonl
Uploading the Dataset to Lumino
Method 1: Uploading via the Lumino SDK
Once the dataset is prepared, it’s time to upload it to Lumino using the SDK. Here’s how to do that:
This script uses the Lumino SDK to upload the dataset and confirm successful upload. Make sure to replace “Formatted_Trivia.jsonl” with the path to your dataset file.
Method 2: Uploading via the Lumino Web App UI
Alternatively, you can upload your dataset through the Lumino Web App, which provides an intuitive UI for managing datasets.
- Log in to the Lumino Web App: Go to the Lumino Web App and log in with your credentials.
- Navigate to the Dataset Page:: Once logged in, head to the “Datasets” section on the dashboard.
- Upload Dataset::
- Click the Upload Dataset button.
- Select your formatted .jsonl file (e.g., Formatted_Trivia.jsonl) from your local machine.
- Confirm the Upload::
- After uploading, you’ll see the dataset listed in the Datasets section. You can now use this dataset for fine-tuning jobs.
Fine-tuning
After uploading the dataset, we can start a fine-tuning job.
Create Fine Tune Job
The fine-tuning parameters are flexible, allowing you to adjust aspects like batch size, learning rate, and the number of epochs. In this example, we’ll use 5 epochs and a small batch size to keep things lightweight.
Monitoring the Job
While the job is running, you can monitor its status or adjust certain parameters by interacting with the Lumino API. Below is an example of retrieving the fine-tuning job’s status:
Inference the Fine-tuned Model
Since Lumino SDK currently does not support model evaluation, we can manually download the fine-tuned model and perform inference using libraries like Hugging Face’s transformers. This allows you to load the model and generate responses based on input prompts.
Step 1: Export Your Fine-tuned Model
Once your model has been fine-tuned using the Lumino SDK, download the model files (this will depend on your hosting method) or save it locally if you’re running the fine-tuning job on your infrastructure.
Step 2: Prepare a Sample Prompt
Let’s say we want to ask the model a simple trivia question or prompt. For example:
You can change this prompt based on your use case.
Step 3: Load the Model and Perform Inference using Hugging Face Transformers
Here’s a Python script to load the fine-tuned model and perform inference:
Running the Inference
The model will return the fine-tuned response based on the prompt provided.
Conclusion
By using the Lumino SDK, you can quickly fine-tune open-source models like Llama-3.1 8B for specific tasks, creating faster, more accurate models at a fraction of the cost of closed-source alternatives. The flexibility of Lumino’s fine-tuning API allows you to customize the entire process, from dataset management to model deployment.
For more details, check out our full documentation or explore the PyPi repo to get started.