Runpod provides an easier method to fine tune an LLM. For more information, see Fine tune a model.
Setting up the environment
Fine-tuning a large language model (LLM) can take up a lot of compute power. Because of this, we recommend fine-tuning using Runpod’s GPUs. To do this, you’ll need to create a Pod, specify a container, then you can begin training. A Pod is an instance on a GPU or multiple GPUs that you can use to run your training job. You also specify a Docker image likeaxolotlai/axolotl-cloud:main-latest
that you want installed on your Pod.
-
Login to Runpod and deploy your Pod.
- Select Deploy.
- Select an appropriate GPU instance.
- Specify the
axolotlai/axolotl-cloud:main-latest
image as your Template image. - Select your GPU count.
- Select Deploy.
For optimal compatibility, we recommend using A100, H100, V100, or RTX 3090 Pods for Axolotl fine-tuning.
-
Wait for the Pod to startup, then connect to it using secure SSH.
- On your Pod page, select Connect.
- Copy the secure SSH string and paste it into your terminal on your machine.
Follow the on-screen prompts to SSH into your Pod.
You should use the SSH connection to your Pod as it is a persistent connection. The Web UI terminal shouldn’t be relied on for long-running processes, as it will be disconnected after a period of inactivity.
Preparing the dataset
The dataset you provide to your LLM is crucial, as it’s the data your model will learn from during fine-tuning. You can make your own dataset that will then be used to fine-tune your own model, or you can use a pre-made one. To continue, use either a local dataset or one stored on Hugging Face.Using a local dataset
To use a local dataset, you’ll need to transfer it to your Runpod instance. You can do this using Runpod CLI to securely transfer files from your local machine to the one hosted by Runpod. All Pods automatically come withrunpodctl
installed with a Pod-scoped API key. To send a file
Run the following on the computer that has the file you want to send, enter the following command:
The following is an example of a command you’d run on your Runpod machine.
Using a Hugging Face dataset
If your dataset is stored on Hugging Face, you can specify its path in thelora.yaml
configuration file under the datasets
key. Axolotl will automatically download the dataset during the preprocessing step.
Review the configuration file in detail and make any adjustments to your file as needed.
Now update your Runpod machine’s requirement and preprocess your data.
Updating requirements and preprocessing data
Before you can start training, you’ll need to install the necessary dependencies and preprocess our dataset.In some cases, your Pod will not contain the Axolotl repository. To add the required repository, run the following commands and then continue with the tutorial:
- Install the required packages by running the following commands:
- Update the
lora.yml
configuration file with your dataset path and other training settings. You can use any of the examples in theexamples
folder as a starting point. - Preprocess your dataset by running:
Fine-tuning the LLM
With your environment set up and data preprocessed, you’re ready to start fine-tuning the LLM. Run the following command to fine-tune the base model.lora.yml
file. The training time will depend on factors like your model size, dataset size, and GPU type. Be prepared to wait a while, especially for larger models and datasets.
Once training is complete, we can move on to testing our fine-tuned model through inference.
Inference
Once training is complete, you can test your fine-tuned model using the inference script:merge_lora
script.
Merge the model
You will merge the base model with the LoRA weights using themerge_lora
script.
Run the following command:
Upload the model to Hugging Face
Finally, you can share your fine-tuned model with others by uploading it to Hugging Face.- Login to Hugging Face through the CLI:
- Create a new model repository on Hugging Face using
huggingface-cli
.
- Then, use the
huggingface-cli upload
command to upload your merged model to the repository.