You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/embedded-and-microcontrollers/llm-fine-tuning-for-web-applications/_index.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,32 @@
1
1
---
2
-
title: LLM Fine-Tuning for Web Applications
2
+
title: LLM fine-tuning for web applications
3
3
4
4
draft: true
5
5
cascade:
6
6
draft: true
7
7
8
8
minutes_to_complete: 60
9
9
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.
11
11
12
12
learning_objectives:
13
13
- Learn the basics of large language models (LLMs) and how fine-tuning enhances model performance for specific use cases.
14
14
- Understand full fine-tuning, parameter-efficient fine-tuning (e.g., LoRA, QLoRA, PEFT), and instruction-tuning.
15
15
- Learn when to use different fine-tuning approaches based on model size, task complexity, and computational constraints.
16
16
- Learn how to curate, clean, and preprocess domain-specific datasets for optimal fine-tuning.
17
17
- 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.
19
19
20
20
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 learningand deep learning.
23
+
- Familiarity with deep learning frameworks such as PyTorch and Hugging Face Transformers.
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.
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:
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.
11
10
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
20
27
21
28
## 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:
23
33
24
34
### 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.
26
37
27
38
### 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.
29
41
30
42
### 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:
32
47
33
48
-###### LoRA (Low-Rank Adaptation)
34
49
- 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.
36
51
37
52
-###### 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.
40
55
41
56
-###### Adapter Layers
42
57
- 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
45
60
- Fine-tunes models based on human preferences using reinforcement learning.
46
61
47
62
-###### 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.
49
64
50
65
-###### Multi-Task Learning (MTL) Fine-Tuning
51
66
- Trains the model on multiple tasks simultaneously, enabling generalization across different applications.
52
67
53
68
69
+
## Fine-Tuning Implementation
54
70
55
-
## Fine-Tuning Implementaion
56
71
The following steps need to be performed to implement fine-tuning:
57
72
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.
- 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.
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
4
5
5
6
### FIXED, DO NOT MODIFY
6
7
layout: learningpathall
7
8
---
8
9
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
10
15
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.
13
17
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
16
18
17
-
###### The transformers library (by Hugging Face) provides pre-trained LLMs
19
+
Install the Hugging Face transformers library to access pre-trained LLMs.
20
+
18
21
```python
19
22
!pip install transformers
20
-
21
23
```
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
+
23
27
```python
24
28
!pip install transformers[torch]
25
29
```
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.
27
32
28
33
```python
29
34
!pip install datasets
30
35
```
31
-
###### The evaluate library provides metrics for model performance assessment
36
+
37
+
The evaluate library provides metrics for model performance assessment.
32
38
33
39
```python
34
40
!pip install evaluate
35
41
```
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
+
38
50
```python
39
51
%%capture
40
-
# %%capture is a Jupyter Notebook magic command that suppresses the output of a cell.
41
-
42
52
```
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.
0 commit comments