Mark Ku's Blog
Podcast ConversationAI dialogue version of this article · Mandarin audio
Audio for this article is powered by VoAIVoAI

Introduction

LLaMA Factory is a very popular framework for fine-tuning your own models. Because I want to build my own customer service chatbot, I looked up some resources and decided to try fine-tuning some open-source AI models.

Potential AI Requirements

  • The AI should be able to answer common customer service FAQs.
  • The AI should be able to recommend pre-built computer packages.
  • The AI should be able to configure a custom PC build based on a customer's budget.

Prerequisites

An Nvidia 4070 Ti Super graphics card

Video card
Video card

Hardware Requirements

MethodBits7B13B30B70B110B8x7B8x22B
Full AMP7120GB240GB600GB1200GB2000GB900GB2400GB
Full1660GB120GB300GB600GB900GB400GB1200GB
Freeze1620GB40GB80GB200GB360GB160GB400GB
LoRA/GaLore/BAdam1616GB32GB64GB160GB240GB120GB320GB
QLoRA810GB20GB40GB80GB140GB60GB160GB
QLoRA46GB12GB24GB48GB72GB30GB96GB
QLoRA24GB8GB16GB24GB48GB18GB48GB

Required Installations

First, download and install Python. Here, we'll install a relatively stable version, 3.12.

Next, download and install CUDA. This needs to match your graphics card version (it's best to install the driver at the same time).

CUDA
CUDA

P.S. If the driver installation fails, try unchecking Nsight VSE and Visual Studio Integration. This can happen if you have multiple versions of Visual Studio installed, which may cause conflicts. install cuda

Check Driver Version and Compatible CUDA Version

nvidia-smi 
test cuda version
test cuda version

Check Installed Driver and CUDA Version

nvcc -V

Then, install PyTorch

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

Test if Python can communicate with the GPU (test-gpu-test.py)

import torch
print(torch.cuda.is_available())  # 是否可以用gpu False不能,True可以
print(torch.cuda.device_count())  # gpu數量, 0就是沒有,1就是檢測到了
test gpu result
test gpu result

Installing LLaMA Factory

First, clone the repository

git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git

Change into the project directory

cd LLaMA-Factory

Install dependencies

pip install -e ".[torch,metrics]"

Verify the installation

llamafactory-cli version

Start the application

llamafactory-cli webui

After selecting a dataset, you can start training the model

llamafactory cli webuillamafactory cli webui console

P.S. Addendum - If you encounter the CUDA environment was not detected. error, you likely missed one of the previous installation steps.

References

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··492

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··334

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··268

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··218

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··217

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11