Skip to content

Commit

Permalink
upgrade transformers/hpu docker image/optimum habana version (#186)
Browse files Browse the repository at this point in the history
no need to maintain mpt model any more in itrex (contained in transformers 4.32.0)

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
Co-authored-by: Haihao Shen <haihao.shen@intel.com>
  • Loading branch information
sywangyi and hshen14 committed Aug 30, 2023
1 parent ac5744f commit 0e1e4d3
Show file tree
Hide file tree
Showing 32 changed files with 144 additions and 4,249 deletions.
12 changes: 5 additions & 7 deletions workflows/chatbot/fine_tuning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ python finetune_clm.py \



**For [MPT](https://huggingface.co/mosaicml/mpt-7b)**, use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.This model also requires that trust_remote_code=True be passed to the from_pretrained method. This is because we use a custom MPT model architecture that is not yet part of the Hugging Face transformers package.
**For [MPT](https://huggingface.co/mosaicml/mpt-7b)**, use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.

```bash
python finetune_clm.py \
Expand All @@ -300,7 +300,6 @@ python finetune_clm.py \
--save_strategy epoch \
--output_dir ./mpt_peft_finetuned_model \
--peft lora \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--no_cuda \
```
Expand Down Expand Up @@ -427,7 +426,6 @@ mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 finetune_clm.py
--group_by_length True \
--dataset_concatenation \
--do_train \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--no_cuda \
--ddp_backend ccl \
Expand Down Expand Up @@ -469,7 +467,7 @@ python finetune_clm.py \
--use_lazy_mode \
```

For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.This model also requires that trust_remote_code=True be passed to the from_pretrained method. This is because we use a custom MPT model architecture that is not yet part of the Hugging Face transformers package.
For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.

```bash
python finetune_clm.py \
Expand All @@ -493,7 +491,6 @@ python finetune_clm.py \
--log_level info \
--output_dir ./mpt_peft_finetuned_model \
--peft lora \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--habana \
--use_habana \
Expand Down Expand Up @@ -541,9 +538,10 @@ python ../../utils/gaudi_spawn.py \
--habana \
--use_habana \
--use_lazy_mode \
--distribution_strategy fast_ddp \
```

For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.This model also requires that trust_remote_code=True be passed to the from_pretrained method. This is because we use a custom MPT model architecture that is not yet part of the Hugging Face transformers package.
For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.

```bash
python ../../utils/gaudi_spawn.py \
Expand All @@ -568,11 +566,11 @@ python ../../utils/gaudi_spawn.py \
--log_level info \
--output_dir ./mpt_peft_finetuned_model \
--peft lora \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--habana \
--use_habana \
--use_lazy_mode \
--distribution_strategy fast_ddp \
```

Where the `--dataset_concatenation` argument is a way to vastly accelerate the fine-tuning process through training samples concatenation. With several tokenized sentences concatenated into a longer and concentrated sentence as the training sample instead of having several training samples with different lengths, this way is more efficient due to the parallelism characteristic provided by the more concentrated training samples.
Expand Down
9 changes: 5 additions & 4 deletions workflows/chatbot/fine_tuning/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ WORKDIR /itrex/workflows/chatbot/fine_tuning
CMD ["/usr/sbin/sshd", "-D"]

# HABANA environment
FROM vault.habana.ai/gaudi-docker/1.10.0/ubuntu22.04/habanalabs/pytorch-installer-2.0.1:latest as hpu
FROM vault.habana.ai/gaudi-docker/1.11.0/ubuntu22.04/habanalabs/pytorch-installer-2.0.1:latest as hpu

ENV LANG=en_US.UTF-8
ENV PYTHONPATH=/root:/usr/lib/habanalabs/
Expand All @@ -95,13 +95,13 @@ RUN apt-get update && \

# Install optimum-habana
RUN git clone https://github.com/huggingface/optimum-habana.git && \
cd optimum-habana/ && git reset --hard 9570fb8f359ef458fddfb4040e2280d5fec0fd11 && pip install -e . && cd ../ && \
cd optimum-habana/ && git reset --hard b6edce65b70e0fadd5d5f51234700bd1144cd0b0 && pip install -e . && cd ../ && \
cd ./optimum-habana/examples/text-generation/ && \
pip install -r requirements.txt && \
cd / && \
pip install einops && \
pip install datasets && \
pip install git+https://github.com/HabanaAI/DeepSpeed.git@1.10.0 && \
pip install git+https://github.com/HabanaAI/DeepSpeed.git@1.11.0 && \
git clone https://github.com/huggingface/peft.git && cd peft && python setup.py install

# Download ITREX code
Expand All @@ -114,6 +114,7 @@ RUN git clone --single-branch --branch=${ITREX_VER} ${REPO} itrex && \

# Build ITREX
RUN cd /itrex && pip install -v . && \
pip install transformers==4.28.1
pip install transformers==4.32.0 && \
pip install accelerate==0.22.0

WORKDIR /itrex/workflows/chatbot/fine_tuning
17 changes: 7 additions & 10 deletions workflows/chatbot/fine_tuning/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ python instruction_tuning_pipeline/finetune_clm.py \
--peft lora \
--use_fast_tokenizer false
```
For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.This model also requires that trust_remote_code=True be passed to the from_pretrained method. This is because we use a custom MPT model architecture that is not yet part of the Hugging Face transformers package.
For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.

```bash
python instruction_tuning_pipeline/finetune_clm.py \
Expand All @@ -124,7 +124,6 @@ python instruction_tuning_pipeline/finetune_clm.py \
--save_strategy epoch \
--output_dir ./mpt_peft_finetuned_model \
--peft lora \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--no_cuda \
```
Expand Down Expand Up @@ -154,7 +153,7 @@ For example, to finetune FLAN-T5 through Distributed Data Parallel training, bas
> Also please note that to use CPU for training in each node with multi-node settings, argument `--no_cuda` is mandatory, and `--ddp_backend ccl` is required if to use ccl as the distributed backend. In multi-node setting, following command needs to be launched in each node, and all the commands should be the same except for *`<NODE_RANK>`*, which should be integer from 0 to *`<NUM_NODES>`*`-1` assigned to each node.
``` bash
mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 finetune_seq2seq.py \
mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 instruction_tuning_pipeline/finetune_seq2seq.py \
--model_name_or_path "google/flan-t5-xl" \
--bf16 True \
--train_file "stanford_alpaca/alpaca_data.json" \
Expand Down Expand Up @@ -206,7 +205,7 @@ Now, run the following command in node0 and **4DDP** will be enabled in node0 an
export CCL_WORKER_COUNT=1
export MASTER_ADDR=xxx.xxx.xxx.xxx #node0 ip
## for DDP ptun for LLama
mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 finetune_clm.py \
mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 instruction_tuning_pipeline/finetune_clm.py \
--model_name_or_path decapoda-research/llama-7b-hf \
--train_file ./alpaca_data.json \
--bf16 True \
Expand All @@ -230,7 +229,7 @@ mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 finetune_clm.py
--ddp_backend ccl \

## for DDP LORA for MPT
mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 finetune_clm.py \
mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 instruction_tuning_pipeline/finetune_clm.py \
--model_name_or_path mosaicml/mpt-7b \
--train_file ./alpaca_data.json \
--bf16 True \
Expand All @@ -249,7 +248,6 @@ mpirun -f nodefile -n 16 -ppn 4 -genv OMP_NUM_THREADS=56 python3 finetune_clm.py
--group_by_length True \
--dataset_concatenation \
--do_train \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--no_cuda \
--ddp_backend ccl \
Expand Down Expand Up @@ -289,10 +287,10 @@ python instruction_tuning_pipeline/finetune_clm.py \
--use_lazy_mode \
```

For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.This model also requires that trust_remote_code=True be passed to the from_pretrained method. This is because we use a custom MPT model architecture that is not yet part of the Hugging Face transformers package.
For [MPT](https://huggingface.co/mosaicml/mpt-7b), use the below command line for finetuning on the Alpaca dataset. Only LORA supports MPT in PEFT perspective.it uses gpt-neox-20b tokenizer, so you need to define it in command line explicitly.

```bash
python finetune_clm.py \
python instruction_tuning_pipeline/finetune_clm.py \
--model_name_or_path "mosaicml/mpt-7b" \
--bf16 True \
--train_file "/path/to/alpaca_data.json" \
Expand All @@ -310,7 +308,6 @@ python finetune_clm.py \
--save_strategy epoch \
--output_dir ./mpt_peft_finetuned_model \
--peft lora \
--trust_remote_code True \
--tokenizer_name "EleutherAI/gpt-neox-20b" \
--habana \
--use_habana \
Expand All @@ -323,4 +320,4 @@ 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.

Add option **"--use_fast_tokenizer False"** when using latest transformers if you met failure in llama fast tokenizer for llama, The `tokenizer_class` in `tokenizer_config.json` should be changed from `LLaMATokenizer` to `LlamaTokenizer`
Add option **"--use_fast_tokenizer False"** when using latest transformers if you met failure in llama fast tokenizer for llama, The `tokenizer_class` in `tokenizer_config.json` should be changed from `LLaMATokenizer` to `LlamaTokenizer`

0 comments on commit 0e1e4d3

Please sign in to comment.