Skip to content

Commit

Permalink
Add LLMUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya-mohammadi committed Jun 21, 2024
1 parent af444c9 commit 390b6c4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion deep_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utils.lib_utils.integeration_utils import import_lazy_module

# Deep Utils version number
__version__ = "1.3.30"
__version__ = "1.3.31"

from .utils.constants import DUMMY_PATH, Backends

Expand Down Expand Up @@ -74,6 +74,7 @@
import_lazy_module("UltralightTorchFaceDetector",
"vision.face_detection.ultralight.torch.ultralight_torch_face_detection")
import_lazy_module("CutMixTF", "augmentation.cutmix.cutmix_tf")
import_lazy_module("LLMUtils", "llm.utils")

if TYPE_CHECKING:
from .utils.box_utils.boxes import Box, Point
Expand Down Expand Up @@ -126,6 +127,7 @@
from .augmentation.cutmix.cutmix_tf import CutMixTF
from .utils.encodes.b64 import BinaryUtils
from .augmentation.torch.augmentation_torch import AugmentTorch
from .llm.utils import LLMUtils
else:
import sys

Expand Down
4 changes: 4 additions & 0 deletions deep_utils/dummy_objects/dummies.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@ class UltralightTorchFaceDetector(metaclass=DummyObject):

class SoundFileUtils(metaclass=DummyObject):
_backend = [Backends.SOUNDFILE]


class LLMUtils(metaclass=DummyObject):
_backend = [Backends.TORCH]
Empty file added deep_utils/llm/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions deep_utils/llm/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from torch import nn


class LLMUtils:
@staticmethod
def get_max_length(model: nn.Module) -> int:
for length_setting in ["n_positions", "max_position_embeddings", "seq_length"]:
max_length = getattr(model.config, length_setting, None)
if max_length:
print(f"Found max length: {max_length}")
break
if not max_length:
max_length = 1024
print(f"Using default max length: {max_length}")
return max_length

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.3.30"
VERSION = "1.3.31"

long_description = open("Readme.md", mode="r", encoding="utf-8").read()

Expand Down

0 comments on commit 390b6c4

Please sign in to comment.