### Install LLaMA Factory from source Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Clone the repository and install the package with required metrics dependencies. ```bash git clone --depth 1 https://github.com/hiyouga/LlamaFactory.git cd LlamaFactory pip install -e . pip install -r requirements/metrics.txt ``` -------------------------------- ### Training Flow Example Source: https://github.com/hiyouga/llamafactory/blob/main/CLAUDE.md Illustrates the training invocation using a YAML configuration file. ```bash llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml ``` -------------------------------- ### Install Docker (Ubuntu/Debian) Source: https://github.com/hiyouga/llamafactory/blob/main/docker/docker-cuda/README.md Installs Docker on Ubuntu/Debian systems. Alternatively, use the official Docker Engine installation guide. ```bash sudo apt-get update sudo apt-get install docker.io ``` -------------------------------- ### Launch LLaMA Board GUI Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Starts the Gradio-based web interface for fine-tuning. ```bash llamafactory-cli webui ``` -------------------------------- ### Install Transformers from source Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Required step to install the latest transformers library from the main branch. ```bash git clone -b main https://github.com/huggingface/transformers.git cd transformers pip install . ``` -------------------------------- ### Install bitsandbytes for Ascend NPU Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Manual compilation steps for bitsandbytes on Ascend NPU environments. ```bash # Install bitsandbytes from source # Clone bitsandbytes repo, Ascend NPU backend is currently enabled on multi-backend-refactor branch git clone -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git cd bitsandbytes/ # Install dependencies pip install -r requirements-dev.txt # Install the dependencies for the compilation tools. Note that the commands for this step may vary depending on the operating system. The following are provided for reference apt-get install -y build-essential cmake # Compile & install cmake -DCOMPUTE_BACKEND=npu -S . make pip install . ``` -------------------------------- ### Build and run Docker containers with Docker Compose Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Commands to initialize the environment and start the container for specific hardware backends. ```bash cd docker/docker-cuda/ docker compose up -d docker compose exec llamafactory bash ``` ```bash cd docker/docker-npu/ docker compose up -d docker compose exec llamafactory bash ``` ```bash cd docker/docker-rocm/ docker compose up -d docker compose exec llamafactory bash ``` -------------------------------- ### Install bitsandbytes on Windows Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Commands for installing bitsandbytes via pip or uv, including a third-party wheel option for compatibility. ```bash pip install bitsandbytes ``` ```bash uv pip install bitsandbytes --no-deps ``` ```bash pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.2.post2-py3-none-win_amd64.whl ``` -------------------------------- ### Launch Web UI ChatBox Source: https://github.com/hiyouga/llamafactory/blob/main/examples/README.md Start a web-based chat interface for interacting with a fine-tuned model. This is useful for a more interactive user experience. ```bash llamafactory-cli webchat examples/inference/qwen3_lora_sft.yaml ``` -------------------------------- ### Install PyTorch for Windows Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Install the CUDA-enabled version of PyTorch and verify the installation. ```bash pip uninstall torch torchvision torchaudio pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 python -c "import torch; print(torch.cuda.is_available())" ``` -------------------------------- ### Install Docker Compose (Ubuntu/Debian) Source: https://github.com/hiyouga/llamafactory/blob/main/docker/docker-cuda/README.md Installs Docker Compose on Ubuntu/Debian systems. The latest version can also be installed from the official Docker Compose documentation. ```bash sudo apt-get install docker-compose ``` -------------------------------- ### Run WebUI with uv Source: https://github.com/hiyouga/llamafactory/blob/main/README.md Launch the LLaMA Factory web interface using the uv package manager. ```bash uv run llamafactory-cli webui ``` -------------------------------- ### Install NVIDIA Container Toolkit Source: https://github.com/hiyouga/llamafactory/blob/main/docker/docker-cuda/README.md Installs the NVIDIA Container Toolkit, which is essential for Docker containers to access NVIDIA GPUs. This involves adding NVIDIA's repository and then installing the toolkit. Remember to restart the Docker service afterwards. ```bash distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update sudo apt-get install -y nvidia-container-toolkit sudo systemctl restart docker ``` -------------------------------- ### Build Package Source: https://github.com/hiyouga/llamafactory/blob/main/CLAUDE.md Compiles and packages the project. ```bash make build ``` -------------------------------- ### Test CUDA Availability Source: https://github.com/hiyouga/llamafactory/wiki/Environment Verify that PyTorch is installed with CUDA support. Ensure CUDA is correctly configured on your system. ```python import torch assert torch.cuda.is_available() is True ``` -------------------------------- ### FSDP+QLoRA Fine-Tuning Script Source: https://github.com/hiyouga/llamafactory/blob/main/examples/README.md Execute a training script that combines Fully Sharded Data Parallel (FSDP) with QLoRA for efficient fine-tuning. This is a specialized training setup. ```bash bash examples/extras/fsdp_qlora/train.sh ```