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

[Whisper test] Fix some failing tests #33450

Merged
merged 6 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions tests/models/whisper/test_modeling_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,9 +1683,9 @@ def test_labels_sequence_max_length_correct(self):
input_features = input_dict["input_features"]

labels_length = config.max_target_positions
labels = torch.ones(1, labels_length, dtype=torch.int64)
labels = torch.ones(1, labels_length, dtype=torch.int64).to(torch_device)

model = model_class(config)
model = model_class(config).to(torch_device)
model(input_features=input_features, labels=labels)

def test_labels_sequence_max_length_correct_after_changing_config(self):
Expand All @@ -1697,9 +1697,9 @@ def test_labels_sequence_max_length_correct_after_changing_config(self):
config.max_target_positions += 100

labels_length = config.max_target_positions
labels = torch.ones(1, labels_length, dtype=torch.int64)
labels = torch.ones(1, labels_length, dtype=torch.int64).to(torch_device)

model = model_class(config)
model = model_class(config).to(torch_device)
model(input_features=input_features, labels=labels)

def test_labels_sequence_max_length_error(self):
Expand All @@ -1709,21 +1709,21 @@ def test_labels_sequence_max_length_error(self):
input_features = input_dict["input_features"]

labels_length = config.max_target_positions + 1
labels = torch.ones(1, labels_length, dtype=torch.int64)
labels = torch.ones(1, labels_length, dtype=torch.int64).to(torch_device)

model = model_class(config)
model = model_class(config).to(torch_device)
with self.assertRaises(ValueError):
model(input_features=input_features, labels=labels)

def test_labels_sequence_max_length_error_after_changing_config(self):
config, input_dict = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_generative_model_classes:
model = model_class(config)
model = model_class(config).to(torch_device)
input_features = input_dict["input_features"]

labels_length = config.max_target_positions + 1
labels = torch.ones(1, labels_length, dtype=torch.int64)
labels = torch.ones(1, labels_length, dtype=torch.int64).to(torch_device)

new_max_length = config.max_target_positions + 100
model.config.max_length = new_max_length
Expand Down Expand Up @@ -2385,7 +2385,9 @@ def test_tiny_token_timestamp_generation_longform(self):
)

inputs = inputs.to(torch_device)
generate_outputs = model.generate(**inputs, return_segments=True, return_token_timestamps=True)
generate_outputs = model.generate(
**inputs, return_segments=True, return_token_timestamps=True, return_timestamps=True
)

token_timestamps_shape = [
[segment["token_timestamps"].shape for segment in segment_list]
Expand Down Expand Up @@ -2550,14 +2552,14 @@ def test_default_multilingual_transcription_long_form(self):
).input_features.to(torch_device)

# task defaults to transcribe
sequences = model.generate(input_features)
sequences = model.generate(input_features, return_timestamps=True)

transcription = processor.batch_decode(sequences)[0]

assert transcription == " मिर्ची में कितने विबिन्द प्रजातियां हैं? मिर्ची में कितने विबिन्द प्रजातियां हैं?"

# set task to translate
sequences = model.generate(input_features, task="translate")
sequences = model.generate(input_features, task="translate", return_timestamps=True)
transcription = processor.batch_decode(sequences)[0]

assert (
Expand Down Expand Up @@ -3264,6 +3266,7 @@ def test_whisper_empty_longform(self):
"num_beams": 5,
"language": "fr",
"task": "transcribe",
"return_timestamps": True,
}

torch.manual_seed(0)
Expand Down
Loading