From 9fe360883e14c3373014e276b2c9db66f77049c1 Mon Sep 17 00:00:00 2001 From: Benjamin Muskalla Date: Mon, 26 Feb 2024 10:01:45 +0100 Subject: [PATCH] Cache `is_vision_available` result (#29280) Cache `is_vision_available` This check is used quite often during process in image models and can take up a serious amount of time compared to the other processing steps. --- src/transformers/utils/import_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/transformers/utils/import_utils.py b/src/transformers/utils/import_utils.py index 57b4e840414b..8cf6c1a14f37 100644 --- a/src/transformers/utils/import_utils.py +++ b/src/transformers/utils/import_utils.py @@ -741,6 +741,7 @@ def is_tokenizers_available(): return _tokenizers_available +@lru_cache def is_vision_available(): _pil_available = importlib.util.find_spec("PIL") is not None if _pil_available: