Skip to content

Commit

Permalink
Release: v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickvonplaten committed Dec 28, 2022
1 parent 91b1a8d commit 8671ba2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# IMPORTANT:
# 1. all dependencies should be listed here with their version requirements if any
# 2. once modified, run: `make deps_table_update` to update src/diffusers/dependency_versions_table.py
_deps = ["torch>=1.9", "transformers>=4.24.0", "black==22.8", "isort>=5.5.4", "flake8>=3.8.3", "numpy", "filelock", "importlib_metadata"]
_deps = ["accelerate>=0.14.0", "torch>=1.9", "transformers>=4.24.0", "black==22.8", "isort>=5.5.4", "flake8>=3.8.3", "numpy", "filelock", "importlib_metadata", "datasets>=2.7.0"]

# this is a lookup table with items like:
#
Expand Down Expand Up @@ -150,7 +150,7 @@ def run(self):
extras["quality"] = deps_list("black", "isort", "flake8")


extras["dev"] = extras["quality"]
extras["dev"] = extras["quality"] + deps_list("transformers", "accelerate", "datasets")


install_requires = [
Expand All @@ -162,7 +162,7 @@ def run(self):

setup(
name="speechbox",
version="0.1.0", # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots)
version="0.1.1", # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots)
description="Speechbox",
long_description=open("README.md", "r", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
8 changes: 4 additions & 4 deletions src/speechbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
# to defer the actual importing for when the objects are requested. This way `import transformers` provides the names
# in the namespace without actually importing anything (and especially none of the backends).

__version__ = "0.1.0"
__version__ = "0.1.1"

from .utils import is_transformers_available
from .utils import is_accelerate_available, is_transformers_available

if is_transformers_available():
if is_transformers_available() and is_accelerate_available():
from .restore import PunctuationRestorer
else:
from .utils.dummy_transformers_objects import *
from .utils.dummy_transformers_and_accelerate_objects import *
2 changes: 2 additions & 0 deletions src/speechbox/dependency_versions_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 1. modify the `_deps` dict in setup.py
# 2. run `make deps_table_update``
deps = {
"accelerate": "accelerate>=0.14.0",
"torch": "torch>=1.9",
"transformers": "transformers>=4.24.0",
"black": "black==22.8",
Expand All @@ -10,4 +11,5 @@
"numpy": "numpy",
"filelock": "filelock",
"importlib_metadata": "importlib_metadata",
"datasets": "datasets>=2.7.0",
}
4 changes: 2 additions & 2 deletions src/speechbox/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .import_utils import (DummyObject, is_transformers_available,
requires_backends)
from .import_utils import (DummyObject, is_accelerate_available,
is_transformers_available, requires_backends)
19 changes: 19 additions & 0 deletions src/speechbox/utils/dummy_transformers_and_accelerate_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is autogenerated by the command `make fix-copies`, do not edit.
# flake8: noqa

from ..utils import DummyObject, requires_backends


class PunctuationRestorer(metaclass=DummyObject):
_backends = ["transformers", "accelerate"]

def __init__(self, *args, **kwargs):
requires_backends(self, ["transformers", "accelerate"])

@classmethod
def from_config(cls, *args, **kwargs):
requires_backends(cls, ["transformers", "accelerate"])

@classmethod
def from_pretrained(cls, *args, **kwargs):
requires_backends(cls, ["transformers", "accelerate"])
18 changes: 18 additions & 0 deletions src/speechbox/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,36 @@
_transformers_available = False


_accelerate_available = importlib.util.find_spec("accelerate") is not None
try:
_ = importlib_metadata.version("accelerate")
_accelerate_metadata = importlib_metadata.metadata("accelerate")
except importlib_metadata.PackageNotFoundError:
_accelerate_available = False


def is_transformers_available():
return _transformers_available


def is_accelerate_available():
return _accelerate_available


TRANSFORMERS_IMPORT_ERROR = """
{0} requires the transformers library but it was not found in your environment. You can install it with pip: `pip install transformers`. Please note that you may need to restart your runtime after installation.
"""


ACCELERATE_IMPORT_ERROR = """
{0} requires the accelerate library but it was not found in your environment. You can install it with pip: `pip install accelerate`. Please note that you may need to restart your runtime after installation.
"""


BACKENDS_MAPPING = OrderedDict(
[
("transformers", (is_transformers_available, TRANSFORMERS_IMPORT_ERROR)),
("accelerate", (is_accelerate_available, ACCELERATE_IMPORT_ERROR)),
]
)

Expand Down

0 comments on commit 8671ba2

Please sign in to comment.