chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:22:34 +08:00
commit 4b22cfda96
9037 changed files with 2363717 additions and 0 deletions
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@@ -0,0 +1,3 @@
<svg height="1024" width="896" xmlns="http://www.w3.org/2000/svg">
<path d="M128 768h256v64H128v-64z m320-384H128v64h320v-64z m128 192V448L384 640l192 192V704h320V576H576z m-288-64H128v64h160v-64zM128 704h160v-64H128v64z m576 64h64v128c-1 18-7 33-19 45s-27 18-45 19H64c-35 0-64-29-64-64V192c0-35 29-64 64-64h192C256 57 313 0 384 0s128 57 128 128h192c35 0 64 29 64 64v320h-64V320H64v576h640V768zM128 256h512c0-35-29-64-64-64h-64c-35 0-64-29-64-64s-29-64-64-64-64 29-64 64-29 64-64 64h-64c-35 0-64 29-64 64z" />
</svg>

After

Width:  |  Height:  |  Size: 519 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M896 128q209 0 385.5 103t279.5 279.5 103 385.5-103 385.5-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103zm128 1247v-190q0-14-9-23.5t-22-9.5h-192q-13 0-23 10t-10 23v190q0 13 10 23t23 10h192q13 0 22-9.5t9-23.5zm-2-344l18-621q0-12-10-18-10-8-24-8h-220q-14 0-24 8-10 6-10 18l17 621q0 10 10 17.5t24 7.5h185q14 0 23.5-7.5t10.5-17.5z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 524 B

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="19px" height="16px" viewBox="0 0 19 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 40 (33762) - http://www.bohemiancoding.com/sketch -->
<title>house</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="1" transform="translate(-11.000000, -237.000000)" stroke-width="1.5" stroke="#0193E1">
<g id="leftnav" transform="translate(0.000000, 74.000000)">
<g id="house" transform="translate(12.000000, 164.000000)">
<g id="Group-5">
<polyline id="Stroke-1" points="3 4.10584211 3 13.9431579 14 13.9431579 14 4.10584211"></polyline>
<polyline id="Stroke-3" points="17 6.71168421 8.5004837 0.5 0 6.71168421"></polyline>
</g>
<path d="M8.75,13.5 L8.75,10.5" id="Line" stroke-linecap="square"></path>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M532 1108l152 152-52 52h-56v-96h-96v-56zm414-390q14 13-3 30l-291 291q-17 17-30 3-14-13 3-30l291-291q17-17 30-3zm-274 690l544-544-288-288-544 544v288h288zm608-608l92-92q28-28 28-68t-28-68l-152-152q-28-28-68-28t-68 28l-92 92zm384-384v960q0 119-84.5 203.5t-203.5 84.5h-960q-119 0-203.5-84.5t-84.5-203.5v-960q0-119 84.5-203.5t203.5-84.5h960q119 0 203.5 84.5t84.5 203.5z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 526 B

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1120 576q0 13-9.5 22.5t-22.5 9.5-22.5-9.5-9.5-22.5q0-46-54-71t-106-25q-13 0-22.5-9.5t-9.5-22.5 9.5-22.5 22.5-9.5q50 0 99.5 16t87 54 37.5 90zm160 0q0-72-34.5-134t-90-101.5-123-62-136.5-22.5-136.5 22.5-123 62-90 101.5-34.5 134q0 101 68 180 10 11 30.5 33t30.5 33q128 153 141 298h228q13-145 141-298 10-11 30.5-33t30.5-33q68-79 68-180zm128 0q0 155-103 268-45 49-74.5 87t-59.5 95.5-34 107.5q47 28 47 82 0 37-25 64 25 27 25 64 0 52-45 81 13 23 13 47 0 46-31.5 71t-77.5 25q-20 44-60 70t-87 26-87-26-60-70q-46 0-77.5-25t-31.5-71q0-24 13-47-45-29-45-81 0-37 25-64-25-27-25-64 0-54 47-82-4-50-34-107.5t-59.5-95.5-74.5-87q-103-113-103-268 0-99 44.5-184.5t117-142 164-89 186.5-32.5 186.5 32.5 164 89 117 142 44.5 184.5z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 868 B

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1024 1375v-190q0-14-9.5-23.5t-22.5-9.5h-192q-13 0-22.5 9.5t-9.5 23.5v190q0 14 9.5 23.5t22.5 9.5h192q13 0 22.5-9.5t9.5-23.5zm-2-374l18-459q0-12-10-19-13-11-24-11h-220q-11 0-24 11-10 7-10 21l17 457q0 10 10 16.5t24 6.5h185q14 0 23.5-6.5t10.5-16.5zm-14-934l768 1408q35 63-2 126-17 29-46.5 46t-63.5 17h-1536q-34 0-63.5-17t-46.5-46q-37-63-2-126l768-1408q17-31 47-49t65-18 65 18 47 49z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

@@ -0,0 +1,20 @@
document.addEventListener("DOMContentLoaded", function () {
var script = document.createElement("script");
script.type = "module";
script.id = "runllm-widget-script"
script.src = "https://widget.runllm.com";
script.setAttribute("runllm-keyboard-shortcut", "Mod+j"); // cmd-j or ctrl-j to open the widget.
script.setAttribute("runllm-name", "MLflow");
script.setAttribute("runllm-position", "BOTTOM_RIGHT");
script.setAttribute("runllm-assistant-id", "116");
script.setAttribute("runllm-theme-color", "#008ED9");
script.setAttribute("runllm-brand-logo", "https://mlflow.org/img/mlflow-favicon.ico");
script.setAttribute("runllm-community-type", "slack");
script.setAttribute("runllm-community-url", "https://mlflow.org/slack");
script.setAttribute("runllm-disable-ask-a-person", "true");
script.async = true;
document.head.appendChild(script);
});
@@ -0,0 +1,22 @@
.. _auth-python-api:
================================
MLflow Authentication Python API
================================
mlflow.server.auth.client
=========================
.. autoclass:: mlflow.server.auth.client.AuthServiceClient()
:members:
:undoc-members:
:show-inheritance:
mlflow.server.auth.entities
===========================
.. automodule:: mlflow.server.auth.entities
:members:
:undoc-members:
:show-inheritance:
+503
View File
@@ -0,0 +1,503 @@
.. _auth-rest-api:
==============================
MLflow Authentication REST API
==============================
The MLflow Authentication REST API allows you to create, get, update and delete users,
experiment permissions and registered model permissions.
The API is hosted under the ``/api`` route on the MLflow tracking server. For example, to list
experiments on a tracking server hosted at ``http://localhost:5000``, access
``http://localhost:5000/api/2.0/mlflow/users/create``.
.. important::
The MLflow REST API requires content type ``application/json`` for all POST requests.
.. contents:: Table of Contents
:local:
:depth: 1
===========================
.. _mlflowAuthServiceCreateUser:
Create User
===========
+-----------------------------+-------------+
| Endpoint | HTTP Method |
+=============================+=============+
| ``2.0/mlflow/users/create`` | ``POST`` |
+-----------------------------+-------------+
.. _mlflowCreateUser:
Request Structure
-----------------
+------------+------------+-------------+
| Field Name | Type | Description |
+============+============+=============+
| username | ``STRING`` | Username. |
+------------+------------+-------------+
| password | ``STRING`` | Password. |
+------------+------------+-------------+
.. _mlflowCreateUserResponse:
Response Structure
------------------
+------------+-------------------+----------------+
| Field Name | Type | Description |
+============+===================+================+
| user | :ref:`mlflowUser` | A user object. |
+------------+-------------------+----------------+
===========================
.. _mlflowAuthServiceGetUser:
Get User
========
+--------------------------+-------------+
| Endpoint | HTTP Method |
+==========================+=============+
| ``2.0/mlflow/users/get`` | ``GET`` |
+--------------------------+-------------+
.. _mlflowGetUser:
Request Structure
-----------------
+------------+------------+-------------+
| Field Name | Type | Description |
+============+============+=============+
| username | ``STRING`` | Username. |
+------------+------------+-------------+
.. _mlflowGetUserResponse:
Response Structure
------------------
+------------+-------------------+----------------+
| Field Name | Type | Description |
+============+===================+================+
| user | :ref:`mlflowUser` | A user object. |
+------------+-------------------+----------------+
===========================
.. _mlflowAuthServiceUpdateUserPassword:
Update User Password
====================
+--------------------------------------+-------------+
| Endpoint | HTTP Method |
+======================================+=============+
| ``2.0/mlflow/users/update-password`` | ``PATCH`` |
+--------------------------------------+-------------+
.. _mlflowUpdateUserPassword:
Request Structure
-----------------
+------------+------------+---------------+
| Field Name | Type | Description |
+============+============+===============+
| username | ``STRING`` | Username. |
+------------+------------+---------------+
| password | ``STRING`` | New password. |
+------------+------------+---------------+
===========================
.. _mlflowAuthServiceUpdateUserAdmin:
Update User Admin
=================
+-----------------------------------+-------------+
| Endpoint | HTTP Method |
+===================================+=============+
| ``2.0/mlflow/users/update-admin`` | ``PATCH`` |
+-----------------------------------+-------------+
.. _mlflowUpdateUserAdmin:
Request Structure
-----------------
+------------+-------------+-------------------+
| Field Name | Type | Description |
+============+=============+===================+
| username | ``STRING`` | Username. |
+------------+-------------+-------------------+
| is_admin | ``BOOLEAN`` | New admin status. |
+------------+-------------+-------------------+
===========================
.. _mlflowAuthServiceDeleteUser:
Delete User
===========
+-----------------------------+-------------+
| Endpoint | HTTP Method |
+=============================+=============+
| ``2.0/mlflow/users/delete`` | ``DELETE`` |
+-----------------------------+-------------+
.. _mlflowDeleteUser:
Request Structure
-----------------
+------------+------------+-------------+
| Field Name | Type | Description |
+============+============+=============+
| username | ``STRING`` | Username. |
+------------+------------+-------------+
===========================
.. _mlflowAuthServiceCreateExperimentPermission:
Create Experiment Permission
============================
+-----------------------------------------------+-------------+
| Endpoint | HTTP Method |
+===============================================+=============+
| ``2.0/mlflow/experiments/permissions/create`` | ``POST`` |
+-----------------------------------------------+-------------+
.. _mlflowCreateExperimentPermission:
Request Structure
-----------------
+---------------+-------------------------+----------------------+
| Field Name | Type | Description |
+===============+=========================+======================+
| experiment_id | ``STRING`` | Experiment id. |
+---------------+-------------------------+----------------------+
| username | ``STRING`` | Username. |
+---------------+-------------------------+----------------------+
| permission | :ref:`mlflowPermission` | Permission to grant. |
+---------------+-------------------------+----------------------+
.. _mlflowCreateExperimentPermissionResponse:
Response Structure
------------------
+-----------------------+-----------------------------------+----------------------------------+
| Field Name | Type | Description |
+=======================+===================================+==================================+
| experiment_permission | :ref:`mlflowExperimentPermission` | An experiment permission object. |
+-----------------------+-----------------------------------+----------------------------------+
===========================
.. _mlflowAuthServiceGetExperimentPermission:
Get Experiment Permission
=========================
+--------------------------------------------+-------------+
| Endpoint | HTTP Method |
+============================================+=============+
| ``2.0/mlflow/experiments/permissions/get`` | ``GET`` |
+--------------------------------------------+-------------+
.. _mlflowGetExperimentPermission:
Request Structure
-----------------
+---------------+------------+----------------+
| Field Name | Type | Description |
+===============+============+================+
| experiment_id | ``STRING`` | Experiment id. |
+---------------+------------+----------------+
| username | ``STRING`` | Username. |
+---------------+------------+----------------+
.. _mlflowGetExperimentPermissionResponse:
Response Structure
------------------
+-----------------------+-----------------------------------+----------------------------------+
| Field Name | Type | Description |
+=======================+===================================+==================================+
| experiment_permission | :ref:`mlflowExperimentPermission` | An experiment permission object. |
+-----------------------+-----------------------------------+----------------------------------+
===========================
.. _mlflowAuthServiceUpdateExperimentPermission:
Update Experiment Permission
============================
+-----------------------------------------------+-------------+
| Endpoint | HTTP Method |
+===============================================+=============+
| ``2.0/mlflow/experiments/permissions/update`` | ``PATCH`` |
+-----------------------------------------------+-------------+
.. _mlflowUpdateExperimentPermission:
Request Structure
-----------------
+---------------+-------------------------+--------------------------+
| Field Name | Type | Description |
+===============+=========================+==========================+
| experiment_id | ``STRING`` | Experiment id. |
+---------------+-------------------------+--------------------------+
| username | ``STRING`` | Username. |
+---------------+-------------------------+--------------------------+
| permission | :ref:`mlflowPermission` | New permission to grant. |
+---------------+-------------------------+--------------------------+
===========================
.. _mlflowAuthServiceDeleteExperimentPermission:
Delete Experiment Permission
============================
+-----------------------------------------------+-------------+
| Endpoint | HTTP Method |
+===============================================+=============+
| ``2.0/mlflow/experiments/permissions/delete`` | ``DELETE`` |
+-----------------------------------------------+-------------+
.. _mlflowDeleteExperimentPermission:
Request Structure
-----------------
+---------------+------------+----------------+
| Field Name | Type | Description |
+===============+============+================+
| experiment_id | ``STRING`` | Experiment id. |
+---------------+------------+----------------+
| username | ``STRING`` | Username. |
+---------------+------------+----------------+
===========================
.. _mlflowAuthServiceCreateRegisteredModelPermission:
Create Registered Model Permission
==================================
+-----------------------------------------------------+-------------+
| Endpoint | HTTP Method |
+=====================================================+=============+
| ``2.0/mlflow/registered-models/permissions/create`` | ``CREATE`` |
+-----------------------------------------------------+-------------+
.. _mlflowCreateRegisteredModelPermission:
Request Structure
-----------------
+------------+-------------------------+------------------------+
| Field Name | Type | Description |
+============+=========================+========================+
| name | ``STRING`` | Registered model name. |
+------------+-------------------------+------------------------+
| username | ``STRING`` | Username. |
+------------+-------------------------+------------------------+
| permission | :ref:`mlflowPermission` | Permission to grant. |
+------------+-------------------------+------------------------+
.. _mlflowCreateRegisteredModelPermissionResponse:
Response Structure
------------------
+-----------------------------+----------------------------------------+---------------------------------------+
| Field Name | Type | Description |
+=============================+========================================+=======================================+
| registered_model_permission | :ref:`mlflowRegisteredModelPermission` | A registered model permission object. |
+-----------------------------+----------------------------------------+---------------------------------------+
===========================
.. _mlflowAuthServiceGetRegisteredModelPermission:
Get Registered Model Permission
===============================
+--------------------------------------------------+-------------+
| Endpoint | HTTP Method |
+==================================================+=============+
| ``2.0/mlflow/registered-models/permissions/get`` | ``GET`` |
+--------------------------------------------------+-------------+
.. _mlflowGetRegisteredModelPermission:
Request Structure
-----------------
+------------+------------+------------------------+
| Field Name | Type | Description |
+============+============+========================+
| name | ``STRING`` | Registered model name. |
+------------+------------+------------------------+
| username | ``STRING`` | Username. |
+------------+------------+------------------------+
.. _mlflowGetRegisteredModelPermissionResponse:
Response Structure
------------------
+-----------------------------+----------------------------------------+---------------------------------------+
| Field Name | Type | Description |
+=============================+========================================+=======================================+
| registered_model_permission | :ref:`mlflowRegisteredModelPermission` | A registered model permission object. |
+-----------------------------+----------------------------------------+---------------------------------------+
===========================
.. _mlflowAuthServiceUpdateRegisteredModelPermission:
Update Registered Model Permission
==================================
+-----------------------------------------------------+-------------+
| Endpoint | HTTP Method |
+=====================================================+=============+
| ``2.0/mlflow/registered-models/permissions/update`` | ``PATCH`` |
+-----------------------------------------------------+-------------+
.. _mlflowUpdateRegisteredModelPermission:
Request Structure
-----------------
+------------+-------------------------+--------------------------+
| Field Name | Type | Description |
+============+=========================+==========================+
| name | ``STRING`` | Registered model name. |
+------------+-------------------------+--------------------------+
| username | ``STRING`` | Username. |
+------------+-------------------------+--------------------------+
| permission | :ref:`mlflowPermission` | New permission to grant. |
+------------+-------------------------+--------------------------+
===========================
.. _mlflowAuthServiceDeleteRegisteredModelPermission:
Delete Registered Model Permission
==================================
+-----------------------------------------------------+-------------+
| Endpoint | HTTP Method |
+=====================================================+=============+
| ``2.0/mlflow/registered-models/permissions/delete`` | ``DELETE`` |
+-----------------------------------------------------+-------------+
.. _mlflowDeleteRegisteredModelPermission:
Request Structure
-----------------
+------------+------------+------------------------+
| Field Name | Type | Description |
+============+============+========================+
| name | ``STRING`` | Registered model name. |
+------------+------------+------------------------+
| username | ``STRING`` | Username. |
+------------+------------+------------------------+
.. _auth-rest-struct:
Data Structures
===============
.. _mlflowUser:
User
----
+------------------------------+----------------------------------------------------+------------------------------------------------------------------+
| Field Name | Type | Description |
+==============================+====================================================+==================================================================+
| id | ``STRING`` | User ID. |
+------------------------------+----------------------------------------------------+------------------------------------------------------------------+
| username | ``STRING`` | Username. |
+------------------------------+----------------------------------------------------+------------------------------------------------------------------+
| is_admin | ``BOOLEAN`` | Whether the user is an admin. |
+------------------------------+----------------------------------------------------+------------------------------------------------------------------+
| experiment_permissions | An array of :ref:`mlflowExperimentPermission` | All experiment permissions explicitly granted to the user. |
+------------------------------+----------------------------------------------------+------------------------------------------------------------------+
| registered_model_permissions | An array of :ref:`mlflowRegisteredModelPermission` | All registered model permissions explicitly granted to the user. |
+------------------------------+----------------------------------------------------+------------------------------------------------------------------+
.. _mlflowPermission:
Permission
----------
Permission of a user to an experiment or a registered model.
+----------------+--------------------------------------+
| Name | Description |
+================+======================================+
| READ | Can read. |
+----------------+--------------------------------------+
| EDIT | Can read and update. |
+----------------+--------------------------------------+
| MANAGE | Can read, update, delete and manage. |
+----------------+--------------------------------------+
| NO_PERMISSIONS | No permissions. |
+----------------+--------------------------------------+
.. _mlflowExperimentPermission:
ExperimentPermission
--------------------
+---------------+-------------------------+---------------------+
| Field Name | Type | Description |
+===============+=========================+=====================+
| experiment_id | ``STRING`` | Experiment id. |
+---------------+-------------------------+---------------------+
| user_id | ``STRING`` | User id. |
+---------------+-------------------------+---------------------+
| permission | :ref:`mlflowPermission` | Permission granted. |
+---------------+-------------------------+---------------------+
.. _mlflowRegisteredModelPermission:
RegisteredModelPermission
-------------------------
+------------+-------------------------+------------------------+
| Field Name | Type | Description |
+============+=========================+========================+
| name | ``STRING`` | Registered model name. |
+------------+-------------------------+------------------------+
| user_id | ``STRING`` | User id. |
+------------+-------------------------+------------------------+
| permission | :ref:`mlflowPermission` | Permission granted. |
+------------+-------------------------+------------------------+
+27
View File
@@ -0,0 +1,27 @@
.. _cli:
Command-Line Interface
======================
The MLflow command-line interface (CLI) provides a simple interface to various functionality in MLflow. You can use the CLI to run projects, start the tracking UI, create and list experiments, download run artifacts,
serve MLflow Python Function and scikit-learn models, serve MLflow Python Function and scikit-learn models, and serve models on
`Microsoft Azure Machine Learning <https://azure.microsoft.com/en-us/services/machine-learning-service/>`_
and `Amazon SageMaker <https://aws.amazon.com/sagemaker/>`_.
Each individual command has a detailed help screen accessible via ``mlflow command_name --help``.
.. attention::
It is advisable to set the ``MLFLOW_TRACKING_URI`` environment variable by default,
as the CLI does not automatically connect to a tracking server. Without this,
the CLI will default to using the local filesystem where the command is executed,
rather than connecting to a localhost or remote HTTP server.
Setting ``MLFLOW_TRACKING_URI`` to the URL of your desired tracking server is required for most of the commands below.
.. contents:: Table of Contents
:local:
:depth: 2
.. click:: mlflow.cli:cli
:prog: mlflow
:show-nested:
+466
View File
@@ -0,0 +1,466 @@
#
# MLflow documentation build configuration file, created by
# cookiecutter pipproject
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import subprocess
import sys
from pathlib import Path
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, os.path.abspath("."))
import languagesections
import sphinx.ext.napoleon as _napoleon
from docutils.nodes import Text
from docutils.parsers.rst import directives
from sphinx.addnodes import pending_xref
from sphinx.directives.code import CodeBlock
import mlflow
# Pydantic's BaseModel always has MockValSer placeholders for __pydantic_validator__ and
# __pydantic_serializer__. Accessing __qualname__ on them raises PydanticUserError instead
# of AttributeError, crashing Napoleon's _skip_member. Wrap it before Napoleon's setup()
# registers it so MockValSer objects are silently skipped.
_original_napoleon_skip_member = _napoleon._skip_member
def _napoleon_skip_member_safe(app, what, name, obj, skip, options):
if "MockValSer" in type(obj).__name__:
return True
return _original_napoleon_skip_member(app, what, name, obj, skip, options)
_napoleon._skip_member = _napoleon_skip_member_safe
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx_click.ext",
"sphinx_tabs.tabs",
"sphinx_reredirects",
]
# Redirects definition in the form of ``("source", "target")``.
# Note that the target is relative to the path of the source and that the
# target must define the final url (i.e. no trailing slash).
redirects = {
"registry": "model-registry.html",
"llms/gateway": "../deployments",
"llms/gateway/index.html": "../deployments/index.html",
"llms/gateway/guides/index.html": "../../deployments/guides/index.html",
"llms/gateway/guides/step1-create-gateway.html": "../../deployments/guides/step1-create-deployments.html",
"llms/gateway/guides/step2-query-gateway.html": "../../deployments/guides/step2-query-deployments.html",
}
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = "index"
# General information about the project.
project = "MLflow"
copyright = "MLflow Project, a Series of LF Projects, LLC. All rights reserved"
author = "MLflow"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
import mlflow.version
# The short X.Y version.
version = mlflow.version.VERSION
# The full version, including alpha/beta/rc tags.
release = mlflow.version.VERSION
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
# We exclude "registry.rst" because it is an orphan redirect
exclude_patterns = ["registry.rst"]
# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_context = {
"gtm_id": os.environ.get("GTM_ID", ""),
}
html_theme_path = ["../theme/"]
html_theme = "mlflow"
html_favicon = "_static/favicon.ico"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
# html_title = 'MLflow v0.0.1'
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_js_files = ["runllm.js"]
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
# html_extra_path = []
# If not None, a 'Last updated on:' timestamp is inserted at every page
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
# html_last_updated_fmt = None
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}
# If false, no module index is generated.
# html_domain_indices = True
# If false, no index is generated.
# html_use_index = True
# If true, the index is split into individual pages for each letter.
# html_split_index = False
# If true, links to the reST sources are added to the pages.
html_show_sourcelink = False
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
html_show_sphinx = False
html_permalinks_icon = " "
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None
# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh'
# html_search_language = 'en'
# A dictionary with options for the search language support, empty by default.
# 'ja' uses this config value.
# 'zh' user can custom change `jieba` dictionary path.
# html_search_options = {'type': 'default'}
# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
# html_search_scorer = 'scorer.js'
# Output file base name for HTML help builder.
# Ref: https://sphinx-tabs.readthedocs.io/en/latest/#sphinx-configuration
htmlhelp_basename = "MLflowdoc"
# Disable closing tab for sphinx-tab extension.
sphinx_tabs_disable_tab_closing = True
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# Latex figure (float) alignment
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "MLflow.tex", "MLflow Documentation", "Databricks", "manual"),
]
# Mock torch imports as per suggestion in
# https://github.com/sphinx-doc/sphinx/issues/6521#issuecomment-505765893
autodoc_mock_imports = [
"torch",
"pytorch_lightning",
"langchain_core",
"langgraph",
"langchain_community",
"langchain_community.chat_models",
"langchain_community.llms",
"ragas",
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False
# If true, show page references after internal links.
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
# latex_appendices = []
# If false, no module index is generated.
# latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "MLflow", "MLflow Documentation", [author], 1)]
# If true, show URL addresses after external links.
# man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(
master_doc,
"MLflow",
"MLflow Documentation",
author,
"MLflow",
"End-to-end machine learning toolkit.",
"Miscellaneous",
),
]
# Documents to append as an appendix to all manuals.
# texinfo_appendices = []
# If false, no module index is generated.
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
# texinfo_no_detailmenu = False
# Enable nitpicky mode to log warnings for broken references
nitpicky = True
nitpick_ignore_regex = [
("py:class", r".+"),
]
def _get_reference_map():
"""
Sphinx computes references for type annotations using fully-qualified classnames,
so references in undocumented modules (even if the referenced object is exposed via
a different module from the one it's defined in) are considered invalid by Sphinx.
Example:
```
def start_run(...) -> ActiveRun:
# ActiveRun is defined in `mlflow/tracking/fluent.py`
...
```
For this code, Sphinx tries to create a link for `ActiveRun` using
`mlflow.tracking.fluent.ActiveRun` as a reference target, but the module
`mlflow.tracking.fluent` is undocumented, so Sphinx raises this warning:
`WARNING: py:class reference target not found: mlflow.tracking.fluent.ActiveRun`.
As a workaround, replace `mlflow.tracking.fluent.ActiveRun` with `mlflow.ActiveRun`.
"""
ref_map = {
# < Invalid reference >: < valid reference >
"mlflow.tracking.fluent.ActiveRun": "mlflow.ActiveRun",
"mlflow.tracking.fluent.ActiveModel": "mlflow.ActiveModel",
"mlflow.store.entities.paged_list.PagedList": "mlflow.store.entities.PagedList",
}
# Tracking entities
for entity_name in mlflow.entities.__all__:
entity_cls = getattr(mlflow.entities, entity_name)
invalid_ref = entity_cls.__module__ + "." + entity_name
valid_ref = f"mlflow.entities.{entity_name}"
ref_map[invalid_ref] = valid_ref
# Model registry entities
for entity_name in mlflow.entities.model_registry.__all__:
entity_cls = getattr(mlflow.entities.model_registry, entity_name)
invalid_ref = entity_cls.__module__ + "." + entity_name
valid_ref = f"mlflow.entities.model_registry.{entity_name}"
ref_map[invalid_ref] = valid_ref
ref_map["mlflow.genai.scorers.base.Scorer"] = "mlflow.genai.Scorer"
return ref_map
REFERENCE_MAP = _get_reference_map()
def resolve_missing_references(app, doctree):
for node in doctree.traverse(condition=pending_xref):
missing_ref = node.get("reftarget", None)
if missing_ref is not None and missing_ref in REFERENCE_MAP:
real_ref = REFERENCE_MAP[missing_ref]
text_to_render = real_ref.split(".")[-1]
node["reftarget"] = real_ref
text_node = next(iter(node.traverse(lambda n: n.tagname == "#text")))
text_node.parent.replace(text_node, Text(text_to_render, ""))
def env_updated(app: Sphinx, env: BuildEnvironment) -> None:
items: list[str] = []
for _domain_name, domain in env.domains.items():
for _name, display_name, obj_type, _doc_name, _anchor, _priority in domain.get_objects():
if obj_type in ("function", "method", "class"):
items.append(display_name)
repo_root = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip()
path = Path(repo_root, "docs", "api_reference", "api_inventory.txt")
if not path.parent.exists():
path.parent.mkdir(parents=True)
path.write_text("\n".join(sorted(items)) + "\n")
class TestCodeBlockDirective(CodeBlock):
"""
Overrides the `code-block` directive to accept the `:test:` option.
The actual test extraction is done by the standalone testcode_block.py script.
"""
option_spec = {**CodeBlock.option_spec, "test": directives.flag}
def setup(app):
languagesections.setup(app)
app.add_directive("code-block", TestCodeBlockDirective, override=True)
app.connect("doctree-read", resolve_missing_references)
app.connect("env-updated", env_updated)
linkcheck_ignore = [
# Ignore local URLs when validating external links
r"http://localhost:\d+/?",
]
+16
View File
@@ -0,0 +1,16 @@
MLflow API Docs
===============
This page hosts the API documentation for MLflow.
.. toctree::
:maxdepth: 1
python_api/index
typescript_api/index
cli
auth/python-api
auth/rest-api
R-api
java_api/index
rest-api
@@ -0,0 +1,6 @@
.. _java_api:
Java API
==========
This file is a placeholder. Javadoc is filled in by the build-javadoc.sh script, executed during "make html".
@@ -0,0 +1,57 @@
import os
from docutils import nodes
from docutils.parsers.rst import Directive
from sphinx.util import logging
from sphinx.util.osutil import copyfile
logger = logging.getLogger(__name__)
JS_FILE = "languagesections.js"
class CodeSectionDirective(Directive):
has_content = True
def run(self):
self.assert_has_content()
text = "\n".join(self.content)
node = nodes.container(text)
node["classes"].append("code-section")
self.add_name(node)
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
class PlainSectionDirective(Directive):
has_content = True
def run(self):
self.assert_has_content()
text = "\n".join(self.content)
node = nodes.container(text)
node["classes"].append("plain-section")
self.add_name(node)
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
def add_assets(app):
app.add_js_file(JS_FILE)
def copy_assets(app, exception):
if app.builder.name != "html" or exception:
return
logger.info("Copying examplecode stylesheet/javascript... ", nonl=True)
dest = os.path.join(app.builder.outdir, "_static", JS_FILE)
source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE)
copyfile(source, dest)
logger.info("done")
def setup(app):
app.add_directive("code-section", CodeSectionDirective)
app.add_directive("plain-section", PlainSectionDirective)
app.connect("builder-inited", add_assets)
app.connect("build-finished", copy_assets)
@@ -0,0 +1,80 @@
$(function() {
$('div.code-section').each(function() {
var example_sel = $('<ul />', { class: 'section-selector' });
var i = 0;
$('div[class^="highlight-"]', this).each(function() {
language_name = $(this).attr('class').substring(10).replace('notranslate', '');
language_name = language_name.charAt(0).toUpperCase() + language_name.substr(1);
var sel_item = $('<li />', {
class: $(this).attr('class'),
text: language_name
});
if (i++) {
$(this).hide();
} else {
sel_item.addClass('selected');
}
example_sel.append(sel_item);
$(this).addClass('example');
});
$(this).prepend(example_sel);
example_sel = null;
i = null;
});
$('div.plain-section').each(function() {
var example_sel = $('<ul />', { class: 'section-selector' });
var i = 0;
$('div.container', this).each(function() {
var language_name = $(this).attr('class').replace(' docutils container', '').trim();
language_name = language_name.charAt(0).toUpperCase() + language_name.substr(1);
var sel_item = $('<li />', {
class: $(this).attr('class'),
text: language_name
});
if (i++) {
$(this).hide();
} else {
sel_item.addClass('selected');
}
example_sel.append(sel_item);
$(this).addClass('example');
});
$(this).prepend(example_sel);
example_sel = null;
i = null;
});
$('div.code-section ul.section-selector li,div.plain-section ul.section-selector li').click(function(evt) {
evt.preventDefault();
var sel_class = $(this).attr('class')
.replace(' docutils container', '')
.replace('notranslate', '')
.replace(' selected', '');
$('ul.section-selector li').each(function() {
var parent = $(this).parent().parent();
var my_sel_class = sel_class;
// When the target language is not available, default to bash or python.
if (!$('div.' + sel_class, parent).length) {
if ($('div.highlight-bash', parent).length)
my_sel_class = 'highlight-bash';
else
my_sel_class = 'highlight-python';
}
$('div.example', parent).hide();
$('div.' + my_sel_class, parent).show();
$('ul.section-selector li', parent).removeClass('selected');
$('ul.section-selector li.' + my_sel_class, parent).addClass('selected');
});
});
});
@@ -0,0 +1,15 @@
:orphan:
mlflow.exceptions
=================
.. exception:: mlflow.exceptions.MlflowException(message, error_code=1, **kwargs)
Generic exception thrown when an MLflow operation fails
.. automodule:: mlflow.exceptions
:members:
:undoc-members:
:show-inheritance:
:exclude-members:
MlflowException
@@ -0,0 +1,33 @@
.. _python-api:
Python API
==========
The MLflow Python API is organized into the following modules. The most common functions are
exposed in the :py:mod:`mlflow` module, so we recommend starting there.
.. toctree::
:glob:
:maxdepth: 1
*
See also the :ref:`index of all functions and classes<genindex>`.
Log Levels
----------
MLflow Python APIs log information during execution using the Python Logging API. You can
configure the log level for MLflow logs using the following code snippet. Learn more about Python
log levels at the
`Python language logging guide <https://docs.python.org/3/howto/logging.html>`_.
.. code-block:: python
import logging
logger = logging.getLogger("mlflow")
# Set log level to debugging
logger.setLevel(logging.DEBUG)
@@ -0,0 +1,7 @@
mlflow.ag2
==========
.. automodule:: mlflow.ag2
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.agno
==================
.. automodule:: mlflow.agno
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.anthropic
================
.. automodule:: mlflow.anthropic
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.artifacts
================
.. automodule:: mlflow.artifacts
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.autogen
==============
.. automodule:: mlflow.autogen
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.bedrock
==============
.. automodule:: mlflow.bedrock
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.catboost
===============
.. automodule:: mlflow.catboost
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,9 @@
.. _mlflow.tracking:
mlflow.client
===============
.. automodule:: mlflow.client
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.config
==============
.. automodule:: mlflow.config
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.crewai
==============
.. automodule:: mlflow.crewai
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,169 @@
mlflow.data
============
The ``mlflow.data`` module helps you record your model training and evaluation datasets to
runs with MLflow Tracking, as well as retrieve dataset information from runs. It provides the
following important interfaces:
* :py:class:`Dataset <mlflow.data.dataset.Dataset>`: Represents a dataset used in model training or
evaluation, including features, targets, predictions, and metadata such as the dataset's name, digest (hash)
schema, profile, and source. You can log this metadata to a run in MLflow Tracking using
the :py:func:`mlflow.log_input()` API. ``mlflow.data`` provides APIs for constructing
:py:class:`Datasets <mlflow.data.dataset.Dataset>` from a variety of Python data objects, including
Pandas DataFrames (:py:func:`mlflow.data.from_pandas()`), NumPy arrays
(:py:func:`mlflow.data.from_numpy()`), Spark DataFrames (:py:func:`mlflow.data.from_spark()`
/ :py:func:`mlflow.data.load_delta()`), Polars DataFrames (:py:func:`mlflow.data.from_polars()`), and more.
* :py:func:`DatasetSource <mlflow.data.dataset_source.DatasetSource>`: Represents the source of a
dataset. For example, this may be a directory of files stored in S3, a Delta Table, or a web URL.
Each :py:class:`Dataset <mlflow.data.dataset.Dataset>` references the source from which it was
derived. A :py:class:`Dataset <mlflow.data.dataset.Dataset>`'s features and targets may differ
from the source if transformations and filtering were applied. You can get the
:py:func:`DatasetSource <mlflow.data.dataset_source.DatasetSource>` of a dataset logged to a
run in MLflow Tracking using the :py:func:`mlflow.data.get_source()` API.
The following example demonstrates how to use ``mlflow.data`` to log a training dataset to a run,
retrieve information about the dataset from the run, and load the dataset's source.
.. code-block:: python
import mlflow.data
import pandas as pd
from mlflow.data.pandas_dataset import PandasDataset
# Construct a Pandas DataFrame using iris flower data from a web URL
dataset_source_url = "http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv"
df = pd.read_csv(dataset_source_url)
# Construct an MLflow PandasDataset from the Pandas DataFrame, and specify the web URL
# as the source
dataset: PandasDataset = mlflow.data.from_pandas(df, source=dataset_source_url)
with mlflow.start_run():
# Log the dataset to the MLflow Run. Specify the "training" context to indicate that the
# dataset is used for model training
mlflow.log_input(dataset, context="training")
# Retrieve the run, including dataset information
run = mlflow.get_run(mlflow.last_active_run().info.run_id)
dataset_info = run.inputs.dataset_inputs[0].dataset
print(f"Dataset name: {dataset_info.name}")
print(f"Dataset digest: {dataset_info.digest}")
print(f"Dataset profile: {dataset_info.profile}")
print(f"Dataset schema: {dataset_info.schema}")
# Load the dataset's source, which downloads the content from the source URL to the local
# filesystem
dataset_source = mlflow.data.get_source(dataset_info)
dataset_source.load()
.. autoclass:: mlflow.data.dataset.Dataset
:members:
:undoc-members:
:show-inheritance:
.. autoclass:: mlflow.data.dataset_source.DatasetSource
:members:
:undoc-members:
:show-inheritance:
:exclude-members: from_json
.. method:: from_json(cls, source_json: str) -> DatasetSource
.. autofunction:: mlflow.data.get_source
pandas
~~~~~~
.. autofunction:: mlflow.data.from_pandas
.. autoclass:: mlflow.data.pandas_dataset.PandasDataset()
:members:
:undoc-members:
:exclude-members: to_pyfunc, to_evaluation_dataset
NumPy
~~~~~
.. autofunction:: mlflow.data.from_numpy
.. autoclass:: mlflow.data.numpy_dataset.NumpyDataset()
:members:
:undoc-members:
:exclude-members: to_pyfunc, to_evaluation_dataset
Spark
~~~~~
.. autofunction:: mlflow.data.load_delta
.. autofunction:: mlflow.data.from_spark
.. autoclass:: mlflow.data.spark_dataset.SparkDataset()
:members:
:undoc-members:
:exclude-members: to_pyfunc, to_evaluation_dataset
Hugging Face
~~~~~~~~~~~~
.. autofunction:: mlflow.data.huggingface_dataset.from_huggingface
.. autoclass:: mlflow.data.huggingface_dataset.HuggingFaceDataset()
:members:
:undoc-members:
:exclude-members: to_pyfunc
TensorFlow
~~~~~~~~~~~~
.. autofunction:: mlflow.data.tensorflow_dataset.from_tensorflow
.. autoclass:: mlflow.data.tensorflow_dataset.TensorFlowDataset()
:members:
:undoc-members:
:exclude-members: to_pyfunc,
.. autoclass:: mlflow.data.evaluation_dataset.EvaluationDataset()
:members:
:undoc-members:
polars
~~~~~~
.. autofunction:: mlflow.data.from_polars
.. autoclass:: mlflow.data.polars_dataset.PolarsDataset()
:members:
:undoc-members:
:exclude-members: to_pyfunc, to_evaluation_dataset
Dataset Sources
~~~~~~~~~~~~~~~~
.. autoclass:: mlflow.data.filesystem_dataset_source.FileSystemDatasetSource()
:members:
:undoc-members:
.. autoclass:: mlflow.data.http_dataset_source.HTTPDatasetSource()
:members:
:undoc-members:
.. autoclass:: mlflow.data.huggingface_dataset_source.HuggingFaceDatasetSource()
:members:
:undoc-members:
:exclude-members:
.. autoclass:: mlflow.data.delta_dataset_source.DeltaDatasetSource()
:members:
:undoc-members:
.. autoclass:: mlflow.data.spark_dataset_source.SparkDatasetSource()
:members:
:undoc-members:
@@ -0,0 +1,12 @@
mlflow.deployments
==================
.. automodule:: mlflow.deployments
:members:
:undoc-members:
:exclude-members: PredictionsResponse
.. autoclass:: mlflow.deployments.PredictionsResponse
:members:
:undoc-members:
:exclude-members: from_json
@@ -0,0 +1,7 @@
mlflow.dspy
==================
.. automodule:: mlflow.dspy
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,15 @@
mlflow.entities
===============
.. automodule:: mlflow.entities
:members:
:undoc-members:
.. automodule:: mlflow.entities.model_registry
:members:
:undoc-members:
:exclude-members: Prompt
.. automodule:: mlflow.store.entities
:members:
:undoc-members:
@@ -0,0 +1,6 @@
mlflow.environment_variables
============================
.. automodule:: mlflow.environment_variables
:members:
:undoc-members:
@@ -0,0 +1,14 @@
mlflow.gateway
==============
.. automodule:: mlflow.gateway
:members:
:undoc-members:
.. automodule:: mlflow.gateway.base_models
:members: ConfigModel
.. automodule:: mlflow.gateway.config
:members:
:undoc-members:
:exclude-members: model_computed_fields
@@ -0,0 +1,7 @@
mlflow.gemini
==============
.. automodule:: mlflow.gemini
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,73 @@
mlflow.genai
============
.. automodule:: mlflow.genai
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.genai.scorers
:members:
:undoc-members:
:show-inheritance:
:exclude-members: Scorer
.. automodule:: mlflow.genai.scorers.deepeval
:members:
:undoc-members:
:show-inheritance:
:exclude-members: DeepEvalScorer
.. automodule:: mlflow.genai.scorers.ragas
:members:
:undoc-members:
:show-inheritance:
:exclude-members: RagasScorer
.. automodule:: mlflow.genai.scorers.phoenix
:members:
:undoc-members:
:show-inheritance:
:exclude-members: PhoenixScorer
.. automodule:: mlflow.genai.scorers.trulens
:members:
:undoc-members:
:show-inheritance:
:exclude-members: TruLensScorer, TruLensAgentScorer
.. automodule:: mlflow.genai.scorers.guardrails
:members:
:undoc-members:
:show-inheritance:
:exclude-members: GuardrailsScorer
.. automodule:: mlflow.genai.datasets
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.genai.label_schemas
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.genai.review_queues
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.genai.optimize
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.genai.judges
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.genai.agent_server
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.groq
================
.. automodule:: mlflow.groq
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.h2o
==========
.. automodule:: mlflow.h2o
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.haystack
==================
.. automodule:: mlflow.haystack
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.johnsnowlabs
===================
.. automodule:: mlflow.johnsnowlabs
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,22 @@
mlflow.keras
==================
.. automodule:: mlflow.keras.autolog
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.keras.callback
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.keras.load
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mlflow.keras.save
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,13 @@
mlflow.langchain
==================
.. automodule:: mlflow.langchain
:members:
:undoc-members:
:show-inheritance:
.. autoclass:: mlflow.langchain.chat_agent_langgraph.ChatAgentState
.. autoclass:: mlflow.langchain.chat_agent_langgraph.ChatAgentToolNode
.. autoclass:: mlflow.langchain.output_parsers.ChatAgentOutputParser
@@ -0,0 +1,7 @@
mlflow.lightgbm
===============
.. automodule:: mlflow.lightgbm
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.litellm
==============
.. automodule:: mlflow.litellm
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.llama_index
==================
.. automodule:: mlflow.llama_index
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,224 @@
mlflow.metrics
==============
The ``mlflow.metrics`` module helps you quantitatively and qualitatively measure your models.
.. autoclass:: mlflow.metrics.EvaluationMetric
These :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>` are used by the :py:func:`mlflow.evaluate()` API, either computed automatically depending on the ``model_type`` or specified via the ``extra_metrics`` parameter.
The following code demonstrates how to use :py:func:`mlflow.evaluate()` with an :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>`.
.. code-block:: python
import mlflow
from mlflow.metrics.genai import EvaluationExample, answer_similarity
eval_df = pd.DataFrame(
{
"inputs": [
"What is MLflow?",
],
"ground_truth": [
"MLflow is the largest open source AI engineering platform for agents, LLM applications, and ML models. It was developed by Databricks, a company that specializes in data and AI solutions. MLflow is designed to address the challenges that data scientists and AI engineers face when developing, evaluating, and deploying AI applications.",
],
}
)
example = EvaluationExample(
input="What is MLflow?",
output="MLflow is the largest open source AI engineering platform "
"for agents, LLM applications, and ML models, including tracing, "
"evaluation, prompt management, experiment tracking, and deployment.",
score=4,
justification="The definition effectively explains what MLflow is "
"its purpose, and its developer. It could be more concise for a 5-score.",
grading_context={
"ground_truth": "MLflow is the largest open source AI engineering "
"platform for agents, LLM applications, and ML models. It was "
"developed by Databricks, a company that specializes in data and "
"AI solutions. MLflow is designed to address the challenges that "
"data scientists and AI engineers face when developing, evaluating, "
"and deploying AI applications."
},
)
answer_similarity_metric = answer_similarity(examples=[example])
results = mlflow.evaluate(
logged_model.model_uri,
eval_df,
targets="ground_truth",
model_type="question-answering",
extra_metrics=[answer_similarity_metric],
)
Information about how an :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>` is calculated, such as the grading prompt used is available via the ``metric_details`` property.
.. code-block:: python
import mlflow
from mlflow.metrics.genai import relevance
my_relevance_metric = relevance()
print(my_relevance_metric.metric_details)
Evaluation results are stored as :py:class:`MetricValue <mlflow.metrics.MetricValue>`. Aggregate results are logged to the MLflow run as metrics, while per-example results are logged to the MLflow run as artifacts in the form of an evaluation table.
.. autoclass:: mlflow.metrics.MetricValue
We provide the following builtin factory functions to create :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>` for evaluating models. These metrics are computed automatically depending on the ``model_type``. For more information on the ``model_type`` parameter, see :py:func:`mlflow.evaluate()` API.
Regressor Metrics
-----------------
.. autofunction:: mlflow.metrics.mae
.. autofunction:: mlflow.metrics.mape
.. autofunction:: mlflow.metrics.max_error
.. autofunction:: mlflow.metrics.mse
.. autofunction:: mlflow.metrics.rmse
.. autofunction:: mlflow.metrics.r2_score
Classifier Metrics
------------------
.. autofunction:: mlflow.metrics.precision_score
.. autofunction:: mlflow.metrics.recall_score
.. autofunction:: mlflow.metrics.f1_score
Text Metrics
------------
.. autofunction:: mlflow.metrics.ari_grade_level
.. autofunction:: mlflow.metrics.flesch_kincaid_grade_level
Question Answering Metrics
---------------------------
Includes all of the above **Text Metrics** as well as the following:
.. autofunction:: mlflow.metrics.exact_match
.. autofunction:: mlflow.metrics.rouge1
.. autofunction:: mlflow.metrics.rouge2
.. autofunction:: mlflow.metrics.rougeL
.. autofunction:: mlflow.metrics.rougeLsum
.. autofunction:: mlflow.metrics.toxicity
.. autofunction:: mlflow.metrics.token_count
.. autofunction:: mlflow.metrics.latency
.. autofunction:: mlflow.metrics.bleu
Retriever Metrics
-----------------
The following metrics are built-in metrics for the ``'retriever'`` model type, meaning they will be
automatically calculated with a default ``retriever_k`` value of 3.
To evaluate document retrieval models, it is recommended to use a dataset with the following
columns:
- Input queries
- Retrieved relevant doc IDs
- Ground-truth doc IDs
Alternatively, you can also provide a function through the ``model`` parameter to represent
your retrieval model. The function should take a Pandas DataFrame containing input queries and
ground-truth relevant doc IDs, and return a DataFrame with a column of retrieved relevant doc IDs.
A "doc ID" is a string or integer that uniquely identifies a document. Each row of the retrieved and
ground-truth doc ID columns should consist of a list or numpy array of doc IDs.
Parameters:
- ``targets``: A string specifying the column name of the ground-truth relevant doc IDs
- ``predictions``: A string specifying the column name of the retrieved relevant doc IDs in either
the static dataset or the Dataframe returned by the ``model`` function
- ``retriever_k``: A positive integer specifying the number of retrieved docs IDs to consider for
each input query. ``retriever_k`` defaults to 3. You can change ``retriever_k`` by using the
:py:func:`mlflow.evaluate` API:
1. .. code-block:: python
# with a model and using `evaluator_config`
mlflow.evaluate(
model=retriever_function,
data=data,
targets="ground_truth",
model_type="retriever",
evaluators="default",
evaluator_config={"retriever_k": 5}
)
2. .. code-block:: python
# with a static dataset and using `extra_metrics`
mlflow.evaluate(
data=data,
predictions="predictions_param",
targets="targets_param",
model_type="retriever",
extra_metrics = [
mlflow.metrics.precision_at_k(5),
mlflow.metrics.precision_at_k(6),
mlflow.metrics.recall_at_k(5),
mlflow.metrics.ndcg_at_k(5)
]
)
NOTE: In the 2nd method, it is recommended to omit the ``model_type`` as well, or else
``precision@3`` and ``recall@3`` will be calculated in addition to ``precision@5``,
``precision@6``, ``recall@5``, and ``ndcg_at_k@5``.
.. autofunction:: mlflow.metrics.precision_at_k
.. autofunction:: mlflow.metrics.recall_at_k
.. autofunction:: mlflow.metrics.ndcg_at_k
Users create their own :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>` using the :py:func:`make_metric <mlflow.metrics.make_metric>` factory function
.. autofunction:: mlflow.metrics.make_metric
.. automodule:: mlflow.metrics
:members:
:undoc-members:
:show-inheritance:
:exclude-members: MetricValue, EvaluationMetric, make_metric, EvaluationExample, ari_grade_level, flesch_kincaid_grade_level, exact_match, rouge1, rouge2, rougeL, rougeLsum, toxicity, answer_similarity, answer_correctness, faithfulness, answer_relevance, mae, mape, max_error, mse, rmse, r2_score, precision_score, recall_score, f1_score, token_count, latency, precision_at_k, recall_at_k, ndcg_at_k, bleu
Generative AI Metrics
---------------------
We also provide generative AI ("genai") :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>`\s for evaluating text models. These metrics use an LLM to evaluate the quality of a model's output text. Note that your use of a third party LLM service (e.g., OpenAI) for evaluation may be subject to and governed by the LLM service's terms of use. The following factory functions help you customize the intelligent metric to your use case.
.. automodule:: mlflow.metrics.genai
:members:
:undoc-members:
:show-inheritance:
:exclude-members: EvaluationExample, make_genai_metric
You can also create your own generative AI :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>`\s using the :py:func:`make_genai_metric <mlflow.metrics.genai.make_genai_metric>` factory function.
.. autofunction:: mlflow.metrics.genai.make_genai_metric
When using generative AI :py:class:`EvaluationMetric <mlflow.metrics.EvaluationMetric>`\s, it is important to pass in an :py:class:`EvaluationExample <mlflow.metrics.genai.EvaluationExample>`
.. autoclass:: mlflow.metrics.genai.EvaluationExample
Users must set the appropriate environment variables for the LLM service they are using for
evaluation. For example, if you are using OpenAI's API, you must set the ``OPENAI_API_KEY``
environment variable. If using Azure OpenAI, you must also set the ``OPENAI_API_TYPE``,
``OPENAI_API_VERSION``, ``OPENAI_API_BASE``, and ``OPENAI_DEPLOYMENT_NAME`` environment variables.
See `Azure OpenAI documentation <https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints>`_
Users do not need to set these environment variables if they are using a gateway route.
@@ -0,0 +1,7 @@
mlflow.mistral
==============
.. automodule:: mlflow.mistral
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,11 @@
mlflow.models
==============
.. automodule:: mlflow.models
:members:
:undoc-members:
:show-inheritance:
:exclude-members: EvaluationMetric
.. autoclass:: mlflow.models.model.ModelInfo
:members:
@@ -0,0 +1,7 @@
mlflow.onnx
==================
.. automodule:: mlflow.onnx
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.openai
=============
.. automodule:: mlflow.openai
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.paddle
==================
.. automodule:: mlflow.paddle
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.pmdarima
===============
.. automodule:: mlflow.pmdarima
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.projects
===============
.. automodule:: mlflow.projects
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.prophet
==================
.. automodule:: mlflow.prophet
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.pydantic_ai
==================
.. automodule:: mlflow.pydantic_ai
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,43 @@
mlflow.pyfunc
=============
.. automodule:: mlflow.pyfunc
:members:
:undoc-members:
:show-inheritance:
.. Include ``get_default_pip_requirements`` and ``get_default_conda_env``,
which are imported from `mlflow.pyfunc.model`, in the `mlflow.pyfunc` namespace
.. autofunction:: mlflow.pyfunc.get_default_pip_requirements
.. autofunction:: mlflow.pyfunc.get_default_conda_env
.. Include ``PythonModelContext`` as a renamed class to avoid documenting constructor parameters.
This class is meant to be constructed implicitly, and users should only be aware of its
documented member properties.
.. autoclass:: mlflow.pyfunc.PythonModelContext()
:members:
:undoc-members:
.. Include ``PythonModel``, which is imported from `mlflow.pyfunc.model`, in the
`mlflow.pyfunc` namespace
.. autoclass:: mlflow.pyfunc.PythonModel
:members:
:undoc-members:
.. Include ``ChatModel``, which is imported from `mlflow.pyfunc.model`, in the
`mlflow.pyfunc` namespace
.. autoclass:: mlflow.pyfunc.ChatModel
:members:
:undoc-members:
.. Include ``ChatAgent``, which is imported from `mlflow.pyfunc.model`, in the
`mlflow.pyfunc` namespace
.. autoclass:: mlflow.pyfunc.ChatAgent
:members:
:undoc-members:
.. Include ``ResponsesAgent``, which is imported from `mlflow.pyfunc.model`, in the
`mlflow.pyfunc` namespace
.. autoclass:: mlflow.pyfunc.ResponsesAgent
:members:
:undoc-members:
@@ -0,0 +1,7 @@
mlflow.pyspark.ml
=================
.. automodule:: mlflow.pyspark.ml
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.pytorch
==================
.. automodule:: mlflow.pytorch
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,83 @@
mlflow
======
.. automodule:: mlflow
:members:
:undoc-members:
:exclude-members:
MlflowClient,
add_trace,
trace,
start_span,
start_span_no_context,
get_trace,
search_traces,
log_assessment,
log_expectation,
log_feedback,
update_assessment,
delete_assessment,
get_current_active_span,
get_last_active_trace_id,
create_external_model,
delete_logged_model_tag,
finalize_logged_model,
get_logged_model,
initialize_logged_model,
last_logged_model,
search_logged_models,
set_active_model,
set_logged_model_tags,
log_model_params,
clear_active_model,
load_prompt,
register_prompt,
search_prompts,
set_prompt_alias,
delete_prompt_alias,
.. _mlflow-tracing-fluent-python-apis:
MLflow Tracing APIs
===================
The ``mlflow`` module provides a set of high-level APIs for `MLflow Tracing <../llms/tracing/index.html>`_. For the detailed
guidance on how to use these tracing APIs, please refer to the `Tracing Fluent APIs Guide <../llms/tracing/index.html#tracing-fluent-apis>`_.
.. autofunction:: mlflow.trace
.. autofunction:: mlflow.start_span
.. autofunction:: mlflow.start_span_no_context
.. autofunction:: mlflow.get_trace
.. autofunction:: mlflow.search_traces
.. autofunction:: mlflow.get_current_active_span
.. autofunction:: mlflow.get_last_active_trace_id
.. autofunction:: mlflow.add_trace
.. autofunction:: mlflow.log_assessment
.. autofunction:: mlflow.log_expectation
.. autofunction:: mlflow.log_feedback
.. autofunction:: mlflow.update_assessment
.. autofunction:: mlflow.delete_assessment
.. automodule:: mlflow.tracing
:members:
:undoc-members:
:noindex:
.. _mlflow-logged-model-fluent-python-apis:
MLflow Logged Model APIs
========================
The ``mlflow`` module provides a set of high-level APIs to interact with ``MLflow Logged Models``.
.. autofunction:: mlflow.clear_active_model
.. autofunction:: mlflow.create_external_model
.. autofunction:: mlflow.delete_logged_model_tag
.. autofunction:: mlflow.finalize_logged_model
.. autofunction:: mlflow.get_logged_model
.. autofunction:: mlflow.initialize_logged_model
.. autofunction:: mlflow.last_logged_model
.. autofunction:: mlflow.search_logged_models
.. autofunction:: mlflow.set_active_model
.. autofunction:: mlflow.set_logged_model_tags
.. autofunction:: mlflow.log_model_params
@@ -0,0 +1,7 @@
mlflow.sagemaker
================
.. automodule:: mlflow.sagemaker
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.sentence_transformers
============================
.. automodule:: mlflow.sentence_transformers
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.server
=============
.. automodule:: mlflow.server
:members: get_app_client
:undoc-members:
:show-inheritance:
@@ -0,0 +1,8 @@
mlflow.shap
===========
.. automodule:: mlflow.shap
:members:
:undoc-members:
:show-inheritance:
:exclude-members: save_model
@@ -0,0 +1,7 @@
mlflow.sklearn
==============
.. automodule:: mlflow.sklearn
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.smolagents
==================
.. automodule:: mlflow.smolagents
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.spacy
============
.. automodule:: mlflow.spacy
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.spark
===============
.. automodule:: mlflow.spark
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.statsmodels
==================
.. automodule:: mlflow.statsmodels
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.strands
==================
.. automodule:: mlflow.strands
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.system_metrics
======================
.. automodule:: mlflow.system_metrics
:members:
:undoc-members:
@@ -0,0 +1,11 @@
mlflow.tensorflow
==================
.. automodule:: mlflow.tensorflow
:members:
:undoc-members:
:show-inheritance:
.. autoclass:: mlflow.tensorflow.MlflowCallback
:members:
:undoc-members:
@@ -0,0 +1,21 @@
mlflow.tracing
==============
.. attention::
The ``mlflow.tracing`` namespace only contains a few utility functions fo managing traces. The main entry point for MLflow
Tracing is :ref:`Tracing Fluent APIs <mlflow-tracing-fluent-python-apis>` defined directly under the
:py:mod:`mlflow` namespace, or the low-level `Tracing Client APIs <../llms/tracing/index.html#tracing-client-apis>`_
.. automodule:: mlflow.tracing
:members:
:undoc-members:
:show-inheritance:
mlflow.tracing.attachments
--------------------------
.. automodule:: mlflow.tracing.attachments
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.transformers
===================
.. automodule:: mlflow.transformers
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,28 @@
mlflow.types
==============
.. automodule:: mlflow.types
:members:
:show-inheritance:
.. automodule:: mlflow.types.responses
:members:
.. automodule:: mlflow.types.responses_helpers
:members:
.. automodule:: mlflow.types.agent
:members:
.. automodule:: mlflow.types.llm
:members:
.. automodule:: mlflow.types.chat
:members:
.. automodule:: mlflow.types.schema
:members: Array, Map, Object, Property, AnyType
:undoc-members:
.. automodule:: mlflow.types.llm._BaseDataclass
:undoc-members:
@@ -0,0 +1,10 @@
mlflow.utils
==================
.. automodule:: mlflow.utils.async_logging
:members:
:undoc-members:
.. automodule:: mlflow.utils.async_logging.run_operations
:members:
:undoc-members:
@@ -0,0 +1,7 @@
mlflow.webhooks
===============
.. automodule:: mlflow.webhooks
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,7 @@
mlflow.xgboost
==============
.. automodule:: mlflow.xgboost
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,256 @@
:orphan:
.. _mlflow.openai.messages:
Supported ``messages`` formats for OpenAI chat completion task
==============================================================
This document covers the following:
- Supported ``messages`` formats for OpenAI chat completion task in the ``openai`` flavor.
- Logged model signature for each format.
- Payload sent to OpenAI chat completion API for each format.
- Expected prediction input types for each format.
``messages`` with variables
---------------------------
The ``messages`` argument accepts a list of dictionaries with ``role`` and ``content`` keys. The
``content`` field in each message can contain variables (= named format fields). When the logged
model is loaded and makes a prediction, the variables are replaced with the values from the
prediction input.
Single variable
~~~~~~~~~~~~~~~
.. code-block:: python
import mlflow
import openai
with mlflow.start_run():
model_info = mlflow.openai.log_model(
name="model",
model="gpt-4o-mini",
task=openai.chat.completions,
messages=[
{
"role": "user",
"content": "Tell me a {adjective} joke",
# ^^^^^^^^^^
# variable
},
# Can contain more messages
],
)
model = mlflow.pyfunc.load_model(model_info.model_uri)
print(model.predict([{"adjective": "funny"}]))
Logged model signature:
.. code-block:: python
{
"inputs": [{"type": "string"}],
"outputs": [{"type": "string"}],
}
Expected prediction input types:
.. code-block:: python
# A list of dictionaries with 'adjective' key
[{"adjective": "funny"}, ...]
# A list of strings
["funny", ...]
Payload sent to OpenAI chat completion API:
.. code-block:: python
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Tell me a funny joke",
}
],
}
Multiple variables
~~~~~~~~~~~~~~~~~~
.. code-block:: python
import mlflow
import openai
with mlflow.start_run():
model_info = mlflow.openai.log_model(
name="model",
model="gpt-4o-mini",
task=openai.chat.completions,
messages=[
{
"role": "user",
"content": "Tell me a {adjective} joke about {thing}.",
# ^^^^^^^^^^ ^^^^^^^
# variable another variable
},
# Can contain more messages
],
)
model = mlflow.pyfunc.load_model(model_info.model_uri)
print(model.predict([{"adjective": "funny", "thing": "vim"}]))
Logged model signature:
.. code-block:: python
{
"inputs": [
{"name": "adjective", "type": "string"},
{"name": "thing", "type": "string"},
],
"outputs": [{"type": "string"}],
}
Expected prediction input types:
.. code-block:: python
# A list of dictionaries with 'adjective' and 'thing' keys
[{"adjective": "funny", "thing": "vim"}, ...]
Payload sent to OpenAI chat completion API:
.. code-block:: python
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Tell me a funny joke about vim",
}
],
}
``messages`` without variables
------------------------------
If no variables are provided, the prediction input will be _appended_ to the logged ``messages``
with ``role = user``.
.. code-block:: python
with mlflow.start_run():
model_info = mlflow.openai.log_model(
name="model",
model="gpt-4o-mini",
task=openai.chat.completions,
messages=[
{
"role": "system",
"content": "You're a frontend engineer.",
}
],
)
model = mlflow.pyfunc.load_model(model_info.model_uri)
print(model.predict(["Tell me a funny joke."]))
Logged model signature:
.. code-block:: python
{
"inputs": [{"type": "string"}],
"outputs": [{"type": "string"}],
}
Expected prediction input type:
- A list of dictionaries with a single key
- A list of strings
Payload sent to OpenAI chat completion API:
.. code-block:: python
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You're a frontend engineer.",
},
{
"role": "user",
"content": "Tell me a funny joke.",
},
],
}
No ``messages``
---------------
The ``messages`` argument is optional and can be omitted. If omitted, the prediction input will be
sent to the OpenAI chat completion API as-is with ``role = user``.
.. code-block:: python
import mlflow
import openai
with mlflow.start_run():
model_info = mlflow.openai.log_model(
name="model",
model="gpt-4o-mini",
task=openai.chat.completions,
)
model = mlflow.pyfunc.load_model(model_info.model_uri)
print(model.predict(["Tell me a funny joke."]))
Logged model signature:
.. code-block:: python
{
"inputs": [{"type": "string"}],
"outputs": [{"type": "string"}],
}
Expected prediction input types:
.. code-block:: python
# A list of dictionaries with a single key
[{"<any key>": "Tell me a funny joke."}, ...]
# A list of strings
["Tell me a funny joke.", ...]
Payload sent to OpenAI chat completion API:
.. code-block:: python
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Tell me a funny joke.",
}
],
}
+10079
View File
File diff suppressed because it is too large Load Diff
+211
View File
@@ -0,0 +1,211 @@
"""
Standalone script to extract code blocks marked with :test: from Python docstrings.
Uses AST to parse Python files and extract docstrings with test code blocks.
"""
import ast
import re
import subprocess
import textwrap
from pathlib import Path
_CODE_BLOCK_HEADER_REGEX = re.compile(r"^\.\.\s+code-block::\s*py(thon)?")
_CODE_BLOCK_OPTION_REGEX = re.compile(r"^:\w+:")
def _get_indent(s: str) -> int:
return len(s) - len(s.lstrip())
def _get_header_indent(s: str) -> int | None:
if _CODE_BLOCK_HEADER_REGEX.match(s.lstrip()):
return _get_indent(s)
return None
def extract_code_blocks_from_docstring(docstring: str | None) -> list[tuple[int, str]]:
"""
Extract all code blocks marked with :test: from a docstring.
Uses the same approach as clint for parsing code blocks.
Returns a list of tuples: (line_number, code_content)
"""
if not docstring:
return []
blocks = []
header_indent: int | None = None
code_lines: list[str] = []
has_test_option = False
code_block_lineno = 0
line_iter = enumerate(docstring.splitlines())
while t := next(line_iter, None):
idx, line = t
if code_lines:
# We're inside a code block
indent = _get_indent(line)
# If we encounter a non-blank line with an indent less than or equal to the header
# we are done parsing the code block
if line.strip() and (header_indent is not None) and indent <= header_indent:
if has_test_option:
code = textwrap.dedent("\n".join(code_lines))
blocks.append((code_block_lineno, code))
# Reset state
code_lines.clear()
has_test_option = False
# It's possible that another code block follows the current one
header_indent = _get_header_indent(line)
continue
code_lines.append(line)
elif header_indent is not None:
# We found a code-block header, now advance to the code body
# Skip options like :test:, :caption:, etc.
while True:
stripped = line.lstrip()
if stripped.startswith(":test:") or stripped == ":test:":
has_test_option = True
# Check if this is still an option line or blank
if stripped and not _CODE_BLOCK_OPTION_REGEX.match(stripped):
# We are at the first line of the code block
code_lines.append(line)
code_block_lineno = idx + 1 # Line number in docstring (1-indexed)
break
if next_line := next(line_iter, None):
idx, line = next_line
else:
break
else:
# Look for code-block headers
header_indent = _get_header_indent(line)
# The docstring ends with a code block
if code_lines and has_test_option:
code = textwrap.dedent("\n".join(code_lines))
blocks.append((code_block_lineno, code))
return blocks
def extract_code_blocks_from_file(filepath: Path, repo_root: Path) -> list[tuple[str, int, str]]:
"""
Extract all code blocks marked with :test: from a Python file.
Args:
filepath: Path to the Python file
repo_root: Root of the repository
Returns:
List of tuples: (location_string, line_number, code_content)
"""
source = filepath.read_text()
tree = ast.parse(source)
results = []
rel_path = filepath.relative_to(repo_root)
for node in ast.walk(tree):
# Check functions and classes for docstrings
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
docstring = ast.get_docstring(node)
if not docstring:
continue
blocks = extract_code_blocks_from_docstring(docstring)
for lineno_in_docstring, code in blocks:
# Calculate the actual line number in the file
# The docstring starts at node.lineno, and lineno_in_docstring is relative to that
actual_line = node.lineno + lineno_in_docstring
location = f"{rel_path}:{actual_line}"
results.append((location, lineno_in_docstring, code))
return results
def find_python_files(directory: Path, repo_root: Path) -> list[Path]:
"""Find all Python files tracked by git in a directory."""
# Get relative path from repo root
rel_dir = directory.relative_to(repo_root)
# Run git ls-files from repo root with the directory as a pattern
output = subprocess.check_output(
["git", "ls-files", f"{rel_dir}/*.py"],
cwd=repo_root,
text=True,
)
files = [repo_root / line for line in output.strip().split("\n") if line]
return sorted(files)
def generate_test_file(location: str, line_num: int, code: str, output_dir: Path) -> Path:
"""Generate a pytest test file for a code block."""
# Create a unique filename based on location
safe_name = re.sub(r"[/\\:.]", "_", location)
filename = f"test_{safe_name}_{line_num}.py"
content = textwrap.indent(code, " " * 4)
test_code = "\n".join([
f"# Location: {location}",
"import pytest",
"",
"",
# Show the code block location in the test report.
f"@pytest.mark.parametrize('_', [' {location} '])",
"def test(_):",
content,
"",
"",
'if __name__ == "__main__":',
" test()",
"",
])
output_path = output_dir / filename
output_path.write_text(test_code)
return output_path
def extract_examples(mlflow_dir: Path, output_dir: Path, repo_root: Path) -> None:
"""
Extract test examples from Python files and generate test files.
Args:
mlflow_dir: Directory containing Python files to scan
output_dir: Directory to write test files to
repo_root: Root of the repository
"""
output_dir.mkdir(exist_ok=True)
# Clean up old test files
for old_file in output_dir.glob("test_*.py"):
old_file.unlink()
print(f"Scanning Python files in: {mlflow_dir}")
python_files = find_python_files(mlflow_dir, repo_root)
print(f"Found {len(python_files)} Python files")
for filepath in python_files:
results = extract_code_blocks_from_file(filepath, repo_root)
for location, line_num, code in results:
output_path = generate_test_file(location, line_num, code, output_dir)
print(f" Generated: {output_path.name}")
def main() -> None:
output = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True)
repo_root = Path(output.strip())
scan_dir = repo_root / "mlflow"
output_dir = Path(".examples")
extract_examples(scan_dir, output_dir, repo_root)
if __name__ == "__main__":
main()
@@ -0,0 +1,6 @@
.. _typescript_api:
TypeScript API
==============
This file is a placeholder. TypeScript documentation is filled in by the build-tsdoc.sh script, executed during "make html".