Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: caikit/caikit-nlp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.4.11
Choose a base ref
...
head repository: caikit/caikit-nlp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.4.12
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on May 29, 2024

  1. Expose model information for embeddings service

    Signed-off-by: Flavia Beo <flavia.beo@ibm.com>
    flaviabeo committed May 29, 2024
    Copy the full SHA
    2dd91d2 View commit details
  2. Bump lower caikit version

    Signed-off-by: Flavia Beo <flavia.beo@ibm.com>
    flaviabeo committed May 29, 2024
    Copy the full SHA
    756b1e1 View commit details

Commits on May 31, 2024

  1. Merge pull request #353 from flaviabeo/embeddings_model_info

    Expose model information for embeddings service
    gkumbhat authored May 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    75cd9ea View commit details
Showing with 31 additions and 2 deletions.
  1. +15 −1 caikit_nlp/modules/text_embedding/embedding.py
  2. +1 −1 pyproject.toml
  3. +15 −0 tests/modules/text_embedding/test_embedding.py
16 changes: 15 additions & 1 deletion caikit_nlp/modules/text_embedding/embedding.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
# Standard
from collections.abc import Sized
from enum import Enum, auto
from typing import Callable, Dict, List, NamedTuple, Optional, TypeVar, Union
from typing import Any, Callable, Dict, List, NamedTuple, Optional, TypeVar, Union
import importlib
import os
import time
@@ -178,6 +178,20 @@ def load(cls, model_path: str, *args, **kwargs) -> "EmbeddingModule":

return cls(model)

@property
def public_model_info(cls) -> Dict[str, Any]: # pylint: disable=no-self-argument
"""Helper property to return public metadata about a specific Model. This
function is separate from `metdata` as that contains the entire ModelConfig
which might not want to be shared/exposed.
Returns:
Dict[str, str]: A dictionary of this models's public metadata
"""
return {
"max_seq_length": cls.model.max_seq_length,
"sentence_embedding_dimension": cls.model.get_sentence_embedding_dimension(),
}

@classmethod
def _get_ipex(cls, ipex_flag):
"""Get IPEX optimization library if enabled and available, else return False
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ classifiers=[
"License :: OSI Approved :: Apache Software License"
]
dependencies = [
"caikit[runtime-grpc,runtime-http]>=0.26.17,<0.27.0",
"caikit[runtime-grpc,runtime-http]>=0.26.27,<0.27.0",
"caikit-tgis-backend>=0.1.27,<0.2.0",
# TODO: loosen dependencies
"grpcio>=1.62.2", # explicitly pin grpc dependencies to a recent version to avoid pip backtracking
15 changes: 15 additions & 0 deletions tests/modules/text_embedding/test_embedding.py
Original file line number Diff line number Diff line change
@@ -197,6 +197,21 @@ def test_save_load_and_run():
_assert_is_expected_embedding_result(result)


def test_public_model_info():
"""Check if we can get model info successfully"""
model_id = "model_id"
with tempfile.TemporaryDirectory(suffix="-1st") as model_dir:
model_path = os.path.join(model_dir, model_id)
BOOTSTRAPPED_MODEL.save(model_path)
new_model = EmbeddingModule.load(model_path)

result = new_model.public_model_info
assert "max_seq_length" in result
assert "sentence_embedding_dimension" in result
assert type(result["max_seq_length"]) is int
assert type(result["sentence_embedding_dimension"]) is int


@pytest.mark.parametrize(
"model_path", ["", " ", " " * 100], ids=["empty", "space", "spaces"]
)