Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Whisper static generation #1275

Merged
merged 20 commits into from
Sep 24, 2024
3 changes: 1 addition & 2 deletions optimum/habana/transformers/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"stablelm",
"mamba",
"deci",
"whisper",
]


Expand Down Expand Up @@ -230,8 +231,6 @@ def _prepare_decoder_input_ids_for_generation(
self.config.model_type == "vision-encoder-decoder" and "donut" in self.config.encoder.model_type.lower()
):
pass
elif self.config.model_type in ["whisper"]:
pass
# user input but doesn't start with decoder_start_token_id -> prepend decoder_start_token_id (and adjust
# decoder_attention_mask if provided)
elif (decoder_input_ids[:, 0] != decoder_start_token_id[:, 0]).all().item():
Expand Down
14 changes: 14 additions & 0 deletions optimum/habana/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
gaudi_StoppingCriteriaList_call,
)
from .models import (
GAUDI_WHISPER_ATTENTION_CLASSES,
DeciLMConfig,
DeciLMForCausalLM,
GaudiBloomForCausalLM,
Expand Down Expand Up @@ -96,6 +97,11 @@
GaudiStarcoder2DecoderLayer,
GaudiStarcoder2ForCausalLM,
GaudiStarcoder2Model,
GaudiWhisperDecoder,
GaudiWhisperDecoderLayer,
GaudiWhisperForConditionalGeneration,
GaudiWhisperModel,
GaudiWhisperSdpaAttention,
LlamaConfig,
MistralConfig,
MixtralConfig,
Expand Down Expand Up @@ -559,5 +565,13 @@ def adapt_transformers_to_gaudi():
gaudi_MambaForCausalLM_update_model_kwargs_for_generation
)

# Optimization for Whisper on Gaudi
transformers.models.whisper.modeling_whisper.WhisperSdpaAttention = GaudiWhisperSdpaAttention
transformers.models.whisper.modeling_whisper.WhisperDecoderLayer = GaudiWhisperDecoderLayer
transformers.models.whisper.modeling_whisper.WhisperDecoder = GaudiWhisperDecoder
transformers.models.whisper.modeling_whisper.WhisperModel = GaudiWhisperModel
transformers.models.whisper.modeling_whisper.WhisperForConditionalGeneration = GaudiWhisperForConditionalGeneration
transformers.models.whisper.modeling_whisper.WHISPER_ATTENTION_CLASSES = GAUDI_WHISPER_ATTENTION_CLASSES

transformers.AutoConfig.register("deci", DeciLMConfig)
transformers.AutoModelForCausalLM.register(DeciLMConfig, DeciLMForCausalLM)
8 changes: 8 additions & 0 deletions optimum/habana/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,11 @@
gaudi_wav2vec2_tdnnlayer_forward,
gaudi_wav2vec2forctc_forward,
)
from .whisper import (
GAUDI_WHISPER_ATTENTION_CLASSES,
GaudiWhisperDecoder,
GaudiWhisperDecoderLayer,
GaudiWhisperForConditionalGeneration,
GaudiWhisperModel,
GaudiWhisperSdpaAttention,
)
8 changes: 8 additions & 0 deletions optimum/habana/transformers/models/whisper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .modeling_whisper import (
GAUDI_WHISPER_ATTENTION_CLASSES,
GaudiWhisperDecoder,
GaudiWhisperDecoderLayer,
GaudiWhisperForConditionalGeneration,
GaudiWhisperModel,
GaudiWhisperSdpaAttention,
)
Loading
Loading