« Llama-Factory » : différence entre les versions
Autres actions
| Ligne 136 : | Ligne 136 : | ||
# cp hy_mt2_support_tmp/train/llama_factory_support/hy_dense_template.py hy_mt2_support/ | # cp hy_mt2_support_tmp/train/llama_factory_support/hy_dense_template.py hy_mt2_support/ | ||
# cp hy_mt2_support_tmp/train/llama_factory_support/hy_v3_patches.py hy_mt2_support/ | # cp hy_mt2_support_tmp/train/llama_factory_support/hy_v3_patches.py hy_mt2_support/ | ||
# rm -rf hy_mt2_support_tmp | |||
Version du 16 août 2026 à 12:12
Prérequis
- Disposer d’un environnement GPU fonctionnel avec CUDA Toolkit pour une carte NVIDIA ou ROCm pour une carte AMD, voir cette page.
- Distribution Ubuntu recommandée.
Installation
# apt update && apt upgrade # apt install -y python3 python3-venv python3-pip
Créer un environnement virtuel dédié :
# mkdir -p /opt/llamafactory # python3 -m venv /opt/llamafactory/venv # source /opt/llamafactory/venv/bin/activate
Mettre à jour les outils Python :
# python -m pip install --upgrade pip setuptools wheel
Télécharger LLaMA-Factory :
# cd /opt/llamafactory # git clone --depth 1 https://github.com/hiyouga/LlamaFactory.git # cd LlamaFactory
Installation de PyTorch
Carte AMD
Installer PyTorch avec le support ROCm (exemple avec ROCm 7.2) :
# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm7.2
Vérifier que PyTorch détecte le GPU :
# python -c "import torch; print(torch.__version__); print(torch.version.hip); print(torch.cuda.is_available()); print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'GPU non détecté')"
Fix pour PyTorch sous Windows WSL
Supprimer l'environnement virtuel existant :
# deactivate 2>/dev/null || true # rm -rf /opt/llamafactory/venv
Installer uv et Python 3.12 :
# curl -LsSf https://astral.sh/uv/install.sh | sh # source ~/.bashrc # uv python install 3.12
Recréer l'environnement virtuel :
# uv venv --python 3.12 /opt/llamafactory/venv # uv pip install --python /opt/llamafactory/venv/bin/python pip setuptools wheel # source /opt/llamafactory/venv/bin/activate
Créer les répertoires temporaires et de téléchargement :
# mkdir -p /opt/pip-tmp # mkdir -p /opt/pytorch-rocm # cd /opt/pytorch-rocm
Télécharger les wheels AMD compatibles ROCm 7.2 :
# wget 'https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/torch-2.9.1%2Brocm7.2.0.lw.git7e1940d4-cp312-cp312-linux_x86_64.whl' # wget 'https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/torchvision-0.24.0%2Brocm7.2.0.gitb919bd0c-cp312-cp312-linux_x86_64.whl' # wget 'https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/torchaudio-2.9.0%2Brocm7.2.0.gite3c6ee2b-cp312-cp312-linux_x86_64.whl' # wget 'https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/triton-3.5.1%2Brocm7.2.0.gita272dfa8-cp312-cp312-linux_x86_64.whl'
Installer les wheels PyTorch AMD :
# TMPDIR=/opt/pip-tmp uv pip install \ --python /opt/llamafactory/venv/bin/python \ --no-cache \ ./torch-2.9.1+rocm7.2.0.lw.git7e1940d4-cp312-cp312-linux_x86_64.whl \ ./torchvision-0.24.0+rocm7.2.0.gitb919bd0c-cp312-cp312-linux_x86_64.whl \ ./torchaudio-2.9.0+rocm7.2.0.gite3c6ee2b-cp312-cp312-linux_x86_64.whl \ ./triton-3.5.1+rocm7.2.0.gita272dfa8-cp312-cp312-linux_x86_64.whl
Sous WSL avec ROCDXG, supprimer le runtime HSA inclus dans la wheel PyTorch afin d'utiliser le runtime HSA système compatible WSL :
# location=$(pip show torch | awk -F ': ' '/Location/{print $2}')
# rm -f "$location/torch/lib/libhsa-runtime64.so"*
# ldconfig
Vérifier que la variable ROCDXG est active :
# echo $HSA_ENABLE_DXG_DETECTION
La commande doit retourner :
1
Vérifier que PyTorch détecte le GPU :
# python -c "import torch; print(torch.__version__); print(torch.version.hip); print(torch.cuda.is_available()); print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'GPU non détecté')"
Exemple de résultat attendu :
2.9.1+rocm7.2.0.git7e1940d4 7.2.x True AMD Radeon RX 9070 XT
Carte NVIDIA
Installation de LLaMA-Factory
# pip install -e . # pip install -r requirements/metrics.txt
Vérification
# llamafactory-cli version # llamafactory-cli env
Interface Web
# llamafactory-cli webui
Exemples
hy_mt2 (QLoRA)
Avec pour exemple le dataset paradox_sft_eu5.jsonl
# source /opt/llamafactory/venv/bin/activate # cd /opt/llamafactory/LlamaFactory # mkdir paradox_data
On place le fichier paradox_sft_eu5.jsonl dans /opt/llamafactory/LlamaFactory/paradox_data
# vi paradox_data/dataset_info.json
{
"paradox_eu5": {
"file_name": "paradox_sft_eu5.jsonl",
"formatting": "sharegpt",
"columns": {
"messages": "messages"
},
"tags": {
"role_tag": "role",
"content_tag": "content",
"user_tag": "user",
"assistant_tag": "assistant",
"system_tag": "system"
}
}
}
On installe bitsandbytes si nécessaire (indispensable pour QLoRA) :
# pip install -U bitsandbytes # python -m bitsandbytes
Ensuite on récupère les 3 petits fichiers officiels Tencent nécessaires au wrapper :
# mkdir -p hy_mt2_support hy_mt2_support_tmp
# hf download tencent/Hy-MT2-7B-GGUF \ train/llama_factory_support/train_hy_dense.py \ train/llama_factory_support/hy_dense_template.py \ train/llama_factory_support/hy_v3_patches.py \ --local-dir hy_mt2_support_tmp
# cp hy_mt2_support_tmp/train/llama_factory_support/train_hy_dense.py hy_mt2_support/ # cp hy_mt2_support_tmp/train/llama_factory_support/hy_dense_template.py hy_mt2_support/ # cp hy_mt2_support_tmp/train/llama_factory_support/hy_v3_patches.py hy_mt2_support/
# rm -rf hy_mt2_support_tmp