Skip to content

Commit

Permalink
Better check for deepspeed availability (#379)
Browse files Browse the repository at this point in the history
* Better check for deepspeed availability

* Address comment

* Simplify a bit
  • Loading branch information
sgugger committed May 20, 2022
1 parent 3c45b6f commit 41427c5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/accelerate/utils/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import importlib
import sys


# The package importlib_metadata is in a different place, depending on the Python version.
if sys.version_info < (3, 8):
import importlib_metadata
else:
import importlib.metadata as importlib_metadata


try:
Expand Down Expand Up @@ -45,7 +52,15 @@ def is_tpu_available():


def is_deepspeed_available():
return importlib.util.find_spec("deepspeed") is not None
package_exists = importlib.util.find_spec("deepspeed") is not None
# Check we're not importing a "deepspeed" directory somewhere but the actual library by trying to grab the version
# AND checking it has an author field in the metadata that is HuggingFace.
if package_exists:
try:
_ = importlib_metadata.metadata("deepspeed")
return True
except importlib_metadata.PackageNotFoundError:
return False


def is_tensorflow_available():
Expand Down

0 comments on commit 41427c5

Please sign in to comment.