Unverified Commit 1c381f36 authored by Cody Yu's avatar Cody Yu Committed by GitHub
Browse files

Cache results of is_torch_tpu_available() (#18777)

* Cache results of is_torch_tpu_available()

* Update src/transformers/utils/import_utils.py

* Update src/transformers/utils/import_utils.py
parent 954e18ab
...@@ -21,7 +21,7 @@ import os ...@@ -21,7 +21,7 @@ import os
import sys import sys
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
from functools import wraps from functools import lru_cache, wraps
from itertools import chain from itertools import chain
from types import ModuleType from types import ModuleType
from typing import Any from typing import Any
...@@ -414,6 +414,7 @@ def is_ftfy_available(): ...@@ -414,6 +414,7 @@ def is_ftfy_available():
return _ftfy_available return _ftfy_available
@lru_cache()
def is_torch_tpu_available(check_device=True): def is_torch_tpu_available(check_device=True):
"Checks if `torch_xla` is installed and potentially if a TPU is in the environment" "Checks if `torch_xla` is installed and potentially if a TPU is in the environment"
if not _torch_available: if not _torch_available:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment