Support mlflow.genai.to_predict_fn for app invocation endpoints#19779
Support mlflow.genai.to_predict_fn for app invocation endpoints#19779jennsun merged 15 commits intomlflow:masterfrom
Conversation
|
Documentation preview for 6e11bbc is available at: More info
|
|
@jennsun Thank you for the contribution! Could you fix the following issue(s)? ⚠ DCO checkThe DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details. |
7297367 to
a108b51
Compare
mlflow/genai/evaluation/base.py
Outdated
|
|
||
| schema, path = _parse_model_uri(endpoint_uri) | ||
|
|
||
| if schema == "apps": |
There was a problem hiding this comment.
nit: can we separate this function into 2 helper functions?
There was a problem hiding this comment.
+1, let's use case match for schema and route to different functions
| mock_get_experiment_id.assert_called_once() | ||
|
|
||
|
|
||
| # ========== Databricks Apps Tests ========== |
There was a problem hiding this comment.
for the manual test, can we do a whole e2e flow for eval?
There was a problem hiding this comment.
e2e notebook example: https://eng-ml-agent-platform.staging.cloud.databricks.com/editor/notebooks/2722550516530718?o=2850744067564480#command/5285377916446537
experiment results with traces: https://eng-ml-agent-platform.staging.cloud.databricks.com/ml/experiments/2722550516530718/evaluation-runs?selectedRunUuid=4fac0bf652c044b598e1505adc26f77c&o=2850744067564480&selectedColumns=trace_id%2Cexecution_duration%2Cstate
mlflow/genai/evaluation/base.py
Outdated
|
|
||
| if schema == "apps": | ||
| try: | ||
| config = get_databricks_workspace_client_config("databricks", scopes=["all-apis"]) |
There was a problem hiding this comment.
nit: can we leave a comment here describing why this will be okay?
bbqiu
left a comment
There was a problem hiding this comment.
great work! left a few comments
you might have to rebase and sign all of your commits btw
in the future you can avoid by running git commit -sm .. to sign each commit
a108b51 to
9c9dfb2
Compare
Signed-off-by: Jenny <jenny.sun@databricks.com>
9c9dfb2 to
a2a3319
Compare
|
Note: upon further testing with notebook oauth it looks like the notebook oauth tokens are failing to query the invocations endpoint for apps in notebook environment due to oauth2proxy failures: This happens because the notebook oauth tokens contain a CNF/X.509 Fingerprint (SHA-256) claim which binds the token to a specific client certificate (intended for notebook usage only). oauth2proxy is not presenting the right certificate when making API calls, so when it tries to use this token without presenting the certificate, the request is rejected and the endpoint redirects to sign-in page. |
mlflow/genai/evaluation/base.py
Outdated
|
|
||
| schema, path = _parse_model_uri(endpoint_uri) | ||
|
|
||
| if schema == "apps": |
There was a problem hiding this comment.
+1, let's use case match for schema and route to different functions
Signed-off-by: Jenny <jenny.sun@databricks.com>
Signed-off-by: Jenny <jenny.sun@databricks.com>
Signed-off-by: Jenny <jenny.sun@databricks.com>
Co-authored-by: Serena Ruan <82044803+serena-ruan@users.noreply.github.com> Signed-off-by: Jenny <jennysunnjm@gmail.com>
mlflow/utils/databricks_utils.py
Outdated
| except TypeError as e: | ||
| if "scopes" in str(e): | ||
| raise MlflowException.invalid_parameter_value( | ||
| "The 'scopes' parameter requires databricks-sdk>=0.74.0. " | ||
| "Please upgrade with: pip install --upgrade databricks-sdk", | ||
| ) from e | ||
| raise |
There was a problem hiding this comment.
Sorry if I didn't make it clear in previous comment, could we check databricks sdk version instead of capturing this error message, which is not reliable? It may capture other errors with scopes but not related to version.
Let's create a function like:
def databricks_workspace_client_supports_scopes:
if Version(databricks.sdk.xxx) < Version("0.74.0"):
raise ...
Then we can reuse this check here and line382 in models/evaluation/base.py
serena-ruan
left a comment
There was a problem hiding this comment.
Overall LGTM! BTW we pushed RC to tomorrow, so you can address the comment before then :)
Signed-off-by: Jenny <jenny.sun@databricks.com>
Signed-off-by: Jenny <jenny.sun@databricks.com>
mlflow/utils/databricks_utils.py
Outdated
| Raises: | ||
| MlflowException: If databricks-sdk version is < 0.74.0 | ||
| """ | ||
| from packaging.version import Version |
There was a problem hiding this comment.
Let's move this to top
| from databricks.sdk import WorkspaceClient | ||
|
|
||
| if scopes is not None: | ||
| check_databricks_sdk_supports_scopes() |
There was a problem hiding this comment.
Let's use kwargs = {"scopes": scopes} here, and pass below to avoid breaking old databricks-sdk
mlflow/genai/evaluation/base.py
Outdated
|
|
||
| # Append /invocations to endpoint | ||
| return DatabricksAppConfig( | ||
| app_url=f"{app.url}/invocations", |
There was a problem hiding this comment.
nit: can we change this to be app_invocation_url?
mlflow/utils/databricks_utils.py
Outdated
|
|
||
| def check_databricks_sdk_supports_scopes(): | ||
| """ | ||
| Check if the installed databricks-sdk version supports the 'scopes' parameter. |
There was a problem hiding this comment.
nit: specify param for workspaceclient
| Returns: | ||
| A predict function that invokes the endpoint | ||
| """ | ||
| from mlflow.deployments import get_deploy_client |
There was a problem hiding this comment.
nit: move imports up
Signed-off-by: Jenny <jenny.sun@databricks.com>
…ow#19779) Signed-off-by: Jenny <jenny.sun@databricks.com> Signed-off-by: Jenny <jennysunnjm@gmail.com> Co-authored-by: Serena Ruan <82044803+serena-ruan@users.noreply.github.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
This PR updates
genai.to_predict_fn(https://mlflow.org/docs/latest/api_reference/python_api/mlflow.genai.html#mlflow.genai.to_predict_fn) to support calls to app invocation endpointsWhere a user can create a predict function by using
adding an additional schema to the existing group (used to only support model serving endpoints with schema
endpoints)Under the hood, an oauth token for the databricks workspace will be used to send a post request to the app's invocation endpoint to be passed in as the prediction function for mlflow e2e eval flow
How is this PR tested?
Tested notebook with mlflow version of this PR [NOTE: app invocations requires a fix for notebook oauth tokens]:

https://eng-ml-agent-platform.staging.cloud.databricks.com/editor/notebooks/2722550516530718?o=2850744067564480
Tested locally:

With mlflow evaluation framework, verifying traces are visible in experiments:
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.