comdoleger commited on
Commit
bd95058
·
verified ·
1 Parent(s): 92e04be

Upload extensions_built_in/diffusion_models/omnigen2/src/utils/import_utils.py with huggingface_hub

Browse files
extensions_built_in/diffusion_models/omnigen2/src/utils/import_utils.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """
15
+ Import utilities: Utilities related to imports and our lazy inits.
16
+ """
17
+
18
+ import importlib.util
19
+ import sys
20
+
21
+ # The package importlib_metadata is in a different place, depending on the python version.
22
+ if sys.version_info < (3, 8):
23
+ import importlib_metadata
24
+ else:
25
+ import importlib.metadata as importlib_metadata
26
+
27
+ def _is_package_available(pkg_name: str):
28
+ pkg_exists = importlib.util.find_spec(pkg_name) is not None
29
+ pkg_version = "N/A"
30
+
31
+ if pkg_exists:
32
+ try:
33
+ pkg_version = importlib_metadata.version(pkg_name)
34
+ except (ImportError, importlib_metadata.PackageNotFoundError):
35
+ pkg_exists = False
36
+
37
+ return pkg_exists, pkg_version
38
+
39
+ _triton_available, _triton_version = _is_package_available("triton")
40
+ _flash_attn_available, _flash_attn_version = _is_package_available("flash_attn")
41
+
42
+ def is_triton_available():
43
+ return _triton_available
44
+
45
+ def is_flash_attn_available():
46
+ return _flash_attn_available