Skip to content

Commit 4df132f

Browse files
Merge pull request #1734 from jasonrandrews/review
First review of LLM fine-tuning for web applications Learning Path.
2 parents 9d7a53f + f0ea4e7 commit 4df132f

File tree

8 files changed

+546
-376
lines changed

8 files changed

+546
-376
lines changed

content/learning-paths/embedded-and-microcontrollers/llm-fine-tuning-for-web-applications/_index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
---
2-
title: LLM Fine-Tuning for Web Applications
2+
title: LLM fine-tuning for web applications
33

44
draft: true
55
cascade:
66
draft: true
77

88
minutes_to_complete: 60
99

10-
who_is_this_for: This learning path provides an introduction for developers and data scientists new to fine-tuning large language models (LLMs) and looking to develop a fine-tuned LLM for web applications. Fine-tuning involves adapting a pre-trained LLM to specific tasks or domains by training it on domain-specific data and optimizing its responses for accuracy and relevance. For web applications, fine-tuning enables personalized interactions, enhanced query handling, and improved contextual understanding, making AI-driven features more effective. This session will cover key concepts, techniques, tools, and best practices, ensuring a structured approach to building a fine-tuned LLM that aligns with real-world web application requirements.
10+
who_is_this_for: This is an introductory topic for developers and data scientists new to fine-tuning large language models (LLMs) and looking to develop a fine-tuned LLM for web applications.
1111

1212
learning_objectives:
1313
- Learn the basics of large language models (LLMs) and how fine-tuning enhances model performance for specific use cases.
1414
- Understand full fine-tuning, parameter-efficient fine-tuning (e.g., LoRA, QLoRA, PEFT), and instruction-tuning.
1515
- Learn when to use different fine-tuning approaches based on model size, task complexity, and computational constraints.
1616
- Learn how to curate, clean, and preprocess domain-specific datasets for optimal fine-tuning.
1717
- Understand dataset formats, tokenization, and annotation techniques for improving model learning.
18-
- Implementing Fine-Tuning with Popular Frameworks like Hugging Face Transformers and PyTorch for LLM fine-tuning.
18+
- Implement fine-tuning with frameworks like Hugging Face Transformers and PyTorch.
1919

2020
prerequisites:
21-
- An AWS Graviton4 r8g.16xlarge instance to test Arm performance optimizations, or any [Arm based instance](/learning-paths/servers-and-cloud-computing/csp/) from a cloud service provider or an on-premise Arm server or Arm based laptop.
22-
- Basic Understanding of Machine Learning & Deep Learning (Familiarity with concepts like supervised learning, neural networks, transfer learning and Understanding of model training, validation, & overfitting concepts).
23-
- Familiarity with Deep Learning Frameworks (Experience with PyTorch for building, training neural networks and Knowledge of Hugging Face Transformers for working with pre-trained LLMs.
21+
- An AWS Graviton4 instance. You can substitute any Arm based Linux computer. Refer to [Get started with Arm-based cloud instances](/learning-paths/servers-and-cloud-computing/csp/) for more information about cloud service providers offering Arm-based instances.
22+
- Basic understanding of machine learning and deep learning.
23+
- Familiarity with deep learning frameworks such as PyTorch and Hugging Face Transformers.
2424

2525
author: Parichay Das
2626

2727
### Tags
2828
skilllevels: Introductory
29-
subjects: GenAI
29+
subjects: ML
3030
armips:
3131
- Neoverse
3232

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Create a Jupyter notebook on an Arm server
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
You can use a Jupyter notebook running on an Arm server for fine-tuning LLMs.
10+
11+
## Install a Jupyter notebook on an Arm server
12+
13+
Follow the steps below to create, configure, and connect to a Jupyter notebook on an Arm server.
14+
15+
### Before you begin
16+
17+
You need an Arm server or other Arm Linux machine to run a Jupyter notebook.
18+
19+
You can use an AWS Graviton4 `r8g.16xlarge` instance to perform fine tuning or a similar Arm server. Refer to [Get started with Arm-based cloud instances](/learning-paths/servers-and-cloud-computing/csp/) for more information about cloud service providers offering Arm-based instances.
20+
21+
The instructions are provided for Ubuntu 24.04, but other Linux distributions are possible.
22+
23+
Make sure you can connect by SSH to the Arm server.
24+
25+
Jupyter notebooks run on port 8888. You can open this port or use SSH port forwarding.
26+
27+
Install the required software:
28+
29+
```console
30+
sudo apt-get update
31+
sudo apt-get install python3-pip python3-venv python3-dev python-is-python3 -y
32+
```
33+
34+
Create a Python virtual environment by running:
35+
36+
```bash
37+
python -m venv venv
38+
source venv/bin/activate
39+
```
40+
41+
In your virtual environment, install Jupyter:
42+
43+
```bash
44+
pip install jupyter
45+
```
46+
47+
### Configure a Jupyter notebook
48+
49+
Generate a Jupyter configuration file with the command below:
50+
51+
```console
52+
jupyter notebook --generate-config
53+
```
54+
55+
Use a text edit to edit the configuration file:
56+
57+
```console
58+
~/.jupyter/jupyter_notebook_config.py
59+
```
60+
61+
Modify the configuration file to include the lines below:
62+
63+
```console
64+
c.NotebookApp.ip = '0.0.0.0'
65+
c.NotebookApp.port = 8888
66+
c.NotebookApp.open_browser = False
67+
c.NotebookApp.notebook_dir = '/home/ubuntu'
68+
```
69+
70+
### Open port 888
71+
72+
To access the Jupyter notebook you need to either open port 8888 in the security group or use SSH port forwarding.
73+
74+
If you are using a cloud instance, add an incoming rule for TCP access to port 8888 from your IP address. Refer to the cloud service provider documentation for security groups.
75+
76+
If you want to use SSH port forwarding, you can connect to the Arm server using:
77+
78+
```console
79+
ssh -i <ssh-private-key> -L 8888:localhost:8888 <user>@<ip-address>
80+
```
81+
82+
### Start Jupyter notebook
83+
84+
Start the Jupyter notebook using:
85+
86+
```console
87+
jupyter notebook
88+
```
89+
90+
URLs are printed in the terminal output.
91+
92+
If you are using SSH port forwarding copy the URL with 127.0.0.0 and if you are opening port 8888 copy the URL with the IP address of the Arm server.
93+
94+
### Connect to the Jupyter notebook using your browser
95+
96+
Open a web browser on your local machine and paste the copied URL into the address bar and press enter.
97+
98+
You are now connected to Jupyter notebook running on your Arm server.
99+
100+
Click `File` from the menu and navigate to `New` select `Notebook`. For the kernel select `Python 3`.
101+
102+
You see an empty cell in your notebook, and you are ready to use your Jupyter notebook for fine-tuning LLMs.
Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
11
---
2-
title: Overview
2+
title: What is fine-tuning?
33
weight: 2
44

55
### FIXED, DO NOT MODIFY
66
layout: learningpathall
77
---
88

9-
## What is Fine-Tuning
10-
Fine-tuning in the context of large language models (LLMs) refers to the process of further training a pre-trained LLM on domain-specific or task-specific data to enhance its performance for a particular application. LLMs, such as GPT, BERT, and LLaMA, are initially trained on massive corpora containing billions of tokens, enabling them to develop a broad linguistic understanding. Fine-tuning refines this knowledge by exposing the model to specialized datasets, allowing it to generate more contextually relevant and accurate responses. Rather than training an LLM from scratch, fine-tuning leverages the pre-existing knowledge embedded in the model, optimizing it for specific use cases such as customer support, content generation, legal document analysis, or medical text processing. This approach significantly reduces computational requirements and data needs while improving adaptability and efficiency in real-world applications.
9+
Fine-tuning in the context of large language models (LLMs) refers to the process of further training a pre-trained LLM on domain-specific or task-specific data to enhance its performance for a particular application. LLMs, such as GPT, BERT, and LLaMA, are initially trained on massive corpora containing billions of tokens, enabling them to develop a broad linguistic understanding.
1110

12-
## Advantage of Fine-Tuning
13-
Fine-tuning is essential for optimizing large language models (LLMs) to meet specific application requirements, enhance performance, and reduce computational costs. While pre-trained LLMs have broad linguistic capabilities, they may not always produce domain-specific, contextually accurate, or application-tailored responses
14-
- Customization for Specific Domains
15-
- Improved Response Quality and Accuracy
16-
- Task-Specific Adaptation
17-
- Reduction in Computational and Data Requirements
18-
- Enhanced Efficiency in Real-World Applications
19-
- Alignment with Ethical, Regulatory, and Organizational Guidelines
11+
Fine-tuning refines this knowledge by exposing the model to specialized datasets, allowing it to generate more contextually relevant and accurate responses. Rather than training an LLM from scratch, fine-tuning leverages the pre-existing knowledge embedded in the model, optimizing it for specific use cases such as customer support, content generation, legal document analysis, or medical text processing.
12+
13+
This approach significantly reduces computational requirements and data needs while improving adaptability and efficiency in real-world applications.
14+
15+
## Advantages of fine-tuning
16+
17+
Fine-tuning is essential for optimizing large language models (LLMs) to meet specific application requirements, enhance performance, and reduce computational costs. While pre-trained LLMs have broad linguistic capabilities, they may not always produce domain-specific, contextually accurate, or application-tailored responses.
18+
19+
The advantages of fine-tuning include:
20+
21+
- Customization for specific domains
22+
- Improved response quality and accuracy
23+
- Task-specific adaptation
24+
- Reduction in computational and data requirements
25+
- Enhanced efficiency in real-world applications
26+
- Alignment with ethical, regulatory, and organizational guidelines
2027

2128
## Fine-Tuning Methods
22-
Fine-tuning LLM uses different techniques based on the various use cases, computational constraints, and efficiency requirements. Below are the key fine-tuning methods:
29+
30+
Fine-tuning LLMs uses different techniques based on the various use cases, computational constraints, and efficiency requirements.
31+
32+
Below are the key fine-tuning methods:
2333

2434
### Full Fine-Tuning (Supervised Learning Approach)
25-
It involves updating all parameters of the LLM using task-specific data, requiring significant computational power and large labeled datasets, which provides the highest level of customization.
35+
36+
Full fine-tuning involves updating all parameters of the LLM using task-specific data, requiring significant computational power and large labeled datasets, which provides the highest level of customization.
2637

2738
### Instruction Fine-Tuning
28-
Instruction fine-tuning is a supervised learning method. A pre-trained large language model (LLM) is further trained on instruction-response pairs to improve its ability to follow human instructions accurately. Instruction Fine-Tuning has some key features using Labeled Instruction-Response Pairs, Enhances Model Alignment with Human Intent, Commonly Used in Chatbots and AI Assistants, and Prepares Models for Zero-Shot and Few-Shot Learning.
39+
40+
Instruction fine-tuning is a supervised learning method. A pre-trained large language model (LLM) is further trained on instruction-response pairs to improve its ability to follow human instructions accurately. Instruction fine-tuning has some key features using labeled instruction-response pairs, enhances model alignment with human intent. It is commonly used in chatbots and AI Assistants, and prepares models for zero-shot and few-shot learning.
2941

3042
### Parameter-Efficient Fine-Tuning (PEFT)
31-
It is a optimized approaches that reduce the number of trainable parameters while maintaining high performance:
43+
44+
PEFT is an optimized approach that reduces the number of trainable parameters while maintaining high performance.
45+
46+
Some approaches are:
3247

3348
- ###### LoRA (Low-Rank Adaptation)
3449
- Introduces small trainable weight matrices (rank decomposition) while freezing the main model weights.
35-
- It will significantly reduce GPU memory usage and training time.
50+
- Significantly reduces GPU memory usage and training time.
3651

3752
- ###### QLoRA (Quantized LoRA)
38-
- It will use quantization (e.g., 4-bit or 8-bit precision) to reduce memory footprint while applying LoRA fine-tuning.
39-
- It is Ideal for fine-tuning large models on limited hardware.
53+
- Uses quantization (e.g., 4-bit or 8-bit precision) to reduce memory footprint while applying LoRA fine-tuning.
54+
- Ideal for fine-tuning large models on limited hardware.
4055

4156
- ###### Adapter Layers
4257
- Inserts small trainable layers between existing layers of the model and Keeps most parameters frozen, reducing computational overhead.
@@ -45,21 +60,24 @@ It is a optimized approaches that reduce the number of trainable parameters whil
4560
- Fine-tunes models based on human preferences using reinforcement learning.
4661

4762
- ###### Domain-Specific Fine-Tuning
48-
- Fine-tunes the LLM with domain-specific datasets and Improves accuracy and relevance in specialized applications.
63+
- Fine-tunes the LLM with domain-specific datasets and improves accuracy and relevance in specialized applications.
4964

5065
- ###### Multi-Task Learning (MTL) Fine-Tuning
5166
- Trains the model on multiple tasks simultaneously, enabling generalization across different applications.
5267

5368

69+
## Fine-Tuning Implementation
5470

55-
## Fine-Tuning Implementaion
5671
The following steps need to be performed to implement fine-tuning:
5772

73+
- Base model selection: Choose a pre-trained model based on your use cases. You can find pre-trained models on [Hugging Face](https://huggingface.co/)
74+
- Fine-tuning method finalization: Select the most appropriate fine-tuning method (supervised, instruction-based, PEFT) based on your use case and dataset. You can typically find various datasets on [Hugging Face](https://huggingface.co/datasets) and [Kaggle](https://www.kaggle.com/datasets).
75+
- Dataset preparation: Organize your data for your use case-specific training, ensuring it aligns with the model's required format.
76+
- Training: Utilize frameworks such as TensorFlow and PyTorch to fine-tune the model.
77+
- Evaluate: Evaluate the model, refine it as needed, and retrain to enhance performance.
78+
79+
The steps are depicted in Figure 1 below:
5880

59-
![example image alt-text#center](1.png "Figure 1. Fine-Tuning Implementaion")
81+
![example image alt-text#center](1.png "Figure 1. Fine-Tuning Implementation")
6082

61-
- Base Model Selection: Choose a pre-trained model based on your use cases. You can find pre-trained models at [Hugging Face](https://huggingface.co/)
62-
- Fine-Tuning Method Finalization: Select the most appropriate fine-tuning method (e.g., supervised, instruction-based, PEFT) based on your use case and dataset. You can typically find various datasets on [Hugging Face](https://huggingface.co/datasets) and [Kaggle](https://www.kaggle.com/datasets).
63-
- Dataset Prepration:Organize your data for your use case-specific training, ensuring it aligns with the model's required format.
64-
- Training:Utilize frameworks such as TensorFlow and PyTorch to fine-tune the model.
65-
- Evaluate: Evaluate the model, refine it as needed, and retrain to enhance performance
83+
With this background you are ready to get started with fine-tuning.
Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,60 @@
11
---
2-
title: Fine Tuning Large Language Model - Setup Environment
3-
weight: 3
2+
title: Set up for fine tuning a large language model
3+
4+
weight: 4
45

56
### FIXED, DO NOT MODIFY
67
layout: learningpathall
78
---
89

9-
## Fine Tuning Large Language Model - Setup Environment
10+
All of the commands are meant to be copied into a cell in your Jupyter notebook.
11+
12+
Copy each command into a cell, and use `Shift + Enter` to run the cell. After the cell is run, advance to the next command and enter it in a new cell.
13+
14+
## Install the required libraries
1015

11-
#### Plartform Required
12-
An AWS Graviton4 r8g.16xlarge instance to test Arm performance optimizations, or any [Arm based instance](/learning-paths/servers-and-cloud-computing/csp/) from a cloud service provider or an on-premise Arm server or Arm based laptop.
16+
The following commands install the necessary libraries, including Hugging Face Transformers, Datasets, and fine-tuning methods. These libraries facilitate model loading, training, and fine-tuning.
1317

14-
#### Set Up Required Libraries
15-
The following commands install the necessary libraries for the task, including Hugging Face Transformers, Datasets, and fine-tuning methods. These libraries facilitate model loading, training, and fine-tuning
1618

17-
###### The transformers library (by Hugging Face) provides pre-trained LLMs
19+
Install the Hugging Face transformers library to access pre-trained LLMs.
20+
1821
```python
1922
!pip install transformers
20-
2123
```
22-
###### This installs transformers along with PyTorch, ensuring that models are trained and fine-tuned using the Torch backend.
24+
25+
Install transformers along with PyTorch, ensuring that models are trained and fine-tuned using the Torch backend.
26+
2327
```python
2428
!pip install transformers[torch]
2529
```
26-
###### The datasets library (by Hugging Face) provides access to a vast collection of pre-built datasets
30+
31+
The datasets library (by Hugging Face) provides access to a vast collection of pre-built datasets.
2732

2833
```python
2934
!pip install datasets
3035
```
31-
###### The evaluate library provides metrics for model performance assessment
36+
37+
The evaluate library provides metrics for model performance assessment.
3238

3339
```python
3440
!pip install evaluate
3541
```
36-
###### Speed up fine-tuning of Large Language Models (LLMs)
37-
[Unsloth](https://huggingface.co/unsloth) is a library designed to speed up fine-tuning of Large Language Models (LLMs) while reducing computational costs. It optimizes training efficiency, particularly for LoRA (Low-Rank Adaptation) fine-tuning
42+
43+
### Speed up fine-tuning of Large Language Models (LLMs)
44+
45+
[Unsloth](https://huggingface.co/unsloth) is a library designed to speed up fine-tuning of Large Language Models (LLMs) while reducing computational costs. It optimizes training efficiency, particularly for LoRA (Low-Rank Adaptation) fine-tuning .
46+
47+
48+
First, use the `%%capture` command, a Jupyter Notebook magic command that suppresses the output of a cell.
49+
3850
```python
3951
%%capture
40-
# %%capture is a Jupyter Notebook magic command that suppresses the output of a cell.
41-
4252
```
43-
##### Uninstalls the existing Unsloth installation and installs the latest version directly from the GitHub repository
53+
54+
Next, uninstall the existing Unsloth and install the latest version directly from the GitHub repository.
4455

4556
```python
4657
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
47-
```
58+
```
59+
60+
You have now installed the required software for fine-tuning.

0 commit comments

Comments
 (0)