Windows Installation

See how to install Unsloth on Windows with or without WSL.

For Windows, pip install unsloth now works, however you must have Pytorch previously installed.

Method #1 - Docker:

Docker might be the easiest way for Windows users to get started with Unsloth as there is no setup needed or dependency issues. unsloth/unsloth is Unsloth's only Docker image. For Blackwell and 50-series GPUs, use this same image - no separate image needed.

For installation instructions, please follow our Docker guide, otherwise here is a quickstart guide:

1

Install Docker and NVIDIA Container Toolkit.

Install Docker via Linux or Desktop (other). Then install NVIDIA Container Toolkit:

export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.17.8-1
sudo apt-get update && sudo apt-get install -y \
  nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}
2

Run the container.

unsloth/unsloth is Unsloth's only Docker image.

docker run -d -e JUPYTER_PASSWORD="mypassword" \
  -p 8888:8888 -p 2222:22 \
  -v $(pwd)/work:/workspace/work \
  --gpus all \
  unsloth/unsloth
3

Access Jupyter Lab

Go to http://localhost:8888 and open Unsloth. Access the unsloth-notebooks tabs to see Unsloth notebooks.

4

Start training with Unsloth

If you're new, follow our step-by-step Fine-tuning Guide, RL Guide or just save/copy any of our premade notebooks.

5

Docker issues - GPU not discovered?

Try doing WSL via Method #2 - WSL:

Method #2 - WSL:

1

Install WSL

Open up Command Prompt, the Terminal, and install Ubuntu. Set the password if asked.

wsl.exe --install Ubuntu-24.04
wsl.exe -d Ubuntu-24.04
2

If you did NOT do (1), so you already installed WSL, enter WSL by typing wsl and ENTER in the command prompt

wsl
3

Install Python

sudo apt update
sudo apt install python3 python3-full python3-pip python3-venv -y
4

Install PyTorch

pip install torch torchvision --force-reinstall --index-url https://download.pytorch.org/whl/cu130

If you encounter permission issues, use –break-system-packages so pip install torch torchvision --force-reinstall --index-url https://download.pytorch.org/whl/cu130 –break-system-packages

5

Install Unsloth and Jupyter Notebook

pip install unsloth jupyter

If you encounter permission issues, use –break-system-packages so pip install unsloth jupyter –break-system-packages

6

Launch Unsloth via Jupyter Notebook

jupyter notebook

Then open up our notebooks within Unsloth Notebooksand load them up! You can also go to Colab notebooks and download > download .ipynb and load them.

Method #3 - Windows directly:

Python 3.13 now works with Unsloth!

1

Install NVIDIA Video Driver

You should install the latest version of your GPUs driver. Download drivers here: NVIDIA GPU Drive

2

Install Visual Studio C++

You will need Visual Studio, with C++ installed. By default, C++ is not installed with Visual Studio, so make sure you select all of the C++ options. Also select options for Windows 10/11 SDK.

  • Launch the Installer here: Visual Studio Community Edition

  • In the installer, navigate to individual components and select all the options listed here:

    • .NET Framework 4.8 SDK

    • .NET Framework 4.7.2 targeting pack

    • C# and Visual Basic Roslyn compilers

    • MSBuild

    • MSVC v143 - VS 2022 C++ x64/x86 build tools

    • C++ 2022 Redistributable Update

    • C++ CMake tools for Windows

    • C++/CLI support for v143 build tools (Latest)

    • MSBuild support for LLVM (clang-cl) toolset

    • C++ Clang Compiler for Windows (19.1.1)

    • Windows 11 SDK (10.0.22621.0)

    • Windows Universal CRT SDK

    • C++ 2022 Redistributable MSMs

Easier method: Or you can open an elevated Command Prompt or PowerShell:

  • Search for "cmd" or "PowerShell", right-click it, and choose "Run as administrator."

  • Paste and run this command (update the Visual Studio path if necessary):

"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify ^
--installPath "C:\Program Files\Microsoft Visual Studio\2022\Community" ^
--add Microsoft.Net.Component.4.8.SDK ^
--add Microsoft.Net.Component.4.7.2.TargetingPack ^
--add Microsoft.VisualStudio.Component.Roslyn.Compiler ^
--add Microsoft.Component.MSBuild ^
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^
--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^
--add Microsoft.VisualStudio.Component.VC.CMake.Project ^
--add Microsoft.VisualStudio.Component.VC.CLI.Support ^
--add Microsoft.VisualStudio.Component.VC.Llvm.Clang ^
--add Microsoft.VisualStudio.ComponentGroup.ClangCL ^
--add Microsoft.VisualStudio.Component.Windows11SDK.22621 ^
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
--add Microsoft.VisualStudio.Component.UniversalCRT.SDK ^
--add Microsoft.VisualStudio.Component.VC.Redist.MSM
3

Install Python and CUDA Toolkit

Follow the instructions to install CUDA Toolkit.

Then install Miniconda (which has Python) here: https://www.anaconda.com/docs/getting-started/miniconda/install

4

Install PyTorch

You will need the correct version of PyTorch that is compatible with your CUDA drivers, so make sure to select them carefully. Install PyTorch

5

Install Unsloth

Open Conda command prompt or your terminal with Python and run the command:

pip install "unsloth[windows] @ git+https://github.com/unslothai/unsloth.git"

Notes

To run Unsloth directly on Windows:

  • Install Triton from this Windows fork and follow the instructions here (be aware that the Windows fork requires PyTorch >= 2.4 and CUDA 12)

  • In the SFTTrainer, set dataset_num_proc=1 to avoid a crashing issue:

Advanced/Troubleshooting

For advanced installation instructions or if you see weird errors during installations:

  1. Install torch and triton. Go to https://pytorch.org to install it. For example pip install torch torchvision torchaudio triton

  2. Confirm if CUDA is installated correctly. Try nvcc. If that fails, you need to install cudatoolkit or CUDA drivers.

  3. Install xformers manually. You can try installing vllm and seeing if vllm succeeds. Check if xformers succeeded with python -m xformers.info Go to https://github.com/facebookresearch/xformers. Another option is to install flash-attn for Ampere GPUs.

  4. Double check that your versions of Python, CUDA, CUDNN, torch, triton, and xformers are compatible with one another. The PyTorch Compatibility Matrix may be useful.

  5. Finally, install bitsandbytes and check it with python -m bitsandbytes

Method #3 - Windows using PowerShell:

Step 1: Install Prerequisites

  1. Install NVIDIA CUDA Toolkit:

    • Download and install the appropriate version of the NVIDIA CUDA Toolkit from CUDA Downloads.

    • Reboot your system after installation if prompted.

    • Note: No additional setup is required after installation for Unsloth.

  2. Install Microsoft C++ Build Tools:

    • Download and install Microsoft Build Tools for Visual Studio from the official website.

    • During installation, select the C++ build tools workload. Ensure the MSVC compiler toolset is included.

  3. Set Environment Variables for the C++ Compiler:

    • Open the System Properties window (search for "Environment Variables" in the Start menu).

    • Click "Environment Variables…".

    • Add or update the following under System variables:

      • CC: Path to the cl.exe C++ compiler. Example (adjust if your version differs):

      • CXX: Same path as CC.

    • Click OK to save changes.

    • Verify: Open a new terminal and type cl. It should show version info.

  4. Install Conda

    1. Download and install Miniconda from the official website

    2. Follow installation instruction from the website

    3. To check whether conda is already installed, you can test it with conda in your PowerShell

Step 2: Run the Unsloth Installation Script

  1. Download the unsloth_windows.ps1 PowerShell script by going through this link.

  2. Open PowerShell as Administrator:

    • Right-click Start and select "Windows PowerShell (Admin)".

  3. Navigate to the script’s location using cd:

  4. Run the script:

Step 3: Using Unsloth

Activate the environment after the installation completes:

Unsloth and its dependencies are now ready!

Last updated

Was this helpful?