Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ODSC-63984] BYOC TEI deployment for embedding models #975

Merged
merged 19 commits into from
Oct 29, 2024

Conversation

VipulMascarenhas
Copy link
Member

@VipulMascarenhas VipulMascarenhas commented Oct 18, 2024

Description

This update adds the ability to use BYOC for deploying an embedding model using custom TEI container. The changes include:

  • While registering the embedding model, the custom metadata will have a new cmd var entry with the details required to start the TEI container.
  • During registration, user can pass the image uri using inference_container_uri parameter.
  • During deployment, two params are added: container_image_uri and cmd_var
    • If model has the default image as TEI in custom metadata, then container_image_uri will be used from metadata. If passed as input param during deployment, the input container_image_uri will be used instead.
    • If model has the default image as TEI in custom metadata, cmd_var will be fetched from the metadata as well. User can add additional parameters if needed. We can add some additional restriction on parameters that can be passed as cmd_var if needed.

Registering a model

ads aqua model register --model_id sentence-transformers/all-MiniLM-L6-v2 --os_path oci://<bucket>@<namespace>/<prefix> --download_from_hf True --inference_container odsc-tei-serving --inference_container_uri <region>.ocir.io/<namespace>/text-embeddings-inference:1.5.0

Deploying a model

With GPU shape
ads aqua deployment create --model_id ocid1.datasciencemodel.oc1.iad.<ocid> --instance_shape VM.GPU.A10.1 --display_name "sentence-transformers/all-MiniLM-L6-v2 MD 1017" --env_var "{'MODEL_DEPLOY_PREDICT_ENDPOINT': '/v1/embeddings'}"
With GPU shape and CMD override
ads aqua deployment create --model_id ocid1.datasciencemodel.oc1.iad.<ocid> --instance_shape VM.GPU.A10.1 --display_name "sentence-transformers/all-MiniLM-L6-v2 MD 1017" --env_var "{'MODEL_DEPLOY_PREDICT_ENDPOINT': '/v1/embeddings'}" --cmd_var "['--max-concurrent-requests', 256, '--auto-truncate', '--payload-limit', 2000000]"
Validation for restricted keys for CMD
ads aqua deployment create --model_id ocid1.datasciencemodel.oc1.iad.<ocid> --instance_shape VM.GPU.A10.1 --display_name "sentence-transformers/all-MiniLM-L6-v2 MD 1017" --env_var "{'MODEL_DEPLOY_PREDICT_ENDPOINT': '/v1/embeddings'}"--cmd_var "['--model-id', 'test-model']"
ERROR:ads:The following keys cannot be overridden: --model-id
With CPU shape

Here, registered model already had the default container URI set to GPU container, but user can override using container_image_uri params.

ads aqua deployment create --model_id ocid1.datasciencemodel.oc1.iad.<ocid> --instance_shape VM.Standard.E4.Flex --display_name "sentence-transformers/all-MiniLM-L6-v2 MD 1017" --env_var "{'MODEL_DEPLOY_PREDICT_ENDPOINT': '/v1/embeddings'}" --container_image_uri iad.ocir.io/ociodscdev/text-embeddings-inference:cpu-1.5

Unit Tests

> python -m pytest -q tests/unitary/with_extras/aqua/*
========================================== test session starts ===========================================
platform darwin -- Python 3.8.19, pytest-7.4.4, pluggy-1.0.0
rootdir: /Users/user/workspace/git/accelerated-data-science
configfile: pytest.ini
plugins: Faker-26.0.0, cov-5.0.0, anyio-4.2.0, xdist-3.6.1
collected 248 items

tests/unitary/with_extras/aqua/test_cli.py ............................                            [  5%]
tests/unitary/with_extras/aqua/test_common_handler.py ...                                          [  6%]
tests/unitary/with_extras/aqua/test_config.py .                                                    [  7%]
tests/unitary/with_extras/aqua/test_decorator.py ..........                                        [ 11%]
tests/unitary/with_extras/aqua/test_deployment.py ......................                           [ 20%]
tests/unitary/with_extras/aqua/test_deployment_handler.py ..s......                                [ 23%]
tests/unitary/with_extras/aqua/test_evaluation.py .............................                    [ 35%]
tests/unitary/with_extras/aqua/test_evaluation_handler.py .........                                [ 39%]
tests/unitary/with_extras/aqua/test_evaluation_service_config.py .....................             [ 47%]
tests/unitary/with_extras/aqua/test_finetuning.py .......                                          [ 50%]
tests/unitary/with_extras/aqua/test_finetuning_handler.py .....                                    [ 52%]
tests/unitary/with_extras/aqua/test_global.py ...                                                  [ 53%]
tests/unitary/with_extras/aqua/test_handlers.py .................                                  [ 60%]
tests/unitary/with_extras/aqua/test_model.py ..........................                            [ 70%]
tests/unitary/with_extras/aqua/test_model_handler.py ..............                                [ 76%]
tests/unitary/with_extras/aqua/test_ui.py ...............                                          [ 82%]
tests/unitary/with_extras/aqua/test_ui_handler.py ..............                                   [ 88%]
tests/unitary/with_extras/aqua/test_ui_websocket_handler.py ....                                   [ 89%]
tests/unitary/with_extras/aqua/test_utils.py ...........

==================================== 247 passed, 1 skipped in 50.04s =====================================

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 18, 2024
@VipulMascarenhas VipulMascarenhas changed the base branch from main to feature/aqua-v1.0.5 October 18, 2024 23:29
@VipulMascarenhas VipulMascarenhas changed the base branch from feature/aqua-v1.0.5 to main October 18, 2024 23:29
@VipulMascarenhas VipulMascarenhas changed the title [ODSC-63984] BYOC TEI image for embedding models WIP - [ODSC-63984] BYOC TEI image for embedding models Oct 18, 2024
@VipulMascarenhas VipulMascarenhas changed the title WIP - [ODSC-63984] BYOC TEI image for embedding models WIP - [ODSC-63984] BYOC TEI deployment for embedding models Oct 18, 2024
mrDzurb
mrDzurb previously approved these changes Oct 18, 2024
-------
Release date: October 18, 2024

* Introduced enhancements for AI Quick Actions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to mention which enhancement.

Copy link

📌 Cov diff with main:

Coverage-46%

📌 Overall coverage:

Coverage-59.05%

@VipulMascarenhas VipulMascarenhas changed the title WIP - [ODSC-63984] BYOC TEI deployment for embedding models [ODSC-63984] BYOC TEI deployment for embedding models Oct 23, 2024
Copy link

📌 Cov diff with main:

Coverage-3%

📌 Overall coverage:

Coverage-20.13%

1 similar comment
Copy link

📌 Cov diff with main:

Coverage-3%

📌 Overall coverage:

Coverage-20.13%

logging.info(f"CMD used for deploying {aqua_model.id} :{cmd_var}")
else:
# fetch image name from config
container_image_uri = get_container_image(container_type=container_type_key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop this if statement and instead follow this logic -

  • get_container_image returns empty when the image is not found
  • If it is empty, we check if aqua_model.custom_metadata_list.get(AQUA_DEPLOYMENT_CONTAINER_URI_METADATA_NAME).value has value.
  • If both are empty we return value error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, dropped the TEI specific check and updated to the above logic.

Copy link

📌 Cov diff with main:

Coverage-3%

📌 Overall coverage:

Coverage-20.13%

Copy link

📌 Cov diff with main:

Coverage-3%

📌 Overall coverage:

Coverage-20.13%

mrDzurb
mrDzurb previously approved these changes Oct 25, 2024
ads/aqua/common/utils.py Outdated Show resolved Hide resolved
"""Helper functions that parses a list into a key-value dictionary. The list contains keys separated by the prefix
'--' and the value of the key is the subsequent element.
"""
it = iter(cmd_list)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link

📌 Cov diff with main:

Coverage-2%

📌 Overall coverage:

Coverage-20.14%

Copy link

📌 Cov diff with main:

Coverage-58%

📌 Overall coverage:

Coverage-59.00%

mrDzurb
mrDzurb previously approved these changes Oct 28, 2024
cmd_var_string = aqua_model.custom_metadata_list.get(
AQUA_DEPLOYMENT_CONTAINER_CMD_VAR_METADATA_NAME
).value
default_cmd_var = cmd_var_string.split(",")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use shlex.split for safety since this is a cmd string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using shlex.split now instead of string split.

"""
it = iter(cmd_list)
return {
key: next(it, None) if not key.startswith("--") else next(it, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the filter on the for loop already takes in key that starts --, do we need to check it again. Also, both if and else, we return the same, so we dont need the if statement right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted to the iterative method, this one made me think twice as well. Easier for readability for the future.

description=f"Inference container mapping for {model_name}",
category="Other",
)
if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen once we have SMC support? The user will see this warning unless they upgrade the sdk right? Let us get rid of this check. There is already check in the upstream code right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this check

f"Proceeding with model registration without the inference container URI for "
f"{inference_container}. You can still add this configuration during model deployment."
)
else:
Copy link
Member

@mayoor mayoor Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add

if inference_container_uri:
      metadata.add(
                        key=AQUA_DEPLOYMENT_CONTAINER_URI_METADATA_NAME,
                        value=inference_container_uri,
                        description=f"Inference container URI for {model_name}",
                        category="Other",
                    )

for the following part, can we have a generate only when the config.json does not any information about the TEI? When we support SMC, we might have backward compatible issue -

cmd_vars = generate_tei_cmd_var(os_path)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we add this to metadata only if the container image family is not in the SMC list.

Copy link

📌 Cov diff with main:

Coverage-55%

📌 Overall coverage:

Coverage-58.63%

Copy link
Member

@kumar-shivam-ranjan kumar-shivam-ranjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@VipulMascarenhas VipulMascarenhas merged commit 4936025 into main Oct 29, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants