Skip to content

Commit

Permalink
added finetuning example for gemma-2b on ARC. (#1328)
Browse files Browse the repository at this point in the history
Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com>
  • Loading branch information
XinyuYe-Intel committed Feb 29, 2024
1 parent ae91bf8 commit ffa8f3c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 2 additions & 4 deletions intel_extension_for_transformers/llm/finetuning/finetuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
is_deepspeed_available,
)
from intel_extension_for_transformers.utils.device_utils import is_hpu_available
from intel_extension_for_transformers.neural_chat.utils.common import get_device_type


if is_bitsandbytes_available():
Expand All @@ -76,10 +77,7 @@ def __init__(self, finetuning_config: BaseFinetuningConfig):
finetuning_config.finetune_args
)
if finetuning_config.finetune_args.device == "auto":
if torch.cuda.is_available():
finetuning_config.finetune_args.device = "cuda"
else:
finetuning_config.finetune_args.device = "cpu"
finetuning_config.finetune_args.device = get_device_type()
if finetuning_config.finetune_args.device == "cpu":
Arguments = type(finetuning_config.training_args)
training_args = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,35 @@ For finetuning on SPR, add `--bf16` argument will speedup the finetuning process
You could also indicate `--peft` to switch peft method in P-tuning, Prefix tuning, Prompt tuning, LLama Adapter, LoRA,
see https://github.com/huggingface/peft. Note for MPT, only LoRA is supported.

## Fine-tuning on Intel Arc GPUs

### 1. Single Card Fine-tuning

Follow the installation guidance in [intel-extension-for-pytorch](https://github.com/intel/intel-extension-for-pytorch) to install intel-extension-for-pytorch for GPU.

For `google/gemma-2b`, use the below command line for finetuning on the Alpaca dataset.

```bash
python finetune_clm.py \
--model_name_or_path "google/gemma-2b" \
--train_file "/path/to/alpaca_data.json" \
--dataset_concatenation \
--per_device_train_batch_size 2 \
--per_device_eval_batch_size 2 \
--gradient_accumulation_steps 4 \
--evaluation_strategy "no" \
--save_strategy "steps" \
--save_steps 2000 \
--save_total_limit 1 \
--learning_rate 1e-4 \
--do_train \
--num_train_epochs 3 \
--overwrite_output_dir \
--log_level info \
--output_dir ./gemma-2b_peft_finetuned_model \
--peft lora \
--gradient_checkpointing True
```

# Evaluation Metrics

Expand Down

0 comments on commit ffa8f3c

Please sign in to comment.