# [Fine-tune PyTorch models on DGX Spark](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/)

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/)
- [Set up your NVIDIA DGX Spark](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/1-setup/)
- [Understand fine-tuning](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/2-finetuning/)
- [Fine-tune a model with PyTorch and Hugging Face](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/3-pytorch/)
- [Test your fine-tuned model with vLLM](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/4-testing/)
- [Next Steps](https://learn.arm.com/learning-paths/laptops-and-desktops/pytorch-finetuning-on-spark/_next-steps/)

## About this Learning Path

| Skill level:            | Advanced            |
|-------------------------|---------------------|
| Reading time:           | 1 hr                |
| Last updated:           | 29 Jul 2026         |

| Author:                        | Michael Hall, Arm                          |
|--------------------------------|--------------------------------------------|
| Arm IP:                        | [Cortex-A](https://support.arm.com/?tab=compute-ip&Product%20Type=Application%20Processors), [Neoverse](https://support.arm.com/?tab=compute-ip&Product%20Type=Infrastructure%20Processors) |
| Tags:                          | [ML](https://learn.arm.com/tag/ml), [Linux](https://learn.arm.com/tag/linux), [Python](https://learn.arm.com/tag/python), [PyTorch](https://learn.arm.com/tag/pytorch), [Docker](https://learn.arm.com/tag/docker), [Hugging Face](https://learn.arm.com/tag/hugging-face) |

### 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.

### What will you learn?
Upon completion of this Learning Path, you will be able to:
- Understand how fine-tuning teaches a model domain-specific knowledge
- Prepare a custom JSONL dataset for supervised fine-tuning
- Fine-tune Llama 3.2 3B on Raspberry Pi datasheet content using PyTorch and Hugging Face
- Compare base and fine-tuned model responses to verify factual accuracy improvements

### Prerequisites
Before starting, you will need the following:
- Hugging Face account and access token
- NVIDIA DGX Spark workstation

### Summary
You’ll fine-tune a Llama 3.2 3B model on an Arm-based NVIDIA DGX Spark, using the Grace CPU for orchestration and the GPU for training. You’ll configure Docker, prepare a JSONL dataset from Raspberry Pi datasheet content, and run supervised fine-tuning in a prebuilt PyTorch container. You’ll then serve both base and fine-tuned models with vLLM to compare factual responses.

### Frequently asked questions
<details>
<summary>How do I know Docker on DGX Spark is ready before pulling containers?</summary>
After configuring permissions, pull and run the pre-built PyTorch container as shown in the setup step. If it runs without permission errors, Docker is configured correctly.
</details>

<details>
<summary>Which Llama model variant does the training script target?</summary>
The path fine-tunes Llama 3.2 3B using `Llama3_3B_full_finetuning.py`. The path uses the 8B example only to illustrate why fine-tuning improves factual responses.
</details>

<details>
<summary>What dataset format should I use for supervised fine-tuning?</summary>
Use a JSONL dataset prepared for supervised fine-tuning. Ensure its fields match what the script loads; check the dataset loading section in the training script to align names and structure.
</details>

<details>
<summary>What output indicates the fine-tuning completed successfully?</summary>
The process produces a fine-tuned Llama model that the testing step can load with vLLM. If you’re able to serve the model in the vLLM container without errors, the fine-tuning completed successfully.
</details>

<details>
<summary>What result should I expect when comparing base and fine-tuned models?</summary>
On Raspberry Pi datasheet questions, the fine-tuned model should answer factual queries correctly. For example, it reports the RP2350 maximum clock as 150 MHz, while the base model might hallucinate a higher value.
</details>
