Skip to content
Merged
Changes from 4 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
20 changes: 19 additions & 1 deletion tests/generation/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def _get_logits_processor_kwargs(self, do_sample=False, config=None):
"vision_start_token_id",
]:
token_index = getattr(config, key, None)
if token_index is None:
if hasattr(self, "model_tester"):
token_index = getattr(self.model_tester, key, None)
Comment thread
ydshieh marked this conversation as resolved.
Outdated
if token_index is not None and token_index < config.get_text_config().vocab_size:
logits_processor_kwargs["bad_words_ids"].append([token_index])

Expand Down Expand Up @@ -1077,14 +1080,20 @@ def test_beam_search_low_memory(self):
):
self.skipTest(reason="May fix in the future: need model-specific fixes")

set_model_tester_for_less_flaky_test(self)

config, inputs_dict = self.prepare_config_and_inputs_for_generate()
set_config_for_less_flaky_test(config)
# batch_size=1 is ok, but batch_size>1 will cause non-identical output

config.use_cache = True
config.is_decoder = True

# test output equality of low versus high memory
model = model_class(config).to(torch_device).eval()
set_model_for_less_flaky_test(model)

logits_processor_kwargs = self._get_logits_processor_kwargs(config=model.config)

low_output = model.generate(
**inputs_dict,
Expand All @@ -1093,6 +1102,10 @@ def test_beam_search_low_memory(self):
early_stopping=True,
low_memory=True,
use_cache=True,
output_scores=True,
output_logits=True,
return_dict_in_generate=True,
**logits_processor_kwargs,
)

high_output = model.generate(
Expand All @@ -1102,8 +1115,13 @@ def test_beam_search_low_memory(self):
early_stopping=True,
low_memory=False,
use_cache=True,
output_scores=True,
output_logits=True,
return_dict_in_generate=True,
**logits_processor_kwargs,
)
self.assertListEqual(low_output.tolist(), high_output.tolist())
# The two outputs must match and their shape must be as expected
self._check_similar_generate_outputs(low_output, high_output)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still required, otherwise 1% of chance to fail for Emu3Vision2TextModelTest


@pytest.mark.generate
@parameterized.expand([("random",), ("same",)])
Expand Down