-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from huggingface/brrr-nanotron-sync
Helping making brrr depend on nanotron
Showing
88 changed files
with
755 additions
and
1,254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,7 @@ | ||
import importlib | ||
import importlib.metadata as importlib_metadata | ||
import platform | ||
import warnings | ||
from typing import Tuple, Union | ||
|
||
from packaging.version import Version, parse | ||
|
||
CHECKPOINT_VERSION = Version("1.2") | ||
CHECKPOINT_VERSION = Version("0.1") | ||
|
||
PY_VERSION = parse(platform.python_version()) | ||
|
||
# https://github.com/huggingface/transformers/blob/f67dac97bdc63874f2288546b3fa87e69d2ea1c8/src/transformers/utils/import_utils.py#L41 | ||
def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[Tuple[bool, str], bool]: | ||
# Check we're not importing a "pkg_name" directory somewhere but the actual library by trying to grab the version | ||
package_exists = importlib.util.find_spec(pkg_name) is not None | ||
package_version = "N/A" | ||
if package_exists: | ||
try: | ||
package_version = importlib_metadata.version(pkg_name) | ||
package_exists = True | ||
except importlib_metadata.PackageNotFoundError: | ||
package_exists = False | ||
if return_version: | ||
return package_exists, package_version | ||
else: | ||
return package_exists | ||
|
||
|
||
def _can_import_from_module(module: str, name: str) -> bool: | ||
""" | ||
Check if a specific module can be imported from a package. | ||
""" | ||
if not _is_package_available(module): | ||
return False | ||
try: | ||
spec = importlib.util.find_spec(module) | ||
module_obj = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module_obj) | ||
return hasattr(module_obj, name) | ||
except Exception as e: | ||
warnings.warn(f"Unable to import {name} from {module}: {e}") | ||
return False | ||
|
||
|
||
TENSORBOARDX_AVAILABLE = _is_package_available("tensorboardX") | ||
HUGGINGFACE_HUB_AVAILABLE = _is_package_available("huggingface_hub") | ||
HF_TENSORBOARD_LOGGER_AVAILABLE = _can_import_from_module("huggingface_hub", "HFSummaryWriter") |
Oops, something went wrong.