AI Notebooks - Tutorial - Fine-tuning LLaMA 2

Knowledge Base

AI Notebooks - Tutorial - Fine-tuning LLaMA 2


Icons/System/eye-open Created with Sketch. 355 Views 25.07.2023 Cloud / AI Notebooks

On July 18, 2023, Meta released LLaMA 2, the latest version of their open-source Large Language Model (LLM).

Trained between January 2023 and July 2023 on 2 trillion tokens, LLaMA 2 outperforms other LLMs on many benchmarks, including reasoning, coding, proficiency, and knowledge tests. This release comes in different flavors, with parameter sizes of 7B, 13B, and a mind-blowing 70B. Models are intended for free for both commercial and research use in English.

Objective

The purpose of this tutorial is to show you how it is possible to fine-tune LLaMA 2 models using OVHcloud AI Notebooks and a single GPU. This allows you to retrain the model to suit your needs, using your own dataset. We will use QLoRA, a highly efficient LLM fine-tuning technique.

Requirements

To access LLaMA 2 models, you will also need to follow the requirements indicated in the notebook.

Instructions

You can launch the notebook from the OVHcloud Control Panel or via the ovhai CLI.

Launching a Jupyter notebook with "Conda" via UI (Control Panel)

To launch your notebook from the OVHcloud Control Panel, refer to the following steps.

Code editor

Choose the Jupyterlab code editor.

Framework

In this tutorial, the conda framework is used.

Resources

Using at least one GPU is mandatory, since fine-tuning LLMs is an intensive task.

Launching a Jupyter notebook with "conda" via CLI

If you do not use our CLI yet, follow this guide to install it.

If you want to launch your notebook with the OVHcloud AI CLI, choose the jupyterlab editor and the conda framework.

To access the different versions of conda available, run the following command:

ovhai capabilities framework get conda -o yaml

If you do not specify a version, your notebook starts with the default version of conda.

You will also need to choose the number of GPUs to use in your notebook using <nb-gpus>.

To launch your notebook, run the following command:

ovhai notebook run conda jupyterlab \
        --name <notebook-name> \
        --framework-version <conda-version> \
        --gpu <nb-gpus>

You can then reach your notebook’s URL once the notebook is running.

Accessing the notebooks

Once our AI examples repository has been cloned in your environment, find the fine-tuning notebook tutorial by following this path: ai-training-examples > notebooks > natural-language-processing > llm > miniconda > llama2-fine-tuning > llama_2_finetuning.ipynb.

Direct link to the notebook can be found here.

Going further

Don't forget to keep an eye on our upcoming tutorials, where we will be deploying our fine-tuned LLaMA model on AI Deploy for inference!

In the meantime, we invite you to take a look at our other NLP tutorials:

If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.

Feedback

Please send us your questions, feedback and suggestions to improve the service:

Related articles