conftest.py 940 B

12345678910111213141516171819202122232425262728
  1. # Copyright (c) Meta Platforms, Inc. and affiliates.
  2. # This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
  3. import pytest
  4. from transformers import LlamaTokenizer
  5. @pytest.fixture(scope="module")
  6. def llama_tokenizer():
  7. try:
  8. return LlamaTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
  9. except OSError:
  10. return None
  11. @pytest.fixture
  12. def setup_tokenizer(llama_tokenizer):
  13. def _helper(tokenizer_mock):
  14. #Align with Llama 2 tokenizer
  15. tokenizer_mock.from_pretrained.return_value = llama_tokenizer
  16. return _helper
  17. @pytest.fixture(autouse=True)
  18. def skip_if_tokenizer_is_missing(request, llama_tokenizer):
  19. if request.node.get_closest_marker("skip_missing_tokenizer"):
  20. if llama_tokenizer is None:
  21. pytest.skip("Llama tokenizer could not be accessed. Did you log into huggingface hub and provided the correct token?")