Skip to content

Conversation

@gante
Copy link
Contributor

@gante gante commented May 20, 2025

What does this PR do?

whisper has a very slow set of tests.

This PR applies low-hanging fruit changes to get faster tests (slow tests: 7m47s -> 6m59s on my machine)

  • the main dataset is now loaded once per test suite (as opposed to once per test in relevant tests)
  • generation tests happen on GPU when possible

@gante gante requested a review from ydshieh May 20, 2025 15:32
@require_torchaudio
class WhisperModelIntegrationTests(unittest.TestCase):
def setUp(self):
self._unpatched_generation_mixin_generate = transformers.GenerationMixin.generate
Copy link
Contributor Author

@gante gante May 20, 2025

Choose a reason for hiding this comment

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

this was only used in one test, and that test should use the base generate. This overcomplicates things.

idk why it was added in the first place 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is linked to #29312, but the change here is only test. So good for me if it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is implicitly tested: the output checked in the test is different if num_beams is not respected :)

(just like in all other beam search integration tests: we check the output, which is sensible enough to detect bad usage of flags)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's definitely way over the top for what it tried. So yea let's keep it simple.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@gante gante requested a review from vasqu May 20, 2025 16:19
transformers.GenerationMixin.generate = self._unpatched_generation_mixin_generate

@cached_property
def default_processor(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused

Comment on lines -1589 to -1590
torch_device = "cpu"
set_seed(0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you run with flakefinder to see if we need seed or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RUN_SLOW=1 py.test tests/models/whisper/test_modeling_whisper.py -k test_tiny_en_generation --flake-finder --flake-runs 100 yields no failures

(set_seed(0) comes from the original whisper commit. However, AFAIK, Whisper has no random components -- in fact, many output-checking tests in this file don't set a seed)

Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

LGTM, but it would be good to check a few things.

tearDownClass is a good practice to cleanup the stuff.

@gante
Copy link
Contributor Author

gante commented May 21, 2025

@ydshieh regarding dataset loading: I've remembered that we had the same issue in the pipeline tests, so I've pushed a new commit which copies the pattern from the pipeline tests

The pattern we added before doesn't have a teardown method -- do we need to add it everywhere the pattern is used?

@ydshieh
Copy link
Collaborator

ydshieh commented May 21, 2025

@gante Thank you for checking and further improvement.

Regarding dataset loading, it's probably minor (for now), so you can proceed to merge.

(Those loaded objects assigned to class attributes will remain forever until the python process exit. At some point, it might be a problem if we have many test classes)

Copy link
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. Was only concerned about the seeds but seems to be a non-issue.

@require_torchaudio
class WhisperModelIntegrationTests(unittest.TestCase):
def setUp(self):
self._unpatched_generation_mixin_generate = transformers.GenerationMixin.generate
Copy link
Contributor

Choose a reason for hiding this comment

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

It's definitely way over the top for what it tried. So yea let's keep it simple.

@gante gante merged commit e4decee into huggingface:main May 21, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants