Windows Installation

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

Method #1 - Windows directly:

To run Unsloth directly on Windows (without WSL):

  • Install Triton from this Windows fork and follow the instructions here.

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

trainer = SFTTrainer(
    dataset_num_proc=1,
    ...
)

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

  1. Install torch and triton. Go to Pytorch 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. Install bitsandbytes and check it with python -m bitsandbytes.

  5. Afterwards, follow our standard pip install procedure: For stable releases, use pip install unsloth. We recommend pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git" for most installations though.


Method #2 - 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):

        C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe
      • CXX: Same path as CC.

    • Click OK to save changes.

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

Step 2: Run the Unsloth Installation Script

  1. Download the unsloth_windows.ps1 PowerShell script.

  2. Open PowerShell as Administrator:

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

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

    cd path\to\script\folder
  4. Run the script:

    powershell.exe -ExecutionPolicy Bypass -File .\unsloth_windows.ps1

Step 3: Using Unsloth

Activate the environment after the installation completes:

conda activate unsloth_env

Unsloth and its dependencies are now ready!


Method #3 - Windows via WSL:

WSL is Window's subsystem for Linux.

  1. Install python though Python's official site.

  2. Start WSL (Should already be preinstalled). Open command prompt as admin then run:

wsl -d ubuntu

Optional: If WSL is not preinstalled, go to the Microsoft store and search "Ubuntu" and the app that says Ubuntu will be WSL. Install it and run it and continue from there.

  1. Update WSL:

sudo apt update && sudo apt upgrade -y
  1. Install pip:

sudo apt install python3-pip
  1. Install unsloth:

pip install unsloth
  1. Optional: Install Jupyter Notebook to run in a Colab like environment:

pip3 install notebook
  1. Launch Jupyter Notebook:

jupyter notebook

Last updated