Skip to content

Commit 4232dd4

Browse files
committed
fixed None language for EN HF models
-fixed missing language in result from EN Hugging Face model causing `refine()` to fail with these results as inputs -improved compatibility of Hugging Face models with certain old versions of PyTorch -updated Hugging Face model loading process to warn users when it fails to convert the model to BetterTransformer
1 parent 78a223f commit 4232dd4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

stable_whisper/whisper_word_level/hf_whisper.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ def load_hf_pipe(model_name: str, device: str = None, flash: bool = False, **pip
8080
if not flash:
8181
try:
8282
model = model.to_bettertransformer()
83-
except ValueError:
84-
pass
83+
except (ValueError, ImportError) as e:
84+
import warnings
85+
warnings.warn(
86+
f'Failed convert model to BetterTransformer due to: {e}'
87+
)
8588

8689
final_pipe_kwargs = dict(
8790
task="automatic-speech-recognition",
@@ -147,6 +150,8 @@ def _inner_transcribe(
147150
pipe_kwargs['batch_size'] = batch_size
148151
output = self._pipe(audio, **pipe_kwargs)
149152
result = output['chunks']
153+
if not language and not self._pipe.model.generation_config.is_multilingual:
154+
language = 'en'
150155
if not language and result and 'language' in result[0]:
151156
language = result[0]['language']
152157
if verbose is not None:
@@ -356,7 +361,10 @@ def as_vanilla_model(self):
356361
new_model.register_buffer("alignment_heads", final_heads.to_sparse(), persistent=False)
357362
else:
358363
setattr(new_model, 'missing_alignment_heads', True)
359-
new_model.load_state_dict(state_dict, strict=True, assign=True)
364+
try:
365+
new_model.load_state_dict(state_dict, strict=True, assign=True)
366+
except TypeError:
367+
new_model.load_state_dict(state_dict, strict=True)
360368
new_model.to(device=self._pipe.model.device)
361369
ln_to_fp32(new_model)
362370
modify_model(new_model)

0 commit comments

Comments
 (0)