Skip to content

Commit

Permalink
Upgrade to Transformers 4.43 (huggingface#1163)
Browse files Browse the repository at this point in the history
Signed-off-by: P V R K Jyothendra Varma <[email protected]>
Signed-off-by: Wang, Yi A <[email protected]>
Co-authored-by: Soila Kavulya <[email protected]>
Co-authored-by: Jimin Ha <[email protected]>
Co-authored-by: ZhengHongming888 <[email protected]>
Co-authored-by: P V R K Jyothendra Varma <[email protected]>
Co-authored-by: Daniel Huang <[email protected]>
Co-authored-by: Dudi Lester <[email protected]>
Co-authored-by: Danny Semiat <[email protected]>
Co-authored-by: Seunghyuk Park <[email protected]>
Co-authored-by: sushil Dubey <[email protected]>
Co-authored-by: Sun Choi <[email protected]>
Co-authored-by: Iman Gohari <[email protected]>
Co-authored-by: Uri Livne <[email protected]>
Co-authored-by: yan tomsinsky <[email protected]>
Co-authored-by: Murthy L <[email protected]>
Co-authored-by: Local Lab User <[email protected]>
Co-authored-by: Thanaji Rao Thakkalapelli <[email protected]>
Co-authored-by: Yaser Afshar <[email protected]>
Co-authored-by: Vivek Goel <[email protected]>
Co-authored-by: Anshuman Tripathy <[email protected]>
Co-authored-by: Witold Szczurek <[email protected]>
Co-authored-by: Sayantan Sarkar <[email protected]>
Co-authored-by: Harish Subramony <[email protected]>
Co-authored-by: Wang, Yi A <[email protected]>
Co-authored-by: Sayantan Sarkar <[email protected]>
Co-authored-by: abhatkal <[email protected]>
Co-authored-by: Colabrese <[email protected]>
Co-authored-by: Abhilash Majumder <[email protected]>
  • Loading branch information
1 parent 13b6452 commit 34c780e
Show file tree
Hide file tree
Showing 128 changed files with 4,463 additions and 3,200 deletions.
4 changes: 2 additions & 2 deletions examples/audio-classification/run_audio_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.14.0", "To fix: pip install -r examples/pytorch/audio-classification/requirements.txt")

Expand Down
11 changes: 4 additions & 7 deletions examples/contrastive-image-text/clip_media_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
media_ext_reader_op_impl,
media_ext_reader_op_tensor_info,
)
from habana_frameworks.torch.hpu import get_device_name
except ImportError:
pass

Expand All @@ -47,7 +46,7 @@ class read_image_text_from_dataset(media_ext_reader_op_impl):
"""

def __init__(self, params):
def __init__(self, params, fw_params):
self.batch_size = 1
params = params["priv_params"]
self.meta_dtype = params["label_dtype"]
Expand All @@ -64,9 +63,7 @@ def __init__(self, params):
else:
self.max_file = get_max_file([img["path"] for img in self.dataset["image"]])
logger.info(f"The largest file is {self.max_file}.")

def set_params(self, params):
self.batch_size = params.batch_size
self.batch_size = fw_params.batch_size

def gen_output_info(self):
out_info = []
Expand Down Expand Up @@ -134,7 +131,7 @@ class ClipMediaPipe(MediaPipe):
instance_count = 0

def __init__(self, dataset=None, sampler=None, batch_size=512, drop_last=False, queue_depth=1):
self.device = get_device_name()
self.device = "legacy"
self.dataset = dataset
self.drop_last = drop_last
self.sampler = sampler
Expand All @@ -157,7 +154,7 @@ def __init__(self, dataset=None, sampler=None, batch_size=512, drop_last=False,
def_output_image_size = [self.image_size, self.image_size]
res_pp_filter = ftype.BICUBIC
self.decode = fn.ImageDecoder(
device=self.device,
device="hpu",
output_format=imgtype.RGB_P,
random_crop_type=randomCropType.CENTER_CROP,
resize=def_output_image_size,
Expand Down
4 changes: 2 additions & 2 deletions examples/contrastive-image-text/run_bridgetower.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.8.0", "To fix: pip install -r examples/pytorch/contrastive-image-text/requirements.txt")

Expand Down
4 changes: 2 additions & 2 deletions examples/contrastive-image-text/run_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.8.0", "To fix: pip install -r examples/pytorch/contrastive-image-text/requirements.txt")

Expand Down
6 changes: 3 additions & 3 deletions examples/image-classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ python run_image_classification.py \
--num_train_epochs 5 \
--per_device_train_batch_size 128 \
--per_device_eval_batch_size 64 \
--evaluation_strategy epoch \
--eval_strategy epoch \
--save_strategy epoch \
--load_best_model_at_end True \
--save_total_limit 3 \
Expand Down Expand Up @@ -197,7 +197,7 @@ python ../gaudi_spawn.py \
--num_train_epochs 5 \
--per_device_train_batch_size 128 \
--per_device_eval_batch_size 64 \
--evaluation_strategy epoch \
--eval_strategy epoch \
--save_strategy epoch \
--load_best_model_at_end True \
--save_total_limit 3 \
Expand Down Expand Up @@ -237,7 +237,7 @@ python ../gaudi_spawn.py \
--num_train_epochs 5 \
--per_device_train_batch_size 128 \
--per_device_eval_batch_size 64 \
--evaluation_strategy epoch \
--eval_strategy epoch \
--save_strategy epoch \
--load_best_model_at_end True \
--save_total_limit 3 \
Expand Down
4 changes: 2 additions & 2 deletions examples/image-classification/run_image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=2.14.0", "To fix: pip install -r examples/pytorch/image-classification/requirements.txt")

Expand Down
29 changes: 25 additions & 4 deletions examples/image-to-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ QUANT_CONFIG=./quantization_config/maxabs_quant.json python run_pipeline.py \

### Inference with FusedSDPA

Habana FusedSDPA is a fused and optimized implementation of torch.nn.functional.scaled_dot_product_attention() for Gaudi. For more details, refer to [Gaudi online documentation](https://docs.habana.ai/en/latest/PyTorch/Model_Optimization_PyTorch/Optimization_in_PyTorch_Models.html?highlight=fusedsdpa#using-fused-scaled-dot-product-attention-fusedsdpa). Currently FusedSDPA works with BF16 precision for Llava models.
Habana FusedSDPA is a fused and optimized implementation of torch.nn.functional.scaled_dot_product_attention() for Gaudi. For more details, refer to [Gaudi online documentation](https://docs.habana.ai/en/latest/PyTorch/Model_Optimization_PyTorch/Optimization_in_PyTorch_Models.html?highlight=fusedsdpa#using-fused-scaled-dot-product-attention-fusedsdpa).

Use the following commands to run Llava-1.5-7b inference with FusedSDPA
Use the following command to run Llava-1.5-7b BF16 inference with FusedSDPA
```bash
python3 run_pipeline.py \
--model_name_or_path llava-hf/llava-1.5-7b-hf \
Expand All @@ -149,12 +149,33 @@ python3 run_pipeline.py \
```


Use the following commands to run Llava-v1.6-mistral-7b inference with FusedSDPA
Use the following command to run Llava-v1.6-mistral-7b BF16 inference with FusedSDPA
```bash
python3 run_pipeline.py \
--model_name_or_path llava-hf/llava-v1.6-mistral-7b-hf \
--image_path "https://llava-vl.github.io/static/images/view.jpg" \
--use_hpu_graphs \
--bf16 \
--use_flash_attention
```
```


Use the following commands to run Llava-v1.6-mistral-7b FP8 inference with FusedSDPA

Here is an example of measuring the tensor quantization statistics on Llava-v1.6-mistral-7b:
```bash
QUANT_CONFIG=./quantization_config/maxabs_measure.json python run_pipeline.py \
--model_name_or_path llava-hf/llava-v1.6-mistral-7b-hf \
--image_path "https://llava-vl.github.io/static/images/view.jpg" \
--use_hpu_graphs \
--bf16 --use_flash_attention
```

Here is an example of quantizing the model based on previous measurements for Llava-v1.6-mistral-7b:
```bash
QUANT_CONFIG=./quantization_config/maxabs_quant.json python run_pipeline.py \
--model_name_or_path llava-hf/llava-v1.6-mistral-7b-hf \
--image_path "https://llava-vl.github.io/static/images/view.jpg" \
--use_hpu_graphs \
--bf16 --use_flash_attention
```
18 changes: 9 additions & 9 deletions examples/language-modeling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ python3 run_lora_clm.py \
--output_dir ./model_lora_llama \
--num_train_epochs 3 \
--per_device_train_batch_size 16 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 1e-4 \
--warmup_ratio 0.03 \
Expand Down Expand Up @@ -410,7 +410,7 @@ LOWER_LIST=ops_bf16.txt python3 run_lora_clm.py \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--gradient_accumulation_steps 16 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 3e-4 \
--max_grad_norm 0.3 \
Expand Down Expand Up @@ -445,7 +445,7 @@ python ../gaudi_spawn.py \
--num_train_epochs 3 \
--per_device_train_batch_size 8 \
--gradient_accumulation_steps 2 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 3e-4 \
--warmup_ratio 0.03 \
Expand Down Expand Up @@ -480,7 +480,7 @@ LOWER_LIST=ops_bf16.txt python ../gaudi_spawn.py \
--num_train_epochs 3 \
--per_device_train_batch_size 16 \
--gradient_accumulation_steps 1 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 3e-4 \
--warmup_ratio 0.03 \
Expand Down Expand Up @@ -518,7 +518,7 @@ python ../gaudi_spawn.py \
--num_train_epochs 5 \
--per_device_train_batch_size 4 \
--per_device_eval_batch_size 4 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 1e-4 \
--logging_steps 1 \
Expand Down Expand Up @@ -547,7 +547,7 @@ LOWER_LIST=ops_bf16.txt python3 ../gaudi_spawn.py \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--gradient_accumulation_steps 16 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 4e-4 \
--max_grad_norm 0.3 \
Expand Down Expand Up @@ -589,7 +589,7 @@ python3 ../gaudi_spawn.py --use_deepspeed --world_size 8 run_lora_clm.py \
--per_device_train_batch_size 10 \
--per_device_eval_batch_size 1 \
--gradient_checkpointing \
--evaluation_strategy epoch \
--eval_strategy epoch \
--eval_delay 2 \
--save_strategy no \
--learning_rate 0.0018 \
Expand Down Expand Up @@ -641,7 +641,7 @@ python3 ../gaudi_spawn.py --world_size 8 --use_mpi run_lora_clm.py \
--fsdp_config fsdp_config.json \
--fsdp auto_wrap \
--num_train_epochs 2 \
--evaluation_strategy epoch \
--eval_strategy epoch \
--per_device_eval_batch_size 1 \
--eval_delay 2 \
--do_eval \
Expand All @@ -668,7 +668,7 @@ DEEPSPEED_HPU_ZERO3_SYNC_MARK_STEP_REQUIRED=1 LOWER_LIST=ops_bf16.txt python3 ..
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--gradient_accumulation_steps 16 \
--evaluation_strategy "no" \
--eval_strategy "no" \
--save_strategy "no" \
--learning_rate 4e-4 \
--max_grad_norm 0.3 \
Expand Down
2 changes: 1 addition & 1 deletion examples/language-modeling/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sentencepiece != 0.1.92
protobuf
evaluate
scikit-learn
peft == 0.10.0
peft == 0.12.0
4 changes: 2 additions & 2 deletions examples/language-modeling/run_clm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=2.14.0", "To fix: pip install -r examples/pytorch/language-modeling/requirements.txt")

Expand Down
4 changes: 2 additions & 2 deletions examples/language-modeling/run_mlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=2.14.0", "To fix: pip install -r examples/pytorch/language-modeling/requirements.txt")

Expand Down
2 changes: 1 addition & 1 deletion examples/protein-folding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ python ../gaudi_spawn.py --world_size 8 --use_mpi run_sequence_classification.py
--num_train_epochs 100 \
--lr_scheduler_type constant \
--do_eval \
--evaluation_strategy epoch \
--eval_strategy epoch \
--per_device_eval_batch_size 32 \
--logging_strategy epoch \
--save_strategy epoch \
Expand Down
2 changes: 1 addition & 1 deletion examples/protein-folding/run_esmfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Optimum Habana is not installed. Remove at your own risks.
check_optimum_habana_min_version("1.11.0")
check_optimum_habana_min_version("1.12.0")


def convert_outputs_to_pdb(outputs):
Expand Down
2 changes: 1 addition & 1 deletion examples/protein-folding/run_sequence_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Optimum Habana is not installed. Remove at your own risks.
check_optimum_habana_min_version("1.11.0")
check_optimum_habana_min_version("1.12.0")

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion examples/protein-folding/run_zero_shot_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Optimum Habana is not installed. Remove at your own risks.
check_optimum_habana_min_version("1.11.0")
check_optimum_habana_min_version("1.12.0")


logging.basicConfig(
Expand Down
4 changes: 2 additions & 2 deletions examples/question-answering/run_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.8.0", "To fix: pip install -r examples/pytorch/question-answering/requirements.txt")

Expand Down
4 changes: 2 additions & 2 deletions examples/question-answering/run_seq2seq_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.8.0", "To fix: pip install -r examples/pytorch/question-answering/requirements.txt")

Expand Down
2 changes: 1 addition & 1 deletion examples/speech-recognition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ python run_speech_recognition_seq2seq.py \
--logging_steps="25" \
--learning_rate="1e-5" \
--warmup_steps="500" \
--evaluation_strategy="steps" \
--eval_strategy="steps" \
--eval_steps="1000" \
--save_strategy="steps" \
--save_steps="1000" \
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-recognition/run_speech_recognition_ctc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def check_optimum_habana_min_version(*a, **b):
logger = logging.getLogger(__name__)

# Will error if the minimal version of Transformers and Optimum Habana are not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.18.0", "To fix: pip install -r examples/pytorch/speech-recognition/requirements.txt")

Expand Down
4 changes: 2 additions & 2 deletions examples/speech-recognition/run_speech_recognition_seq2seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Transformers is not installed. Remove at your own risks.
check_min_version("4.40.0")
check_optimum_habana_min_version("1.11.0")
check_min_version("4.43.0")
check_optimum_habana_min_version("1.12.0")

require_version("datasets>=1.18.0", "To fix: pip install -r examples/pytorch/speech-recognition/requirements.txt")

Expand Down
2 changes: 1 addition & 1 deletion examples/stable-diffusion/image_to_image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Optimum Habana is not installed. Remove at your own risks.
check_optimum_habana_min_version("1.10.0")
check_optimum_habana_min_version("1.12.0")


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion examples/stable-diffusion/image_to_video_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Optimum Habana is not installed. Remove at your own risks.
check_optimum_habana_min_version("1.8.1")
check_optimum_habana_min_version("1.12.0")


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion examples/stable-diffusion/text_to_image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check_optimum_habana_min_version(*a, **b):


# Will error if the minimal version of Optimum Habana is not installed. Remove at your own risks.
check_optimum_habana_min_version("1.11.0")
check_optimum_habana_min_version("1.12.0")


logger = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit 34c780e

Please sign in to comment.