Skip to content

Commit

Permalink
fix: Fix UPI integration test (#548)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. Run unit tests and ensure that they are passing
2. If your change introduces any API changes, make sure to update the
e2e tests
3. Make sure documentation is updated for your PR!

-->
# Description
<!-- Briefly describe the motivation for the change. Please include
illustrations where appropriate. -->
In recent [PR](#544)
accidentally update env variable for transformer that fail the test as
the infer method is not correct for upi http predictor. This PR fix the
infer method and parameterize the test whether it is using http
predictor or not
# Modifications
<!-- Summarize the key code changes. -->
Update pyfunc_upi_integration_test.py
# Tests
<!-- Besides the existing / updated automated tests, what specific
scenarios should be tested? Consider the backward compatibility of the
changes, whether corner cases are covered, etc. Please describe the
tests and check the ones that have been completed. Eg:
- [x] Deploying new and existing standard models
- [ ] Deploying PyFunc models
-->

# Checklist
- [ ] Added PR label
- [ ] Added unit test, integration, and/or e2e tests
- [ ] Tested locally
- [ ] Updated documentation
- [ ] Update Swagger spec if the PR introduce API changes
- [ ] Regenerated Golang and Python client if the PR introduces API
changes

# Release Notes
<!--
Does this PR introduce a user-facing change?
If no, just write "NONE" in the release-note block below.
If yes, a release note is required. Enter your extended release note in
the block below.
If the PR requires additional action from users switching to the new
release, include the string "action required".

For more information about release notes, see kubernetes' guide here:
http://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```
  • Loading branch information
tiopramayudi authored Mar 6, 2024
1 parent 09a8e71 commit 0a79211
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions python/sdk/test/pyfunc_upi_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import xgboost as xgb
from caraml.upi.utils import df_to_table, table_to_df
from caraml.upi.v1 import type_pb2, upi_pb2, upi_pb2_grpc, variable_pb2
from google.protobuf.json_format import MessageToDict, ParseDict
from merlin.deployment_mode import DeploymentMode
from merlin.endpoint import Status
from merlin.model import ModelType, PyFuncModel
Expand Down Expand Up @@ -63,7 +64,13 @@ class SimpleForwarder(PyFuncModel):
target_name = "probability"

def infer(self, request: dict, **kwargs):
return request
upi_request = upi_pb2.PredictValuesRequest()
ParseDict(request, upi_request)
upi_response = upi_pb2.PredictValuesResponse(
prediction_result_table=upi_request.prediction_table,
target_name=self.target_name,
)
return MessageToDict(upi_response)

def upiv1_infer(
self, request: upi_pb2.PredictValuesRequest, context: grpc.ServicerContext
Expand Down Expand Up @@ -107,12 +114,14 @@ def test_deploy(integration_test_url, project_name, use_google_oauth, requests):

@pytest.mark.pyfunc
@pytest.mark.integration
@pytest.mark.parametrize("upi_http_predictor", [False, True])
def test_pyfunc_with_standard_transformer(
integration_test_url, project_name, use_google_oauth, requests
integration_test_url, project_name, upi_http_predictor, use_google_oauth, requests
):
merlin.set_url(integration_test_url, use_google_oauth=use_google_oauth)
merlin.set_project(project_name)
merlin.set_model("pyfunc-upi-std", ModelType.PYFUNC)
model_name = "pyfunc-upi-std-http" if upi_http_predictor else "pyfunc-upi-std"
merlin.set_model(model_name, ModelType.PYFUNC)

undeploy_all_version()
with merlin.new_model_version() as v:
Expand All @@ -125,10 +134,12 @@ def test_pyfunc_with_standard_transformer(
transformer_config_path = os.path.join(
"test/transformer", "upi_standard_transformer_no_feast.yaml"
)

upi_http_enabled_val = "true" if upi_http_predictor else "false"
transformer = StandardTransformer(
config_file=transformer_config_path,
enabled=True,
env_vars={"PREDICTOR_UPI_HTTP_ENABLED": "true"},
env_vars={"PREDICTOR_UPI_HTTP_ENABLED": upi_http_enabled_val},
)
endpoint = merlin.deploy(v, transformer=transformer, protocol=Protocol.UPI_V1)

Expand Down

0 comments on commit 0a79211

Please sign in to comment.