Skip to content

Commit 6b1f66d

Browse files
Merge pull request #2942 from madeline-underwood/nvda
Nvda_reviewed
2 parents 55f0491 + ec46f03 commit 6b1f66d

5 files changed

Lines changed: 20 additions & 15 deletions

File tree

content/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/1-setup.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ weight: 2
66
layout: learningpathall
77
---
88

9+
## Overview
10+
911
The NVIDIA DGX Spark pairs an Arm-based Grace CPU with a Blackwell GPU in a compact desktop form factor. The GPU handles the compute-intensive training passes while the Grace CPU manages data preprocessing and orchestration, making the system well suited for fine-tuning large language models locally without sending data to the cloud.
1012

1113
To get started, you'll configure Docker, pull a pre-built PyTorch container, and install the libraries you need for fine-tuning.
@@ -39,7 +41,7 @@ Pull the latest PyTorch container from NVIDIA's container registry:
3941
docker pull nvcr.io/nvidia/pytorch:25.11-py3
4042
```
4143

42-
This command downloads the November 2025 release of the PyTorch container, which includes PyTorch, CUDA libraries, cuDNN, and other essential tools pre-configured for optimal performance on NVIDIA hardware. The download size is several gigabytes, so this step might take a few minutes depending on your internet connection.
44+
This command downloads the November 2025 release of the PyTorch container, which includes PyTorch, CUDA libraries, cuDNN, and other essential tools pre-configured for optimal performance on NVIDIA hardware. The download size is several gigabytes, so this step can take a few minutes depending on your internet connection.
4345

4446
## Launch container instance
4547

@@ -81,7 +83,7 @@ These packages serve specific purposes:
8183
- `trl` (Transformer Reinforcement Learning) includes training utilities and recipes for language models
8284
- `bitsandbytes` enables 4-bit and 8-bit quantization for memory-efficient training
8385

84-
The installation typically takes a few minutes as pip downloads and installs each package along with their dependencies.
86+
The installation can take a few minutes as pip downloads and installs each package along with their dependencies.
8587

8688
## Authenticate with Hugging Face
8789

content/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/2-finetuning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The NVIDIA playbook scripts use the Alpaca prompt format, which structures each
3636

3737
**Input** -- optional additional context (left empty for most questions)
3838

39-
**Output** -- the correct answer sourced from official datasheets
39+
**output** -- the correct answer sourced from official datasheets
4040

4141
Here's an example from the dataset you'll use:
4242

content/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/3-pytorch.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ weight: 4
66
layout: learningpathall
77
---
88

9+
## Overview
10+
911
Now that you understand how fine-tuning works, it's time to look at the actual code. In this section, you'll walk through the key parts of the `Llama3_3B_full_finetuning.py` script and run it with the Raspberry Pi dataset to produce your own fine-tuned Llama model.
1012

1113

@@ -23,7 +25,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
2325

2426
The `DATASET_PROMPT_TEMPLATE` defines the instruction-following format for training data with three fields: instruction, input, and response. Each training example is formatted using this template so the model learns to recognize the pattern and produce structured answers.
2527

26-
The `get_dataset()` function loads the dataset from (Hugging Face by default) and formats each example using the template, appending the EOS (End of String) token. You'll pass in the Raspberry Pi dataset from a local JSONL file instead.
28+
The `get_dataset()` function loads the dataset from Hugging Face by default and formats each example using the template, appending the EOS (End of Sequence) token. You'll pass in the Raspberry Pi dataset from a local JSONL file instead.
2729

2830
```python
2931
# Define prompt templates
@@ -154,13 +156,13 @@ cp /workspace/raspberry_pi_qa.jsonl .
154156

155157
## Run the fine-tuning
156158

157-
With the dataset patch applied, you're ready to run the fine-tuning. The command below trains the Llama 3.1 8B model using full fine-tuning on the Raspberry Pi dataset:
159+
With the dataset in place, you're ready to run the fine-tuning. The command below trains the Llama 3.2 3B model using full fine-tuning on the Raspberry Pi dataset:
158160

159161
```bash
160162
python Llama3_3B_full_finetuning.py \
161163
--model_name "meta-llama/Llama-3.2-3B-Instruct" \
162164
--dataset "json" \
163-
--dataset_files="/workspace/projects/pytorch-finetuning/raspberry_pi_qa.jsonl" \
165+
--dataset_files="raspberry_pi_qa.jsonl" \
164166
--dataset_size 300 \
165167
--output_dir "/workspace/models/Llama-3.2-3B-FineTuned"
166168
```

content/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/4-testing.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ weight: 5
66
layout: learningpathall
77
---
88

9+
## Overview
10+
911
Now that you've fine-tuned your model on Raspberry Pi datasheet content, it's time to compare its behavior against the original. You'll serve both versions using vLLM, a high-performance inference server optimized for large language models, and observe how fine-tuning on domain-specific data changes the model's factual accuracy.
1012

1113
## Download vLLM container
@@ -64,8 +66,7 @@ Wait for the server to fully load the model and display the message indicating i
6466

6567
### Test prompt
6668

67-
68-
From a new terminal window (outside the container), send a Raspberry Pi hardware question to the model using the Alpaca instruction format. For this example, use a question about the memory size:
69+
From a new terminal window (outside the container), use `curl` to send an HTTP request to the model server. The request contains a Raspberry Pi hardware question formatted using the Alpaca instruction template. For this example, ask about the RP2350 memory size:
6970

7071
```bash
7172
curl http://localhost:8000/v1/completions \
@@ -109,7 +110,7 @@ The base model confidently reports the RP2350 has "256MB of memory," which is of
109110

110111
Now test your fine-tuned model to see how training on Raspberry Pi datasheet content improved its factual accuracy. Stop the current vLLM server (press Ctrl+C in the container terminal) before launching the fine-tuned model.
111112

112-
{{% notice Dependency Conflict %}}
113+
{{% notice Note %}}
113114
As of this writing, vLLM does not support version 5 of the `transformers` library that was used when fine-tuning the model, so you need to patch its `tokenizer_config.json`. Run the following command to update the `tokenizer_class` to `PreTrainedTokenizerFast`, which is compatible with the older `transformers` version bundled in the vLLM container:
114115

115116
```bash
@@ -132,7 +133,7 @@ The only change from the previous command is the `--model` parameter, which now
132133

133134
### Test prompt
134135

135-
Send the same Raspberry Pi question to your fine-tuned model:
136+
Send the same Raspberry Pi question to your fine-tuned model using the same `curl` command format:
136137

137138
```bash
138139
curl http://localhost:8000/v1/completions \

content/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/_index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
---
22
title: Fine-tune PyTorch models on DGX Spark
33

4-
draft: true
5-
cascade:
6-
draft: true
7-
84
minutes_to_complete: 60
95

106
who_is_this_for: This is an advanced topic for AI developers and ML engineers who want to fine-tune large language models using PyTorch and Hugging Face on the NVIDIA DGX Spark platform.
117

128
learning_objectives:
139
- Understand how fine-tuning teaches a model domain-specific knowledge
1410
- Prepare a custom JSONL dataset for supervised fine-tuning
15-
- Fine-tune Llama 3.1 8B on Raspberry Pi datasheet content using PyTorch and Hugging Face
11+
- Fine-tune Llama 3.2 3B on Raspberry Pi datasheet content using PyTorch and Hugging Face
1612
- Compare base and fine-tuned model responses to verify factual accuracy improvements
1713

1814
prerequisites:
@@ -55,6 +51,10 @@ further_reading:
5551
title: PyTorch Training Documentation
5652
link: https://pytorch.org/tutorials/beginner/introyt/trainingyt.html
5753
type: documentation
54+
- resource:
55+
title: Build a serverless LLM inference application with AWS Lambda and Arm processors
56+
link: /learning-paths/servers-and-cloud-computing/llama-cpu/
57+
type: website
5858

5959
### FIXED, DO NOT MODIFY
6060
# ================================================================================

0 commit comments

Comments
 (0)