From 581ebf610494f90259b8d3ff38581bb7473c3753 Mon Sep 17 00:00:00 2001 From: Heyang Sun <60865256+Uxito-Ada@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:47:41 +0800 Subject: [PATCH] GaLore Finetuning Example (#10722) * GaLore Finetuning Example * Update README.md * Update README.md * change data to HuggingFaceH4/helpful_instructions * Update README.md * Update README.md * shrink train size and delete cache before starting training to save memory * Update README.md * Update galore_finetuning.py * change model to llama2 3b * Update README.md --- .../GPU/LLM-Finetuning/GaLore/README.md | 54 ++++++++++ .../GaLore/galore_finetuning.py | 99 +++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 python/llm/example/GPU/LLM-Finetuning/GaLore/README.md create mode 100644 python/llm/example/GPU/LLM-Finetuning/GaLore/galore_finetuning.py diff --git a/python/llm/example/GPU/LLM-Finetuning/GaLore/README.md b/python/llm/example/GPU/LLM-Finetuning/GaLore/README.md new file mode 100644 index 00000000..d39e2b92 --- /dev/null +++ b/python/llm/example/GPU/LLM-Finetuning/GaLore/README.md @@ -0,0 +1,54 @@ +# GaLore Finetuning with IPEX-LLM + +This is an example of IPEX-LLM GaLore fine-tuning on [Intel GPU](../../../README.md), which refers [Huggingface GaLore blog](https://huggingface.co/blog/galore) and changes model to [openlm-research/open_llama_3b_v2](https://huggingface.co/openlm-research/open_llama_3b_v2) and dataset to [HuggingFaceH4/helpful_instructions](https://huggingface.co/datasets/HuggingFaceH4/helpful_instructions). + +### 0. Requirements +To run this example with IPEX-LLM on Intel GPUs, we have some recommended requirements for your machine, please refer to [here](../../../README.md#requirements) for more information. + +### 1. Install + +```bash +conda create -n llm python=3.11 +conda activate llm +# below command will install intel_extension_for_pytorch==2.1.10+xpu as default +pip install --pre --upgrade ipex-llm[xpu] --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ +pip install galore-torch +pip install accelerate==0.28.0 +pip install bitsandbytes==0.43.0 +pip install datasets==2.18.0 +pip install transformers==4.39.1 +pip install trl==0.8.1 +``` + +### 2. GaLore Finetune + +Currently, GaLore only supports local fine-tuning, and here is how to fine-tune Llama2 7B on an Intel Max GPU server: + +```bash +# Configures OneAPI environment variables +source /opt/intel/oneapi/setvars.sh +python galore_finetuning.py # optional parameters as below +``` + +Optional parameters for `galore_finetuning.py`: + +**--repo-id-or-model-path** : default to `openlm-research/open_llama_3b_v2`, and you can also specify your local model path. + +**--data-path** : default to `HuggingFaceH4/helpful_instructions`, and you can also specify your local datal path, while note that changing to the other datasets will introduce code modification effort for yourself. + +**--output-dir** : default to `./ipex-llm-galore` to save fine-tuned model, and you can change if needed. + +### 3. Sample Output +```log +...... +{'loss': 2.0989, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.0} +{'loss': 1.9064, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.0} +{'loss': 1.7483, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.01} +{'loss': 1.9551, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.01} +{'loss': 1.783, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.01} +{'loss': 1.3328, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.01} +{'loss': 1.4622, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.01} +{'loss': 1.9094, 'grad_norm': 0.0, 'learning_rate': 0.001, 'epoch': 0.02} + 5%|████▏ | 70/1500 [xx:xx