---
title: "Fine-Tune Faster with Unsloth — Instructions"
canonical: "https://build.nvidia.com/playbooks/unsloth/instructions.md"
---

> [!NOTE]
> These instructions target **Linux** with a GPU-enabled PyTorch container. Run the install and validation steps inside the container unless noted otherwise.

# Step 1. Verify prerequisites

Confirm the CUDA toolkit and GPU resources on your hardware platform.

```bash
nvcc --version
```

Expected output should show CUDA 13.0.

```bash
nvidia-smi
```

Expected output should show a summary of GPU information.

# Step 2. Pull the container image

```bash
docker pull nvcr.io/nvidia/pytorch:25.11-py3
```

# Step 3. Launch the container

```bash
docker run --gpus all --ulimit memlock=-1 -it --ulimit stack=67108864 --entrypoint /usr/bin/bash --rm nvcr.io/nvidia/pytorch:25.11-py3
```

You are now in an interactive shell inside the container for the remaining install and validation steps.

# Step 4. Install dependencies

Inside the container:

```bash
pip install transformers peft hf_transfer "datasets==4.3.0" "trl==0.26.1"
pip install --no-deps unsloth unsloth_zoo bitsandbytes
```

# Step 5. Get the validation script

Download the test script into the container. The file is also listed under Ancillary files in the **Overview** tab.

```bash
curl -O https://raw.githubusercontent.com/NVIDIA/dgx-spark-playbooks/refs/heads/main/nvidia/playbook-unsloth/assets/test_unsloth.py
```

This script runs a short fine-tuning job to validate the Unsloth install.

# Step 6. Run the validation test

```bash
python test_unsloth.py
```

Expected output in the terminal:

- A message that Unsloth will patch the environment for faster fine-tuning
- Training progress bars with loss decreasing over 60 steps
- Final training metrics showing completion

# Step 7. Next steps

Adapt `test_unsloth.py` for your own model and dataset:

```python
# Replace the model_name argument in FastModel.from_pretrained with your choice
model_name = "unsloth/Meta-Llama-3.1-8B-bnb-4bit"

# Load your custom dataset (see the dataset load near the top of the script)
dataset = load_dataset("your_dataset_name")

# Adjust training parameters in SFTConfig (for example)
per_device_train_batch_size = 4
max_steps = 1000
```

For advanced usage, see the [Unsloth wiki](https://github.com/unslothai/unsloth/wiki), including:

- [Saving models in GGUF format](https://github.com/unslothai/unsloth/wiki#saving-to-gguf)
- [Continued training from checkpoints](https://github.com/unslothai/unsloth/wiki#loading-lora-adapters-for-continued-finetuning)
- [Using custom chat templates](https://github.com/unslothai/unsloth/wiki#chat-templates)
- [Running evaluation loops](https://github.com/unslothai/unsloth/wiki#evaluation-loop---also-fixes-oom-or-crashing)

# Step 8. Cleanup (optional)

When you exit the interactive container (`exit` or Ctrl-D), the `--rm` flag removes it. Pulled images remain on the host until you remove them:

```bash
docker rmi nvcr.io/nvidia/pytorch:25.11-py3
```

> [!WARNING]
> Removing the image deletes the local copy of `nvcr.io/nvidia/pytorch:25.11-py3`. Re-pull it if you run this playbook again.