Skip to content

Conversation

@muellerzr
Copy link
Contributor

@muellerzr muellerzr commented Mar 20, 2024

What does this PR do?

Hi, noticed our tests on our PR CI for Accelerate have been red for a week, due to #29675

Specifically, before most of the tests in test_trainer_seq2seq were marked as slow so they were being skipped on our normal CI. However now that it's unslow for once, these tests require sentencepiece.

I've added two different options for this:

  1. The test suite now has the require_sentencepiece decorator, else we get an err:
=================================== FAILURES ===================================
__________ Seq2seqTrainerTester.test_bad_generation_config_fail_early __________

self = <tests.trainer.test_trainer_seq2seq.Seq2seqTrainerTester testMethod=test_bad_generation_config_fail_early>

    @require_torch
    def test_bad_generation_config_fail_early(self):
        # Tests that a bad geneartion config causes the trainer to fail early
        model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-small")
>       tokenizer = T5Tokenizer.from_pretrained("google-t5/t5-small")

tests/trainer/test_trainer_seq2seq.py:189: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/transformers/utils/import_utils.py:1412: in __getattribute__
    requires_backends(cls, cls._backends)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

obj = <class 'transformers.utils.dummy_sentencepiece_objects.T5Tokenizer'>
backends = ['sentencepiece']

    def requires_backends(obj, backends):
        if not isinstance(backends, (list, tuple)):
            backends = [backends]
    
        name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__
    
        # Raise an error for users who might not realize that classes without "TF" are torch-only
        if "torch" in backends and "tf" not in backends and not is_torch_available() and is_tf_available():
            raise ImportError(PYTORCH_IMPORT_ERROR_WITH_TF.format(name))
    
        # Raise the inverse error for PyTorch users trying to load TF classes
        if "tf" in backends and "torch" not in backends and is_torch_available() and not is_tf_available():
            raise ImportError(TF_IMPORT_ERROR_WITH_PYTORCH.format(name))
    
        checks = (BACKENDS_MAPPING[backend] for backend in backends)
        failed = [msg.format(name) for available, msg in checks if not available()]
        if failed:
>           raise ImportError("".join(failed))
E           ImportError: 
E           T5Tokenizer requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the
E           installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones
E           that match your environment. Please note that you may need to restart your runtime after installation.

/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/transformers/utils/import_utils.py:1400: ImportError
  1. This PR also adds sentencepiece as a test dep, to allow for pip install -e .[torch,testing] to work fine and minimize downstream impact

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

cc @amyeroberts

@muellerzr muellerzr requested a review from amyeroberts March 20, 2024 14:55
@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.

Copy link
Contributor

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

@amyeroberts amyeroberts merged commit c78f577 into main Mar 20, 2024
@amyeroberts amyeroberts deleted the muellerzr-sentencepiece branch March 20, 2024 15:53
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.

3 participants